Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 41.50 KB | None | 0 0
  1. --[[
  2. Main Lua script file for Treant system
  3. --]]
  4.  
  5. require "able"
  6. require "affs"
  7. require "bals"
  8. require "calendar"
  9. require "criticals"
  10. require "defs"
  11. require "display"
  12. require "failsafe"
  13. require "flags"
  14. require "gear"
  15. require "herbs"
  16. require "kills"
  17. require "magic"
  18. require "nocure"
  19. require "parry"
  20. require "pipes"
  21. require "poisonist"
  22. require "potions"
  23. require "prompt"
  24. require "queue"
  25. require "scan"
  26. require "stag"
  27. require "stance"
  28. require "todo"
  29. require "wounds"
  30.  
  31. -- Simple utility function to test for the existence of a file
  32. function io.exists(filename)
  33.   local file = io.open(filename)
  34.   if file then
  35.     io.close(file)
  36.     return true
  37.   end
  38.   return false
  39. end
  40.  
  41.  
  42. if not treant then
  43.   treant = {}
  44. end
  45.  
  46. if not vial_map then
  47.   vial_map = {}
  48. end
  49.  
  50. -- Auto-require premium add-on scripts
  51. if io.exists("enemy.lua") then
  52.   require "enemy"
  53. end
  54. if io.exists("influence.lua") then
  55.   require "influence"
  56. end
  57. if io.exists("acquire.lua") then
  58.   require "acquire"
  59. end
  60. if io.exists("debate.lua") then
  61.   require "debate"
  62. end
  63. if io.exists("names.lua") then
  64.   require "names"
  65. end
  66. if io.exists("target.lua") then
  67.   require "target"
  68. end
  69. if io.exists("beast.lua") then
  70.   require "beast"
  71. end
  72. if io.exists("iht.lua") then
  73.   require "iht"
  74. end
  75. if io.exists("mapper.lua") then
  76.   require "mapper"
  77. end
  78.  
  79. -- Initialization code executes every time this loads
  80. affs:reset()
  81. bals:reset()
  82. defs:reset()
  83. flags:reset()
  84.  
  85. affs:init_priorities()
  86.  
  87. calendar:init()
  88.  
  89. local version = tonumber(GetVariable("treant_version") or "0")
  90. if version > 0 then
  91.   display.Info(string.format("Initialized version 1.%02d", version))
  92. else
  93.   display.Info("Initialized")
  94. end
  95.  
  96. -- OBSOLETE
  97. function treant:Init()
  98. end
  99.  
  100. -- Imports all triggers needed for the system
  101. function treant:Install()
  102.   if not io then
  103.     error("Disk I/O is disabled in the Lua sandbox")
  104.     return
  105.   end
  106.  
  107.   local previous_version = tonumber(GetVariable("treant_version") or "0")
  108.   local version = 34
  109.   SetVariable("treant_version", version)
  110.  
  111.   -- A little housekeeping for anyone who is upgrading
  112.   if previous_version <= 8 then
  113.     for i = 6,12 do
  114.       DeleteTrigger("wound_status" .. i .. "__")
  115.     end
  116.     DeleteTrigger("curerupture__")
  117.     DeleteTrigger("kata_rupture__")
  118.     DeleteTrigger("shofangi__")
  119.     DeleteTrigger("shofangi_tongue1__")
  120.    
  121.     -- Failsafe timers have been replaced and are now dynamically created when missing
  122.     DeleteTimer("score_failsafe__")
  123.     DeleteTimer("def_failsafe__")
  124.     DeleteTimer("diag_failsafe__")
  125.     DeleteTimer("insomnia_failsafe__")
  126.     DeleteTimer("stun_failsafe__")
  127.     DeleteTimer("stand_failsafe__")
  128.     DeleteTimer("wake_failsafe__")
  129.     DeleteTimer("writhe_failsafe__")
  130.     DeleteTimer("aeon_sap_failsafe__")
  131.     DeleteTimer("focus_spirit_failsafe__")
  132.     DeleteTimer("health_failsafe__")
  133.     DeleteTimer("salve_failsafe__")
  134.     DeleteTimer("regeneration_failsafe__")
  135.     DeleteTimer("clot_failsafe__")
  136.     DeleteTimer("rebounding_failsafe__")
  137.     DeleteTimer("climb_failsafe__")
  138.     DeleteTimer("climb_up_failsafe__")
  139.     DeleteTimer("climb_down_failsafe__")
  140.     DeleteTimer("pipe_lighting__")
  141.     DeleteTimer("protection_failsafe__")
  142.     DeleteTimer("sixthsense_failsafe__")
  143.   end
  144.  
  145.   if previous_version <= 12 then
  146.     -- The "red" defense was renamed to "roots"
  147.     DeleteTrigger("def_red__")
  148.     DeleteTrigger("defup_red__")
  149.   end
  150.  
  151.   if previous_version <= 16 then
  152.     -- Aggregated AB triggers in 1.17
  153.     DeleteTriggerGroup("Treant_Abilities")
  154.   end
  155.  
  156.   if previous_version <= 19 then
  157.     -- Made proper failsafes so stun doesn't mess with them
  158.     DeleteTimer("parry_failsafe__")
  159.     DeleteTimer("stance_failsafe__")
  160.   end
  161.  
  162.   if previous_version <= 21 then
  163.     DeleteAlias("apply_liniment__")
  164.     DeleteTrigger("defdown_barkskin__")
  165.   end
  166.  
  167.   if previous_version <= 22 then
  168.     DeleteTrigger("affbeastgas__")
  169.   end
  170.  
  171.   -- Monk updates
  172.   if previous_version <= 27 then
  173.     DeleteTrigger("ninjakari_dysentery__")
  174.     DeleteTrigger("ninjakari_broken_chest__")
  175.     DeleteTrigger("ninjakari_mangle_limb__")
  176.   end
  177.  
  178.   -- New way of tracking repelled affs
  179.   if previous_version <= 28 then
  180.     DeleteTrigger("tea_repels__")
  181.   end
  182.  
  183.   -- Duplicate triggers not needed
  184.   if previous_version <= 29 then
  185.     DeleteTrigger("defdown_psi_shield__")
  186.     DeleteTrigger("defup_psi_shield__")
  187.  
  188.     DeleteTrigger("poison_immune__")
  189.     DeleteTrigger("scorpions1__")
  190.     DeleteTrigger("scorpions2__")
  191.     DeleteTrigger("scorpions3__")
  192.     DeleteTrigger("conservatory_freak1__")
  193.     DeleteGroup("Treant_Scorpions")
  194.   end
  195.  
  196.   if previous_version <= 33 then
  197.     DeleteTrigger("aff_pyro_wildfire__")
  198.     DeleteTrigger("kata_bomrakini_head__")
  199.     DeleteTrigger("ninjakari_ninughi_arm1__")
  200.     DeleteTrigger("ninjakari_ninughi_arm2__")
  201.     DeleteTrigger("ninjakari_ninughi_leg1__")
  202.     DeleteTrigger("ninjakari_ninughi_leg2__")
  203.     DeleteTrigger("shofangi_paralysis__")
  204.     DeleteTrigger("shofangi_braindamage__")
  205.   end
  206.  
  207.   DeleteTrigger("cureunconscious__")
  208.   DeleteTrigger("gag_prompt__")
  209.   DeleteTrigger("prompt__")
  210.  
  211.   ChangeDir(GetInfo(68))
  212.  
  213.   local xml
  214.   local scripts = {
  215.     "events", "interface", "tracking", "affs", "cures", "defs", "defense",
  216.     "poisons", "wounds", "gear", "kills", "abilities", "calendar", "combat",
  217.     "criticals", "pipelist", "potionlist", "magiclist", "diagnose"
  218.   }
  219.  
  220.   -- Import all base scripts
  221.   for _,s in ipairs(scripts) do
  222.     io.input("treant_" .. s .. ".xml")
  223.     xml = io.read("*all")
  224.     ImportXML(xml)
  225.   end
  226.  
  227.   local premium = {
  228.     "enemy", "influence", "acquire", "bashing", "highlight", "linking",
  229.     "debate", "abs", "names", "beast", "iht", "target",
  230.     "mapper"
  231.   }
  232.   -- Import any extra settings that may have been purchased
  233.   for _,s in ipairs(premium) do
  234.     if io.exists("treant_" .. s .. ".xml") then
  235.       io.input("treant_" .. s .. ".xml")
  236.       xml = io.read("*all")
  237.       ImportXML(xml)
  238.     end
  239.   end
  240.  
  241.   local skills = {
  242.     ["defup_adroitness__"] = "acrobatics",
  243.     ["defup_spiritshield__"] = "aquamancy",
  244.     ["defup_weathering__"] = "athletics",
  245.     ["defup_stigmata__"] = "celestialism",
  246.     ["defup_timeslip__"] = "cosmic",
  247.     ["defup_twirl__"] = "druidry",
  248.     ["defup_stoneskin__"] = "elementalism",
  249.     ["defup_illusoryself__"] = "glamours",
  250.     ["herbs_growing__"] = "herbs",
  251.     ["defup_hexaura__"] = "hexes",
  252.     ["defup_geburah__"] = "highmagic",
  253.     ["defup_changeself__"] = "illusions",
  254.     ["prompt_momentum__"] = "kata",
  255.     ["defup_combatstyle__"] = "knighthood",
  256.     ["defup_yellow__"] = "lowmagic",
  257.     ["defup_moonaura__"] = "moon",
  258.     ["defup_bardicpresence__"] = "music",
  259.     ["defup_blend__"] = "nature",
  260.     ["defup_putrefaction__"] = "necromancy",
  261.     ["defup_nekotai__"] = "nekotai",
  262.     ["defup_garb__"] = "night",
  263.     ["defup_nihilism__"] = "nihilism",
  264.     ["defup_ninjakari__"] = "ninjakari",
  265.     ["defup_phantomarmour__"] = "phantasms",
  266.     ["defup_psiarmour__"] = "psionics",
  267.     ["defup_gliding__"] = "psychometabolism",
  268.     ["defup_fireproof__"] = "pyromancy",
  269.     ["defup_draconis__"] = "rituals",
  270.     ["defup_honour__"] = "sacraments",
  271.     ["defup_shofangi__"] = "shofangi",
  272.     ["defup_bolting__"] = "stag",
  273.     ["defup_sneak__"] = "stealth",
  274.     ["defup_tahtetso__"] = "tahtetso",
  275.     ["defup_wicca__"] = "wicca"
  276.   }
  277.   -- Import skill-specific upgrades
  278.   for t,s in pairs(skills) do
  279.     if IsTrigger(t) == 0 then
  280.       io.input("treant_" .. s .. ".xml")
  281.       xml = io.read("*all")
  282.       ImportXML(xml)
  283.     end
  284.   end
  285.  
  286.   -- Initialize configurable variables that do not yet exist
  287.   if GetVariable("treant_option_debug") == nil then
  288.     SetVariable("treant_option_debug", 0)
  289.   end
  290.   if GetVariable("treant_option_diagnose") == nil then
  291.     SetVariable("treant_option_diagnose", 1)
  292.   end
  293.   if GetVariable("treant_option_notrees") == nil then
  294.     SetVariable("treant_option_notrees", 1)
  295.   end
  296.   if GetVariable("treant_option_maxpuffs") == nil then
  297.     SetVariable("treant_option_maxpuffs", 10)
  298.   end
  299.   if GetVariable("treant_option_artipipes") == nil then
  300.     SetVariable("treant_option_artipipes", 0)
  301.   end
  302.   if GetVariable("treant_option_sparkle") == nil then
  303.     SetVariable("treant_option_sparkle", "sparkleberry")
  304.   end
  305.   if GetVariable("treant_option_magictome") == nil then
  306.     SetVariable("treant_option_magictome", 0)
  307.   end
  308.   if GetVariable("treant_option_contort") == nil then
  309.     SetVariable("treant_option_contort", 0)
  310.   end
  311.   if GetVariable("treant_option_springup") == nil then
  312.     SetVariable("treant_option_springup", 0)
  313.   end
  314.   if GetVariable("treant_option_deathmark") == nil then
  315.     SetVariable("treant_option_deathmark", 14)
  316.   end
  317.  
  318.   display.Info("Installation completed!")
  319.   display.Info("Use TCONFIG to set things up.")
  320. end
  321.  
  322. -- Removes all imported triggers from world file, thereby uninstalling the system
  323. function treant:Uninstall()
  324.   -- TODO: some form of confirmation dialog
  325.  
  326.   DeleteGroup("Treant_Abilities")
  327.   DeleteGroup("Treant_Acquire")
  328.   DeleteGroup("Treant_Bashable")
  329.   DeleteGroup("Treant_Basher")
  330.   DeleteGroup("Treant_Bashing")
  331.   DeleteGroup("Treant_Belt")
  332.   DeleteGroup("Treant_Blackout")
  333.   DeleteGroup("Treant_Cleanse")
  334.   DeleteGroup("Treant_Cures")
  335.   DeleteGroup("Treant_Defs")
  336.   DeleteGroup("Treant_Diagnose")
  337.   DeleteGroup("Treant_Events")
  338.   DeleteGroup("Treant_Interface")
  339.   DeleteGroup("Treant_KataMods")
  340.   DeleteGroup("Treant_Linking")
  341.   DeleteGroup("Treant_Magiclist")
  342.   DeleteGroup("Treant_Mapper")
  343.   DeleteGroup("Treant_MapperSpecials")
  344.   DeleteGroup("Treant_NekotaiMods")
  345.   DeleteGroup("Treant_NinjakariMods")
  346.   DeleteGroup("Treant_Pipelist")
  347.   DeleteGroup("Treant_Plants")
  348.   DeleteGroup("Treant_Poisons")
  349.   DeleteGroup("Treant_Potionhide")
  350.   DeleteGroup("Treant_Potionlist")
  351.   DeleteGroup("Treant_Rainbows")
  352.   DeleteGroup("Treant_Rift")
  353.   DeleteGroup("Treant_Scorpions")
  354.   DeleteGroup("Treant_ShofangiMods")
  355.   DeleteGroup("Treant_Sipping")
  356.   DeleteGroup("Treant_TahtetsoMods")
  357.   DeleteGroup("Treant_Tracking")
  358.   DeleteGroup("Treant_Wounds")
  359.   DeleteGroup("Treant_WoundStatus")
  360.  
  361.   local skills = {
  362.     "Acrobatics", "Aquamancy", "Athletics", "Celestialism",
  363.     "Cosmic", "Druidry", "Elementalism", "Geomancy", "Glamours",
  364.     "Herbs", "Hexes", "Highmagic", "Hunting", "Illusions", "Kata",
  365.     "Knighthood", "Lowmagic", "Moon", "Music",
  366.     "Nature", "Necromancy", "Nekotai", "Night",
  367.     "Nihilism", "Ninjakari", "Phantasms", "Poisonist", "Psionics",
  368.     "Psychometabolism", "Pyromancy", "Rituals", "Sacraments",
  369.     "Shofangi", "Stag", "Stealth", "Tahtetso", "Wicca"
  370.   }
  371.   for _,s in ipairs(skills) do
  372.     DeleteGroup("Treant_" .. skills)
  373.   end
  374.  
  375.   -- Delete any variable that starts with the 'treant_' prefix
  376.   for v in pairs(GetVariableList()) do
  377.     if string.find(v, "treant_") == 1 then
  378.       DeleteVariable(v)
  379.     end
  380.   end
  381.  
  382.   display.Info("System settings removed from world")
  383. end
  384.  
  385. -- Pauses the system, of course!
  386. function treant:Pause()
  387.   if not self.IsPaused() then
  388.     SetVariable("treant_pause", 1)
  389.  
  390.     display.Alert("** PAUSED **")
  391.  
  392.     if gui then
  393.       gui:update_pause()
  394.     end
  395.   end
  396. end
  397.  
  398. -- And this unpauses it, of course!
  399. function treant:Unpause()
  400.   if self.IsPaused() then
  401.     SetVariable("treant_pause", 0)
  402.  
  403.     display.Alert("** UNPAUSED **")
  404.  
  405.     if gui then
  406.       gui:update_pause()
  407.     end
  408.  
  409.     -- Rescan afflictions to see what needs to be processed now
  410.     affs:scan()
  411.     defs:scan()
  412.     todo:scan()
  413.  
  414.     -- Send a newline to force a prompt and get some reaction
  415.     Send("")
  416.   end
  417. end
  418.  
  419. -- Quick check to see whether the whole system is paused or not
  420. function treant:IsPaused()
  421.   if GetVariable("treant_pause") == "1" then
  422.     return true
  423.   end
  424.  
  425.   return false
  426. end
  427.  
  428.  
  429.  
  430. --[[
  431. Internal functions not really intended to be used by the end user
  432. --]]
  433.  
  434. function treant:command(...)
  435.   local gag = false
  436.   if my_gag then
  437.     if my_gag[...] then
  438.       gag = true
  439.     else
  440.       local cmd = table.concat{...}
  441.       for _,g in ipairs(my_gag) do
  442.         if string.find(cmd, g) then
  443.           gag = true
  444.           break
  445.         end
  446.       end
  447.     end
  448.   end
  449.  
  450.   if gag then
  451.     SendNoEcho(...)
  452.   else
  453.     Send(...)
  454.   end
  455. end
  456.  
  457. -- Sipping mana, health, or bromides
  458. function treant:sip_heal(name)
  459.   bals:lose("health")
  460.  
  461.   flags:set("elixir", name, 0)
  462.   flags:clear("health_applying")
  463.  
  464.   -- Uses a special failsafe to handle the application of health
  465.   local time = 2
  466.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  467.     time = 4
  468.   end
  469.   failsafe:exec("health", time)
  470.  
  471.   treant:command("sip ", name)
  472. end
  473.  
  474. -- Sipping any purgative elixir
  475. function treant:sip_purgative(name)
  476.   bals:lose("purgative", 2)
  477.  
  478.   flags:set("elixir", name, 0)
  479.  
  480.   local time = 2
  481.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  482.     time = 4
  483.   end
  484.   failsafe:exec("purgative", time)
  485.  
  486.   treant:command("sip ", name)
  487. end
  488.  
  489. -- Sipping tea (how British of you)
  490. function treant:sip_tea(name)
  491.   flags:set("tea_try", true, 2)
  492.  
  493.   local time = 2
  494.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  495.     time = 4
  496.   end
  497.   failsafe:exec("tea", time)
  498.  
  499.   if name == "green" or name == "oolong" or name == "white" or name == "black" then
  500.     name = name .. "tea"
  501.   end
  502.   flags:set("elixir", name, 0)
  503.  
  504.   treant:command("sip ", name)
  505. end
  506.  
  507. -- Sipping allheale elixir
  508. function treant:sip_allheale()
  509.   bals:lose("allheale", 2)
  510.  
  511.   flags:set("elixir", "allheale", 0)
  512.  
  513.   treant:command("sip allheale")
  514. end
  515.  
  516. -- Sipping quicksilver elixir
  517. function treant:sip_quicksilver()
  518.   flags:set("elixir", "quicksilver", 0)
  519.   flags:set("speed_try", true, 2)
  520.  
  521.   -- Uses a special failsafe because quicksilver uses no real balance
  522.   failsafe:exec("quicksilver", 2)
  523.  
  524.   treant:command("sip quicksilver")
  525. end
  526.  
  527. -- Using adrenaline instead of quicksilver
  528. function treant:adrenaline()
  529.   flags:set("speed_try", true, 2)
  530.  
  531.   failsafe:exec("adrenaline", 2)
  532.  
  533.   treant:command("adrenaline")
  534. end
  535.  
  536. -- Sipping moonwater
  537. function treant:sip_moonwater()
  538.   flags:set("elixir", "moonwater", 0)
  539.   flags:set("moonwater_try", true, 2)
  540.  
  541.   -- Uses a special failsafe because moonwater uses no real balance
  542.   failsafe:exec("moonwater", 2)
  543.  
  544.   treant:command("sip moonwater")
  545. end
  546.  
  547. -- Sipped any elixir
  548. function treant:sipped(vial)
  549.   local elixir = vial_map[vial] or flags:get("elixir") or "unknown"
  550.   display.Debug("Sipped " .. elixir)
  551.  
  552.   EnableGroup("Treant_Sipping", true)
  553.  
  554.   if string.find("health mana bromide", elixir) then
  555.     if bals:confirm("health", 8) then
  556.       failsafe:disable("health")
  557.       flags:set("last_cure", "sip " .. elixir, 0)
  558.     end
  559.   elseif elixir == "allheale" then
  560.     if bals:confirm("allheale", 25) then
  561.       affs:del("allheale")
  562.       flags:clear("allheale")
  563.       flags:set("last_cure", "sip allheale", 0)
  564.       treant:cures_on()
  565.     end
  566.   elseif string.find("antidote choleric fire frost galvanism love phlegmatic sanguine", elixir) then
  567.     if bals:confirm("purgative", 4) then
  568.       affs:del(elixir)
  569.       failsafe:disable("purgative")
  570.       flags:set("last_cure", "sip " .. elixir, 0)
  571.       treant:cures_on()
  572.     end
  573.   elseif elixir == "quicksilver" then
  574.     if flags:get("speed_try") then
  575.       flags:clear("speed_try")
  576.       flags:set("waiting_for_speed", true, 0)
  577.       failsafe:exec("wait for speed", 7)
  578.     end
  579.   elseif string.find("blacktea greentea oolongtea teapot whitetea", elixir) then
  580.     if flags:get("tea_try") then
  581.       queue:add(function () flags:clear("tea_try") end)
  582.     end
  583.   end
  584.  
  585.   flags:clear("elixir")
  586.   scan:add("elixir")
  587.  
  588.   treant:poisons_on()
  589. end
  590.  
  591. -- Applying a health potion to heal deep wounds
  592. function treant:apply_health(part)
  593.   bals:lose("health")
  594.  
  595.   flags:set("health_applying", part, 0)
  596.  
  597.   -- Uses a special failsafe to handle the application of health
  598.   local time = 2
  599.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  600.     time = 4
  601.   end
  602.   failsafe:exec("health", time)
  603.  
  604.   treant:command("apply", " health to ", part)
  605. end
  606.  
  607. -- Health potion applied successfully
  608. function treant:applied_health(part)
  609.   if bals:confirm("health", 8) then
  610.     flags:set("last_cure", "apply health to " .. part, 0)
  611.     treant:cures_on()
  612.  
  613.     failsafe:disable("health")
  614.  
  615.     -- Looks for the 'no discernable effect' line to reset balance
  616.     EnableTrigger("healthappfailed__", true)
  617.     queue:add(function () EnableTrigger("healthappfailed__", false) end)
  618.   end
  619. end
  620.  
  621. -- Eating any herb
  622. function treant:eat_herb(name)
  623.   name = string.lower(name)
  624.   if name == (GetVariable("treant_option_sparkle") or "sparkleberry") then
  625.     bals:lose("sparkle", 2)
  626.   end
  627.  
  628.   if name ~= "rawtea" and name ~= "sparkleberry" then
  629.     bals:lose("herb", 2)
  630.   end
  631.  
  632.   if GetVariable("treant_option_antistupid") == "1" and
  633.      name == "pennyroyal" and affs:has("stupidity") and
  634.      not (affs:has("choke") or affs:has("aeon") or affs:has("sap")) then
  635.     treant:command("outr ", name)
  636.     treant:command("outr ", name)
  637.     treant:command("eat ", name)
  638.     treant:command("inr ", name)
  639.     treant:command("eat ", name)
  640.     treant:command("inr ", name)
  641.     return
  642.   end
  643.  
  644.   Send("outr ", name)
  645.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  646.     flags:set("to_eat", name, 0)
  647.     EnableTrigger("eat_now__", true)
  648.   else
  649.     treant:command("eat ", name)
  650.   end
  651. end
  652.  
  653. -- Herb has been eaten
  654. function treant:ate_herb(name)
  655.   local herb
  656.   if name == "a calamus root" then
  657.     herb = "calamus"
  658.   elseif name == "a sprig of chervil" then
  659.     herb = "chervil"
  660.   elseif name == "a plug of coltsfoot" then
  661.     herb = "coltsfoot"
  662.   elseif name == "a piece of black earwort" then
  663.     herb = "earwort"
  664.   elseif name == "a stalk of faeleaf" then
  665.     herb = "faeleaf"
  666.   elseif name == "a stem of galingale" then
  667.     herb = "galingale"
  668.   elseif name == "a horehound blossom" then
  669.     herb = "horehound"
  670.   elseif name == "a kafe bean" then
  671.     herb = "kafe"
  672.   elseif name == "kombu seaweed" then
  673.     herb = "kombu"
  674.   elseif name == "a sprig of marjoram" then
  675.     herb = "marjoram"
  676.   elseif name == "a piece of merbloom seaweed" then
  677.     herb = "merbloom"
  678.   elseif name == "a bog myrtle leaf" then
  679.     herb = "myrtle"
  680.   elseif name == "a bunch of pennyroyal" then
  681.     herb = "pennyroyal"
  682.   elseif name == "raw tea leaves" then
  683.     herb = "rawtea"
  684.   elseif name == "a reishi mushroom" then
  685.     herb = "reishi"
  686.   elseif name == "a sparkleberry" then
  687.     herb = "sparkleberry"
  688.   elseif name == "a wormwood stem" then
  689.     herb = "wormwood"
  690.   elseif name == "a yarrow sprig" then
  691.     herb = "yarrow"
  692.   end
  693.  
  694.   if herb then
  695.     if herb == (GetVariable("treant_option_sparkle") or "sparkleberry") then
  696.       if bals:confirm("sparkle", 10) then
  697.         EnableTrigger("sparkleberry_healing__", true)
  698.         queue:add(function () EnableTrigger("sparkleberry_healing__", false) end)
  699.       end
  700.     end
  701.  
  702.     if herb ~= "sparkleberry" and herb ~= "rawtea" and bals:confirm("herb") then
  703.       affs:del(herb)
  704.       flags:set("last_cure", "eat " .. herb, 0)
  705.       treant:cures_on()
  706.     end
  707.   end
  708. end
  709.  
  710. -- Took a drag off a pipe
  711. function treant:smoked_herb(name)
  712.   if not name then
  713.     display.Debug("What are you smoking?")
  714.     return
  715.   end
  716.  
  717.   if name == "faeleaf" then
  718.     if affs:has("coils") then
  719.       if bals:confirm("herb", 8) then
  720.         affs:del("smoke_faeleaf")
  721.         flags:set("last_cure", "smoke faeleaf", 0)
  722.         treant:cures_on()
  723.       end
  724.     elseif not defs:has("rebounding") then
  725.       flags:set("aura_timer", true, 0)
  726.       failsafe:exec("rebounding", 8, true)
  727.     end
  728.   elseif name == "myrtle" then
  729.     if bals:confirm("herb", 8) then
  730.       affs:del("smoke_myrtle")
  731.       flags:set("last_cure", "smoke myrtle", 0)
  732.       treant:cures_on()
  733.  
  734.       if affs:has("phrenic_nerve") then
  735.         flags:set("phrenic_smoke", (flags:get("phrenic_smoke") or 0) + 1, 0)
  736.       end
  737.     end
  738.   elseif name == "coltsfoot" then
  739.     if bals:confirm("herb", 8) then
  740.       affs:del("smoke_coltsfoot")
  741.       flags:set("last_cure", "smoke coltsfoot", 0)
  742.       treant:cures_on()
  743.     end
  744.   end
  745.  
  746.   if not flags:get("arena") then
  747.     pipes:puffs(name, pipes:puffs(name) - 1)
  748.  
  749.     -- Check pipes that need to be refilled
  750.     if pipes:puffs(name) <= 0 then
  751.       pipes:maintain()
  752.     end
  753.   end
  754.  
  755.   flags:clear("smoking")
  756. end
  757.  
  758. -- Apply arnica where needed
  759. function treant:apply_arnica(part)
  760.   bals:lose("herb", 2)
  761.  
  762.   if GetVariable("treant_option_antistupid") == "1" and
  763.      affs:has("fractured_skull") and
  764.      not (affs:has("choke") or affs:has("aeon") or affs:has("sap")) then
  765.     treant:command("outr arnica")
  766.     treant:command("outr arnica")
  767.     treant:command("apply arnica to head")
  768.     treant:command("inr arnica")
  769.     treant:command("apply arnica to head")
  770.     treant:command("inr arnica")
  771.     return
  772.   end
  773.  
  774.   treant:command("outr arnica")
  775.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  776.     flags:set("to_apply", "arnica to " .. part, 0)
  777.     EnableTrigger("apply_now__", true)
  778.   else
  779.     treant:command("apply arnica to ", part)
  780.   end
  781. end
  782.  
  783. -- Arnica applied successfully
  784. function treant:applied_arnica(part)
  785.   if bals:confirm("herb", 8) then
  786.     affs:del("arnica_" .. part)
  787.     flags:set("last_cure", "apply arnica " .. part, 0)
  788.     treant:cures_on()
  789.   end
  790. end
  791.  
  792. -- Apply salve where needed
  793. function treant:apply_salve(name, part)
  794.   bals:lose("salve")
  795.  
  796.   flags:set("salve", name, 0)
  797.  
  798.   if name == "regeneration" then
  799.     flags:set("regenerating_" .. part, true, 0)
  800.   end
  801.  
  802.   -- Salves use a special failsafe to handle regeneration properly
  803.   local time = 2
  804.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  805.     time = 4
  806.   end
  807.   failsafe:exec("salve", time)
  808.  
  809.   if part then
  810.     flags:set("applied_to", part)
  811.     treant:command("apply ", name, " to ", part)
  812.   else
  813.     treant:command("apply ", name)
  814.   end
  815. end
  816.  
  817. -- Salve applied successfully
  818. function treant:applied_salve(part)
  819.   if bals:confirm("salve", 8) then
  820.     if flags:get("salve") ~= "regeneration" then
  821.       affs:del(flags:get("salve") .. "_" .. part)
  822.       flags:set("last_cure", "apply " .. flags:get("salve") .. " to " .. part, 0)
  823.       treant:cures_on()
  824.     else
  825.       affs:del("regen_" .. part)
  826.       failsafe:exec("regeneration_" .. part, 7, true)
  827.     end
  828.  
  829.     flags:set("applied", flags:get("salve"))
  830.     flags:clear("salve")
  831.  
  832.     failsafe:disable("salve")
  833.  
  834.     -- Looks for the 'no discernable effect' line to reset balance
  835.     EnableTrigger("salvefailed__", true)
  836.     queue:add(function () EnableTrigger("salvefailed__", false) end)
  837.   end
  838. end
  839.  
  840. -- Cleansing away some nasty affliction
  841. function treant:cleanse()
  842.   local time = 2
  843.   if affs:has("aeon") or affs:has("sap") or affs:has("choke") then
  844.     time = 4
  845.   end
  846.   flags:set("cleanse_try", true, 0)
  847.   failsafe:exec("cleanse", time)
  848.  
  849.   if GetVariable("treant_option_cleanse") == "soap" then
  850.     treant:command("scrub")
  851.   elseif GetVariable("treant_option_cleanse") == "cast" then
  852.     treant:command("cast cleanse me")
  853.   else
  854.     treant:command("rub cleanse")
  855.   end
  856. end
  857.  
  858. -- Igniting yourself to remove thorns is painful but sometimes necessary
  859. function treant:ignite()
  860.   local time = 2
  861.   if affs:has("aeon") or affs:has("sap") or affs:has("choke") then
  862.     time = 4
  863.   end
  864.   flags:set("ignite_try", true, 0)
  865.   failsafe:exec("ignite", time)
  866.  
  867.   treant:command("point ignite at me")
  868. end
  869.  
  870. -- Focusing body/mind/spirit
  871. function treant:focus(bms)
  872.   bals:lose("focus", 2)
  873.  
  874.   treant:command("focus ", bms)
  875. end
  876.  
  877. -- Successfully focused body/mind/spirit
  878. function treant:focused(bms)
  879.   if bals:confirm("focus", 5) then
  880.     affs:del("focus_" .. bms)
  881.     if string.find("mind spirit", bms) then
  882.       flags:set("last_cure", "focus " .. bms, 0)
  883.       treant:cures_on()
  884.     else
  885.       flags:set("focusing", "body", 4)
  886.       flags:clear({ "sap_try", "choke_try" })
  887.     end
  888.   end
  889. end
  890.  
  891. -- Successfully focused body out of paralysis
  892. function treant:focused_body()
  893.   if flags:get("focusing") then
  894.     flags:clear("focusing")
  895.     affs:del("paralysis")
  896.     bals:gain("focus")
  897.   end
  898. end
  899.  
  900. -- Rubbing a focus enchantment to heal debate afflictions
  901. function treant:rub_focus()
  902.   bals:lose("charm", 2)
  903.  
  904.   treant:command("rub focus")
  905. end
  906.  
  907. -- Successfully rubbed a focus enchantment
  908. function treant:rubbed_focus()
  909.   if bals:confirm("charm", 7) then
  910.     affs:del("focus")
  911.     flags:set("last_cure", "rub focus")
  912.     treant:cures_on()
  913.   end
  914. end
  915.  
  916. -- Read a healing scroll now
  917. function treant:scroll_heal(tome)
  918.   bals:lose("scroll", 2)
  919.  
  920.   if tome then
  921.     treant:command("read magictome healing")
  922.     flags:set("tome", "healing", 4)
  923.     return
  924.   end
  925.  
  926.   local id = GetVariable("treant_scroll_healing_id")
  927.   if not id then
  928.     display.Error("No healing scroll found. Either check MagicList or disable auto-scroll.")
  929.     return
  930.   end
  931.  
  932.   local charges = tonumber(GetVariable("treant_scroll_healing_charges") or "0")
  933.   if charges <= 1 then
  934.     display.Alert("Healing scroll has one charge left. Recharge it!")
  935.     return
  936.   end
  937.  
  938.   treant:command("read ", id)
  939. end
  940.  
  941. -- Healing scroll has been read
  942. function treant:scroll_healed()
  943.   bals:confirm("scroll", 12)
  944.   magic:use_charge("healing")
  945. end
  946.  
  947. -- Auto-diagnose, if enabled
  948. function treant:diag()
  949.   if GetVariable("treant_option_diagnose") == "1" then
  950.     flags:set("diagnose", true, 0)
  951.     scan:add("balance")
  952.   elseif GetVariable("treant_option_diagnose") == "2" then
  953.     flags:set("succor", true, 0)
  954.     scan:add("balance")
  955.   end
  956. end
  957.  
  958. -- Turns active cure triggers on now, off at the next prompt
  959. function treant:cures_on()
  960.   display.Debug("Active cures enabled")
  961.   EnableGroup("Treant_Cures", true)
  962. end
  963.  
  964. -- Enable all poison affliction triggers
  965. --  If the source is a darts trap, leave the triggers on for about a minute
  966. function treant:poisons_on(darts)
  967.   display.Debug("Poison afflictions enabled")
  968.   EnableGroup("Treant_Poisons", true)
  969.   if darts then
  970.     EnableAlias("poisons_prompt__", false)
  971.     EnableTimer("poison_darts__", true)
  972.     ResetTimer("poison_darts__")
  973.   end
  974. end
  975.  
  976. -- Enable the modifier triggers for a kata specialization
  977. function treant:kata_mods(skill)
  978.   if not skill then
  979.     display.Error("Invalid skill provided to treant:kata_mods")
  980.     return
  981.   end
  982.  
  983.   if type(skill) == "table" then
  984.     for _,sk in pairs(skill) do
  985.       treant:kata_mods(sk)
  986.     end
  987.     return
  988.   end
  989.  
  990.   EnableGroup("Treant_" .. skill .. "Mods", true)
  991.   EnableGroup("Treant_KataMods", true)
  992. end
  993.  
  994. -- Clot failsafe
  995. function treant:clot()
  996.   flags:set("clot_try", true, 0)
  997.   local time = 1
  998.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  999.     time = 3
  1000.   end
  1001.   failsafe:exec("clot", time)
  1002.   treant:command("clot")
  1003. end
  1004.  
  1005. -- Concentration failsafe
  1006. function treant:concentrate()
  1007.   flags:set("concentrate_try", true, 0)
  1008.   local time = 1
  1009.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  1010.     time = 3
  1011.   end
  1012.   failsafe:exec("concentrate", time)
  1013.   treant:command("concentrate")
  1014. end
  1015.  
  1016. -- Insomnia failsafe
  1017. function treant:insomnia()
  1018.   flags:set("insomnia_try", true, 0)
  1019.   local time = 1
  1020.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  1021.     time = 3
  1022.   end
  1023.   failsafe:exec("insomnia", time)
  1024.   treant:command("insomnia")
  1025. end
  1026.  
  1027. -- Nightsight failsafe
  1028. function treant:nightsight()
  1029.   flags:set("nightsight_try", true, 0)
  1030.   failsafe:exec("nightsight", 2)
  1031.   treant:command("nightsight")
  1032. end
  1033.  
  1034. -- Stand up now!
  1035. function treant:stand()
  1036.   flags:set("stand_try", true, 0)
  1037.   local time = 1
  1038.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  1039.     time = 3
  1040.   end
  1041.   failsafe:exec("stand", time)
  1042.   local s = "stand"
  1043.   if GetVariable("treant_option_springup") == "1" then
  1044.     s = "springup"
  1045.   end
  1046.   treant:command(s)
  1047. end
  1048.  
  1049. -- Successfully standing up
  1050. function treant:standing()
  1051.   if flags:get("stand_try") then
  1052.     failsafe:disable("stand")
  1053.     flags:clear("stand_try")
  1054.     affs:del("prone")
  1055.  
  1056.     affs:scan()
  1057.     defs:scan()
  1058.     todo:scan()
  1059.   end
  1060. end
  1061.  
  1062. -- Wake up now!
  1063. function treant:wake()
  1064.   flags:set("wake_try", true, 0)
  1065.   if affs:has("choke") then
  1066.     failsafe:exec("wake", 2)
  1067.   else
  1068.     failsafe:exec("wake", 1)
  1069.   end
  1070.   treant:command("wake")
  1071. end
  1072.  
  1073. -- Successfully waking up
  1074. function treant:waking()
  1075.   if flags:get("wake_try") then
  1076.     failsafe:disable("wake")
  1077.     flags:clear("wake_try")
  1078.     flags:set("waking", true, 0)
  1079.   end
  1080. end
  1081.  
  1082. -- Finally woke up
  1083. function treant:awake(insom)
  1084.   if flags:get("waking") then
  1085.     flags:clear({ "wake_try", "waking" })
  1086.     affs:del("asleep")
  1087.     if insom then
  1088.       defs:del("insomnia")
  1089.     end
  1090.   end
  1091.   affs:prone()
  1092. end
  1093.  
  1094. -- Writhe out of entanglements
  1095. function treant:writhe(name)
  1096.   flags:set("writhe_try", name or true, 0)
  1097.   local time = 2
  1098.   if affs:has("choke") or affs:has("aeon") or affs:has("sap") then
  1099.     time = 4
  1100.   end
  1101.   failsafe:exec("writhe", time)
  1102.   local w = "writhe"
  1103.   if GetVariable("treant_option_contort") == "1" then
  1104.     w = "contort"
  1105.   end
  1106.   if name then
  1107.     treant:command(w, " ", name)
  1108.   else
  1109.     treant:command(w)
  1110.   end
  1111. end
  1112.  
  1113. -- Successfully writhing
  1114. function treant:writhing()
  1115.   if flags:get("writhe_try") then
  1116.     failsafe:disable("writhe")
  1117.     flags:clear("writhe_try")
  1118.     flags:set("writhing", true, 6)
  1119.   end
  1120. end
  1121.  
  1122. -- Successfully writhing from impalements
  1123. function treant:writhing_impale()
  1124.   if flags:get("writhe_try") then
  1125.     failsafe:disable("writhe")
  1126.     flags:clear("writhe_try")
  1127.     flags:set("writhing_impale", (flags:get("writhing_impale") or 0) + 1, 6)
  1128.   end
  1129. end
  1130.  
  1131. -- Climb down from the trees unless we want to be in the trees
  1132. function treant:no_trees()
  1133.   flags:set("in_trees", true, 0)
  1134.   if GetVariable("treant_option_notrees") == "1" then
  1135.     flags:set("climb_down", true, 0)
  1136.     flags:clear("climbing_down")
  1137.     scan:add("balance")
  1138.   end
  1139. end
  1140.  
  1141. -- Climb up out of a pit when you fall in
  1142. function treant:pitfall()
  1143.   flags:set("climb_up", true, 0)
  1144.   flags:clear("climbing_up")
  1145.  
  1146.   if not defs:has("levitating") then
  1147.     affs:limb("left", "leg", "broken")
  1148.     affs:limb("right", "leg", "broken")
  1149.   end
  1150.  
  1151.   stance:scan()
  1152.   parry:scan()
  1153.  
  1154.   scan:add({ "balance", "general" })
  1155. end
  1156.  
  1157. -- Interfacing function for actually doing the climbing up/down
  1158. function treant:climb(dir)
  1159.   flags:set("climb_try", dir, 0)
  1160.   if flags:get("climb_" .. dir) then
  1161.     failsafe:exec("climb", 1)
  1162.   end
  1163.   treant:command("climb " .. dir)
  1164. end
  1165.  
  1166. -- Function for getting out of entanglements quickly, if configured
  1167. function treant:fastwrithe()
  1168.   local fw = string.lower(GetVariable("treant_option_fastwrithe") or "off")
  1169.  
  1170.   flags:set("fastwrithe", fw, 2)
  1171.   if fw == "summer" then
  1172.     Send("invoke summer")
  1173.   else
  1174.     Send("evoke tipheret")
  1175.   end
  1176. end
  1177.  
  1178. -- Check arms or legs for any unknown afflictions that need to be diagnosed
  1179. function treant:check_limbs(limbs)
  1180.   -- If auto-diagnose is off, this is unnecessary
  1181.   if GetVariable("treant_option_diagnose") ~= "1" then
  1182.     return
  1183.   end
  1184.  
  1185.   -- Check conditions on arms or legs?
  1186.   if limbs == "arms" then
  1187.     if affs:has("hemiplegy_left") or
  1188.        affs:has("hemiplegy_right") or
  1189.        affs:has("clamped_left") or
  1190.        affs:has("clamped_right") or
  1191.        affs:limb("left", "arm") ~= "healthy" or
  1192.        affs:limb("right", "arm") ~= "healthy" or
  1193.        affs.grapples["leftarm"] or
  1194.        affs.grapples["rightarm"] then
  1195.       return
  1196.     end
  1197.   else
  1198.     if affs:has("tendon_left") or
  1199.        affs:has("tendon_right") or
  1200.        affs:has("hemiplegy_left") or
  1201.        affs:has("hemiplegy_right") or
  1202.        affs:has("hemiplegy_legs") or
  1203.        affs:limb("left", "leg") ~= "healthy" or
  1204.        affs:limb("right", "leg") ~= "healthy" or
  1205.        affs.grapples["leftleg"] or
  1206.        affs.grapples["rightleg"] then
  1207.       return
  1208.     end
  1209.   end
  1210.  
  1211.   treant:diag()
  1212. end
  1213.  
  1214. -- Handling of the Maestoso effect from Music's Octave, preventing certain cures
  1215. function treant:maestoso(caster)
  1216.   if caster then
  1217.     flags:set("maestoso_caster", string.lower(caster), 180)
  1218.   elseif not flags:get("maestoso") then
  1219.     flags:set("maestoso", true, 0)
  1220.     failsafe:exec("maestoso", tonumber(GetVariable("treant_option_maestoso") or "15"))
  1221.   end
  1222. end
  1223.  
  1224. -- Gag the prompt, for anyone who needs to decorate and re-echo it or just to keep the spam down
  1225. function treant:gag_prompt()
  1226.   flags:set("no_prompt", true, 0)
  1227. end
  1228.  
  1229. function treant:prefix(fn)
  1230.   self.pre = self.pre or {}
  1231.   table.insert(self.pre, fn)
  1232. end
  1233.  
  1234. function treant:suffix(fn)
  1235.   self.suff = self.suff or {}
  1236.   table.insert(self.suff, fn)
  1237. end
  1238.  
  1239. function treant_prompt_decorate(name, line, wildcards, styles)
  1240.   -- Process health, mana, ego, power, endurance, willpower, and flags
  1241.   prompt:capture(tonumber(wildcards[1]), tonumber(wildcards[2]), tonumber(wildcards[3]), tonumber(wildcards[4]),
  1242.     tonumber(wildcards[5]), tonumber(wildcards[6]), wildcards[7])
  1243.  
  1244.   -- Just want to gag this prompt entirely
  1245.   if flags:get("no_prompt") then
  1246.     flags:clear("no_prompt")
  1247.     return
  1248.   end
  1249.  
  1250.   -- Prefix functions evaluated first
  1251.   for _,fn in ipairs(treant.pre or {}) do
  1252.     fn()
  1253.   end
  1254.   treant.pre = nil
  1255.  
  1256.   -- Display text as it was captured
  1257.   for _, v in ipairs(styles) do
  1258.     if v.text ~= wildcards[7] then
  1259.       ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), v.text)
  1260.     end
  1261.   end
  1262.  
  1263.   -- Color the prompt flags based on balance status
  1264.   if bals:can_act() then
  1265.     ColourTell(GetVariable("treant_prompt_onbal") or "yellowgreen", "", wildcards[7])
  1266.   else
  1267.     ColourTell(GetVariable("treant_prompt_offbal") or "darkolivegreen", "", wildcards[7])
  1268.   end
  1269.  
  1270.   -- Display the most important alert status (stunned, locked, etc)
  1271.   if prompt.alert then
  1272.     ColourTell("purple", "", " [", "red", "", prompt.alert, "purple", "", "]")
  1273.   end
  1274.  
  1275.   -- Suffix functions evaluated last
  1276.   for _,fn in ipairs(treant.suff or {}) do
  1277.     fn()
  1278.   end
  1279.   treant.suff = nil
  1280.  
  1281.   Note("")
  1282. end
  1283.  
  1284. -- Checking whether or not we're really dead
  1285. function treant:dead()
  1286.   EnableTimer("death_failsafe__", true)
  1287. end
  1288.  
  1289. function treant:telepathy()
  1290.   local pc = flags:get("prone_check")
  1291.   if pc and string.find(prompt.fl, "p") then
  1292.     return
  1293.   end
  1294.  
  1295.   treant:diag()
  1296.  
  1297.   flags:set("telepathy", tonumber(flags:get("telepathy") or "0") + 1, 4)
  1298.   local plural = ""
  1299.   if flags:get("telepathy") > 1 then
  1300.     plural = "s"
  1301.     flags:set("allheale", true, 0)
  1302.     scan:add("elixir")
  1303.   end
  1304.   display.Alert("Hit by " .. flags:get("telepathy") .. " telepathy affliction" .. plural)
  1305. end
  1306.  
  1307. function treant:charybdon()
  1308.   flags:set("charybdon", true)
  1309.   prompt:queue(function () if flags:get("charybdon") then treant:diag() end end)
  1310.   treant:poisons_on()
  1311. end
  1312.  
  1313. function treant:max_health()
  1314.   local hm = tonumber(GetVariable("treant_health_max") or "0")
  1315.   if affs:has("illusory_wounds") then
  1316.     hm = hm * 2 / 3
  1317.     if prompt.health > hm then
  1318.       affs:del("illusory_wounds")
  1319.     end
  1320.   end
  1321.   return hm
  1322. end
  1323.  
  1324. function treant:max_mana()
  1325.   return tonumber(GetVariable("treant_mana_max") or "0")
  1326. end
  1327.  
  1328. function treant:max_ego()
  1329.   return tonumber(GetVariable("treant_ego_max") or "0")
  1330. end
  1331.  
  1332. -- Turn automatic systems on/off
  1333. --  Passing in a name with no value simply retrieves the current value
  1334. function treant:auto(name, val)
  1335.   if val ~= nil then
  1336.     SetVariable("treant_auto_" .. name, tostring(val))  -- Stored in the world for persistence
  1337.  
  1338.     local enabled = "DISABLED"
  1339.     if treant:auto(name) then
  1340.       enabled = "ENABLED"
  1341.     end
  1342.     display.Info("Auto " .. name .. " " .. enabled)
  1343.  
  1344.     affs:scan()
  1345.     defs:scan()
  1346.   end
  1347.  
  1348.   return GetVariable("treant_auto_" .. name) == "true"
  1349. end
  1350.  
  1351. -- Display automatic systems status
  1352. function treant:show_auto(nocr)
  1353.   display.Info("Automatic Systems Report:")
  1354.  
  1355.   local autos = {
  1356.     ["Healing"] = { "sipping", "sparkle", "scroll" },
  1357.     ["Defenses"] = { "insomnia", "kafe", "metawake", "fire", "frost", "sixthsense", "truehearing",
  1358.                      "lusting", "selfish", "speed", "rebounding", "breathing", "parry", "stance" },
  1359.     ["Miscellaneous"] = { "pipes" }
  1360.   }
  1361.  
  1362.   -- Configure for pseudo-acquisitio addon
  1363.   if IsTrigger("acquire_killed__") == 0 then
  1364.     table.insert(autos["Miscellaneous"], "acquire")
  1365.   end
  1366.  
  1367.   -- Configure for Herbs skill
  1368.   if IsTrigger("herbs_growing__") == 0 then
  1369.     table.insert(autos["Miscellaneous"], "herbs")
  1370.   end
  1371.  
  1372.   -- Configure for influencing add-in
  1373.   if IsAlias("influence__") == 0 then
  1374.     table.insert(autos["Miscellaneous"], "influence")
  1375.   end
  1376.  
  1377.   -- Configure for auto-raze script
  1378.   if IsAlias("autoraze_target__") == 0 then
  1379.     table.insert(autos["Miscellaneous"], "raze")
  1380.   end
  1381.  
  1382.   -- Configure for debating add-in
  1383.   if IsTrigger("debate_mindset1__") == 0 then
  1384.     table.insert(autos["Miscellaneous"], "mindset")
  1385.     table.insert(autos["Miscellaneous"], "debate")
  1386.   end
  1387.  
  1388.   for cat,list in pairs(autos) do
  1389.     display.Prefix()
  1390.     ColourNote("cyan", "", " " .. cat)
  1391.  
  1392.     for _,a in pairs(list) do
  1393.       display.Prefix()
  1394.       ColourTell("darkgray", "", "   [")
  1395.       if treant:auto(a) then
  1396.         ColourTell("yellow", "", "X")
  1397.       else
  1398.         Tell(" ")
  1399.       end
  1400.       ColourTell("darkgray", "", "] ")
  1401.       ColourNote("darkcyan", "", a)
  1402.     end
  1403.   end
  1404.  
  1405.   -- T are speshul
  1406.   display.Prefix()
  1407.   ColourTell("darkgray", "", "   [")
  1408.   if treant:auto("tea") then
  1409.     local tea = GetVariable("treant_option_tea") or "tea"
  1410.     ColourTell("yellow", "", "X")
  1411.     ColourTell("darkgray", "", "] ")
  1412.     ColourNote("darkcyan", "", "tea - " .. tea)
  1413.   else
  1414.     Tell(" ")
  1415.     ColourTell("darkgray", "", "] ")
  1416.     ColourNote("darkcyan", "", "tea")
  1417.   end
  1418.  
  1419.   if IsConnected() and not nocr then
  1420.     Send("")
  1421.   end
  1422. end
  1423.  
  1424. -- Display helpful information on how to configure the system
  1425. function treant:config_help()
  1426.   local options = php:Table()
  1427.   options["TCONFIG SKILLS"] = {
  1428.     ["info"] = "Checks your skills and automatically installs available scripts"
  1429.   }
  1430.   options["TCONFIG DIAGNOSE <ON/OFF/SUCCOR>"] = {
  1431.     ["info"] = "Toggle the automatic diagnosing of afflictions in certain situations",
  1432.     ["value"] = function () if GetVariable("treant_option_diagnose") == "1" then return "ON" elseif GetVariable("treant_option_diagnose") == "2" then return "SUCCOR" end return "OFF" end
  1433.   }
  1434.   options["TCONFIG NOTREES <ON/OFF>"] = {
  1435.     ["info"] = "Toggle automatically climbing down from trees in a druid's demesne",
  1436.     ["value"] = function () if GetVariable("treant_option_notrees") == "1" then return "ON" end return "OFF" end
  1437.   }
  1438.   options["TCONFIG PIPES <ARTIFACT/STANDARD>"] = {
  1439.     ["info"] = "Using a full set of artifact pipes means never having to light them",
  1440.     ["value"] = function () if GetVariable("treant_option_artipipes") == "1" then return "ARTIFACT" end return "STANDARD" end
  1441.   }
  1442.   options["TCONFIG SETPIPE <herb> <#> [<# puffs>]"] = {
  1443.     ["info"] = "Manually setup pipe number for an herb with optional number of puffs remaining"
  1444.   }
  1445.   options["TCONFIG MAXPUFFS <#>"] = {
  1446.     ["info"] = "Set the maximum number of puffs a pipe can hold",
  1447.     ["value"] = function () return GetVariable("treant_option_maxpuffs") or "10" end
  1448.   }
  1449.   options["TCONFIG THORNS <#>"] = {
  1450.     ["info"] = "Given 0, it will writhe from thorns. Given 1-4, it will ignite after that many thorns",
  1451.     ["value"] = function () return GetVariable("treant_option_thorns") or "0" end
  1452.   }
  1453.   options["TCONFIG SPARKLE <herb>"] = {
  1454.     ["info"] = "May use the Nature Domoth herb instead of sparkleberry",
  1455.     ["value"] = function () return string.upper(GetVariable("treant_option_sparkle") or "sparkleberry") end
  1456.   }
  1457.   options["TCONFIG MAGICTOME <ON/OFF>"] = {
  1458.     ["info"] = "Read the healing scroll from a magic tome",
  1459.     ["value"] = function () if GetVariable("treant_option_magictome") == "1" then return "ON" end return "OFF" end
  1460.   }
  1461.   options["TCONFIG CONTORT <ON/OFF>"] = {
  1462.     ["info"] = "Use Acrobatics Contort to writhe out of entanglements",
  1463.     ["value"] = function () if GetVariable("treant_option_contort") == "1" then return "ON" end return "OFF" end
  1464.   }
  1465.   options["TCONFIG SPRINGUP <ON/OFF>"] = {
  1466.     ["info"] = "Use Acrobatics Springup to stand up",
  1467.     ["value"] = function () if GetVariable("treant_option_springup") == "1" then return "ON" end return "OFF" end
  1468.   }
  1469.   options["TCONFIG DEATHMARK <#>"] = {
  1470.     ["info"] = "Cure the deathmark after the count reaches this number (1-15). To disable, use 0",
  1471.     ["value"] = function () return GetVariable("treant_option_deathmark") or "14" end
  1472.   }
  1473.   options["TCONFIG CLEANSE <SOAP/CAST/RUB>"] = {
  1474.     ["info"] = "Cleansing will use artifact soap, elemental spell, or enchanted item",
  1475.     ["value"] = function () return string.upper(GetVariable("treant_option_cleanse") or "RUB") end
  1476.   }
  1477.   options["TCONFIG FASTWRITHE <SUMMER/TIPHERET/OFF> <#>"] = {
  1478.     ["info"] = "Will use Summer or Tipheret after a number of concurrent entanglements",
  1479.     ["value"] = function ()
  1480.                   local v = string.upper(GetVariable("treant_option_fastwrithe") or "off")
  1481.                   if v ~= "OFF" then
  1482.                     v = v .. " " .. (GetVariable("treant_option_fastwrithe_n") or "2")
  1483.                   end
  1484.                   return v
  1485.                 end
  1486.   }
  1487.   options["TCONFIG ADRENALINE <ON/OFF>"] = {
  1488.     ["info"] = "Enable the use of adrenaline in addition to quicksilver",
  1489.     ["value"] = function () if GetVariable("treant_option_adrenaline") == "1" then return "ON" end return "OFF" end
  1490.   }
  1491.  
  1492.   display.Info("Treant Configuration Options:")
  1493.   for k,v in options:pairs() do
  1494.     display.Prefix()
  1495.     ColourTell("cyan", "", string.format("  %-48s", k))
  1496.     if v["value"] then
  1497.       ColourTell("darkcyan", "", string.format(" (%15s)", v["value"]()))
  1498.     end
  1499.     Note("")
  1500.  
  1501.     display.Prefix()
  1502.     ColourNote("silver", "", "    " .. v["info"])
  1503.   end
  1504.  
  1505.   if IsConnected() then
  1506.     Send("")
  1507.   end
  1508. end
  1509.  
  1510. -- This is a module and needs a return table
  1511. return treant
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement