Advertisement
legacy163

Kikon's System

Dec 24th, 2013
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 46.06 KB | None | 0 0
  1. --[[
  2. Dat System             Created: By me
  3.  
  4. Organize your code so that other people can read it, you might want to give this away
  5. one day to a pretty lady, or some stupid thing like that.
  6. --]]
  7.  
  8. -- All globals that require initialization should be set here.
  9.  
  10. system = true             -- Full on/off toggle for automated responses.
  11. safe_only = false         -- Switches off everything but important responses (ie, for behead).
  12.  
  13. vitals = nil              -- Vitals table that we receive from GMCP.
  14.  
  15. plugin_GMCP = "54bd8f89ff91b21ea6e3e07f"           -- Plugin ID for GMCP.
  16. plugin_G15Display = "21b1c9f780b8984e2e1450fa"     -- Plugin ID for G15 Display.
  17.  
  18. -- Balance queue for queuing up various commands.
  19.  
  20. queue = {}                     -- Table for balance queue.
  21. awaiting_balance_use = false   -- Waiting for consumption of balance or equilibrium.
  22.  
  23. -- Healing for vitals (health, mana, etc) and related stuff.
  24.  
  25. sipper = true             -- Switch for sipping health/mana.
  26. use_moss = true           -- Switch for eating moss.
  27.  
  28. health_threshold = 0.82         -- Threshold for sipping health.
  29. mana_threshold = 0.85           -- Threshold for sipping mana.
  30. force_mana_threshold = 0.35     -- Threshold for sipping mana over health.
  31. moss_threshold = 0.65           -- Threshold for consuming moss.
  32.  
  33. sent_sip = false          -- Attempting to sip for health/mana.
  34. sent_moss = false         -- Attempting to eat moss.
  35.  
  36. -- Healing for afflictions (salves, pipes, etc) and related stuff.
  37.  
  38. herb = {}                 -- Table for current herbal afflictions.
  39. salve = {}                -- Table for current salve afflictions.
  40. pipe = {}                 -- Table for current pipe afflictions.
  41. elixir = {}               -- Table for current elixir afflictions.
  42. writhe = {}               -- Table for current writhe afflictions.
  43. other = {}                -- Table for current afflictions that don't fall into the above.
  44.  
  45. curing = {}               -- Table for afflictions that the system is currently attempting to heal.
  46.  
  47. unknown_afflictions = 0   -- Counter for amount of hidden afflictions.
  48.  
  49. vlock_warning = 0         -- Levelled warning system for when a venom-lock is achieved.
  50.  
  51. last_pipe = ""            -- Last pipe we smoked. Might be redundant later.
  52.  
  53. sent_herb = false         -- Attempting to eat herb.
  54. sent_salve = false        -- Attempting to apply salve.
  55. sent_pipe = false         -- Attempting to smoke pipe.
  56. sent_elixir = false       -- Attempting to drink affliction healing elixir.
  57. sent_writhe = false       -- Attempting to writhe.
  58.  
  59. sent_tree = false         -- Attempting to touch tree.
  60. sent_focus = false        -- Attempting to use focus.
  61. sent_renew = false        -- Attempting to use renew.
  62.  
  63. -- Automatic application of combat-related defences (like blindness).
  64.  
  65. stay_blind_deaf = true      -- Automatic application of bayberry and hawthorn.
  66. stay_insomniac = true       -- Automatic use of insomnia to prevent sleep.
  67.  
  68. stay_massed = false         -- Automatic mass application on fade.
  69. stay_rebounded = false      -- Automatic application of skullcap.
  70.  
  71. -- GUI required variables and the such. This'll get complicated.
  72.  
  73. gui_elements = true       -- Draw all GUI elements. Switch it off if you just want the game by default.
  74.  
  75. map = {}                  -- Captured line styles of MAP for replication to a miniwindow.
  76.  
  77.  
  78. --[[ Affliction database. Contains information on all the afflictions for the system to call upon. ]]--
  79.  
  80. -- Name:       Cure, Type, Priority.                                       Random cure? Mental cure? Physical cure?
  81.  
  82. affliction = { ["paralysis"]           = { "bloodroot",    "herb",    1,     true,  false, true   },
  83.                ["blindness"]           = { "bayberry",     "herb",    2,     false, false, false  },
  84.                ["stupidity"]           = { "goldenseal",   "herb",    3,     true,  true,  false  },
  85.                ["thin_blood"]          = { "ginseng",      "herb",    4,     true,  false, false  },
  86.                ["masochism"]           = { "lobelia",      "herb",    5,     true,  true,  false  },
  87.                ["sandrot"]             = { "bloodroot",    "herb",    6,     true,  false, true   },
  88.                ["asthma"]              = { "kelp",         "herb",    7,     true,  false, true   },
  89.                ["recklessness"]        = { "lobelia",      "herb",    8,     true,  true,  false  },
  90.                ["mirroring"]           = { "bloodroot",    "herb",    9,     true,  false, false  },
  91.                ["epilepsy"]            = { "goldenseal",   "herb",    10,    true,  true,  false  },
  92.                ["paranoia"]            = { "ash",          "herb",    11,    true,  true,  false  },
  93.                ["hallucinations"]      = { "ash",          "herb",    12,    true,  true,  false  },
  94.                ["confusion"]           = { "ash",          "herb",    13,    true,  true,  false  },
  95.                ["loneliness"]          = { "lobelia",      "herb",    14,    true,  true,  false  },
  96.                ["magic_impaired"]      = { "kelp",         "herb",    15,    true,  false, true   },
  97.                ["berserking"]          = { "lobelia",      "herb",    16,    true,  true,  false  },
  98.                ["dementia"]            = { "ash",          "herb",    17,    true,  true,  false  },
  99.                ["sensitivity"]         = { "kelp",         "herb",    18,    true,  false, true   },
  100.                ["deafness"]            = { "hawthorn",     "herb",    19,    false, false, false  },
  101.                ["impatience"]          = { "goldenseal",   "herb",    20,    true,  true,  false  },
  102.                ["mental_disruption"]   = { "ginseng",      "herb",    21,    true,  false, false  },
  103.                ["physical_disruption"] = { "ginseng",      "herb",    22,    true,  false, false  },
  104.                ["hypersomnia"]         = { "ash",          "herb",    23,    true,  false, false  },
  105.                ["sunlight_allergy"]    = { "ginseng",      "herb",    24,    true,  false, false  },
  106.                ["vertigo"]             = { "lobelia",      "herb",    25,    true,  true,  false  },
  107.                ["superstition"]        = { "bellwort",     "herb",    26,    true,  false, false  },
  108.                ["hypochondria"]        = { "kelp",         "herb",    27,    true,  false, false  },
  109.                ["blood_curse"]         = { "ash",          "herb",    28,    true,  false, true   },
  110.                ["clumsiness"]          = { "kelp",         "herb",    29,    true,  false, true   },
  111.                ["haemophilia"]         = { "ginseng",      "herb",    30,    true,  false, true   },
  112.                ["vomiting"]            = { "ginseng",      "herb",    31,    true,  false, true   },
  113.                ["shyness"]             = { "goldenseal",   "herb",    32,    true,  true,  false  },
  114.                ["crippled"]            = { "bloodroot",    "herb",    33,    true,  false, false  },
  115.                ["crippled_body"]       = { "bloodroot",    "herb",    34,    true,  false, false  },
  116.                ["peace"]               = { "bellwort",     "herb",    35,    true,  false, false  },
  117.                ["pacifism"]            = { "bellwort",     "herb",    36,    true,  true,  false  },
  118.                ["lovers_effect"]       = { "bellwort",     "herb",    37,    true,  true,  false  },
  119.                ["justice"]             = { "bellwort",     "herb",    38,    true,  false, false  },
  120.                ["generosity"]          = { "bellwort",     "herb",    39,    true,  true,  false  },
  121.                ["lethargy"]            = { "ginseng",      "herb",    40,    true,  false, false  },
  122.                ["blood_poison"]        = { "kelp",         "herb",    41,    true,  false, true   },
  123.                ["weariness"]           = { "kelp",         "herb",    42,    true,  true,  false  },
  124.                ["dizziness"]           = { "goldenseal",   "herb",    43,    true,  true,  false  },
  125.                ["claustrophobia"]      = { "lobelia",      "herb",    44,    true,  true,  false  },
  126.                ["addiction"]           = { "ginseng",      "herb",    45,    true,  false, false  },
  127.                ["hatred"]              = { "ash",          "herb",    46,    true,  true,  false  },
  128.                ["agoraphobia"]         = { "lobelia",      "herb",    47,    true,  true,  false  },
  129.                ["dissonance"]          = { "goldenseal",   "herb",    48,    true,  false, false  },
  130.                ["heartflutter"]        = { "bloodroot",    "herb",    49,    true,  false, false  },
  131.                ["rend"]                = { "ginseng",      "herb",    50,    true,  false, false  },
  132.                ["infested"]            = { "goldenseal",   "herb",    51,    true,  false, false  },
  133.                ["blighted"]            = { "ash",          "herb",    52,    true,  false, false  },
  134.                ["limp_veins"]          = { "kelp",         "herb",    59,    true,  false, true   },
  135.                
  136.                ["commitment_fear"]     = { "lobelia",      "herb",    60,    false, false, false  },
  137.                ["hubris"]              = { "bellwort",     "herb",    61,    false, false, false  },
  138.                ["body_odor"]           = { "ginseng",      "herb",    62,    false, false, false  },
  139.                ["baldness"]            = { "kelp",         "herb",    63,    false, false, false  },
  140.                ["sadness"]             = { "ash",          "herb",    64,    false, false, false  },
  141.                
  142.                ["anorexia"]                    = { "epidermal to torso",        "salve",    1,     true,  true,  false  },
  143.                ["indifference"]                = { "epidermal to head",         "salve",    2,     true,  true,  false  },
  144.                ["destroyed_throat"]            = { "mending to head",           "salve",    3,     true,  false, false  },
  145.                ["head_mangled"]                = { "restoration to head",       "salve",    4,     false, false, false  },
  146.                ["head_bruised_critical"]       = { "mending to head",           "salve",    5,     false, false, false  },
  147.                ["torso_bruised_critical"]      = { "mending to torso",          "salve",    6,     false, false, false  },
  148.                ["right_leg_bruised_critical"]  = { "mending to right leg",      "salve",    7,     false, false, false  },
  149.                ["left_leg_bruised_critical"]   = { "mending to left leg",       "salve",    8,     false, false, false  },
  150.                ["right_arm_bruised_critical"]  = { "mending to right arm",      "salve",    9,     false, false, false  },
  151.                ["left_arm_bruised_critical"]   = { "mending to left arm",       "salve",    10,    false, false, false  },
  152.                ["right_leg_mangled"]           = { "restoration to right leg",  "salve",    11,    false, false, false  },              
  153.                ["left_leg_mangled"]            = { "restoration to left leg",   "salve",    12,    false, false, false  },
  154.                ["right_arm_mangled"]           = { "restoration to right arm",  "salve",    13,    false, false, false  },
  155.                ["left_arm_mangled"]            = { "restoration to left arm",   "salve",    14,    false, false, false  },
  156.                ["right_leg_damaged"]           = { "restoration to right leg",  "salve",    15,    false, false, false  },
  157.                ["left_leg_damaged"]            = { "restoration to left leg",   "salve",    16,    false, false, false  },
  158.                ["right_arm_damaged"]           = { "restoration to right arm",  "salve",    17,    false, false, false  },
  159.                ["left_arm_damaged"]            = { "restoration to left arm",   "salve",    18,    false, false, false  },
  160.                ["frozen"]                      = { "caloric",                   "salve",    19,    true,  false, false  },
  161.                ["shivering"]                   = { "caloric",                   "salve",    20,    true,  false, false  },
  162.                ["ablaze"]                      = { "mending to body",           "salve",    21,    true,  false, false  },
  163.                ["left_leg_broken"]             = { "mending to left leg",       "salve",    22,    true,  false, true   },
  164.                ["right_leg_broken"]            = { "mending to right leg",      "salve",    23,    true,  false, true   },
  165.                ["left_arm_broken"]             = { "mending to left arm",       "salve",    24,    true,  false, true   },
  166.                ["right_arm_broken"]            = { "mending to right arm",      "salve",    25,    true,  false, true   },
  167.                ["spinal_rip"]                  = { "restoration to torso",      "salve",    26,    false, false, false  },
  168.                ["head_bruised_moderate"]       = { "mending to head",           "salve",    27,    false, false, false  },
  169.                ["torso_bruised_moderate"]      = { "mending to torso",          "salve",    28,    false, false, false  },
  170.                ["right_leg_bruised_moderate"]  = { "mending to right leg",      "salve",    29,    false, false, false  },
  171.                ["left_leg_bruised_moderate"]   = { "mending to left leg",       "salve",    30,    false, false, false  },
  172.                ["right_arm_bruised_moderate"]  = { "mending to right arm",      "salve",    31,    false, false, false  },
  173.                ["left_arm_bruised_moderate"]   = { "mending to left arm",       "salve",    32,    false, false, false  },
  174.                ["head_damaged"]                = { "restoration to head",       "salve",    33,    false, false, false  },
  175.                ["head_bruised"]                = { "mending to head",           "salve",    34,    false, false, false  },
  176.                ["torso_bruised"]               = { "mending to torso",          "salve",    35,    false, false, false  },
  177.                ["right_leg_bruised"]           = { "mending to right leg",      "salve",    36,    false, false, false  },
  178.                ["left_leg_bruised"]            = { "mending to left leg",       "salve",    37,    false, false, false  },
  179.                ["right_arm_bruised"]           = { "mending to right arm",      "salve",    38,    false, false, false  },
  180.                ["left_arm_bruised"]            = { "mending to left arm",       "salve",    39,    false, false, false  },
  181.                ["blurry_vision"]               = { "epidermal to head",         "salve",    40,    true,  false, false  },
  182.                ["insulation"]                  = { "caloric",                   "salve",    41,    false, false, false  },
  183.                ["throatclaw"]                  = { "mending to head",           "salve",    42,    true,  false, true   },
  184.                ["crippled_throat"]             = { "mending to head",           "salve",    43,    true,  false, true   },
  185.                ["stuttering"]                  = { "epidermal to head",         "salve",    44,    true,  true,  false  },
  186.                ["density"]                     = { "mass",                      "salve",    45,    false, false, false  },
  187.                ["torso_mangled"]               = { "restoration to torso",      "salve",    46,    false, false, false  },
  188.                ["torso_damaged"]               = { "restoration to torso",      "salve",    47,    false, false, false  },
  189.                ["left_leg_prerestore"]         = { "restoration to left leg",   "salve",    48,    false, false, false  },
  190.                ["right_leg_prerestore"]        = { "restoration to right leg",  "salve",    49,    false, false, false  },
  191.                ["left_arm_prerestore"]         = { "restoration to left arm",   "salve",    50,    false, false, false  },
  192.                ["right_arm_prerestore"]        = { "restoration to right leg",  "salve",    51,    false, false, false  },
  193.                ["head_prerestore"]             = { "restoration to head",       "salve",    52,    false, false, false  },
  194.                ["torso_prerestore"]            = { "restoration to torso",      "salve",    53,    false, false, false  },
  195.                ["selarnia"]                    = { "mending to body",           "salve",    54,    true,  false, false  },
  196.              
  197.                ["aeon"]                = { "elm",          "pipe",    1,    true,  false, false  },
  198.                ["slickness"]           = { "valerian",     "pipe",    2,    true,  false, false  },
  199.                ["hellsight"]           = { "elm",          "pipe",    3,    true,  false, false  },
  200.                ["withering"]           = { "elm",          "pipe",    4,    true,  false, false  },
  201.                ["disfigurement"]       = { "valerian",     "pipe",    5,    true,  false, true   },
  202.                ["rebounding"]          = { "skullcap",     "pipe",    6,    false, false, false  },
  203.                ["deadening"]           = { "elm",          "pipe",    7,    true,  false, false  },
  204.  
  205.                ["voyria"]              = { "immunity",     "elixir",  1,    false, false, false  },
  206.                ["levitation"]          = { "levitation",   "elixir",  2,    false, false, false  },
  207.                ["venom_resistance"]    = { "venom",        "elixir",  3,    false, false, false  },
  208.                
  209.                ["writhe_impaled"]      = { "writhe from impale",            "writhe",    1,    false, false, false  },
  210.                ["writhe_feed"]         = { "writhe from feed",              "writhe",    2,    false, false, false  },
  211.                ["writhe_armpitlock"]   = { "writhe from armpit-jawlock",    "writhe",    3,    false, false, false  },
  212.                ["writhe_thighlock"]    = { "writhe from thigh-jawlock",     "writhe",    4,    false, false, false  },
  213.                ["writhe_necklock"]     = { "writhe from neck-jawlock",      "writhe",    5,    false, false, false  },
  214.                ["writhe_transfix"]     = { "writhe from transfix",          "writhe",    6,    false, false, false  },
  215.                ["writhe_ropes"]        = { "writhe from ropes",             "writhe",    7,    false, false, false  },
  216.                ["writhe_bind"]         = { "writhe from bind",              "writhe",    8,    false, false, false  },
  217.                ["writhe_web"]          = { "writhe from web",               "writhe",    9,    false, false, false  },
  218.                ["writhe_vines"]        = { "writhe from vines",             "writhe",    10,   false, false, false  },
  219.                ["mob_impaled"]         = { "writhe from impale",            "writhe",    11,   false, false, false  },
  220.                
  221.                ["idiocy"]              = { "-",                     "other",   1,    false, false, false  },
  222.                ["plodding"]            = { "-",                     "other",   2,    false, false, false  },
  223.                ["fear"]                = { "compose",               "other",   3,    false, false, false  },
  224.                ["asleep"]              = { "wake",                  "other",   4,    false, false, false  },
  225.                ["stun"]                = { "-",                     "other",   5,    false, false, false  },
  226.                ["void"]                = { "-",                     "other",   6,    false, false, false  },
  227.                ["weakvoid"]            = { "-",                     "other",   7,    false, false, false  },
  228.                ["blackout"]            = { "-",                     "other",   8,    false, false, false  },
  229.                ["disrupted"]           = { "concentrate",           "other",   9,    false, false, false  },
  230.                ["stormtouched"]        = { "-",                     "other",   10,   false, false, false  },
  231.                ["omen"]                = { "-",                     "other",   11,   false, false, false  },
  232.                ["vitalbane"]           = { "-",                     "other",   12,   false, false, false  },
  233.                ["shadowbrand"]         = { "-",                     "other",   13,   false, false, false  },
  234.                ["stonebrand"]          = { "-",                     "other",   14,   false, false, false  },
  235.                ["windbrand"]           = { "-",                     "other",   15,   false, false, false  },
  236.                ["spiritbrand"]         = { "-",                     "other",   16,   false, false, false  },
  237.                ["emberbrand"]          = { "-",                     "other",   17,   false, false, false  },
  238.                ["mistbrand"]           = { "-",                     "other",   18,   false, false, false  },
  239.                ["retardation"]         = { "-",                     "other",   19,   false, false, false  },
  240.                ["lifebane"]            = { "-",                     "other",   20,   false, false, false  },
  241.                ["premonition"]         = { "-",                     "other",   21,   false, true,  false  },
  242.                ["vinethorns"]          = { "-",                     "other",   22,   false, false, false  },
  243.                ["fallen"]              = { "-",                     "other",   23,   false, false, false  } }
  244.                
  245.  
  246.  
  247. --[[ Run certain things on world open and close. ]]--
  248.  
  249. function worldOpen()
  250.  
  251.    -- This just creates the windows and such for now.
  252.  
  253.    drawMap()
  254.    drawAfflictions()
  255.    
  256. end
  257.  
  258. function worldClose()
  259.  
  260. end
  261.  
  262.  
  263.  
  264. --[[ This is what we run when a prompt pops up. This really needs to be as smooth as possible. :/ ]] --
  265.  
  266. function onPrompt( name, line, wildcards, styles )
  267.  
  268.    -- First thing we do is rebuild the prompt to a more information friendly version.
  269.    
  270.    -- customPrompt( wildcards, styles )
  271.  
  272.    -- We grab GMCP data here from a plugin (as all OnPlugin...etc functions are only supported by plugins).
  273.    
  274.    require "json"
  275.  
  276.    vitals = json.decode( GetPluginVariable( plugin_GMCP, "gmcp_vitals" ) )
  277.    
  278.    -- Healing/reaction functions.
  279.  
  280.    if system == false then
  281.       return
  282.    end
  283.    
  284.    healVitals()           -- Sip health/mana, and eat moss.
  285.    cureAfflictions()      -- Eat herbs, apply salves, or use things like focus.
  286.    
  287.    checkDefences()        -- Check and see if defences like blindness and deafness are applied.
  288.    
  289.    executeBalanceQueue()  -- Queued commands waiting for balance and equilibrium.
  290.    
  291.    -- autoBasher()        -- Shitty autobasher. Really shitty.
  292.  
  293. end
  294.  
  295. function customPrompt( wildcards )
  296.  
  297.    if haveAffliction("blackout") or vitals == nil then
  298.       ColourNote( "silver", "black", ":" )
  299.       return
  300.    end
  301.    
  302.    -- Health.
  303.    
  304.    local health = tonumber(wildcards[1])
  305.    
  306.    if health > vitals.maxhp * 0.75 then
  307.       ColourTell( "green", "black", "H:" .. health .. " " )
  308.    elseif health > vitals.maxhp * 0.25 then
  309.       ColourTell( "yellow", "black", "H:" .. health .. " " )
  310.    elseif health > 0 then
  311.       ColourTell( "red", "black", "H:" .. health .. " " )
  312.    else
  313.       ColourTell( "silver", "black", "H:" .. health .. " " )
  314.    end
  315.    
  316.    -- Health change.
  317.      
  318.    if tonumber(vitals.hp) > health then
  319.       ColourTell( "red", "black", "<-" .. vitals.hp - health .. "> " )
  320.    elseif tonumber(vitals.hp) < health then
  321.       ColourTell( "lime", "black", "<" .. health - vitals.hp .. "> " )
  322.    -- else
  323.       -- ColourTell( "gray", "black", "<0> " )
  324.    end
  325.  
  326.    -- Mana.
  327.    
  328.    local mana = tonumber(wildcards[2])
  329.    
  330.    if mana > vitals.maxmp * 0.75 then
  331.       ColourTell( "green", "black", "M:" .. mana .. " " )
  332.    elseif mana > vitals.maxmp * 0.25 then
  333.       ColourTell( "yellow", "black", "M:" .. mana .. " " )
  334.    elseif mana > 0 then
  335.       ColourTell( "red", "black", "M:" .. mana .. " " )
  336.    else
  337.       ColourTell( "silver", "black", "M:" .. mana .. " " )
  338.    end
  339.  
  340.    -- Mana change.
  341.    
  342.    if tonumber(vitals.mp) > mana then
  343.       ColourTell( "red", "black", "<-" .. vitals.mp - mana .. "> " )
  344.    elseif tonumber(vitals.mp) < mana then
  345.       ColourTell( "lime", "black", "<" .. mana - vitals.mp .. "> " )
  346.    -- else
  347.       -- ColourTell( "gray", "black", " <0> " )
  348.    end
  349.    
  350.    -- Blood.
  351.    
  352.    ColourTell( "red", "black", "B:" .. wildcards[3] .. "% " )
  353.    
  354.    -- Status.
  355.    
  356.    ColourNote( "silver", "black", "[" .. wildcards[4] .. "]" )
  357.    
  358. end
  359.  
  360.  
  361.  
  362. --[[ This'll handle afflictions, the main bulk of shit. ]]--
  363.  
  364. function addAffliction( aff, secondary )
  365.  
  366.    if affliction[aff] == nil then
  367.       ColourTell( "red", "black", "Unknown affliction: " )
  368.       Note( aff )
  369.       return
  370.    end
  371.  
  372.    if haveAffliction(aff) then
  373.       return
  374.    end
  375.  
  376.    
  377.    local t, prio = whatAfflictionTable( affliction[aff][2] ), 1
  378.    
  379.    for i, name in ipairs(t) do
  380.       if affliction[aff][3] > affliction[name][3] then
  381.          prio = prio + 1
  382.       else
  383.          break
  384.       end
  385.    end
  386.  
  387.    table.insert(t, prio, aff)
  388.  
  389.  
  390.    -- Small hack fix to deal with things like fear in the mean time.
  391.    if t == other and affliction[aff][1] ~= "-" then
  392.       Send( affliction[aff][1] )
  393.    end
  394.    
  395.    -- GUI element.
  396.    drawAfflictions()  
  397.  
  398. end
  399.  
  400. function removeAffliction( aff )
  401.  
  402.    if affliction[aff] == nil then
  403.       ColourTell( "red", "black", "Unknown affliction: " )
  404.       Note( aff )
  405.       return
  406.    end
  407.  
  408.    if not haveAffliction(aff) then
  409.       return
  410.    end
  411.  
  412.  
  413.    local t, pos = whatAfflictionTable( affliction[aff][2] )
  414.    
  415.    for i, name in ipairs(t) do
  416.       if aff == name then
  417.          pos = i
  418.          break
  419.       end
  420.    end
  421.  
  422.    table.remove(t, pos)
  423.  
  424.    
  425.    -- GUI element.
  426.    drawAfflictions()
  427.  
  428. end
  429.  
  430. function haveAffliction( aff )
  431.  
  432.    local aff_t = { herb, salve, pipe, elixir, writhe, other }
  433.    
  434.    for i, t in ipairs(aff_t) do
  435.       for _, name in ipairs(t) do
  436.          if aff == name then
  437.             return true
  438.          end
  439.       end
  440.    end
  441.  
  442.    return false
  443.  
  444. end
  445.  
  446. function venomlockWarning()
  447.  
  448.    -- Basic warnings for venomlocks!
  449.  
  450.    if vlock_warning > 0 then
  451.       return
  452.    end
  453.    
  454.    if ( haveAffliction("anorexia") or haveAffliction("indifference") or haveAffliction("destroyed_throat") ) and
  455.       ( haveAffliction("slickness") or haveAffliction("earthrot") ) and
  456.         haveAffliction("asthma") then
  457.       if haveAffliction("paralysis") then
  458.          Note( "+-------------------------------------------+" )
  459.          Tell( "|    " )
  460.          ColourTell( "yellow", "black", "--*> " )
  461.          ColourTell( "red", "black", "VENOM-LOCKED + PARALYSIS" )
  462.          ColourTell( "yellow", "black", " <*--" )
  463.          Note( "     |" )
  464.          Note( "| HOPE FOR LUCKY PURITY TICKS / TRY TUMBLE! |" )
  465.          Note( "+-------------------------------------------+" )
  466.          vlock_warning = 2
  467.       else
  468.          Note( "+-------------------------------------------+" )
  469.          Note( "|           !!! VENOM-LOCKED !!!            |" )
  470.          Note( "| YOU'VE STILL GOT A CHANCE / BLOODBOIL OUT |" )
  471.          Note( "+-------------------------------------------+" )
  472.          vlock_warning = 1
  473.       end
  474.       AddTimer( "reset_vlock_lvl", 0, 0, 10, "", 1061, "venomlockResetLvl" )
  475.    end
  476.    
  477. end
  478.  
  479. function venomlockResetLvl()
  480.    vlock_warning = 0
  481. end
  482.  
  483. function cureAfflictionsHerbs()
  484.  
  485.    if #herb == 0 then
  486.       return
  487.    end
  488.  
  489.    if vitals.herb == "1" and sent_herb == false and
  490.       not haveAffliction("anorexia") and
  491.       not haveAffliction("indifference") and
  492.       not haveAffliction("destroyed_throat") and
  493.       #writhe == 0 then
  494.    
  495.       for i, name in ipairs(herb) do
  496.          if ( name == "blighted" or name == "infested" ) and haveAffliction("premonition") then
  497.             -- Do nothing.
  498.          else
  499.             sent_herb = true
  500.             if haveAffliction("stupidity") then
  501.                Send( "outc " .. affliction[name][1] )
  502.                Send( "outc " .. affliction[name][1] )
  503.                Send( "eat " .. affliction[name][1] )
  504.                Send( "inc " .. affliction[name][1] )
  505.                Send( "eat " .. affliction[name][1] )
  506.                Send( "eat " .. affliction[name][1] )
  507.             else
  508.                Send( "outc " .. affliction[name][1] )
  509.                Send( "eat " .. affliction[name][1] )
  510.             end
  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.          if haveAffliction("stupidity") or haveAffliction("head_mangled") then
  533.             Send( "apply " .. affliction[name][1] )
  534.             Send( "apply " .. affliction[name][1] )
  535.          else
  536.             Send( "apply " .. affliction[name][1] )
  537.          end
  538.          AddTimer( "salve_reset", 0, 0, resetDelay(), "", 1061, "resetSalve" )
  539.          break
  540.       end
  541.      
  542.    end
  543.    
  544. end
  545.  
  546. function cureAfflictionsPipes()
  547.  
  548.    if #pipe == 0 then
  549.       return
  550.    end
  551.  
  552.    if vitals.pipe == "1" and sent_pipe == false and
  553.       not haveAffliction("asthma") then
  554.    
  555.       for i, name in ipairs(pipe) do
  556.          sent_pipe = true
  557.          SSend( "smoke " .. affliction[name][1] )
  558.          AddTimer( "pipe_reset", 0, 0, resetDelay(), "", 1061, "resetPipe" )
  559.          break
  560.       end
  561.      
  562.    end
  563.    
  564. end
  565.  
  566. function cureAfflictionsElixirs()
  567.  
  568.    if #elixir == 0 then
  569.       return
  570.    end
  571.  
  572.    if vitals.affelixir == "1" and sent_elixir == false and
  573.       not haveAffliction("anorexia") and
  574.       not haveAffliction("indifference") and
  575.       not haveAffliction("destroyed_throat") then
  576.    
  577.       for i, name in ipairs(elixir) do
  578.          sent_elixir = true
  579.          SSend( "drink " .. affliction[name][1] )
  580.          AddTimer( "aff_elixir_reset", 0, 0, resetDelay(), "", 1061, "resetAffElixir" )
  581.          break
  582.       end
  583.      
  584.    end
  585.    
  586. end
  587.  
  588. function cureAfflictionsWrithes()
  589.  
  590.    if #writhe == 0 then
  591.       return
  592.    end
  593.  
  594.    if vitals.writhing ~= "1" and sent_writhe == false then
  595.    
  596.       for i, name in ipairs(writhe) do
  597.          if ( name == "writhe_impaled" or name == "writhe_feed" ) and vitals.balance == "0" then
  598.             break
  599.          end
  600.          sent_writhe = true
  601.          SSend( affliction[name][1] )
  602.          AddTimer( "writhe_reset", 0, 0, resetDelay(), "", 1061, "resetWrithe" )
  603.          break
  604.       end
  605.      
  606.    end
  607.    
  608. end
  609.  
  610. function cureAfflictionsTree( force )
  611.  
  612.    --[[ Basically, we check and see if we have 2 or more afflictions in a curing tree before firing off the
  613.         curing method. This way we know we won't use tree pointlessly, if we happen to have already sent off
  614.         a command to cure an affliction via a herb/salve. ]]--
  615.  
  616.    local aff_t, n = { herb, salve }, { 0, 0 }
  617.    local oktree = false
  618.  
  619.    for i, t in ipairs(aff_t) do
  620.       for _, name in ipairs(t) do
  621.          if affliction[name][4] == true then
  622.             n[i] = n[i] + 1
  623.             if n[i] == 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.       not haveAffliction("paralysis") and
  634.       not ( haveAffliction("left_arm_broken") and haveAffliction("right_arm_broken") ) then
  635.       sent_tree = true
  636.       Send( "touch tree" )
  637.       AddTimer( "reset_tree", 0, 0, resetDelay(), "", 1061, "resetTree" )
  638.    end
  639.  
  640. end
  641.  
  642. function cureAfflictionsFocus( force )
  643.  
  644.    -- Same thing as above, but now it's three because we might have sent tree.
  645.  
  646.    local aff_t, n = { herb, salve }, { 0, 0 }
  647.    local okfocus = false
  648.  
  649.    for i, t in ipairs(aff_t) do
  650.       for _, name in ipairs(t) do
  651.          if affliction[name][5] == true then
  652.             n[i] = n[i] + 1
  653.             if n[i] == 3 then okfocus = true break end
  654.          end
  655.       end
  656.    end
  657.    
  658.    -- Premonition will cause focus to send as long as we have focus balance. Only way to cure it.
  659.    if not haveAffliction("premonition") and not okfocus and not force then
  660.       return
  661.    end
  662.    
  663.    if vitals.focus == "1" and ( sent_tree == false or force ) and sent_focus == false and
  664.       not haveAffliction("impatience") and
  665.       tonumber(vitals.mp) >= vitals.maxmp / 2 then
  666.       sent_focus = true
  667.       Send( "focus" )
  668.       AddTimer( "reset_focus", 0, 0, resetDelay(), "", 1061, "resetFocus" )
  669.    end
  670.  
  671. end
  672.  
  673. function cureAfflictionsRenew( force )
  674.  
  675.    -- Like above, but now it's four because of focus as well.
  676.  
  677.    local aff_t, n = { herb, salve }, { 0, 0 }
  678.    local okrenew = false
  679.  
  680.    for i, t in ipairs(aff_t) do
  681.       for _, name in ipairs(t) do
  682.          if affliction[name][4] == true then
  683.             n[i] = n[i] + 1
  684.             if n[i] == 4 then okrenew = true break end
  685.          end
  686.       end
  687.    end
  688.    
  689.    if not okrenew and not force then
  690.       return
  691.    end
  692.  
  693.    if vitals.renew == "1" and ( sent_tree == false and sent_focus == false or force ) and sent_renew == false and
  694.       vitals.balance == "1" and vitals.equilibrium == "1" and
  695.       tonumber(vitals.mp) >= vitals.maxmp / 2 then
  696.       sent_renew = true
  697.       Send( "reconstitute" )
  698.       AddTimer( "reset_renew", 0, 0, resetDelay(), "", 1061, "resetRenew" )
  699.    end
  700.  
  701. end
  702.  
  703. function cureAfflictions()
  704.  
  705.    -- This is the beast function that calls all the curing functions!
  706.  
  707.    venomlockWarning()
  708.    
  709.    -- Dead.
  710.    if vitals.hp == "0" then
  711.       return
  712.    end
  713.    
  714.    -- Incapable of action.
  715.    if haveAffliction("stun") or haveAffliction("asleep") or haveAffliction("unconscious") then
  716.       return
  717.    end
  718.  
  719.    cureAfflictionsWrithes()
  720.  
  721.    -- Only writhes can fire with safety on, so channelled abilities can do their thing.
  722.    if safe_only == true then
  723.       return
  724.    end
  725.  
  726.    cureAfflictionsHerbs()
  727.    cureAfflictionsSalves()
  728.    cureAfflictionsPipes()
  729.    
  730.    cureAfflictionsElixirs()
  731.  
  732.    cureAfflictionsTree()
  733.    cureAfflictionsFocus()
  734.    cureAfflictionsRenew()
  735.  
  736. end
  737.  
  738. function resetAfflictions()
  739.  
  740.    -- Resets all afflictions.
  741.  
  742.    herb = {}
  743.    salve = {}
  744.    pipe = {}
  745.    elixir = {}
  746.    writhe = {}
  747.    other = {}
  748.    
  749.    healing = {}
  750.    
  751.    vlock_warning = 0
  752.    
  753.    -- GUI element.
  754.    drawAfflictions()
  755.  
  756. end
  757.  
  758. function resetAfflictionsType( cat )
  759.  
  760.    -- If we need to reset a group of afflictions belonging to one of these categories.
  761.  
  762.    local category = {
  763.       ["random"] = 4,
  764.       ["mental"] = 5,
  765.       ["physical"] = 6
  766.    }
  767.    
  768.    if category[cat] == nil then
  769.       return
  770.    end
  771.  
  772.    local aff_t = { herb, salve, pipe, other }
  773.  
  774.    local list, key = {}, category[cat]
  775.    
  776.    for i, t in ipairs(aff_t) do
  777.       for _, name in ipairs(t) do
  778.          if affliction[name][key] == true then
  779.             list[#list+1] = name
  780.          end
  781.       end
  782.    end
  783.    
  784.    for i, name in ipairs(list) do
  785.       removeAffliction(name)
  786.    end
  787.    
  788. end
  789.  
  790. function resetBalances()
  791.  
  792.    sent_sip = false
  793.    sent_moss = false
  794.  
  795.    sent_herb = false
  796.    sent_salve = false
  797.    sent_pipe = false
  798.    sent_elixir = false
  799.    sent_writhe = false
  800.  
  801.    sent_tree = false
  802.    sent_focus = false
  803.    sent_renew = false
  804.  
  805. end
  806.  
  807.  
  808. function resetOnConsumePlant( plant )
  809.  
  810.    local consumable = {
  811.       ["a bloodroot leaf"] = "bloodroot",
  812.       ["some prickly ash bark"] = "ash",
  813.       ["a goldenseal root"] = "goldenseal",
  814.       ["a piece of kelp"] = "kelp",
  815.       ["a lobelia seed"] = "lobelia",
  816.       ["a ginseng root"] = "ginseng",
  817.       ["a bellwort flower"] = "bellwort"
  818.    }
  819.    
  820.    if consumable[plant] == nil then
  821.       return
  822.    end
  823.    
  824.    local list = {}
  825.  
  826.    for i, name in ipairs(herb) do
  827.       if affliction[name][1] == consumable[plant] then
  828.          list[#list+1] = name
  829.       end
  830.    end
  831.    
  832.    for i, name in ipairs(list) do
  833.       removeAffliction(name)
  834.    end
  835.  
  836. end
  837.  
  838. function resetOnApplySalve( app, bpart )
  839.  
  840.    local application = {
  841.       ["an epidermal salve"] = { ["head"] = "epidermal to head",
  842.                                  ["torso"] = "epidermal to torso" },
  843.       ["a salve of mending"] = { ["head"] = "mending to head",
  844.                                  ["torso"] = "mending to torso",
  845.                                  ["body"] = "mending to body",      
  846.                                  ["left arm"] = "mending to left arm",
  847.                                  ["right arm"] = "mending to right arm",
  848.                                  ["left leg"] = "mending to left leg",
  849.                                  ["right leg"] = "mending to right leg" }
  850.    }
  851.  
  852.    if application[app][bpart] == nil then
  853.       return
  854.    end
  855.  
  856.    local list = {}
  857.  
  858.    for i, name in ipairs(salve) do
  859.       if affliction[name][1] == application[app][bpart] then
  860.          list[#list+1] = name
  861.       end
  862.    end
  863.  
  864.    for i, name in ipairs(list) do
  865.       removeAffliction(name)
  866.    end
  867.  
  868. end
  869.  
  870. function resetOnSmokePipe( plant )
  871.  
  872.    if plant ~= "valerian" and
  873.       plant ~= "elm" then
  874.       return
  875.    end
  876.    
  877.    local list = {}
  878.    
  879.    for i, name in ipairs(pipe) do
  880.       if affliction[name][1] == plant then
  881.          list[#list+1] = name
  882.       end
  883.    end
  884.  
  885.    for i, name in ipairs(list) do
  886.       removeAffliction(name)
  887.    end
  888.    
  889. end  
  890.  
  891. function resetOnEmptyWrithe()
  892.  
  893.    local list = {}
  894.  
  895.    for i, name in ipairs(writhe) do
  896.       list[#list+1] = name
  897.    end
  898.  
  899.    for i, name in ipairs(list) do
  900.       removeAffliction(name)
  901.    end
  902.  
  903. end
  904.  
  905.  
  906. function resetHerb()
  907.    sent_herb = false
  908. end
  909.  
  910. function resetSalve()
  911.    sent_salve = false
  912. end
  913.  
  914. function resetPipe()
  915.    sent_pipe = false
  916. end
  917.  
  918. function resetAffElixir()
  919.    sent_elixir = false
  920. end
  921.  
  922. function resetWrithe()
  923.    sent_writhe = false
  924. end
  925.  
  926.  
  927. function resetTree()
  928.    sent_tree = false
  929. end
  930.  
  931. function resetFocus()
  932.    sent_focus = false
  933. end
  934.  
  935. function resetRenew()
  936.    sent_renew = false
  937. end
  938.  
  939.  
  940.  
  941. --[[ Functions for AutoSipper and healing vitals ]]--
  942.  
  943. function healVitals()
  944.  
  945.    if sipper == true and safe_only == false and vitals.hp ~= "0" and
  946.       not haveAffliction("anorexia") and
  947.       not haveAffliction("indifference") then
  948.  
  949.       if vitals.elixir == "1" and sent_sip == false then
  950.     --[[ if tonumber(vitals.mp) <= vitals.maxmp * force_mana_threshold then
  951.             sent_sip = true
  952.             Send( "drink mana" )
  953.             AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
  954.          ]]--  
  955.          if tonumber(vitals.hp) <= vitals.maxhp * health_threshold then
  956.             sent_sip = true
  957.             Send( "drink health" )
  958.             AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
  959.          elseif tonumber(vitals.mp) <= vitals.maxmp * mana_threshold then
  960.             sent_sip = true
  961.             Send( "drink mana" )
  962.             AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
  963.          end
  964.       end
  965.  
  966.       if vitals.moss == "1" and sent_moss == false and #writhe == 0 then
  967.          if tonumber(vitals.hp) <= vitals.maxhp * moss_threshold or
  968.             tonumber(vitals.mp) <= vitals.maxmp * moss_threshold or
  969.             haveAffliction("idiocy") or
  970.             haveAffliction("plodding") then
  971.             sent_moss = true
  972.             Send( "outc moss" )
  973.             Send( "eat moss" )
  974.             AddTimer( "moss_reset", 0, 0, resetDelay(), "", 1061, "resetMoss" )
  975.          end
  976.       end
  977.      
  978.    end
  979.    
  980. end
  981.  
  982. function resetElixir()
  983.    sent_sip = false
  984. end
  985.  
  986. function resetMoss()
  987.    sent_moss = false
  988. end
  989.  
  990.  
  991.  
  992. --[[ Queue for performing actions that require balance or equilibrium. ]]--
  993.  
  994. function addBalanceQueue( cmd, bal, eq, wait, exe )
  995.  
  996.    if type(cmd) ~= "string" then
  997.       ColourTell( "red", "black", "ERROR: " )
  998.       Note( "addBalanceQueue(str,str,str,bool,bool) - 'cmd' is not a string." )
  999.       return
  1000.    end
  1001.    
  1002.    if type(bal) ~= "string" and ( bal ~= "1" and bal ~= "0" ) then
  1003.       ColourTell( "red", "black", "ERROR: " )
  1004.       Note( "addBalanceQueue(str,str,str,bool,bool) - 'bal' is not a string, or is not \"1\" or \"0\"." )
  1005.       return
  1006.    end
  1007.  
  1008.    if type(eq) ~= "string" and ( eq ~= "1" and eq ~= "0" ) then
  1009.       ColourTell( "red", "black", "ERROR: " )
  1010.       Note( "addBalanceQueue(str,str,str,bool,bool) - 'eq' is not a string, or is not \"1\" or \"0\"." )
  1011.       return
  1012.    end
  1013.    
  1014.    if type(wait) ~= "boolean" then
  1015.       ColourTell( "red", "black", "ERROR: " )
  1016.       Note( "addBalanceQueue(str,str,str,bool,bool) - 'wait' is not a boolean." )
  1017.       return
  1018.    end
  1019.    
  1020.    if type(exe) ~= "boolean" then
  1021.       ColourTell( "red", "black", "ERROR: " )
  1022.       Note( "addBalanceQueue(str,str,str,bool,bool) - 'exe' is not a boolean." )
  1023.       return
  1024.    end    
  1025.  
  1026.    queue[#queue+1] = { cmd, bal, eq, wait, exe }
  1027.    
  1028.    executeBalanceQueue()
  1029.  
  1030. end
  1031.  
  1032. function executeBalanceQueue()
  1033.  
  1034.    -- This handles queued commands, and can make sure we're on balance and such.
  1035.  
  1036.    if awaiting_balance_use == true then
  1037.       if vitals.balance == "0" or vitals.equilibrium == "0" then
  1038.          awaiting_balance_use = false
  1039.          DeleteTimer( "queue_reset" )
  1040.       else
  1041.          return
  1042.       end
  1043.    end
  1044.    
  1045.    if safe_only == true then
  1046.       return
  1047.    end
  1048.  
  1049.    local del = 0
  1050.    
  1051.    for i, name in ipairs(queue) do
  1052.       if vitals.balance == queue[i][2] and vitals.equilibrium == queue[i][3] then
  1053.      
  1054.          if queue[i][5] == true then
  1055.             Execute( queue[i][1] )
  1056.          else
  1057.             Send( queue[i][1] )
  1058.          end  
  1059.          
  1060.          del = del + 1
  1061.          
  1062.          if queue[i][4] == true then
  1063.             awaiting_balance_use = true
  1064.             AddTimer( "queue_reset", 0, 0, 5, "", 1061, "resetQueue" )
  1065.             break
  1066.          end
  1067.          
  1068.       end
  1069.    end
  1070.    
  1071.    while del > 0 do
  1072.       table.remove(queue, 1)
  1073.       del = del - 1
  1074.    end
  1075.    
  1076. end
  1077.  
  1078. function clearQueue()
  1079.    queue = {}
  1080.    awaiting_balance_use = false
  1081. end
  1082.  
  1083. function resetQueue()
  1084.    awaiting_balance_use = false
  1085. end
  1086.  
  1087.  
  1088.  
  1089. --[[ Basic routine that'll be expanded later to deal with defences. ]]--
  1090.  
  1091. function checkDefences()
  1092.  
  1093.    if stay_blind_deaf == true then
  1094.    
  1095.       if vitals.blind == "0" then
  1096.          addAffliction("blindness")
  1097.       end
  1098.      
  1099.       if vitals.deaf == "0" then
  1100.          addAffliction("deafness")
  1101.       end
  1102.  
  1103.    end
  1104.  
  1105. end
  1106.  
  1107.  
  1108.  
  1109. --[[ This is all the scripting for the GUI. For now it'll probably be tacky until I learn more about miniwindows. ]]--
  1110.  
  1111. function drawMap( name, line, wildcards, styles )
  1112.  
  1113.    map[#map+1] = styles
  1114.  
  1115.    -- So basically we draw the map at the end once we have everything.
  1116.    
  1117.    if gui_elements == false then
  1118.       return
  1119.    end
  1120.    
  1121.    local win = GetPluginID() .. ":map"
  1122.    local font = "f"
  1123.    
  1124.    if not WindowInfo( win, 1 ) then
  1125.       WindowCreate( win, 0, 0, 0, 0, 6, 0, 0 )
  1126.       WindowFont( win, font, "FixedSys", 9 )
  1127.    end
  1128.    
  1129.    local font_height = WindowFontInfo( win, font, 1 )
  1130.    
  1131.    local window_width = 370 + 18
  1132.    local window_height = font_height * 26 + 10
  1133.    
  1134.    WindowCreate( win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB("black") )
  1135.    WindowRectOp( win, 5, 0, 0, 0, 0, 5, 15 + 0x1000 )
  1136.    
  1137.    local y = font_height / 2 + 5
  1138.  
  1139.    for i, styles in ipairs(map) do
  1140.       local x = 5 + 8
  1141.       for _, style in ipairs(styles) do
  1142.          x = x + WindowText( win, font, style.text, x, y, 0, 0, style.textcolour )
  1143.       end
  1144.       y = y + font_height
  1145.    end
  1146.  
  1147.    WindowShow( win, true )
  1148.    
  1149. end
  1150.  
  1151. function captureMap( name, line, wildcards, styles )
  1152.    map[#map+1] = styles
  1153. end
  1154.  
  1155.  
  1156. function drawAfflictions()
  1157.  
  1158.    if gui_elements == false then
  1159.       return
  1160.    end
  1161.  
  1162.    local win = GetPluginID() .. ":afflictions"
  1163.    local font = "f"
  1164.    
  1165.    if not WindowInfo( win, 1 ) then
  1166.       WindowCreate( win, 0, 0, 0, 0, 8, 0, 0 )
  1167.       WindowFont( win, font, "FixedSys", 9 )
  1168.    end
  1169.    
  1170.    local font_height = WindowFontInfo( win, font, 1 )
  1171.    
  1172.    local window_width = 370 + 18
  1173.    local window_height = font_height * 24 + 10
  1174.    
  1175.    WindowCreate( win, 0, 0, window_width, window_height, 8, 0, ColourNameToRGB("black") )
  1176.    -- WindowRectOp( win, 5, 0, 0, 0, 0, 5, 15 + 0x1000 )
  1177.    
  1178.    local y = font_height / 2 + 5
  1179.    local x = 13
  1180.  
  1181.    WindowText( win, font, "Afflictions:", x, y, 0, 0, ColourNameToRGB("red") )
  1182.    
  1183.    y = y + font_height
  1184.    
  1185.    local aff_t = { herb, salve, pipe, elixir, writhe, other }
  1186.  
  1187.    x = x + 10
  1188.    
  1189.    for i, t in ipairs(aff_t) do
  1190.       y = y + 3
  1191.       for _, name in ipairs(t) do
  1192.          WindowText( win, font, "* " .. name, x, y, 0, 0, whatAfflictionColour(t) )
  1193.          y = y + font_height
  1194.          
  1195.          if y >= font_height * 23 then
  1196.             y = font_height / 2 + 5 + font_height
  1197.             x = 224 + 5
  1198.          end
  1199.       end
  1200.    end
  1201.      
  1202.    WindowShow( win, true )
  1203.    
  1204. end
  1205.    
  1206.  
  1207.  
  1208. --[[ Utility functions sit below! They make life a lot easier. :) ]]--
  1209.  
  1210. function SSend( command )
  1211.  
  1212.    -- Sends twice if you have stupidity, else it'll only send once.
  1213.  
  1214.    if haveAffliction("stupidity") then
  1215.       Send( command )
  1216.    end
  1217.    
  1218.    Send( command )
  1219.  
  1220. end
  1221.  
  1222. function ringVibes()
  1223.  
  1224.    -- Why AddTimer doesn't allow newline chars is beyond me. >:(
  1225.  
  1226.    Note( " +--------------------------+ " )
  1227.    Note( " | NEED TO RING VIBRATIONS! | " )
  1228.    Note( " +--------------------------+ " )
  1229.    
  1230. end
  1231.  
  1232. function whatAfflictionTable( name )
  1233.  
  1234.    -- Find the right affliction table.
  1235.  
  1236.    local list = {
  1237.       ["herb"] = herb,
  1238.       ["salve"] = salve,
  1239.       ["pipe"] = pipe,
  1240.       ["elixir"] = elixir,
  1241.       ["writhe"] = writhe,
  1242.       ["other"] = other
  1243.    }
  1244.    
  1245.    return list[name]
  1246.    
  1247. end
  1248.  
  1249. function whatAfflictionColour( t )
  1250.  
  1251.    -- What colour each affliction should be for drawing.
  1252.  
  1253.    if t == herb then
  1254.       return ColourNameToRGB("lime")
  1255.    elseif t == salve then
  1256.       return ColourNameToRGB("darkorange")
  1257.    elseif t == pipe then
  1258.       return ColourNameToRGB("blueviolet")
  1259.    elseif t == elixir then
  1260.       return ColourNameToRGB("dodgerblue")
  1261.    elseif t == writhe then
  1262.       return ColourNameToRGB("darkgray")
  1263.    elseif t == other then
  1264.       return ColourNameToRGB("yellow")
  1265.    end
  1266.    
  1267.    return ColourNameToRGB("white")
  1268.  
  1269. end
  1270.  
  1271. function roundNum( x )
  1272.  
  1273.    -- Rounding because Lua doesn't have one inbuilt.
  1274.  
  1275.    if x >= 0 then
  1276.       return math.floor( x + 0.5 )
  1277.    end
  1278.  
  1279.    return math.ceil( x - 0.5 )
  1280.    
  1281. end
  1282.  
  1283. function resetSafeOnly()
  1284.  
  1285.    -- Resets the safe_only variable so curing can begin kicking in again.
  1286.    
  1287.    ColourNote( "olive", "black", "-- Overriding safety --" )
  1288.    
  1289.    safe_only = false
  1290.  
  1291. end
  1292.  
  1293. function resetDelay()
  1294.  
  1295.    -- Aeon and Retardation delay input by 1.5 seconds, so we need to account for that.
  1296.  
  1297.    if haveAffliction("aeon") or haveAffliction("retardation") then
  1298.       return 2.5
  1299.    end
  1300.  
  1301.    return 1.2
  1302.  
  1303. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement