Skip to content

Instantly share code, notes, and snippets.

@njs50
Last active October 26, 2018 06:04
Show Gist options
  • Save njs50/73ca29b73ed43fd977ff6fa0b2169978 to your computer and use it in GitHub Desktop.
Save njs50/73ca29b73ed43fd977ff6fa0b2169978 to your computer and use it in GitHub Desktop.
function that checks shield status and has a callback for if they are good and one for if some are fading
common = common or {}
common.checkShields = function (cbGood, cbBad)
-- Affect Source
--
-- ------ ------
-- You sense a divine protection. leech: a male vyan
-- You feel righteous. leech: a male vyan
local affectWatcher = nil
local tempAffects = false
local affectCount = 0
local okayTempAffects = {
['You feel sick!'] = true,
['You are embraced by earthen protection.'] = true,
}
local startAffectsTrig = tempRegexTrigger('^Affect', function ()
echo('^^ --- looking at affects...\n')
affectWatcher = tempRegexTrigger([[^(You .+?)\s{3,}(\S.*)$]], function ()
if (matches[3] == 'temporary') then
-- earthen protection is always tempporary
if not okayTempAffects[matches[2]] then
echo(' <-- expiring\n')
tempAffects = true
else
echo(' <-- okay to expire\n')
end
end
affectCount = affectCount + 1
end)
common.onNextEvent(common.events.PARSED_PROMPT, function()
killTrigger(affectWatcher)
if (tempAffects) then
cecho('\n<red>WARNING: <white>Affects Checked!, some shields will expire!\n')
if (cbBad) then
cbBad()
end
else
cecho('\n<green>Affects Checked!, ' .. tostring(affectCount) .. ' affects are good\n')
if (cbGood) then
cbGood()
end
end
end)
end, 1)
send('affect')
end
common.onNextEvent = function (evt, callback)
local handlerId = nil
local cb2 = callback
local cb = function (evt, args)
-- cecho('\n<blue>self destructing handler: ' .. evt .. ' : ' .. tostring(handlerId) .. '\n')
cb2(evt, args)
end
handlerId = registerAnonymousEventHandler(evt, cb, true)
-- cecho('\n<green>registering self destruct event: ' .. evt .. ' : ' .. tostring(handlerId) .. '\n')
return function ()
-- cecho('\n<orange>destructing handler: ' .. evt .. ' : ' .. tostring(handlerId) .. '\n')
killAnonymousEventHandler(handlerId)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment