Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Main Lua script file for Treant system
- --]]
- require "able"
- require "affs"
- require "bals"
- require "calendar"
- require "criticals"
- require "defs"
- require "display"
- require "failsafe"
- require "flags"
- require "gear"
- require "herbs"
- require "kills"
- require "magic"
- require "nocure"
- require "parry"
- require "pipes"
- require "poisonist"
- require "potions"
- require "prompt"
- require "queue"
- require "scan"
- require "stag"
- require "stance"
- require "todo"
- require "wounds"
- -- Simple utility function to test for the existence of a file
- function io.exists(filename)
- local file = io.open(filename)
- if file then
- io.close(file)
- return true
- end
- return false
- end
- if not treant then
- treant = {}
- end
- if not vial_map then
- vial_map = {}
- end
- -- Auto-require premium add-on scripts
- if io.exists("enemy.lua") then
- require "enemy"
- end
- if io.exists("influence.lua") then
- require "influence"
- end
- if io.exists("acquire.lua") then
- require "acquire"
- end
- if io.exists("debate.lua") then
- require "debate"
- end
- if io.exists("names.lua") then
- require "names"
- end
- if io.exists("target.lua") then
- require "target"
- end
- if io.exists("beast.lua") then
- require "beast"
- end
- if io.exists("iht.lua") then
- require "iht"
- end
- if io.exists("mapper.lua") then
- require "mapper"
- end
- -- Initialization code executes every time this loads
- affs:reset()
- bals:reset()
- defs:reset()
- flags:reset()
- affs:init_priorities()
- calendar:init()
- local version = tonumber(GetVariable("treant_version") or "0")
- if version > 0 then
- display.Info(string.format("Initialized version 1.%02d", version))
- else
- display.Info("Initialized")
- end
- -- OBSOLETE
- function treant:Init()
- end
- -- Imports all triggers needed for the system
- function treant:Install()
- if not io then
- error("Disk I/O is disabled in the Lua sandbox")
- return
- end
- local previous_version = tonumber(GetVariable("treant_version") or "0")
- local version = 34
- SetVariable("treant_version", version)
- -- A little housekeeping for anyone who is upgrading
- if previous_version <= 8 then
- for i = 6,12 do
- DeleteTrigger("wound_status" .. i .. "__")
- end
- DeleteTrigger("curerupture__")
- DeleteTrigger("kata_rupture__")
- DeleteTrigger("shofangi__")
- DeleteTrigger("shofangi_tongue1__")
- -- Failsafe timers have been replaced and are now dynamically created when missing
- DeleteTimer("score_failsafe__")
- DeleteTimer("def_failsafe__")
- DeleteTimer("diag_failsafe__")
- DeleteTimer("insomnia_failsafe__")
- DeleteTimer("stun_failsafe__")
- DeleteTimer("stand_failsafe__")
- DeleteTimer("wake_failsafe__")
- DeleteTimer("writhe_failsafe__")
- DeleteTimer("aeon_sap_failsafe__")
- DeleteTimer("focus_spirit_failsafe__")
- DeleteTimer("health_failsafe__")
- DeleteTimer("salve_failsafe__")
- DeleteTimer("regeneration_failsafe__")
- DeleteTimer("clot_failsafe__")
- DeleteTimer("rebounding_failsafe__")
- DeleteTimer("climb_failsafe__")
- DeleteTimer("climb_up_failsafe__")
- DeleteTimer("climb_down_failsafe__")
- DeleteTimer("pipe_lighting__")
- DeleteTimer("protection_failsafe__")
- DeleteTimer("sixthsense_failsafe__")
- end
- if previous_version <= 12 then
- -- The "red" defense was renamed to "roots"
- DeleteTrigger("def_red__")
- DeleteTrigger("defup_red__")
- end
- if previous_version <= 16 then
- -- Aggregated AB triggers in 1.17
- DeleteTriggerGroup("Treant_Abilities")
- end
- if previous_version <= 19 then
- -- Made proper failsafes so stun doesn't mess with them
- DeleteTimer("parry_failsafe__")
- DeleteTimer("stance_failsafe__")
- end
- if previous_version <= 21 then
- DeleteAlias("apply_liniment__")
- DeleteTrigger("defdown_barkskin__")
- end
- if previous_version <= 22 then
- DeleteTrigger("affbeastgas__")
- end
- -- Monk updates
- if previous_version <= 27 then
- DeleteTrigger("ninjakari_dysentery__")
- DeleteTrigger("ninjakari_broken_chest__")
- DeleteTrigger("ninjakari_mangle_limb__")
- end
- -- New way of tracking repelled affs
- if previous_version <= 28 then
- DeleteTrigger("tea_repels__")
- end
- -- Duplicate triggers not needed
- if previous_version <= 29 then
- DeleteTrigger("defdown_psi_shield__")
- DeleteTrigger("defup_psi_shield__")
- DeleteTrigger("poison_immune__")
- DeleteTrigger("scorpions1__")
- DeleteTrigger("scorpions2__")
- DeleteTrigger("scorpions3__")
- DeleteTrigger("conservatory_freak1__")
- DeleteGroup("Treant_Scorpions")
- end
- if previous_version <= 33 then
- DeleteTrigger("aff_pyro_wildfire__")
- DeleteTrigger("kata_bomrakini_head__")
- DeleteTrigger("ninjakari_ninughi_arm1__")
- DeleteTrigger("ninjakari_ninughi_arm2__")
- DeleteTrigger("ninjakari_ninughi_leg1__")
- DeleteTrigger("ninjakari_ninughi_leg2__")
- DeleteTrigger("shofangi_paralysis__")
- DeleteTrigger("shofangi_braindamage__")
- end
- DeleteTrigger("cureunconscious__")
- DeleteTrigger("gag_prompt__")
- DeleteTrigger("prompt__")
- ChangeDir(GetInfo(68))
- local xml
- local scripts = {
- "events", "interface", "tracking", "affs", "cures", "defs", "defense",
- "poisons", "wounds", "gear", "kills", "abilities", "calendar", "combat",
- "criticals", "pipelist", "potionlist", "magiclist", "diagnose"
- }
- -- Import all base scripts
- for _,s in ipairs(scripts) do
- io.input("treant_" .. s .. ".xml")
- xml = io.read("*all")
- ImportXML(xml)
- end
- local premium = {
- "enemy", "influence", "acquire", "bashing", "highlight", "linking",
- "debate", "abs", "names", "beast", "iht", "target",
- "mapper"
- }
- -- Import any extra settings that may have been purchased
- for _,s in ipairs(premium) do
- if io.exists("treant_" .. s .. ".xml") then
- io.input("treant_" .. s .. ".xml")
- xml = io.read("*all")
- ImportXML(xml)
- end
- end
- local skills = {
- ["defup_adroitness__"] = "acrobatics",
- ["defup_spiritshield__"] = "aquamancy",
- ["defup_weathering__"] = "athletics",
- ["defup_stigmata__"] = "celestialism",
- ["defup_timeslip__"] = "cosmic",
- ["defup_twirl__"] = "druidry",
- ["defup_stoneskin__"] = "elementalism",
- ["defup_illusoryself__"] = "glamours",
- ["herbs_growing__"] = "herbs",
- ["defup_hexaura__"] = "hexes",
- ["defup_geburah__"] = "highmagic",
- ["defup_changeself__"] = "illusions",
- ["prompt_momentum__"] = "kata",
- ["defup_combatstyle__"] = "knighthood",
- ["defup_yellow__"] = "lowmagic",
- ["defup_moonaura__"] = "moon",
- ["defup_bardicpresence__"] = "music",
- ["defup_blend__"] = "nature",
- ["defup_putrefaction__"] = "necromancy",
- ["defup_nekotai__"] = "nekotai",
- ["defup_garb__"] = "night",
- ["defup_nihilism__"] = "nihilism",
- ["defup_ninjakari__"] = "ninjakari",
- ["defup_phantomarmour__"] = "phantasms",
- ["defup_psiarmour__"] = "psionics",
- ["defup_gliding__"] = "psychometabolism",
- ["defup_fireproof__"] = "pyromancy",
- ["defup_draconis__"] = "rituals",
- ["defup_honour__"] = "sacraments",
- ["defup_shofangi__"] = "shofangi",
- ["defup_bolting__"] = "stag",
- ["defup_sneak__"] = "stealth",
- ["defup_tahtetso__"] = "tahtetso",
- ["defup_wicca__"] = "wicca"
- }
- -- Import skill-specific upgrades
- for t,s in pairs(skills) do
- if IsTrigger(t) == 0 then
- io.input("treant_" .. s .. ".xml")
- xml = io.read("*all")
- ImportXML(xml)
- end
- end
- -- Initialize configurable variables that do not yet exist
- if GetVariable("treant_option_debug") == nil then
- SetVariable("treant_option_debug", 0)
- end
- if GetVariable("treant_option_diagnose") == nil then
- SetVariable("treant_option_diagnose", 1)
- end
- if GetVariable("treant_option_notrees") == nil then
- SetVariable("treant_option_notrees", 1)
- end
- if GetVariable("treant_option_maxpuffs") == nil then
- SetVariable("treant_option_maxpuffs", 10)
- end
- if GetVariable("treant_option_artipipes") == nil then
- SetVariable("treant_option_artipipes", 0)
- end
- if GetVariable("treant_option_sparkle") == nil then
- SetVariable("treant_option_sparkle", "sparkleberry")
- end
- if GetVariable("treant_option_magictome") == nil then
- SetVariable("treant_option_magictome", 0)
- end
- if GetVariable("treant_option_contort") == nil then
- SetVariable("treant_option_contort", 0)
- end
- if GetVariable("treant_option_springup") == nil then
- SetVariable("treant_option_springup", 0)
- end
- if GetVariable("treant_option_deathmark") == nil then
- SetVariable("treant_option_deathmark", 14)
- end
- display.Info("Installation completed!")
- display.Info("Use TCONFIG to set things up.")
- end
- -- Removes all imported triggers from world file, thereby uninstalling the system
- function treant:Uninstall()
- -- TODO: some form of confirmation dialog
- DeleteGroup("Treant_Abilities")
- DeleteGroup("Treant_Acquire")
- DeleteGroup("Treant_Bashable")
- DeleteGroup("Treant_Basher")
- DeleteGroup("Treant_Bashing")
- DeleteGroup("Treant_Belt")
- DeleteGroup("Treant_Blackout")
- DeleteGroup("Treant_Cleanse")
- DeleteGroup("Treant_Cures")
- DeleteGroup("Treant_Defs")
- DeleteGroup("Treant_Diagnose")
- DeleteGroup("Treant_Events")
- DeleteGroup("Treant_Interface")
- DeleteGroup("Treant_KataMods")
- DeleteGroup("Treant_Linking")
- DeleteGroup("Treant_Magiclist")
- DeleteGroup("Treant_Mapper")
- DeleteGroup("Treant_MapperSpecials")
- DeleteGroup("Treant_NekotaiMods")
- DeleteGroup("Treant_NinjakariMods")
- DeleteGroup("Treant_Pipelist")
- DeleteGroup("Treant_Plants")
- DeleteGroup("Treant_Poisons")
- DeleteGroup("Treant_Potionhide")
- DeleteGroup("Treant_Potionlist")
- DeleteGroup("Treant_Rainbows")
- DeleteGroup("Treant_Rift")
- DeleteGroup("Treant_Scorpions")
- DeleteGroup("Treant_ShofangiMods")
- DeleteGroup("Treant_Sipping")
- DeleteGroup("Treant_TahtetsoMods")
- DeleteGroup("Treant_Tracking")
- DeleteGroup("Treant_Wounds")
- DeleteGroup("Treant_WoundStatus")
- local skills = {
- "Acrobatics", "Aquamancy", "Athletics", "Celestialism",
- "Cosmic", "Druidry", "Elementalism", "Geomancy", "Glamours",
- "Herbs", "Hexes", "Highmagic", "Hunting", "Illusions", "Kata",
- "Knighthood", "Lowmagic", "Moon", "Music",
- "Nature", "Necromancy", "Nekotai", "Night",
- "Nihilism", "Ninjakari", "Phantasms", "Poisonist", "Psionics",
- "Psychometabolism", "Pyromancy", "Rituals", "Sacraments",
- "Shofangi", "Stag", "Stealth", "Tahtetso", "Wicca"
- }
- for _,s in ipairs(skills) do
- DeleteGroup("Treant_" .. skills)
- end
- -- Delete any variable that starts with the 'treant_' prefix
- for v in pairs(GetVariableList()) do
- if string.find(v, "treant_") == 1 then
- DeleteVariable(v)
- end
- end
- display.Info("System settings removed from world")
- end
- -- Pauses the system, of course!
- function treant:Pause()
- if not self.IsPaused() then
- SetVariable("treant_pause", 1)
- display.Alert("** PAUSED **")
- if gui then
- gui:update_pause()
- end
- end
- end
- -- And this unpauses it, of course!
- function treant:Unpause()
- if self.IsPaused() then
- SetVariable("treant_pause", 0)
- display.Alert("** UNPAUSED **")
- if gui then
- gui:update_pause()
- end
- -- Rescan afflictions to see what needs to be processed now
- affs:scan()
- defs:scan()
- todo:scan()
- -- Send a newline to force a prompt and get some reaction
- Send("")
- end
- end
- -- Quick check to see whether the whole system is paused or not
- function treant:IsPaused()
- if GetVariable("treant_pause") == "1" then
- return true
- end
- return false
- end
- --[[
- Internal functions not really intended to be used by the end user
- --]]
- function treant:command(...)
- local gag = false
- if my_gag then
- if my_gag[...] then
- gag = true
- else
- local cmd = table.concat{...}
- for _,g in ipairs(my_gag) do
- if string.find(cmd, g) then
- gag = true
- break
- end
- end
- end
- end
- if gag then
- SendNoEcho(...)
- else
- Send(...)
- end
- end
- -- Sipping mana, health, or bromides
- function treant:sip_heal(name)
- bals:lose("health")
- flags:set("elixir", name, 0)
- flags:clear("health_applying")
- -- Uses a special failsafe to handle the application of health
- local time = 2
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 4
- end
- failsafe:exec("health", time)
- treant:command("sip ", name)
- end
- -- Sipping any purgative elixir
- function treant:sip_purgative(name)
- bals:lose("purgative", 2)
- flags:set("elixir", name, 0)
- local time = 2
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 4
- end
- failsafe:exec("purgative", time)
- treant:command("sip ", name)
- end
- -- Sipping tea (how British of you)
- function treant:sip_tea(name)
- flags:set("tea_try", true, 2)
- local time = 2
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 4
- end
- failsafe:exec("tea", time)
- if name == "green" or name == "oolong" or name == "white" or name == "black" then
- name = name .. "tea"
- end
- flags:set("elixir", name, 0)
- treant:command("sip ", name)
- end
- -- Sipping allheale elixir
- function treant:sip_allheale()
- bals:lose("allheale", 2)
- flags:set("elixir", "allheale", 0)
- treant:command("sip allheale")
- end
- -- Sipping quicksilver elixir
- function treant:sip_quicksilver()
- flags:set("elixir", "quicksilver", 0)
- flags:set("speed_try", true, 2)
- -- Uses a special failsafe because quicksilver uses no real balance
- failsafe:exec("quicksilver", 2)
- treant:command("sip quicksilver")
- end
- -- Using adrenaline instead of quicksilver
- function treant:adrenaline()
- flags:set("speed_try", true, 2)
- failsafe:exec("adrenaline", 2)
- treant:command("adrenaline")
- end
- -- Sipping moonwater
- function treant:sip_moonwater()
- flags:set("elixir", "moonwater", 0)
- flags:set("moonwater_try", true, 2)
- -- Uses a special failsafe because moonwater uses no real balance
- failsafe:exec("moonwater", 2)
- treant:command("sip moonwater")
- end
- -- Sipped any elixir
- function treant:sipped(vial)
- local elixir = vial_map[vial] or flags:get("elixir") or "unknown"
- display.Debug("Sipped " .. elixir)
- EnableGroup("Treant_Sipping", true)
- if string.find("health mana bromide", elixir) then
- if bals:confirm("health", 8) then
- failsafe:disable("health")
- flags:set("last_cure", "sip " .. elixir, 0)
- end
- elseif elixir == "allheale" then
- if bals:confirm("allheale", 25) then
- affs:del("allheale")
- flags:clear("allheale")
- flags:set("last_cure", "sip allheale", 0)
- treant:cures_on()
- end
- elseif string.find("antidote choleric fire frost galvanism love phlegmatic sanguine", elixir) then
- if bals:confirm("purgative", 4) then
- affs:del(elixir)
- failsafe:disable("purgative")
- flags:set("last_cure", "sip " .. elixir, 0)
- treant:cures_on()
- end
- elseif elixir == "quicksilver" then
- if flags:get("speed_try") then
- flags:clear("speed_try")
- flags:set("waiting_for_speed", true, 0)
- failsafe:exec("wait for speed", 7)
- end
- elseif string.find("blacktea greentea oolongtea teapot whitetea", elixir) then
- if flags:get("tea_try") then
- queue:add(function () flags:clear("tea_try") end)
- end
- end
- flags:clear("elixir")
- scan:add("elixir")
- treant:poisons_on()
- end
- -- Applying a health potion to heal deep wounds
- function treant:apply_health(part)
- bals:lose("health")
- flags:set("health_applying", part, 0)
- -- Uses a special failsafe to handle the application of health
- local time = 2
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 4
- end
- failsafe:exec("health", time)
- treant:command("apply", " health to ", part)
- end
- -- Health potion applied successfully
- function treant:applied_health(part)
- if bals:confirm("health", 8) then
- flags:set("last_cure", "apply health to " .. part, 0)
- treant:cures_on()
- failsafe:disable("health")
- -- Looks for the 'no discernable effect' line to reset balance
- EnableTrigger("healthappfailed__", true)
- queue:add(function () EnableTrigger("healthappfailed__", false) end)
- end
- end
- -- Eating any herb
- function treant:eat_herb(name)
- name = string.lower(name)
- if name == (GetVariable("treant_option_sparkle") or "sparkleberry") then
- bals:lose("sparkle", 2)
- end
- if name ~= "rawtea" and name ~= "sparkleberry" then
- bals:lose("herb", 2)
- end
- if GetVariable("treant_option_antistupid") == "1" and
- name == "pennyroyal" and affs:has("stupidity") and
- not (affs:has("choke") or affs:has("aeon") or affs:has("sap")) then
- treant:command("outr ", name)
- treant:command("outr ", name)
- treant:command("eat ", name)
- treant:command("inr ", name)
- treant:command("eat ", name)
- treant:command("inr ", name)
- return
- end
- Send("outr ", name)
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- flags:set("to_eat", name, 0)
- EnableTrigger("eat_now__", true)
- else
- treant:command("eat ", name)
- end
- end
- -- Herb has been eaten
- function treant:ate_herb(name)
- local herb
- if name == "a calamus root" then
- herb = "calamus"
- elseif name == "a sprig of chervil" then
- herb = "chervil"
- elseif name == "a plug of coltsfoot" then
- herb = "coltsfoot"
- elseif name == "a piece of black earwort" then
- herb = "earwort"
- elseif name == "a stalk of faeleaf" then
- herb = "faeleaf"
- elseif name == "a stem of galingale" then
- herb = "galingale"
- elseif name == "a horehound blossom" then
- herb = "horehound"
- elseif name == "a kafe bean" then
- herb = "kafe"
- elseif name == "kombu seaweed" then
- herb = "kombu"
- elseif name == "a sprig of marjoram" then
- herb = "marjoram"
- elseif name == "a piece of merbloom seaweed" then
- herb = "merbloom"
- elseif name == "a bog myrtle leaf" then
- herb = "myrtle"
- elseif name == "a bunch of pennyroyal" then
- herb = "pennyroyal"
- elseif name == "raw tea leaves" then
- herb = "rawtea"
- elseif name == "a reishi mushroom" then
- herb = "reishi"
- elseif name == "a sparkleberry" then
- herb = "sparkleberry"
- elseif name == "a wormwood stem" then
- herb = "wormwood"
- elseif name == "a yarrow sprig" then
- herb = "yarrow"
- end
- if herb then
- if herb == (GetVariable("treant_option_sparkle") or "sparkleberry") then
- if bals:confirm("sparkle", 10) then
- EnableTrigger("sparkleberry_healing__", true)
- queue:add(function () EnableTrigger("sparkleberry_healing__", false) end)
- end
- end
- if herb ~= "sparkleberry" and herb ~= "rawtea" and bals:confirm("herb") then
- affs:del(herb)
- flags:set("last_cure", "eat " .. herb, 0)
- treant:cures_on()
- end
- end
- end
- -- Took a drag off a pipe
- function treant:smoked_herb(name)
- if not name then
- display.Debug("What are you smoking?")
- return
- end
- if name == "faeleaf" then
- if affs:has("coils") then
- if bals:confirm("herb", 8) then
- affs:del("smoke_faeleaf")
- flags:set("last_cure", "smoke faeleaf", 0)
- treant:cures_on()
- end
- elseif not defs:has("rebounding") then
- flags:set("aura_timer", true, 0)
- failsafe:exec("rebounding", 8, true)
- end
- elseif name == "myrtle" then
- if bals:confirm("herb", 8) then
- affs:del("smoke_myrtle")
- flags:set("last_cure", "smoke myrtle", 0)
- treant:cures_on()
- if affs:has("phrenic_nerve") then
- flags:set("phrenic_smoke", (flags:get("phrenic_smoke") or 0) + 1, 0)
- end
- end
- elseif name == "coltsfoot" then
- if bals:confirm("herb", 8) then
- affs:del("smoke_coltsfoot")
- flags:set("last_cure", "smoke coltsfoot", 0)
- treant:cures_on()
- end
- end
- if not flags:get("arena") then
- pipes:puffs(name, pipes:puffs(name) - 1)
- -- Check pipes that need to be refilled
- if pipes:puffs(name) <= 0 then
- pipes:maintain()
- end
- end
- flags:clear("smoking")
- end
- -- Apply arnica where needed
- function treant:apply_arnica(part)
- bals:lose("herb", 2)
- if GetVariable("treant_option_antistupid") == "1" and
- affs:has("fractured_skull") and
- not (affs:has("choke") or affs:has("aeon") or affs:has("sap")) then
- treant:command("outr arnica")
- treant:command("outr arnica")
- treant:command("apply arnica to head")
- treant:command("inr arnica")
- treant:command("apply arnica to head")
- treant:command("inr arnica")
- return
- end
- treant:command("outr arnica")
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- flags:set("to_apply", "arnica to " .. part, 0)
- EnableTrigger("apply_now__", true)
- else
- treant:command("apply arnica to ", part)
- end
- end
- -- Arnica applied successfully
- function treant:applied_arnica(part)
- if bals:confirm("herb", 8) then
- affs:del("arnica_" .. part)
- flags:set("last_cure", "apply arnica " .. part, 0)
- treant:cures_on()
- end
- end
- -- Apply salve where needed
- function treant:apply_salve(name, part)
- bals:lose("salve")
- flags:set("salve", name, 0)
- if name == "regeneration" then
- flags:set("regenerating_" .. part, true, 0)
- end
- -- Salves use a special failsafe to handle regeneration properly
- local time = 2
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 4
- end
- failsafe:exec("salve", time)
- if part then
- flags:set("applied_to", part)
- treant:command("apply ", name, " to ", part)
- else
- treant:command("apply ", name)
- end
- end
- -- Salve applied successfully
- function treant:applied_salve(part)
- if bals:confirm("salve", 8) then
- if flags:get("salve") ~= "regeneration" then
- affs:del(flags:get("salve") .. "_" .. part)
- flags:set("last_cure", "apply " .. flags:get("salve") .. " to " .. part, 0)
- treant:cures_on()
- else
- affs:del("regen_" .. part)
- failsafe:exec("regeneration_" .. part, 7, true)
- end
- flags:set("applied", flags:get("salve"))
- flags:clear("salve")
- failsafe:disable("salve")
- -- Looks for the 'no discernable effect' line to reset balance
- EnableTrigger("salvefailed__", true)
- queue:add(function () EnableTrigger("salvefailed__", false) end)
- end
- end
- -- Cleansing away some nasty affliction
- function treant:cleanse()
- local time = 2
- if affs:has("aeon") or affs:has("sap") or affs:has("choke") then
- time = 4
- end
- flags:set("cleanse_try", true, 0)
- failsafe:exec("cleanse", time)
- if GetVariable("treant_option_cleanse") == "soap" then
- treant:command("scrub")
- elseif GetVariable("treant_option_cleanse") == "cast" then
- treant:command("cast cleanse me")
- else
- treant:command("rub cleanse")
- end
- end
- -- Igniting yourself to remove thorns is painful but sometimes necessary
- function treant:ignite()
- local time = 2
- if affs:has("aeon") or affs:has("sap") or affs:has("choke") then
- time = 4
- end
- flags:set("ignite_try", true, 0)
- failsafe:exec("ignite", time)
- treant:command("point ignite at me")
- end
- -- Focusing body/mind/spirit
- function treant:focus(bms)
- bals:lose("focus", 2)
- treant:command("focus ", bms)
- end
- -- Successfully focused body/mind/spirit
- function treant:focused(bms)
- if bals:confirm("focus", 5) then
- affs:del("focus_" .. bms)
- if string.find("mind spirit", bms) then
- flags:set("last_cure", "focus " .. bms, 0)
- treant:cures_on()
- else
- flags:set("focusing", "body", 4)
- flags:clear({ "sap_try", "choke_try" })
- end
- end
- end
- -- Successfully focused body out of paralysis
- function treant:focused_body()
- if flags:get("focusing") then
- flags:clear("focusing")
- affs:del("paralysis")
- bals:gain("focus")
- end
- end
- -- Rubbing a focus enchantment to heal debate afflictions
- function treant:rub_focus()
- bals:lose("charm", 2)
- treant:command("rub focus")
- end
- -- Successfully rubbed a focus enchantment
- function treant:rubbed_focus()
- if bals:confirm("charm", 7) then
- affs:del("focus")
- flags:set("last_cure", "rub focus")
- treant:cures_on()
- end
- end
- -- Read a healing scroll now
- function treant:scroll_heal(tome)
- bals:lose("scroll", 2)
- if tome then
- treant:command("read magictome healing")
- flags:set("tome", "healing", 4)
- return
- end
- local id = GetVariable("treant_scroll_healing_id")
- if not id then
- display.Error("No healing scroll found. Either check MagicList or disable auto-scroll.")
- return
- end
- local charges = tonumber(GetVariable("treant_scroll_healing_charges") or "0")
- if charges <= 1 then
- display.Alert("Healing scroll has one charge left. Recharge it!")
- return
- end
- treant:command("read ", id)
- end
- -- Healing scroll has been read
- function treant:scroll_healed()
- bals:confirm("scroll", 12)
- magic:use_charge("healing")
- end
- -- Auto-diagnose, if enabled
- function treant:diag()
- if GetVariable("treant_option_diagnose") == "1" then
- flags:set("diagnose", true, 0)
- scan:add("balance")
- elseif GetVariable("treant_option_diagnose") == "2" then
- flags:set("succor", true, 0)
- scan:add("balance")
- end
- end
- -- Turns active cure triggers on now, off at the next prompt
- function treant:cures_on()
- display.Debug("Active cures enabled")
- EnableGroup("Treant_Cures", true)
- end
- -- Enable all poison affliction triggers
- -- If the source is a darts trap, leave the triggers on for about a minute
- function treant:poisons_on(darts)
- display.Debug("Poison afflictions enabled")
- EnableGroup("Treant_Poisons", true)
- if darts then
- EnableAlias("poisons_prompt__", false)
- EnableTimer("poison_darts__", true)
- ResetTimer("poison_darts__")
- end
- end
- -- Enable the modifier triggers for a kata specialization
- function treant:kata_mods(skill)
- if not skill then
- display.Error("Invalid skill provided to treant:kata_mods")
- return
- end
- if type(skill) == "table" then
- for _,sk in pairs(skill) do
- treant:kata_mods(sk)
- end
- return
- end
- EnableGroup("Treant_" .. skill .. "Mods", true)
- EnableGroup("Treant_KataMods", true)
- end
- -- Clot failsafe
- function treant:clot()
- flags:set("clot_try", true, 0)
- local time = 1
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 3
- end
- failsafe:exec("clot", time)
- treant:command("clot")
- end
- -- Concentration failsafe
- function treant:concentrate()
- flags:set("concentrate_try", true, 0)
- local time = 1
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 3
- end
- failsafe:exec("concentrate", time)
- treant:command("concentrate")
- end
- -- Insomnia failsafe
- function treant:insomnia()
- flags:set("insomnia_try", true, 0)
- local time = 1
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 3
- end
- failsafe:exec("insomnia", time)
- treant:command("insomnia")
- end
- -- Nightsight failsafe
- function treant:nightsight()
- flags:set("nightsight_try", true, 0)
- failsafe:exec("nightsight", 2)
- treant:command("nightsight")
- end
- -- Stand up now!
- function treant:stand()
- flags:set("stand_try", true, 0)
- local time = 1
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 3
- end
- failsafe:exec("stand", time)
- local s = "stand"
- if GetVariable("treant_option_springup") == "1" then
- s = "springup"
- end
- treant:command(s)
- end
- -- Successfully standing up
- function treant:standing()
- if flags:get("stand_try") then
- failsafe:disable("stand")
- flags:clear("stand_try")
- affs:del("prone")
- affs:scan()
- defs:scan()
- todo:scan()
- end
- end
- -- Wake up now!
- function treant:wake()
- flags:set("wake_try", true, 0)
- if affs:has("choke") then
- failsafe:exec("wake", 2)
- else
- failsafe:exec("wake", 1)
- end
- treant:command("wake")
- end
- -- Successfully waking up
- function treant:waking()
- if flags:get("wake_try") then
- failsafe:disable("wake")
- flags:clear("wake_try")
- flags:set("waking", true, 0)
- end
- end
- -- Finally woke up
- function treant:awake(insom)
- if flags:get("waking") then
- flags:clear({ "wake_try", "waking" })
- affs:del("asleep")
- if insom then
- defs:del("insomnia")
- end
- end
- affs:prone()
- end
- -- Writhe out of entanglements
- function treant:writhe(name)
- flags:set("writhe_try", name or true, 0)
- local time = 2
- if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
- time = 4
- end
- failsafe:exec("writhe", time)
- local w = "writhe"
- if GetVariable("treant_option_contort") == "1" then
- w = "contort"
- end
- if name then
- treant:command(w, " ", name)
- else
- treant:command(w)
- end
- end
- -- Successfully writhing
- function treant:writhing()
- if flags:get("writhe_try") then
- failsafe:disable("writhe")
- flags:clear("writhe_try")
- flags:set("writhing", true, 6)
- end
- end
- -- Successfully writhing from impalements
- function treant:writhing_impale()
- if flags:get("writhe_try") then
- failsafe:disable("writhe")
- flags:clear("writhe_try")
- flags:set("writhing_impale", (flags:get("writhing_impale") or 0) + 1, 6)
- end
- end
- -- Climb down from the trees unless we want to be in the trees
- function treant:no_trees()
- flags:set("in_trees", true, 0)
- if GetVariable("treant_option_notrees") == "1" then
- flags:set("climb_down", true, 0)
- flags:clear("climbing_down")
- scan:add("balance")
- end
- end
- -- Climb up out of a pit when you fall in
- function treant:pitfall()
- flags:set("climb_up", true, 0)
- flags:clear("climbing_up")
- if not defs:has("levitating") then
- affs:limb("left", "leg", "broken")
- affs:limb("right", "leg", "broken")
- end
- stance:scan()
- parry:scan()
- scan:add({ "balance", "general" })
- end
- -- Interfacing function for actually doing the climbing up/down
- function treant:climb(dir)
- flags:set("climb_try", dir, 0)
- if flags:get("climb_" .. dir) then
- failsafe:exec("climb", 1)
- end
- treant:command("climb " .. dir)
- end
- -- Function for getting out of entanglements quickly, if configured
- function treant:fastwrithe()
- local fw = string.lower(GetVariable("treant_option_fastwrithe") or "off")
- flags:set("fastwrithe", fw, 2)
- if fw == "summer" then
- Send("invoke summer")
- else
- Send("evoke tipheret")
- end
- end
- -- Check arms or legs for any unknown afflictions that need to be diagnosed
- function treant:check_limbs(limbs)
- -- If auto-diagnose is off, this is unnecessary
- if GetVariable("treant_option_diagnose") ~= "1" then
- return
- end
- -- Check conditions on arms or legs?
- if limbs == "arms" then
- if affs:has("hemiplegy_left") or
- affs:has("hemiplegy_right") or
- affs:has("clamped_left") or
- affs:has("clamped_right") or
- affs:limb("left", "arm") ~= "healthy" or
- affs:limb("right", "arm") ~= "healthy" or
- affs.grapples["leftarm"] or
- affs.grapples["rightarm"] then
- return
- end
- else
- if affs:has("tendon_left") or
- affs:has("tendon_right") or
- affs:has("hemiplegy_left") or
- affs:has("hemiplegy_right") or
- affs:has("hemiplegy_legs") or
- affs:limb("left", "leg") ~= "healthy" or
- affs:limb("right", "leg") ~= "healthy" or
- affs.grapples["leftleg"] or
- affs.grapples["rightleg"] then
- return
- end
- end
- treant:diag()
- end
- -- Handling of the Maestoso effect from Music's Octave, preventing certain cures
- function treant:maestoso(caster)
- if caster then
- flags:set("maestoso_caster", string.lower(caster), 180)
- elseif not flags:get("maestoso") then
- flags:set("maestoso", true, 0)
- failsafe:exec("maestoso", tonumber(GetVariable("treant_option_maestoso") or "15"))
- end
- end
- -- Gag the prompt, for anyone who needs to decorate and re-echo it or just to keep the spam down
- function treant:gag_prompt()
- flags:set("no_prompt", true, 0)
- end
- function treant:prefix(fn)
- self.pre = self.pre or {}
- table.insert(self.pre, fn)
- end
- function treant:suffix(fn)
- self.suff = self.suff or {}
- table.insert(self.suff, fn)
- end
- function treant_prompt_decorate(name, line, wildcards, styles)
- -- Process health, mana, ego, power, endurance, willpower, and flags
- prompt:capture(tonumber(wildcards[1]), tonumber(wildcards[2]), tonumber(wildcards[3]), tonumber(wildcards[4]),
- tonumber(wildcards[5]), tonumber(wildcards[6]), wildcards[7])
- -- Just want to gag this prompt entirely
- if flags:get("no_prompt") then
- flags:clear("no_prompt")
- return
- end
- -- Prefix functions evaluated first
- for _,fn in ipairs(treant.pre or {}) do
- fn()
- end
- treant.pre = nil
- -- Display text as it was captured
- for _, v in ipairs(styles) do
- if v.text ~= wildcards[7] then
- ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), v.text)
- end
- end
- -- Color the prompt flags based on balance status
- if bals:can_act() then
- ColourTell(GetVariable("treant_prompt_onbal") or "yellowgreen", "", wildcards[7])
- else
- ColourTell(GetVariable("treant_prompt_offbal") or "darkolivegreen", "", wildcards[7])
- end
- -- Display the most important alert status (stunned, locked, etc)
- if prompt.alert then
- ColourTell("purple", "", " [", "red", "", prompt.alert, "purple", "", "]")
- end
- -- Suffix functions evaluated last
- for _,fn in ipairs(treant.suff or {}) do
- fn()
- end
- treant.suff = nil
- Note("")
- end
- -- Checking whether or not we're really dead
- function treant:dead()
- EnableTimer("death_failsafe__", true)
- end
- function treant:telepathy()
- local pc = flags:get("prone_check")
- if pc and string.find(prompt.fl, "p") then
- return
- end
- treant:diag()
- flags:set("telepathy", tonumber(flags:get("telepathy") or "0") + 1, 4)
- local plural = ""
- if flags:get("telepathy") > 1 then
- plural = "s"
- flags:set("allheale", true, 0)
- scan:add("elixir")
- end
- display.Alert("Hit by " .. flags:get("telepathy") .. " telepathy affliction" .. plural)
- end
- function treant:charybdon()
- flags:set("charybdon", true)
- prompt:queue(function () if flags:get("charybdon") then treant:diag() end end)
- treant:poisons_on()
- end
- function treant:max_health()
- local hm = tonumber(GetVariable("treant_health_max") or "0")
- if affs:has("illusory_wounds") then
- hm = hm * 2 / 3
- if prompt.health > hm then
- affs:del("illusory_wounds")
- end
- end
- return hm
- end
- function treant:max_mana()
- return tonumber(GetVariable("treant_mana_max") or "0")
- end
- function treant:max_ego()
- return tonumber(GetVariable("treant_ego_max") or "0")
- end
- -- Turn automatic systems on/off
- -- Passing in a name with no value simply retrieves the current value
- function treant:auto(name, val)
- if val ~= nil then
- SetVariable("treant_auto_" .. name, tostring(val)) -- Stored in the world for persistence
- local enabled = "DISABLED"
- if treant:auto(name) then
- enabled = "ENABLED"
- end
- display.Info("Auto " .. name .. " " .. enabled)
- affs:scan()
- defs:scan()
- end
- return GetVariable("treant_auto_" .. name) == "true"
- end
- -- Display automatic systems status
- function treant:show_auto(nocr)
- display.Info("Automatic Systems Report:")
- local autos = {
- ["Healing"] = { "sipping", "sparkle", "scroll" },
- ["Defenses"] = { "insomnia", "kafe", "metawake", "fire", "frost", "sixthsense", "truehearing",
- "lusting", "selfish", "speed", "rebounding", "breathing", "parry", "stance" },
- ["Miscellaneous"] = { "pipes" }
- }
- -- Configure for pseudo-acquisitio addon
- if IsTrigger("acquire_killed__") == 0 then
- table.insert(autos["Miscellaneous"], "acquire")
- end
- -- Configure for Herbs skill
- if IsTrigger("herbs_growing__") == 0 then
- table.insert(autos["Miscellaneous"], "herbs")
- end
- -- Configure for influencing add-in
- if IsAlias("influence__") == 0 then
- table.insert(autos["Miscellaneous"], "influence")
- end
- -- Configure for auto-raze script
- if IsAlias("autoraze_target__") == 0 then
- table.insert(autos["Miscellaneous"], "raze")
- end
- -- Configure for debating add-in
- if IsTrigger("debate_mindset1__") == 0 then
- table.insert(autos["Miscellaneous"], "mindset")
- table.insert(autos["Miscellaneous"], "debate")
- end
- for cat,list in pairs(autos) do
- display.Prefix()
- ColourNote("cyan", "", " " .. cat)
- for _,a in pairs(list) do
- display.Prefix()
- ColourTell("darkgray", "", " [")
- if treant:auto(a) then
- ColourTell("yellow", "", "X")
- else
- Tell(" ")
- end
- ColourTell("darkgray", "", "] ")
- ColourNote("darkcyan", "", a)
- end
- end
- -- T are speshul
- display.Prefix()
- ColourTell("darkgray", "", " [")
- if treant:auto("tea") then
- local tea = GetVariable("treant_option_tea") or "tea"
- ColourTell("yellow", "", "X")
- ColourTell("darkgray", "", "] ")
- ColourNote("darkcyan", "", "tea - " .. tea)
- else
- Tell(" ")
- ColourTell("darkgray", "", "] ")
- ColourNote("darkcyan", "", "tea")
- end
- if IsConnected() and not nocr then
- Send("")
- end
- end
- -- Display helpful information on how to configure the system
- function treant:config_help()
- local options = php:Table()
- options["TCONFIG SKILLS"] = {
- ["info"] = "Checks your skills and automatically installs available scripts"
- }
- options["TCONFIG DIAGNOSE <ON/OFF/SUCCOR>"] = {
- ["info"] = "Toggle the automatic diagnosing of afflictions in certain situations",
- ["value"] = function () if GetVariable("treant_option_diagnose") == "1" then return "ON" elseif GetVariable("treant_option_diagnose") == "2" then return "SUCCOR" end return "OFF" end
- }
- options["TCONFIG NOTREES <ON/OFF>"] = {
- ["info"] = "Toggle automatically climbing down from trees in a druid's demesne",
- ["value"] = function () if GetVariable("treant_option_notrees") == "1" then return "ON" end return "OFF" end
- }
- options["TCONFIG PIPES <ARTIFACT/STANDARD>"] = {
- ["info"] = "Using a full set of artifact pipes means never having to light them",
- ["value"] = function () if GetVariable("treant_option_artipipes") == "1" then return "ARTIFACT" end return "STANDARD" end
- }
- options["TCONFIG SETPIPE <herb> <#> [<# puffs>]"] = {
- ["info"] = "Manually setup pipe number for an herb with optional number of puffs remaining"
- }
- options["TCONFIG MAXPUFFS <#>"] = {
- ["info"] = "Set the maximum number of puffs a pipe can hold",
- ["value"] = function () return GetVariable("treant_option_maxpuffs") or "10" end
- }
- options["TCONFIG THORNS <#>"] = {
- ["info"] = "Given 0, it will writhe from thorns. Given 1-4, it will ignite after that many thorns",
- ["value"] = function () return GetVariable("treant_option_thorns") or "0" end
- }
- options["TCONFIG SPARKLE <herb>"] = {
- ["info"] = "May use the Nature Domoth herb instead of sparkleberry",
- ["value"] = function () return string.upper(GetVariable("treant_option_sparkle") or "sparkleberry") end
- }
- options["TCONFIG MAGICTOME <ON/OFF>"] = {
- ["info"] = "Read the healing scroll from a magic tome",
- ["value"] = function () if GetVariable("treant_option_magictome") == "1" then return "ON" end return "OFF" end
- }
- options["TCONFIG CONTORT <ON/OFF>"] = {
- ["info"] = "Use Acrobatics Contort to writhe out of entanglements",
- ["value"] = function () if GetVariable("treant_option_contort") == "1" then return "ON" end return "OFF" end
- }
- options["TCONFIG SPRINGUP <ON/OFF>"] = {
- ["info"] = "Use Acrobatics Springup to stand up",
- ["value"] = function () if GetVariable("treant_option_springup") == "1" then return "ON" end return "OFF" end
- }
- options["TCONFIG DEATHMARK <#>"] = {
- ["info"] = "Cure the deathmark after the count reaches this number (1-15). To disable, use 0",
- ["value"] = function () return GetVariable("treant_option_deathmark") or "14" end
- }
- options["TCONFIG CLEANSE <SOAP/CAST/RUB>"] = {
- ["info"] = "Cleansing will use artifact soap, elemental spell, or enchanted item",
- ["value"] = function () return string.upper(GetVariable("treant_option_cleanse") or "RUB") end
- }
- options["TCONFIG FASTWRITHE <SUMMER/TIPHERET/OFF> <#>"] = {
- ["info"] = "Will use Summer or Tipheret after a number of concurrent entanglements",
- ["value"] = function ()
- local v = string.upper(GetVariable("treant_option_fastwrithe") or "off")
- if v ~= "OFF" then
- v = v .. " " .. (GetVariable("treant_option_fastwrithe_n") or "2")
- end
- return v
- end
- }
- options["TCONFIG ADRENALINE <ON/OFF>"] = {
- ["info"] = "Enable the use of adrenaline in addition to quicksilver",
- ["value"] = function () if GetVariable("treant_option_adrenaline") == "1" then return "ON" end return "OFF" end
- }
- display.Info("Treant Configuration Options:")
- for k,v in options:pairs() do
- display.Prefix()
- ColourTell("cyan", "", string.format(" %-48s", k))
- if v["value"] then
- ColourTell("darkcyan", "", string.format(" (%15s)", v["value"]()))
- end
- Note("")
- display.Prefix()
- ColourNote("silver", "", " " .. v["info"])
- end
- if IsConnected() then
- Send("")
- end
- end
- -- This is a module and needs a return table
- return treant
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement