Advertisement
legacy163

aetolia.lua

Jul 26th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 40.31 KB | None | 0 0
  1. --[[
  2.  
  3. Dat System             Created by: Kikon
  4.  
  5. Organize your code so that other people can read it, you might want to give this away
  6. one day to a pretty lady, or some stupid thing like that.
  7.  
  8. Requirements:
  9.    CONFIG MAPVIEW ON
  10.    CONFIG AFFLICTION_VIEW FULL
  11.    CONFIG COMBATMESSAGES ON
  12.    
  13. --]]
  14.  
  15. require "json.decode"          -- JSON decoder.
  16.  
  17. require "worlds.database"      -- Pull in databases for afflictions and defences.
  18.  
  19. require "worlds.afftracker"    -- Affliction tracker module.
  20.  
  21. -- Definitions.
  22.  
  23. local AFF_CURE = 1
  24. local AFF_CURE_AUX = 2
  25. local AFF_TYPE = 3
  26. local AFF_PRIORITY = 4
  27. local AFF_RANDOM_CURE = 5
  28. local AFF_MENTAL_CURE = 6
  29. local AFF_PHYS_CURE = 7
  30.  
  31. local DEF_COMMAND = 1
  32. local DEF_CLASS = 2
  33. local DEF_BALANCE = 3
  34. local DEF_EQUIL = 4
  35. local DEF_AUTO_AP = 5
  36.  
  37. local QU_COMMAND = 1
  38. local QU_BALANCE = 2
  39. local QU_EQUIL = 3
  40. local QU_EXECUTE = 4
  41.  
  42.  
  43. -- All globals that require initialization should be set here.
  44.  
  45. system = true             -- Full on/off toggle for automated responses.
  46. safe_only = false         -- Switches off everything but important responses (ie, for behead).
  47.  
  48. plugin_GMCP = "54bd8f89ff91b21ea6e3e07f"           -- Plugin ID for GMCP.
  49. plugin_G15Display = "21b1c9f780b8984e2e1450fa"     -- Plugin ID for G15 Display.
  50.  
  51.  
  52. -- Balance queue for queuing up various commands.
  53.  
  54. local queue = {}                     -- Table for balance queue.
  55. local reset_queue = false            -- Freezing queue for short period of time.
  56.  
  57. -- Healing for vitals (health, mana, etc) and related stuff.
  58.  
  59. local vitals = nil              -- Vitals table that we receive from GMCP.
  60. local old_vitals = nil          -- Old vitals table from the previous prompt.
  61.  
  62. sipper = true             -- Switch for sipping health/mana.
  63. use_moss = true           -- Switch for eating moss.
  64.  
  65. local sent_sip = false          -- Attempting to sip for health/mana.
  66. local sent_moss = false         -- Attempting to eat moss.
  67.  
  68. -- Healing for afflictions (salves, pipes, etc) and related stuff.
  69.  
  70. local herb = {}                 -- Table for current herbal afflictions.
  71. local salve = {}                -- Table for current salve afflictions.
  72. local pipe = {}                 -- Table for current pipe afflictions.
  73. local elixir = {}               -- Table for current elixir afflictions.
  74. local writhe = {}               -- Table for current writhe afflictions.
  75. local other = {}                -- Table for current afflictions that don't fall into the above.
  76.  
  77. local limb_damage = {}          -- Table for limb damage counters.
  78.  
  79. local unknown_afflictions = 0   -- Counter for amount of hidden afflictions.
  80.  
  81. local vlock_warning = 0         -- Levelled warning system for when a venom-lock is achieved.
  82.  
  83. last_pipe = ""                  -- Last pipe we smoked.
  84.  
  85. local hidden_check = false      -- Check for hidden afflictions.
  86.  
  87. sent_herb = false         -- Attempting to eat herb.
  88. sent_salve = false        -- Attempting to apply salve.
  89. sent_pipe = false         -- Attempting to smoke pipe.
  90. sent_elixir = false       -- Attempting to drink affliction healing elixir.
  91. sent_writhe = false       -- Attempting to writhe.
  92.  
  93. sent_tree = false         -- Attempting to touch tree.
  94. sent_focus = false        -- Attempting to use focus.
  95. sent_renew = false        -- Attempting to use renew.
  96.  
  97. -- Automatic application of combat-related defences.
  98.  
  99. local defence = {}          -- Defence table.
  100.  
  101. apply_defences = true       -- Applies a defence if stripped, as long as its allowed.
  102.  
  103. stay_blind_deaf = true      -- Automatic application of bayberry and hawthorn.
  104. stay_insomniac = true       -- Automatic use of insomnia to prevent sleep.
  105. stay_standing = true        -- Stay standing at all times.
  106.  
  107. use_prerestore = true       -- Automatic use of pre-restoring to heal limb damage.
  108. auto_parry = false          -- Automatic use of parrying. Will parry most strategic limb.
  109.  
  110. stay_massed = false         -- Automatic mass application on fade.
  111. stay_rebounded = false      -- Automatic application of skullcap aura.
  112.  
  113. -- GUI required variables and the such. This'll get complicated.
  114.  
  115. gui_elements = true       -- Draw all GUI elements. Switch it off if you just want the game by default.
  116.  
  117. local map = {}            -- Captured line styles of MAP for replication to a miniwindow.
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. --[[ Run certain things on world open and close. ]]--
  125.  
  126. function worldOpen()
  127.  
  128.    -- Create the miniwindows so the screen doesn't appear blank.
  129.    
  130.    local top, height, left, width = 350, 10, 1090, 860
  131.    
  132.    MoveWorldWindow( top, height, left, width )
  133.  
  134.    drawMap()
  135.    drawAfflictions()
  136.  
  137. end
  138.  
  139. function worldDisconnect()
  140.  
  141.    -- Wipe temporary variables.
  142.  
  143.    SetVariable( "replicate", "n/a" )
  144.  
  145. end
  146.  
  147.  
  148.  
  149. --[[ This is what we run when a prompt pops up. This really needs to be as smooth as possible! ]] --
  150.  
  151. function onPrompt()
  152.  
  153.    -- Let's make sure GMCP has setup our vitals table first.
  154.  
  155.    if vitals == nil then
  156.       return
  157.    end
  158.  
  159.    -- Check/detection functions.
  160.  
  161.    detectHiddenAffs()     -- Detection of certain hidden afflictions.
  162.    checkBlindDeaf()       -- Check and see if blindness and deafness are applied.  
  163.    
  164.    if system == false or vitals.hp == "0" then
  165.       return
  166.    end
  167.    
  168.    venomlockWarning()     -- Are we venom locked? This is a problem!
  169.    
  170.    if haveAffliction("stun") or haveAffliction("asleep") or haveAffliction("unconscious") then
  171.       return
  172.    end
  173.    
  174.    -- Healing/reaction functions.
  175.    
  176.    healVitals()           -- Sip health/mana, and eat moss.
  177.    cureAfflictions()      -- Eat herbs, apply salves, or use things like focus.
  178.    
  179.    applyDefences()        -- Apply queued defences for activation.
  180.  
  181.    executeBalanceQueue()  -- Queued commands waiting for balance and equilibrium.
  182.  
  183. end
  184.  
  185. --[[
  186. function customPrompt( wildcards )
  187.  
  188.    if haveAffliction("blackout") or vitals == nil then
  189.       ColourNote( "silver", "black", ":" )
  190.       return
  191.    end
  192.    
  193.    -- Health.
  194.    
  195.    local health = tonumber(wildcards[1])
  196.    
  197.    if health > vitals.maxhp * 0.75 then
  198.       ColourTell( "green", "black", "H:" .. health .. " " )
  199.    elseif health > vitals.maxhp * 0.25 then
  200.       ColourTell( "yellow", "black", "H:" .. health .. " " )
  201.    elseif health > 0 then
  202.       ColourTell( "red", "black", "H:" .. health .. " " )
  203.    else
  204.       ColourTell( "silver", "black", "H:" .. health .. " " )
  205.    end
  206.    
  207.    -- Health change.
  208.      
  209.    if tonumber(vitals.hp) > health then
  210.       ColourTell( "red", "black", "<-" .. vitals.hp - health .. "> " )
  211.    elseif tonumber(vitals.hp) < health then
  212.       ColourTell( "lime", "black", "<" .. health - vitals.hp .. "> " )
  213.    -- else
  214.       -- ColourTell( "gray", "black", "<0> " )
  215.    end
  216.  
  217.    -- Mana.
  218.    
  219.    local mana = tonumber(wildcards[2])
  220.    
  221.    if mana > vitals.maxmp * 0.75 then
  222.       ColourTell( "green", "black", "M:" .. mana .. " " )
  223.    elseif mana > vitals.maxmp * 0.25 then
  224.       ColourTell( "yellow", "black", "M:" .. mana .. " " )
  225.    elseif mana > 0 then
  226.       ColourTell( "red", "black", "M:" .. mana .. " " )
  227.    else
  228.       ColourTell( "silver", "black", "M:" .. mana .. " " )
  229.    end
  230.  
  231.    -- Mana change.
  232.    
  233.    if tonumber(vitals.mp) > mana then
  234.       ColourTell( "red", "black", "<-" .. vitals.mp - mana .. "> " )
  235.    elseif tonumber(vitals.mp) < mana then
  236.       ColourTell( "lime", "black", "<" .. mana - vitals.mp .. "> " )
  237.    -- else
  238.       -- ColourTell( "gray", "black", " <0> " )
  239.    end
  240.    
  241.    -- Blood.
  242.    
  243.    ColourTell( "red", "black", "B:" .. wildcards[3] .. "% " )
  244.    
  245.    -- Status.
  246.    
  247.    ColourNote( "silver", "black", "[" .. wildcards[4] .. "]" )
  248.    
  249. end
  250. ]]--
  251.  
  252.  
  253.  
  254. --[[ Functions for calling by GMCP plugin. ]]--
  255.  
  256. function GMCP_Vitals()
  257.  
  258.    -- Plugin ID is GMCP.xml, didn't want to make an extra call to global table.
  259.    local params = GetPluginVariable( "54bd8f89ff91b21ea6e3e07f", "vitals" )
  260.    
  261.    old_vitals = vitals
  262.    vitals = json.decode(params)
  263.  
  264. end
  265.  
  266. function GMCP_Login()
  267.  
  268.    local login = GetPluginVariable( plugin_GMCP, "name" )
  269.  
  270.    login = json.decode(login)
  271.  
  272.    SetVariable( "name", login.name )
  273.    
  274.    if login.name == "Kikon" then
  275.  
  276.       SetVariable( "mount", "moonfire" )
  277.       SetVariable( "pack", "200024" )
  278.      
  279.       SetVariable( "pipe_elm", "133451" )
  280.       SetVariable( "pipe_skullcap", "132883" )
  281.       SetVariable( "pipe_valerian", "133245" )
  282.      
  283.       SetVariable( "bow", "bow137961" )
  284.       SetVariable( "shield", "shield112317" )
  285.       SetVariable( "staff", "staff47088" )
  286.      
  287.    elseif login.name == "Torlin" then
  288.  
  289.       SetVariable( "mount", "201447" )
  290.  
  291.       SetVariable( "pipe_elm", "79880" )
  292.       SetVariable( "pipe_skullcap", "36261" )
  293.       SetVariable( "pipe_valerian", "79880" )
  294.    
  295.    end
  296.  
  297. end
  298.  
  299. function GMCP_Comm()
  300.  
  301.    local msg = GetPluginVariable( plugin_GMCP, "comm" )
  302.  
  303.    msg = json.decode(msg)
  304.  
  305.    if msg.channel == "tell" and msg.talker ~= GetVariable("name") then
  306.       Sound( "c:/windows/media/notify.wav" )
  307.    end
  308.  
  309. end
  310.  
  311.  
  312.  
  313. --[[ This'll handle afflictions, the main bulk of shit. ]]--
  314.  
  315. function addAffliction( aff, secondary )
  316.  
  317.    if affDB[aff] == nil then
  318.       ColourTell( "red", "black", "Unknown affliction: " )
  319.       Note( aff )
  320.       return
  321.    end
  322.  
  323.    if haveAffliction(aff) then
  324.       return
  325.    end
  326.    
  327.    -- If the affliction comes from a secondary source, then we need to know.
  328.    if secondary == true then
  329.       decreaseHiddenAffs()
  330.    end
  331.  
  332.    
  333.    -- Add affliction to corresponding table.
  334.    
  335.    local t = whatAfflictionTable( affDB[aff][AFF_TYPE] )
  336.  
  337.    local priority = affDB[aff][AFF_PRIORITY]
  338.    local pos = 0
  339.    
  340.    for i, name in ipairs(t) do
  341.       if priority < affDB[name][AFF_PRIORITY] then
  342.          break
  343.       end
  344.       pos = i
  345.    end
  346.  
  347.    table.insert( t, pos+1, aff )
  348.    
  349.    
  350.    -- Small hack fix to deal with things like fear in the mean time.
  351.    if t == other and affDB[aff][AFF_CURE] ~= "-" and system == true then
  352.       Send( affDB[aff][AFF_CURE] )
  353.    end
  354.    
  355.    -- GUI element.
  356.    drawAfflictions()
  357.  
  358. end
  359.  
  360. function removeAffliction( aff, confirmed )
  361.  
  362.    if affDB[aff] == nil then
  363.       ColourTell( "red", "black", "Unknown affliction: " )
  364.       Note( aff )
  365.       return
  366.    end
  367.  
  368.    if not haveAffliction(aff) then
  369.       if confirmed == true then
  370.          decreaseHiddenAffs()
  371.       end
  372.       return
  373.    end
  374.  
  375.    
  376.    -- Remove affliction from corresponding table.
  377.    
  378.    local t = whatAfflictionTable( affDB[aff][AFF_TYPE] )
  379.    
  380.    local pos
  381.    
  382.    for i, name in ipairs(t) do
  383.       if aff == name then
  384.          pos = i
  385.          break
  386.       end
  387.    end
  388.    
  389.    table.remove( t, pos )
  390.  
  391.    -- GUI element.
  392.    drawAfflictions()
  393.  
  394. end
  395.  
  396. function haveAffliction( aff )
  397.  
  398.    local aff_t = { herb, salve, pipe, elixir, writhe, other }
  399.    
  400.    for i, t in ipairs(aff_t) do
  401.       for _, name in ipairs(t) do
  402.          if aff == name then
  403.             return true
  404.          end
  405.       end
  406.    end
  407.  
  408.    return false
  409.  
  410. end
  411.  
  412.  
  413. function increaseHiddenAffs()
  414.  
  415.    unknown_afflictions = unknown_afflictions + 1
  416.    
  417.    hidden_check = true
  418.    
  419.    -- GUI element.
  420.    drawAfflictions()
  421.  
  422. end
  423.  
  424. function decreaseHiddenAffs()
  425.  
  426.    if unknown_afflictions == 0 then
  427.       return
  428.    end
  429.  
  430.    unknown_afflictions = unknown_afflictions - 1
  431.    
  432.    -- GUI element.
  433.    drawAfflictions()
  434.  
  435. end
  436.  
  437. function detectHiddenAffs()
  438.  
  439.    if hidden_check == false then
  440.       return
  441.    end
  442.    
  443.    hidden_check = false
  444.    
  445.    -- Do we have recklessness?
  446.    if vitals.hp == vitals.maxhp and old_vitals.hp < vitals.maxhp and
  447.       vitals.mp == vitals.maxmp and old_vitals.mp < vitals.maxmp then
  448.       addAffliction( "recklessness", true )
  449.    end
  450.  
  451. end
  452.  
  453.  
  454. function venomlockWarning()
  455.  
  456.    -- Basic warnings for venomlocks!
  457.  
  458.    if ( haveAffliction("anorexia") or haveAffliction("indifference") or haveAffliction("destroyed_throat") ) and
  459.       ( haveAffliction("slickness") or haveAffliction("earthrot") ) and
  460.         haveAffliction("asthma") then
  461.       if haveAffliction("paralysis") and vlock_warning < 2 then
  462.          Note( "+-------------------------------------------+" )
  463.          Tell( "|    " )
  464.          ColourTell( "yellow", "black", "--*> " )
  465.          ColourTell( "red", "black", "VENOM-LOCKED + PARALYSIS" )
  466.          ColourTell( "yellow", "black", " <*--" )
  467.          Note( "     |" )
  468.          Note( "| HOPE FOR LUCKY PURITY TICKS / TRY TUMBLE! |" )
  469.          Note( "+-------------------------------------------+" )
  470.          vlock_warning = 2
  471.       elseif vlock_warning < 1 then
  472.          Note( "+-------------------------------------------+" )
  473.          Note( "|           !!! VENOM-LOCKED !!!            |" )
  474.          Note( "| YOU'VE STILL GOT A CHANCE / BLOODBOIL OUT |" )
  475.          Note( "+-------------------------------------------+" )
  476.          vlock_warning = 1
  477.       end
  478.       AddTimer( "reset_vlock_lvl", 0, 0, 10, "", 1061, "venomlockResetLvl" )
  479.    end
  480.    
  481. end
  482.  
  483. function venomlockResetLvl()
  484.    vlock_warning = 0
  485. end
  486.  
  487.  
  488. function cureAfflictionsHerbs()
  489.  
  490.    if #herb == 0 then
  491.       return
  492.    end
  493.  
  494.    if vitals.herb == "1" and sent_herb == false and
  495.       not haveAffliction("anorexia") and
  496.       not haveAffliction("indifference") and
  497.       not haveAffliction("destroyed_throat") and
  498.       #writhe == 0 then
  499.    
  500.       for i, name in ipairs(herb) do
  501.          if ( name == "blighted" or name == "infested" ) and haveAffliction("premonition") then
  502.             -- Do nothing.
  503.          else
  504.             sent_herb = true
  505.             local cure = affDB[name][AFF_CURE]
  506.             if haveAffliction("stupidity") then
  507.                Send( "eat " .. cure )
  508.             end
  509.             Send( "outc " .. cure )
  510.             Send( "eat " .. cure )
  511.             AddTimer( "herb_reset", 0, 0, resetDelay(), "", 1061, "resetHerb" )
  512.             break
  513.          end
  514.       end
  515.  
  516.    end
  517.    
  518. end
  519.  
  520. function cureAfflictionsSalves()
  521.  
  522.    if #salve == 0 then
  523.       return
  524.    end
  525.  
  526.    if vitals.salve == "1" and sent_salve == false and
  527.       not haveAffliction("slickness") and
  528.       not haveAffliction("earthrot") then
  529.    
  530.       for i, name in ipairs(salve) do
  531.          sent_salve = true
  532.          local cure = affDB[name][AFF_CURE]
  533.          if haveAffliction("stupidity") or haveAffliction("head_mangled") then
  534.             Send( "apply " .. cure )
  535.          end
  536.          Send( "apply " .. cure )
  537.          AddTimer( "salve_reset", 0, 0, resetDelay(), "", 1061, "resetSalve" )
  538.          break
  539.       end
  540.      
  541.    end
  542.    
  543. end
  544.  
  545. function cureAfflictionsPipes()
  546.  
  547.    if #pipe == 0 then
  548.       return
  549.    end
  550.  
  551.    if vitals.pipe == "1" and sent_pipe == false and
  552.       not haveAffliction("asthma") then
  553.    
  554.       for i, name in ipairs(pipe) do
  555.          sent_pipe = true
  556.          local cure = affDB[name][AFF_CURE]
  557.          last_pipe = cure
  558.          SSend( "smoke " .. cure )
  559.          AddTimer( "pipe_reset", 0, 0, resetDelay(), "", 1061, "resetPipe" )
  560.          break
  561.       end
  562.      
  563.    end
  564.    
  565. end
  566.  
  567. function cureAfflictionsElixirs()
  568.  
  569.    if #elixir == 0 then
  570.       return
  571.    end
  572.  
  573.    if vitals.affelixir == "1" and sent_elixir == false and
  574.       not haveAffliction("anorexia") and
  575.       not haveAffliction("indifference") and
  576.       not haveAffliction("destroyed_throat") then
  577.    
  578.       for i, name in ipairs(elixir) do
  579.          sent_elixir = true
  580.          SSend( "drink " .. affDB[name][AFF_CURE] )
  581.          AddTimer( "aff_elixir_reset", 0, 0, resetDelay(), "", 1061, "resetAffElixir" )
  582.          break
  583.       end
  584.      
  585.    end
  586.    
  587. end
  588.  
  589. function cureAfflictionsWrithes()
  590.  
  591.    if #writhe == 0 then
  592.       return
  593.    end
  594.  
  595.    if vitals.writhing ~= "1" and sent_writhe == false then
  596.    
  597.       for i, name in ipairs(writhe) do
  598.          if ( name == "writhe_impaled" or name == "writhe_feed" ) and vitals.balance == "0" then
  599.             break
  600.          end
  601.          sent_writhe = true
  602.          SSend( affDB[name][AFF_CURE] )
  603.          AddTimer( "writhe_reset", 0, 0, resetDelay(), "", 1061, "resetWrithe" )
  604.          break
  605.       end
  606.      
  607.    end
  608.    
  609. end
  610.  
  611. function cureAfflictionsTree( force )
  612.  
  613.    -- We want to make sure we have at least two afflictions, in case one is being cured by normal means.
  614.  
  615.    local aff_t = { herb, salve }
  616.    local oktree = false
  617.  
  618.    for i, t in ipairs(aff_t) do
  619.       local n = 0
  620.       for _, name in ipairs(t) do
  621.          if affDB[name][AFF_RANDOM_CURE] == true then
  622.             n = n + 1
  623.             if n == 2 then oktree = true break end
  624.          end
  625.       end
  626.    end
  627.    
  628.    if unknown_afflictions == 0 and not oktree and not force then
  629.       return
  630.    end
  631.  
  632.    if ( vitals.tree == "1" and sent_tree == false ) and
  633.       ( sent_focus == false and sent_renew == false or force ) and
  634.       not haveAffliction("paralysis") and
  635.       not haveAffliction("paresis") and
  636.       not ( haveAffliction("left_arm_broken") and haveAffliction("right_arm_broken") ) then
  637.       sent_tree = true
  638.       Send( "touch tree" )
  639.       AddTimer( "reset_tree", 0, 0, resetDelay(), "", 1061, "resetTree" )
  640.    end
  641.  
  642. end
  643.  
  644. function cureAfflictionsFocus( force )
  645.  
  646.    -- Same thing as above, but we're making sure that we have afflictions that are focusable.
  647.  
  648.    local aff_t = { herb, salve }
  649.    local okfocus = false
  650.  
  651.    for i, t in ipairs(aff_t) do
  652.       local n = 0
  653.       for _, name in ipairs(t) do
  654.          if affDB[name][AFF_MENTAL_CURE] == true then
  655.             n = n + 1
  656.             if n == 2 then okfocus = true break end
  657.          end
  658.       end
  659.    end
  660.    
  661.    -- Premonition will cause focus to send as long as we have focus balance. Only way to cure it.
  662.    if not haveAffliction("premonition") and not okfocus and not force then
  663.       return
  664.    end
  665.    
  666.    if ( vitals.focus == "1" and sent_focus == false ) and
  667.       ( sent_tree == false and sent_renew == false or force ) and
  668.       not haveAffliction("impatience") and
  669.       tonumber(vitals.mp) >= vitals.maxmp * 0.5 then
  670.       sent_focus = true
  671.       Send( "focus" )
  672.       AddTimer( "reset_focus", 0, 0, resetDelay(), "", 1061, "resetFocus" )
  673.    end
  674.  
  675. end
  676.  
  677. function cureAfflictionsRenew( force )
  678.  
  679.    -- Reconstitute (renew) waits for three afflictions, since it's unique in that it'll work through anything. Save it!
  680.  
  681.    local aff_t = { herb, salve }
  682.    local okrenew = false
  683.  
  684.    for i, t in ipairs(aff_t) do
  685.       local n = 0
  686.       for _, name in ipairs(t) do
  687.          if affDB[name][AFF_RANDOM_CURE] == true then
  688.             n = n + 1
  689.             if n == 3 then okrenew = true break end
  690.          end
  691.       end
  692.    end
  693.    
  694.    if unknown_afflictions < 3 and not okrenew and not force then
  695.       return
  696.    end
  697.  
  698.    if ( vitals.renew == "1" and sent_renew == false ) and
  699.       ( sent_tree == false and sent_focus == false or force ) and
  700.       vitals.balance == "1" and vitals.equilibrium == "1" and
  701.       tonumber(vitals.mp) >= vitals.maxmp * 0.5 then
  702.       sent_renew = true
  703.       Send( "reconstitute" )
  704.       AddTimer( "reset_renew", 0, 0, resetDelay(), "", 1061, "resetRenew" )
  705.    end
  706.  
  707. end
  708.  
  709. function cureAfflictions()
  710.  
  711.    -- This is the beast function that calls all the curing functions!
  712.  
  713.    cureAfflictionsWrithes()
  714.  
  715.    -- Only writhes can fire with safety on, so channelled abilities can do their thing.
  716.    if safe_only == true then
  717.       return
  718.    end
  719.  
  720.    cureAfflictionsHerbs()
  721.    cureAfflictionsSalves()
  722.    cureAfflictionsPipes()
  723.    
  724.    cureAfflictionsElixirs()
  725.  
  726.    cureAfflictionsTree()
  727.    cureAfflictionsFocus()
  728.    cureAfflictionsRenew()
  729.  
  730. end
  731.  
  732. function resetAfflictions()
  733.  
  734.    -- Resets all afflictions.
  735.  
  736.    herb = {}
  737.    salve = {}
  738.    pipe = {}
  739.    elixir = {}
  740.    writhe = {}
  741.    other = {}
  742.    
  743.    unknown_afflictions = 0
  744.    
  745.    vlock_warning = 0
  746.    
  747.    -- GUI element.
  748.    drawAfflictions()
  749.  
  750. end
  751.  
  752. function resetAfflictionsType( kind )
  753.  
  754.    -- If we need to reset a group of afflictions belonging to one of these categories.
  755.  
  756.    local category = {
  757.       ["random"] = AFF_RANDOM_CURE,
  758.       ["mental"] = AFF_MENTAL_CURE,
  759.       ["physical"] = AFF_PHYS_CURE
  760.    }
  761.    
  762.    local key = category[kind]
  763.  
  764.    if key == nil then
  765.       return
  766.    end
  767.  
  768.    local aff_t = { herb, salve, pipe, other }
  769.  
  770.    local list = {}
  771.    
  772.    for i, t in ipairs(aff_t) do
  773.       for _, name in ipairs(t) do
  774.          if affDB[name][key] == true then
  775.             list[#list+1] = name
  776.          end
  777.       end
  778.    end
  779.    
  780.    for i, name in ipairs(list) do
  781.       removeAffliction(name)
  782.    end
  783.    
  784.    if key == AFF_RANDOM_CURE then
  785.       unknown_afflictions = 0
  786.       drawAfflictions()
  787.    end
  788.    
  789. end
  790.  
  791. function resetBalances()
  792.  
  793.    sent_sip = false
  794.    sent_moss = false
  795.  
  796.    sent_herb = false
  797.    sent_salve = false
  798.    sent_pipe = false
  799.    sent_elixir = false
  800.    sent_writhe = false
  801.  
  802.    sent_tree = false
  803.    sent_focus = false
  804.    sent_renew = false
  805.  
  806. end
  807.  
  808.  
  809. function resetOnConsumePlant( plant )
  810.  
  811.    local consumable = {
  812.       ["a bloodroot leaf"] = "bloodroot",
  813.       ["some prickly ash bark"] = "ash",
  814.       ["a goldenseal root"] = "goldenseal",
  815.       ["a piece of kelp"] = "kelp",
  816.       ["a lobelia seed"] = "lobelia",
  817.       ["a ginseng root"] = "ginseng",
  818.       ["a bellwort flower"] = "bellwort",
  819.      
  820.       ["a lung slice"] = "lung",
  821.       ["a bladder slice"] = "bladder",
  822.       ["a liver slice"] = "liver",
  823.       ["an eyeball slice"] = "eyeball",
  824.       ["a testis slice"] = "testis",
  825.       ["an ovary slice"] = "ovary",
  826.       ["a castorite gland slice"] = "castorite"
  827.    }
  828.    
  829.    local cure = consumable[plant]
  830.    
  831.    if cure == nil then
  832.       return
  833.    end
  834.    
  835.    local list = {}
  836.  
  837.    for i, name in ipairs(herb) do
  838.       if affDB[name][AFF_CURE] == cure then
  839.          list[#list+1] = name
  840.       end
  841.    end
  842.    
  843.    for i, name in ipairs(list) do
  844.       removeAffliction(name)
  845.    end
  846.  
  847. end
  848.  
  849. function resetOnApplySalve( app, bpart )
  850.  
  851.    local application = {
  852.       ["an epidermal salve"] = { ["head"] = "epidermal to head",
  853.                                  ["torso"] = "epidermal to torso" },
  854.       ["a salve of mending"] = { ["head"] = "mending to head",
  855.                                  ["torso"] = "mending to torso",
  856.                                  ["body"] = "mending to body",      
  857.                                  ["left arm"] = "mending to left arm",
  858.                                  ["right arm"] = "mending to right arm",
  859.                                  ["left leg"] = "mending to left leg",
  860.                                  ["right leg"] = "mending to right leg" },
  861.  
  862.       ["an oculi poultice"]  = { ["head"] = "oculi to head",
  863.                                  ["torso"] = "ocull to torso" },
  864.       ["an orbis poultice"]  = { ["head"] = "orbis to head",
  865.                                  ["torso"] = "orbis to torso",
  866.                                  ["body"] = "orbis to body",      
  867.                                  ["left arm"] = "orbis to left arm",
  868.                                  ["right arm"] = "orbis to right arm",
  869.                                  ["left leg"] = "orbis to left leg",
  870.                                  ["right leg"] = "orbis to right leg" }
  871.    }
  872.  
  873.    if application[app] == nil then
  874.       return
  875.    end
  876.    
  877.    local cure = application[app][bpart]
  878.    
  879.    if cure == nil then
  880.       return
  881.    end
  882.  
  883.    local list = {}
  884.  
  885.    for i, name in ipairs(salve) do
  886.       if affDB[name][AFF_CURE] == cure then
  887.          list[#list+1] = name
  888.       end
  889.    end
  890.  
  891.    for i, name in ipairs(list) do
  892.       removeAffliction(name)
  893.    end
  894.  
  895. end
  896.  
  897. function resetOnSmokePipe( plant )
  898.  
  899.    if plant ~= "valerian" and
  900.       plant ~= "elm" and
  901.  
  902.       plant ~= "antispasmadic" and
  903.       plant ~= "demulcent" then
  904.       return
  905.    end
  906.    
  907.    local list = {}
  908.    
  909.    for i, name in ipairs(pipe) do
  910.       if affDB[name][AFF_CURE] == plant then
  911.          list[#list+1] = name
  912.       end
  913.    end
  914.  
  915.    for i, name in ipairs(list) do
  916.       removeAffliction(name)
  917.    end
  918.    
  919. end  
  920.  
  921. function resetOnEmptyWrithe()
  922.  
  923.    local list = {}
  924.  
  925.    for i, name in ipairs(writhe) do
  926.       list[#list+1] = name
  927.    end
  928.  
  929.    for i, name in ipairs(list) do
  930.       removeAffliction(name)
  931.    end
  932.  
  933. end
  934.  
  935.  
  936. function resetHerb()
  937.    sent_herb = false
  938. end
  939.  
  940. function resetSalve()
  941.    sent_salve = false
  942. end
  943.  
  944. function resetPipe()
  945.    sent_pipe = false
  946. end
  947.  
  948. function resetAffElixir()
  949.    sent_elixir = false
  950. end
  951.  
  952. function resetWrithe()
  953.    sent_writhe = false
  954. end
  955.  
  956.  
  957. function resetTree()
  958.    sent_tree = false
  959. end
  960.  
  961. function resetFocus()
  962.    sent_focus = false
  963. end
  964.  
  965. function resetRenew()
  966.    sent_renew = false
  967. end
  968.  
  969.  
  970.  
  971. --[[ Functions for dealing with pre-restoration and parry. ]]--
  972.  
  973. function increaseLimbDamage( limb, dmg )
  974.  
  975.    -- Increases the limb damage value of a limb, and deals with pre-restore.
  976.    
  977.    local result = ( limb_damage[limb] or 0 ) + dmg
  978.    
  979.    if result > 100 then
  980.       result = 100
  981.    end
  982.    
  983.    if use_prerestore == true and result >= 15 then
  984.       addAffliction( limb:gsub(" ","_") .. "_prerestore" )
  985.    end
  986.  
  987.    limb_damage[limb] = result
  988.  
  989. end
  990.  
  991. function decreaseLimbDamage( limb, dmg )
  992.  
  993.    -- Decreases the limb damage value of a limb, and clears pre-restore.
  994.  
  995.    local result = ( limb_damage[limb] or 0 ) - dmg
  996.  
  997.    if result < 0 then
  998.       result = 0
  999.    end
  1000.  
  1001.    if use_prerestore == true and result < 15 then
  1002.       removeAffliction( limb:gsub(" ","_") .. "_prerestore" )
  1003.    end
  1004.    
  1005.    limb_damage[limb] = result
  1006.  
  1007. end
  1008.  
  1009. function setLimbDamage( limb, dmg )
  1010.  
  1011.    -- Sometimes we need to set a specific limb to a value.
  1012.  
  1013.    if not dmg then
  1014.       return
  1015.    end
  1016.    
  1017.    if dmg > 100 then
  1018.       dmg = 100
  1019.    end
  1020.    
  1021.    if dmg < 0 then
  1022.       dmg = 0
  1023.    end
  1024.    
  1025.     if use_prerestore == true then
  1026.       if dmg >= 15 then
  1027.          addAffliction( limb:gsub(" ","_") .. "_prerestore" )
  1028.       else
  1029.          removeAffliction( limb:gsub(" ","_") .. "_prerestore" )
  1030.       end
  1031.    end
  1032.    
  1033.    limb_damage[limb] = dmg
  1034.  
  1035. end
  1036.  
  1037. --[[
  1038. function handlePreRestore()
  1039.  
  1040.    if use_prerestore == false then
  1041.       return
  1042.    end
  1043.    
  1044.    for limb, dmg in pairs(limb_damage) do
  1045.       local affname = limb:gsub( " ", "_" )
  1046.       if haveAffliction( affname .. "_damaged" ) then
  1047.          removeAffliction( affname .. "_prerestore" )
  1048.       else
  1049.          if dmg >= 20.00 then
  1050.             addAffliction( affname .. "_prerestore" )
  1051.          else
  1052.             removeAffliction( affname .. "_prerestore" )
  1053.          end
  1054.       end
  1055.    end
  1056.  
  1057. end
  1058. ]]--
  1059.  
  1060. function displayLimbDamage()
  1061.  
  1062.    -- Basic display.
  1063.  
  1064.    for k, dmg in pairs(limb_damage) do
  1065.       Tell( k .. ": " )
  1066.       Note( dmg )
  1067.    end
  1068.  
  1069. end
  1070.  
  1071. function resetLimbDamage()
  1072.  
  1073.    limb_damage = {}
  1074.  
  1075.    removeAffliction("head_prerestore")
  1076.    removeAffliction("torso_prerestore")
  1077.    removeAffliction("left_arm_prerestore")
  1078.    removeAffliction("right_arm_prerestore")
  1079.    removeAffliction("left_leg_prerestore")
  1080.    removeAffliction("right_leg_prerestore")
  1081.  
  1082. end
  1083.  
  1084.  
  1085. function shiftParry( limb )
  1086.  
  1087.    if auto_parry == false then
  1088.       return
  1089.    end
  1090.    
  1091.  
  1092. end
  1093.  
  1094. function resetParry()
  1095.  
  1096. end
  1097.  
  1098.  
  1099.  
  1100. --[[ Functions for AutoSipper and healing vitals ]]--
  1101.  
  1102. function displayVitals()
  1103.  
  1104.    -- Because this table is pretty useful to see, I don't even use 90% of it.
  1105.  
  1106.    for k, v in pairs(vitals) do
  1107.       print(k,v)
  1108.    end
  1109.    
  1110. end
  1111.  
  1112. function healVitals()
  1113.  
  1114.    if sipper == false or safe_only == true then
  1115.       return
  1116.    end
  1117.    
  1118.    if haveAffliction("anorexia") or haveAffliction("indifference") then
  1119.       return
  1120.    end
  1121.    
  1122.    -- TODO: Add a special forced mana threshold toggle when being targeted by an ability like angel sap.
  1123.    
  1124.    if vitals.elixir == "1" and sent_sip == false then
  1125.  --[[ if tonumber(vitals.mp) <= vitals.maxmp * force_mana_threshold then
  1126.          sent_sip = true
  1127.          Send( "drink mana" )
  1128.          AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
  1129.       ]]--  
  1130.       if tonumber(vitals.hp) <= vitals.maxhp * 0.82 or haveAffliction("blackout") then
  1131.          sent_sip = true
  1132.          Send( "drink health" )
  1133.          AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
  1134.       elseif tonumber(vitals.mp) <= vitals.maxmp * 0.85 then
  1135.          sent_sip = true
  1136.          Send( "drink mana" )
  1137.          AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
  1138.       end
  1139.    end
  1140.    
  1141.    if vitals.moss == "1" and sent_moss == false and #writhe == 0 then
  1142.       if tonumber(vitals.hp) <= vitals.maxhp * 0.65 or
  1143.          tonumber(vitals.mp) <= vitals.maxmp * 0.65 or
  1144.          haveAffliction("idiocy") or
  1145.          haveAffliction("plodding") or
  1146.          haveAffliction("blackout") then
  1147.          sent_moss = true
  1148.          Send( "outc moss" )
  1149.          Send( "eat moss" )
  1150.          AddTimer( "moss_reset", 0, 0, resetDelay(), "", 1061, "resetMoss" )
  1151.       end
  1152.    end
  1153.    
  1154. end
  1155.  
  1156. function resetElixir()
  1157.    sent_sip = false
  1158. end
  1159.  
  1160. function resetMoss()
  1161.    sent_moss = false
  1162. end
  1163.  
  1164.  
  1165.  
  1166. --[[ Functions to deal with wielded items and the sort. ]]--
  1167.  
  1168. function unwieldLeft()
  1169.  
  1170.    if vitals.wield_left ~= "" then
  1171.       local weapon = string.match(vitals.wield_left,"%a+")
  1172.       if weapon == "shield" or
  1173.          weapon == "bow" then
  1174.          Send( "unwield " .. vitals.wield_left )
  1175.          Send( "wear " .. vitals.wield_left )
  1176.       else
  1177.          Send( "secure " .. vitals.wield_left )
  1178.          Send( "unwield " .. vitals.wield_left )
  1179.       end
  1180.    end
  1181.  
  1182. end
  1183.  
  1184. function unwieldRight()
  1185.  
  1186.    if vitals.wield_right ~= "" then
  1187.       local weapon = string.match(vitals.wield_right,"%a+")
  1188.       if weapon == "shield" or
  1189.          weapon == "bow" then
  1190.          Send( "unwield " .. vitals.wield_right )
  1191.          Send( "wear " .. vitals.wield_right )
  1192.       else
  1193.          Send( "secure " .. vitals.wield_right )
  1194.          Send( "unwield " .. vitals.wield_right )
  1195.       end
  1196.    end
  1197.  
  1198. end
  1199.  
  1200. function wieldWeapon( item, hand )
  1201.  
  1202.    if item == nil then
  1203.       return
  1204.    end
  1205.    
  1206.    if hand == "left" and vitals.wield_left ~= item then
  1207.       unwieldLeft()
  1208.       Send( "wield " .. item .. " left" )
  1209.    elseif hand == "right" and vitals.wield_right ~= item then
  1210.       unwieldRight()
  1211.       Send( "wield " .. item .. " right" )
  1212.    elseif hand == "both" and vitals.wield_left ~= item then
  1213.       unwieldLeft()
  1214.       unwieldRight()
  1215.       Send( "wield " .. item )
  1216.    end
  1217.  
  1218. end
  1219.  
  1220.  
  1221.  
  1222. --[[ Queue for performing actions that require balance or equilibrium. ]]--
  1223.  
  1224. function addBalanceQueue( cmd, bal, eq, exe, t_rmvl )
  1225.  
  1226.    if not cmd then
  1227.       ColourTell( "red", "black", "ERROR: " )
  1228.       Note( "No command supplied for balance queue." )
  1229.    end
  1230.    
  1231.    if type(bal) ~= "boolean" then
  1232.       bal = false
  1233.    end
  1234.    if type(eq) ~= "boolean" then
  1235.       eq = false
  1236.    end
  1237.    if type(exe) ~= "boolean" then
  1238.       exe = false
  1239.    end
  1240.    if type(t_rmvl) ~= "boolean" then
  1241.       t_rmvl = false
  1242.    end
  1243.    
  1244.    queue[#queue+1] = { cmd, bal, eq, exe, t_rmvl }
  1245.    
  1246.    executeBalanceQueue()
  1247.  
  1248. end
  1249.  
  1250. function executeBalanceQueue()
  1251.  
  1252.    -- This handles queued commands, and can make sure we're on balance and such.
  1253.  
  1254.    if #queue == 0 or sent_queue == true or safe_only == true then
  1255.       return
  1256.    end
  1257.  
  1258.    if ( vitals.balance == "1" or not queue[1][QU_BALANCE] ) and
  1259.       ( vitals.equilibrium  == "1" or not queue[1][QU_EQUIL] ) then
  1260.  
  1261.       sent_queue = true
  1262.  
  1263.       local func = queue[1][QU_EXECUTE] and Execute or Send
  1264.       local t = queue[1][QU_COMMAND]
  1265.  
  1266.       if type(t) == "table" then
  1267.          for i, cmd in ipairs(t) do
  1268.             func (cmd)
  1269.          end
  1270.       else
  1271.          func (t)
  1272.       end
  1273.  
  1274.       AddTimer( "queue_reset", 0, 0, 1.5, "", 1061, "resetQueue" )
  1275.  
  1276.       table.remove( queue, 1 )
  1277.  
  1278.    end
  1279.  
  1280. end
  1281.  
  1282. function clearQueue()
  1283.    queue = {}
  1284.    sent_queue = false
  1285. end
  1286.  
  1287. function resetQueue()
  1288.    sent_queue = false
  1289. end
  1290.  
  1291.  
  1292.  
  1293. --[[ Basic routine that'll be expanded later to deal with defences. ]]--
  1294.  
  1295. function lostDefence( def )
  1296.  
  1297.    -- When we lose a defence, we queue it for re-application/tracking.
  1298.  
  1299.    if defDB[def] == nil then
  1300.       return
  1301.    end
  1302.    
  1303.    if queuedDefence(def) then
  1304.       return
  1305.    end
  1306.    
  1307.    defence[#defence+1] = def
  1308.  
  1309. end
  1310.  
  1311. function gainedDefence( def )
  1312.  
  1313.    -- We regained a defence, wipe it from our queue. It isn't important anymore.
  1314.  
  1315.    if defDB[def] == nil then
  1316.       return
  1317.    end
  1318.    
  1319.    if not queuedDefence(def) then
  1320.       return
  1321.    end
  1322.    
  1323.    local pos
  1324.    
  1325.    for i, name in ipairs(defence) do
  1326.       if def == name then
  1327.          pos = i
  1328.          break
  1329.       end
  1330.    end
  1331.    
  1332.    table.remove( defence, pos )
  1333.    
  1334. end
  1335.  
  1336. function queuedDefence( def )
  1337.  
  1338.    -- Is a defence already queued/tracked as being lost?
  1339.  
  1340.    for i, name in ipairs(defence) do
  1341.       if def == name then
  1342.          return true
  1343.       end
  1344.    end
  1345.    
  1346.    return false
  1347.  
  1348. end
  1349.  
  1350.  
  1351. function applyDefences()
  1352.  
  1353.    -- We want to go through and see what we need to re-apply, if it's been set to automatically do so.
  1354.  
  1355.    if #defence == 0 or sent_defence == true or safe_only == true or apply_defences == false then
  1356.       return
  1357.    end
  1358.    
  1359.    for i, def in ipairs(defence) do
  1360.  
  1361.       if defDB[def][DEF_AUTO_AP] and
  1362.          ( vitals.balance == "1" or not defDB[def][DEF_BALANCE] ) and
  1363.          ( vitals.equilibrium == "1" or not defDB[def][DEF_EQUIL] ) then
  1364.  
  1365.          sent_defence = true
  1366.      
  1367.          local t = defDB[def][DEF_COMMAND]
  1368.          
  1369.          -- Commands can be supplied as an array for multi-command defences.
  1370.      
  1371.          if type(t) == "table" then
  1372.             for i, cmd in ipairs(t) do
  1373.                Send(cmd)
  1374.             end
  1375.          else
  1376.             Send(t)
  1377.          end
  1378.    
  1379.          AddTimer( "defence_reset", 0, 0, resetDelay(), "", 1061, "resetDefence" )
  1380.  
  1381.          break
  1382.  
  1383.       end
  1384.  
  1385.    end
  1386.    
  1387. end
  1388.  
  1389.  
  1390. function displayDefences()
  1391.  
  1392.    ColourNote( "yellow", "black", "Missing defences:" )
  1393.    
  1394.    if #defence == 0 then
  1395.       Note( "none" )
  1396.       return
  1397.    end
  1398.  
  1399.    for k, def in ipairs(defence) do
  1400.       Tell( k .. ") " .. def .. ": \"" )
  1401.       local cmd = defDB[def][DEF_COMMAND]
  1402.       if type(cmd) == "table" then
  1403.          Note( table.concat( cmd, ";" ) .. "\"" )
  1404.       else
  1405.          Note( cmd .. "\"" )
  1406.       end
  1407.    end
  1408.    
  1409. end
  1410.  
  1411.  
  1412. function clearDefences()
  1413.    defence = {}
  1414.    sent_defence = false
  1415. end
  1416.  
  1417. function resetDefence()
  1418.    sent_defence = false
  1419. end
  1420.  
  1421.  
  1422. function checkBlindDeaf()
  1423.  
  1424.    if stay_blind_deaf == true then
  1425.  
  1426.       if vitals.blind == "0" then
  1427.          addAffliction("blindness")
  1428.       end
  1429.  
  1430.       if vitals.deaf == "0" then
  1431.          addAffliction("deafness")
  1432.       end
  1433.  
  1434.    end
  1435.  
  1436. end
  1437.  
  1438.  
  1439.  
  1440. --[[ This is all the scripting for the GUI. For now it'll probably be tacky until I learn more about miniwindows. ]]--
  1441.  
  1442. function drawMap( name, line, wildcards, styles )
  1443.  
  1444.    map[#map+1] = styles
  1445.  
  1446.    -- So basically we draw the map at the end once we have everything.
  1447.    
  1448.    if gui_elements == false then
  1449.       return
  1450.    end
  1451.    
  1452.    local win = GetPluginID() .. ":map"
  1453.    local font = "f"
  1454.    
  1455.    if not WindowInfo( win, 1 ) then
  1456.       WindowCreate( win, 0, 0, 0, 0, 6, 0, 0 )
  1457.       WindowFont( win, font, "FixedSys", 9 )
  1458.    end
  1459.    
  1460.    local font_height = WindowFontInfo( win, font, 1 )
  1461.    
  1462.    local window_width = 370 + 18
  1463.    local window_height = font_height * 26 + 10
  1464.    
  1465.    WindowCreate( win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB("black") )
  1466.    WindowRectOp( win, 5, 0, 0, 0, 0, 5, 15 + 0x1000 )
  1467.    
  1468.    local y = font_height * 0.5 + 5
  1469.  
  1470.    for i, styles in ipairs(map) do
  1471.       local x = 5 + 8
  1472.       for _, style in ipairs(styles) do
  1473.          x = x + WindowText( win, font, style.text, x, y, 0, 0, style.textcolour )
  1474.       end
  1475.       y = y + font_height
  1476.    end
  1477.  
  1478.    WindowShow( win, true )
  1479.    
  1480. end
  1481.  
  1482. function captureMap( name, line, wildcards, styles )
  1483.    map[#map+1] = styles
  1484. end
  1485.  
  1486. function clearMap()
  1487.    map = {}
  1488. end
  1489.  
  1490.  
  1491. function drawAfflictions()
  1492.  
  1493.    if gui_elements == false then
  1494.       return
  1495.    end
  1496.  
  1497.    local win = GetPluginID() .. ":afflictions"
  1498.    local font = "f"
  1499.    
  1500.    if not WindowInfo( win, 1 ) then
  1501.       WindowCreate( win, 0, 0, 0, 0, 8, 0, 0 )
  1502.       WindowFont( win, font, "FixedSys", 9 )
  1503.    end
  1504.    
  1505.    local font_height = WindowFontInfo( win, font, 1 )
  1506.    
  1507.    local window_width = 370 + 18
  1508.    local window_height = font_height * 24 + 10
  1509.    
  1510.    WindowCreate( win, 0, 0, window_width, window_height, 8, 0, ColourNameToRGB("black") )
  1511.    -- WindowRectOp( win, 5, 0, 0, 0, 0, 5, 15 + 0x1000 )
  1512.    
  1513.    local y = font_height * 0.5 + 5
  1514.    local x = 13
  1515.  
  1516.    WindowText( win, font, "Afflictions:", x, y, 0, 0, ColourNameToRGB("red") )
  1517.    
  1518.    y = y + font_height
  1519.    
  1520.    local aff_t = { herb, salve, pipe, elixir, writhe, other }
  1521.  
  1522.    x = x + 10
  1523.    
  1524.    for i, t in ipairs(aff_t) do
  1525.       if #t > 0 then y = y + 5 end      
  1526.       for _, name in ipairs(t) do
  1527.          WindowText( win, font, "* " .. name, x, y, 0, 0, whatAfflictionColour(t) )
  1528.          y = y + font_height
  1529.          
  1530.          if y >= font_height * 20 then
  1531.             y = font_height * 1.5 + 5
  1532.             x = 224 + 5
  1533.          end
  1534.       end
  1535.    end
  1536.    
  1537.    if unknown_afflictions > 0 then
  1538.       y = y + 5
  1539.       local clr = ColourNameToRGB("blueviolet")
  1540.       if unknown_afflictions >= 4 then
  1541.          clr = ColourNameToRGB("fuchsia")
  1542.       end
  1543.      
  1544.       WindowText( win, font, "* unknown afflict (x" .. unknown_afflictions .. ")", x, y, 0, 0, clr )
  1545.    end
  1546.    
  1547.    WindowShow( win, true )
  1548.    
  1549. end
  1550.    
  1551.  
  1552.  
  1553. --[[ Utility functions sit below! They make life a lot easier. :) ]]--
  1554.  
  1555. function SSend( command )
  1556.  
  1557.    -- Sends twice if you have stupidity, else it'll only send once.
  1558.  
  1559.    if haveAffliction("stupidity") then
  1560.       Send( command )
  1561.    end
  1562.    
  1563.    Send( command )
  1564.  
  1565. end
  1566.  
  1567. function ringVibes()
  1568.  
  1569.    -- Why AddTimer doesn't allow newline chars is beyond me. >:(
  1570.  
  1571.    Note( " +--------------------------+ " )
  1572.    Note( " | NEED TO RING VIBRATIONS! | " )
  1573.    Note( " +--------------------------+ " )
  1574.    
  1575. end
  1576.  
  1577. function whatAfflictionTable( name )
  1578.  
  1579.    -- Find the right affliction table.
  1580.  
  1581.    local list = {
  1582.       ["herb"] = herb,
  1583.       ["salve"] = salve,
  1584.       ["pipe"] = pipe,
  1585.       ["elixir"] = elixir,
  1586.       ["writhe"] = writhe,
  1587.       ["other"] = other
  1588.    }
  1589.    
  1590.    return list[name]
  1591.    
  1592. end
  1593.  
  1594. function whatAfflictionColour( t )
  1595.  
  1596.    -- What colour each affliction should be for drawing.
  1597.  
  1598.    if t == herb then
  1599.       return ColourNameToRGB("lime")
  1600.    elseif t == salve then
  1601.       return ColourNameToRGB("darkorange")
  1602.    elseif t == pipe then
  1603.       return ColourNameToRGB("cyan")
  1604.    elseif t == elixir then
  1605.       return ColourNameToRGB("dodgerblue")
  1606.    elseif t == writhe then
  1607.       return ColourNameToRGB("red")
  1608.    elseif t == other then
  1609.       return ColourNameToRGB("yellow")
  1610.    end
  1611.    
  1612.    return ColourNameToRGB("white")
  1613.  
  1614. end
  1615.  
  1616. function whatAfflictionColour2( t )
  1617.  
  1618.    -- A variation of the above.
  1619.  
  1620.    if t == "herb" then
  1621.       return "lime"
  1622.    elseif t == "salve" then
  1623.       return "darkorange"
  1624.    elseif t == "pipe" then
  1625.       return "cyan"
  1626.    elseif t == "elixir" then
  1627.       return "dodgerblue"
  1628.    elseif t == "writhe" then
  1629.       return "red"
  1630.    elseif t == "other" then
  1631.       return "yellow"
  1632.    end
  1633.    
  1634.    return "white"
  1635.  
  1636. end
  1637.  
  1638. --[[
  1639. function limbToBodypartKey( limb )
  1640.  
  1641.    -- Convert a limb name into it's corresponding key.
  1642.  
  1643.    local list = {
  1644.       ["head"] = BP_HEAD,
  1645.       ["torso"] = BP_TORSO,
  1646.       ["left arm"] = BP_LEFT_ARM,
  1647.       ["right arm"] = BP_RIGHT_ARM,
  1648.       ["left leg"] = BP_LEFT_LEG,
  1649.       ["right leg"] = BP_RIGHT_LEG
  1650.    }
  1651.    
  1652.    if list[limb] == nil then
  1653.       return
  1654.    end
  1655.    
  1656.    return list[limb]
  1657.  
  1658. end
  1659.  
  1660. function bodypartKeyToLimb( key )
  1661.  
  1662.    local list = {
  1663.       [BP_HEAD] = "head",
  1664.       [BP_TORSO] = "torso",
  1665.       [BP_LEFT_ARM] = "left arm",
  1666.       [BP_RIGHT_ARM] = "right arm",
  1667.       [BP_LEFT_LEG] = "left arm",
  1668.       [BP_RIGHT_LEG] = "right arm"
  1669.    }
  1670.    
  1671.    if list[key] == nil then
  1672.       return
  1673.    end
  1674.    
  1675.    return list[key]
  1676.  
  1677. end
  1678. ]]--
  1679.  
  1680. function roundNum( x )
  1681.  
  1682.    -- Rounding because Lua doesn't have one inbuilt.
  1683.  
  1684.    if x >= 0 then
  1685.       return math.floor( x + 0.5 )
  1686.    end
  1687.  
  1688.    return math.ceil( x - 0.5 )
  1689.    
  1690. end
  1691.  
  1692. function splitString( str )
  1693.  
  1694.    -- Converts a string list into a table.
  1695.    
  1696.    local t = {}
  1697.    
  1698.    str = str:gsub( " and ", " " )
  1699.    str:gsub( "(%w+)", function(c) table.insert( t, c ) end )
  1700.    
  1701.    return t
  1702.  
  1703. end
  1704.  
  1705. function resetSafeOnly()
  1706.  
  1707.    -- Resets the safe_only variable so curing can begin kicking in again.
  1708.    
  1709.    ColourNote( "olive", "black", "-- Overriding safety --" )
  1710.    
  1711.    safe_only = false
  1712.  
  1713. end
  1714.  
  1715. function resetDelay(name)
  1716.  
  1717.    -- Aeon and Retardation delay input by 1.5 seconds, so we need to account for that.
  1718.  
  1719.    if haveAffliction("aeon") or haveAffliction("retardation") then
  1720.       return 2.5
  1721.    end
  1722.  
  1723.    return 1.2
  1724.  
  1725. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement