Rework storage of level range constants, clean up Consider.mob, add Consider.keywordCount

main
AreiaAard 4 years ago
parent 926fd8c7ea
commit e4b520aaf4

@ -84,7 +84,7 @@ function Main.kill(alias, line, wc)
Utility.print("There are only %d mobs currently indexed. Enter @Yac @wto refresh.") Utility.print("There are only %d mobs currently indexed. Enter @Yac @wto refresh.")
return return
end end
if (Settings.should_ignore(mob)) then if (mob.ignore) then
Utility.print("That mob is currently being ignored.") Utility.print("That mob is currently being ignored.")
return return
end end
@ -104,7 +104,7 @@ function Main.kill_all(alias, line, wc)
end end
local cmds = {} local cmds = {}
for _, mob in ipairs(Consider.mobs) do for _, mob in ipairs(Consider.mobs) do
if (not Settings.should_ignore(mob)) then if (not mob.ignore) then
table.insert(cmds, Settings.get_kill_cmd(mob)) table.insert(cmds, Settings.get_kill_cmd(mob))
end end
end end
@ -246,9 +246,9 @@ end
function Settings.ignore_level_display() function Settings.ignore_level_display()
Utility.plugin_msg("Ignored levels:") Utility.plugin_msg("Ignored levels:")
for i = 1, 13 do for i, range in ipairs(Consider.LEVEL_RANGE) do
Utility.print(string.format(" @Y%2.d@w. %-11.11s (%-5.5s@w)", Utility.print(string.format(" @Y%2.d@w. %-11.11s (%-5.5s@w)",
i, Consider.OUTPUTS[i + 2].level, Settings.config.ignore.level[i] and "@GYes" or "@RNo" i, range, Settings.config.ignore.level[i] and "@GYes" or "@RNo"
)) ))
end end
end end
@ -273,18 +273,18 @@ function Settings.ignore_level_toggle(alias, line, wc)
Settings.save() Settings.save()
Utility.plugin_msg(string.format("%s @wignoring mobs in level range @y%s @wwhile killing all.", Utility.plugin_msg(string.format("%s @wignoring mobs in level range @y%s @wwhile killing all.",
Settings.config.ignore.level[level] and "@GNow" or "@RNo longer", Settings.config.ignore.level[level] and "@GNow" or "@RNo longer",
Consider.OUTPUTS[level + 2].level Consider.LEVEL_RANGE[level]
)) ))
end end
function Settings.should_ignore(mob) function Settings.should_ignore(mob)
-- ignore mob if protected (divine protection, safe room) -- ignore mob if it has divine protection
local ignoreMob = mob.protected local ignoreMob = mob.protected
-- ignore if already ignored or mob's level range is set to ignored -- ignore if already ignored or mob's level range is set to ignored
ignoreMob = ignoreMob or Settings.config.ignore.level[mob.levelRange] ignoreMob = ignoreMob or Settings.config.ignore.level[mob.levelRange]
for flag, ignoreFlaggedMob in pairs(Settings.config.ignore.flags) do for flag in pairs(mob.flags) do
-- ignore if already ignored or mob has a flag that is set to be ignored -- ignore if already ignored or mob has a flag that is set to be ignored
ignoreMob = ignoreMob or (ignoreFlaggedMob and mob.flags[flag]) ignoreMob = ignoreMob or Settings.config.ignore.flags[flag]
end end
return ignoreMob return ignoreMob
end end
@ -348,27 +348,32 @@ function Consider.initialize()
"Consider.start" "Consider.start"
) )
Consider.LEVEL_RANGE = {
"-20 or less", "-10 to -19", "-5 to -9", "-2 to -4",
"-1 to +1", "+2 to +4", "+5 to +9", "+10 to +15",
"+16 to +20", "+21 to +30", "+31 to +40", "+41 to +50",
"+51 or more"
}
Consider.OUTPUTS = { Consider.OUTPUTS = {
{pattern="(?<name>Strange forces) (?<protected>prevent) violence here\\.", level="Protected"}, "You would stomp (?<name>.+?) into the ground\\.",
{pattern="(?<name>.+?) has divine (?<protected>protection)\\.", level="Protected"}, "(?<name>.+?) would be easy, but is it even worth the work out\\?",
{pattern="You would stomp (?<name>.+?) into the ground\\.", level="-20 or less"}, "No Problem! (?<name>.+?) is weak compared to you\\.",
{pattern="(?<name>.+?) would be easy, but is it even worth the work out\\?", level="-10 to -19"}, "(?<name>.+?) looks a little worried about the idea\\.",
{pattern="No Problem! (?<name>.+?) is weak compared to you\\.", level="-5 to -9"}, "(?<name>.+?) should be a fair fight!",
{pattern="(?<name>.+?) looks a little worried about the idea\\.", level="-2 to -4"}, "(?<name>.+?) snickers nervously\\.",
{pattern="(?<name>.+?) should be a fair fight!", level="-1 to +1"}, "(?<name>.+?) chuckles at the thought of you fighting (?:him|her|it)\\.",
{pattern="(?<name>.+?) snickers nervously\\.", level="+2 to +4"}, "Best run away from (?<name>.+?) while you can!",
{pattern="(?<name>.+?) chuckles at the thought of you fighting (?:him|her|it)\\.", level="+5 to +9"}, "Challenging (?<name>.+?) would be either very brave or very stupid\\.",
{pattern="Best run away from (?<name>.+?) while you can!", level="+10 to +15"}, "(?<name>.+?) would crush you like a bug!",
{pattern="Challenging (?<name>.+?) would be either very brave or very stupid\\.", level="+16 to +20"}, "(?<name>.+?) would dance on your grave!",
{pattern="(?<name>.+?) would crush you like a bug!", level="+21 to +30"}, "(?<name>.+?) says 'BEGONE FROM MY SIGHT unworthy!'",
{pattern="(?<name>.+?) would dance on your grave!", level="+31 to +40"}, "You would be completely annihilated by (?<name>.+?)!",
{pattern="(?<name>.+?) says 'BEGONE FROM MY SIGHT unworthy!'", level="+41 to +50"}, "(?<name>.+?) has divine protection\\.",
{pattern="You would be completely annihilated by (?<name>.+?)!", level="+51 or more"},
} }
for i, output in ipairs(Consider.OUTPUTS) do for i, subpattern in ipairs(Consider.OUTPUTS) do
local triggerName = string.format("trigger_consider_mob%d", i) local triggerName = string.format("trigger_consider_mob%d", i)
AddTriggerEx(triggerName, AddTriggerEx(triggerName,
string.format("^(?<flags>(?:\\([\\w\\s]+\\)\\s*)+)?%s$", output.pattern), "", string.format("^(?<flags>(?:\\([\\w\\s]+\\)\\s*)+)?%s$", subpattern), "",
trigger_flag.OmitFromOutput + trigger_flag.RegularExpression + trigger_flag.Temporary, trigger_flag.OmitFromOutput + trigger_flag.RegularExpression + trigger_flag.Temporary,
custom_colour.NoChange, 0, "", custom_colour.NoChange, 0, "",
"Consider.mob", sendto.script, 100 "Consider.mob", sendto.script, 100
@ -390,8 +395,9 @@ function Consider.initialize()
["merdevil"] = true, ["onyx"] = true, ["merdevil"] = true, ["onyx"] = true,
} }
Consider.mobs = {} Consider.mobs = {} -- main mob info obtained from consider
Consider.cache = {} Consider.keywordCount = {} -- keywords-to-count record used to track proper indices (see Consider.mob)
Consider.keywordCache = {} -- session name-to-keywords record (see Consider.get_mob_keywords)
end end
function Consider.start() function Consider.start()
@ -413,35 +419,40 @@ function Consider.start_CR()
return return
end end
Consider.mobs = {} Consider.mobs = {}
Consider.keywordCount = {}
EnableTriggerGroup("trigger_group_consider_mobs", true) EnableTriggerGroup("trigger_group_consider_mobs", true)
end end
function Consider.mob(trigger, line, wc) function Consider.mob(trigger, line, wc)
local mob = {}
mob.name = wc.name
mob.keywords = Consider.get_mob_keywords(mob.name)
-- update count of mobs with these particular keywords. The count directly
-- determines the mob's proper index (i.e., is this 1.goblin, 2.goblin, etc.).
Consider.keywordCount[mob.keywords] = (Consider.keywordCount[mob.keywords] or 0) + 1
mob.index = Consider.keywordCount[mob.keywords]
mob.levelRange = tonumber(trigger:match("%d+"))
mob.protected = mob.levelRange == 14 -- divine protection
local flagsStr = wc.flags:lower() local flagsStr = wc.flags:lower()
local flags = { mob.flags = {
aimed = (flagsStr:match("%(a%)") or flagsStr:match("%(aimed%)")) and true or false, aimed = flagsStr:match("%(a%)") or flagsStr:match("%(aimed%)"),
evil = (flagsStr:match("%(r%)") or flagsStr:match("%(red aura%)")) and true or false, evil = flagsStr:match("%(r%)") or flagsStr:match("%(red aura%)"),
good = (flagsStr:match("%(g%)") or flagsStr:match("%(golden aura%)")) and true or false, good = flagsStr:match("%(g%)") or flagsStr:match("%(golden aura%)"),
sanctuary = (flagsStr:match("%(w%)") or flagsStr:match("%(white aura%)")) and true or false, sanctuary = flagsStr:match("%(w%)") or flagsStr:match("%(white aura%)"),
wounded = flagsStr:match("%(wounded%)") and true or false wounded = flagsStr:match("%(wounded%)")
}
local name = wc.name
local keywords = Consider.get_mob_keywords(name)
local protected = wc.protected and true or false
local index = 1
for _, mob in ipairs(Consider.mobs) do
if (mob.keywords == keywords) then
index = index + 1
end
end
local levelRange = tonumber(trigger:match("%d+")) - 2 -- -2 adjusts for divine/safe msgs
local mob = {flags=flags, name=name, keywords=keywords,
protected=protected, index=index, levelRange=levelRange
} }
mob.ignore = Settings.should_ignore(mob)
table.insert(Consider.mobs, 1, mob) table.insert(Consider.mobs, 1, mob)
if (Settings.config.showConsiderOutput) then if (Settings.config.showConsiderOutput) then
local level = Consider.OUTPUTS[tonumber(trigger:match("%d+"))].level or "Unknown" Utility.print(string.format("%-10.10s %s, %s, %s",
Utility.print(string.format("%s, %s, %s", mob.name, flagsStr ~= "" and flagsStr or "None", level)) mob.ignore and "(Ignored)" or "", mob.name,
flagsStr ~= "" and flagsStr or "None",
Consider.LEVEL_RANGE[mob.levelRange]
))
end end
end end
@ -454,8 +465,8 @@ function Consider.finish()
end end
function Consider.get_mob_keywords(name) function Consider.get_mob_keywords(name)
if (Consider.cache[name]) then if (Consider.keywordCache[name]) then
return Consider.cache[name] return Consider.keywordCache[name]
end end
local keywords = {} local keywords = {}
for word in name:lower():gmatch("[^%s]+") do -- iterate through each string of non-whitespace chars for word in name:lower():gmatch("[^%s]+") do -- iterate through each string of non-whitespace chars
@ -475,7 +486,7 @@ function Consider.get_mob_keywords(name)
return name return name
end end
local keywordsStr = table.concat(keywords, " ") local keywordsStr = table.concat(keywords, " ")
Consider.cache[name] = keywordsStr Consider.keywordCache[name] = keywordsStr
return keywordsStr return keywordsStr
end end

Loading…
Cancel
Save