Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Dat System Created: By me
- Organize your code so that other people can read it, you might want to give this away
- one day to a pretty lady, or some stupid thing like that.
- --]]
- -- All globals that require initialization should be set here.
- system = true -- Full on/off toggle for automated responses.
- safe_only = false -- Switches off everything but important responses (ie, for behead).
- vitals = nil -- Vitals table that we receive from GMCP.
- plugin_GMCP = "54bd8f89ff91b21ea6e3e07f" -- Plugin ID for GMCP.
- plugin_G15Display = "21b1c9f780b8984e2e1450fa" -- Plugin ID for G15 Display.
- -- Balance queue for queuing up various commands.
- queue = {} -- Table for balance queue.
- awaiting_balance_use = false -- Waiting for consumption of balance or equilibrium.
- -- Healing for vitals (health, mana, etc) and related stuff.
- sipper = true -- Switch for sipping health/mana.
- use_moss = true -- Switch for eating moss.
- health_threshold = 0.82 -- Threshold for sipping health.
- mana_threshold = 0.85 -- Threshold for sipping mana.
- force_mana_threshold = 0.35 -- Threshold for sipping mana over health.
- moss_threshold = 0.65 -- Threshold for consuming moss.
- sent_sip = false -- Attempting to sip for health/mana.
- sent_moss = false -- Attempting to eat moss.
- -- Healing for afflictions (salves, pipes, etc) and related stuff.
- herb = {} -- Table for current herbal afflictions.
- salve = {} -- Table for current salve afflictions.
- pipe = {} -- Table for current pipe afflictions.
- elixir = {} -- Table for current elixir afflictions.
- writhe = {} -- Table for current writhe afflictions.
- other = {} -- Table for current afflictions that don't fall into the above.
- curing = {} -- Table for afflictions that the system is currently attempting to heal.
- unknown_afflictions = 0 -- Counter for amount of hidden afflictions.
- vlock_warning = 0 -- Levelled warning system for when a venom-lock is achieved.
- last_pipe = "" -- Last pipe we smoked. Might be redundant later.
- sent_herb = false -- Attempting to eat herb.
- sent_salve = false -- Attempting to apply salve.
- sent_pipe = false -- Attempting to smoke pipe.
- sent_elixir = false -- Attempting to drink affliction healing elixir.
- sent_writhe = false -- Attempting to writhe.
- sent_tree = false -- Attempting to touch tree.
- sent_focus = false -- Attempting to use focus.
- sent_renew = false -- Attempting to use renew.
- -- Automatic application of combat-related defences (like blindness).
- stay_blind_deaf = true -- Automatic application of bayberry and hawthorn.
- stay_insomniac = true -- Automatic use of insomnia to prevent sleep.
- stay_massed = false -- Automatic mass application on fade.
- stay_rebounded = false -- Automatic application of skullcap.
- -- GUI required variables and the such. This'll get complicated.
- gui_elements = true -- Draw all GUI elements. Switch it off if you just want the game by default.
- map = {} -- Captured line styles of MAP for replication to a miniwindow.
- --[[ Affliction database. Contains information on all the afflictions for the system to call upon. ]]--
- -- Name: Cure, Type, Priority. Random cure? Mental cure? Physical cure?
- affliction = { ["paralysis"] = { "bloodroot", "herb", 1, true, false, true },
- ["blindness"] = { "bayberry", "herb", 2, false, false, false },
- ["stupidity"] = { "goldenseal", "herb", 3, true, true, false },
- ["thin_blood"] = { "ginseng", "herb", 4, true, false, false },
- ["masochism"] = { "lobelia", "herb", 5, true, true, false },
- ["sandrot"] = { "bloodroot", "herb", 6, true, false, true },
- ["asthma"] = { "kelp", "herb", 7, true, false, true },
- ["recklessness"] = { "lobelia", "herb", 8, true, true, false },
- ["mirroring"] = { "bloodroot", "herb", 9, true, false, false },
- ["epilepsy"] = { "goldenseal", "herb", 10, true, true, false },
- ["paranoia"] = { "ash", "herb", 11, true, true, false },
- ["hallucinations"] = { "ash", "herb", 12, true, true, false },
- ["confusion"] = { "ash", "herb", 13, true, true, false },
- ["loneliness"] = { "lobelia", "herb", 14, true, true, false },
- ["magic_impaired"] = { "kelp", "herb", 15, true, false, true },
- ["berserking"] = { "lobelia", "herb", 16, true, true, false },
- ["dementia"] = { "ash", "herb", 17, true, true, false },
- ["sensitivity"] = { "kelp", "herb", 18, true, false, true },
- ["deafness"] = { "hawthorn", "herb", 19, false, false, false },
- ["impatience"] = { "goldenseal", "herb", 20, true, true, false },
- ["mental_disruption"] = { "ginseng", "herb", 21, true, false, false },
- ["physical_disruption"] = { "ginseng", "herb", 22, true, false, false },
- ["hypersomnia"] = { "ash", "herb", 23, true, false, false },
- ["sunlight_allergy"] = { "ginseng", "herb", 24, true, false, false },
- ["vertigo"] = { "lobelia", "herb", 25, true, true, false },
- ["superstition"] = { "bellwort", "herb", 26, true, false, false },
- ["hypochondria"] = { "kelp", "herb", 27, true, false, false },
- ["blood_curse"] = { "ash", "herb", 28, true, false, true },
- ["clumsiness"] = { "kelp", "herb", 29, true, false, true },
- ["haemophilia"] = { "ginseng", "herb", 30, true, false, true },
- ["vomiting"] = { "ginseng", "herb", 31, true, false, true },
- ["shyness"] = { "goldenseal", "herb", 32, true, true, false },
- ["crippled"] = { "bloodroot", "herb", 33, true, false, false },
- ["crippled_body"] = { "bloodroot", "herb", 34, true, false, false },
- ["peace"] = { "bellwort", "herb", 35, true, false, false },
- ["pacifism"] = { "bellwort", "herb", 36, true, true, false },
- ["lovers_effect"] = { "bellwort", "herb", 37, true, true, false },
- ["justice"] = { "bellwort", "herb", 38, true, false, false },
- ["generosity"] = { "bellwort", "herb", 39, true, true, false },
- ["lethargy"] = { "ginseng", "herb", 40, true, false, false },
- ["blood_poison"] = { "kelp", "herb", 41, true, false, true },
- ["weariness"] = { "kelp", "herb", 42, true, true, false },
- ["dizziness"] = { "goldenseal", "herb", 43, true, true, false },
- ["claustrophobia"] = { "lobelia", "herb", 44, true, true, false },
- ["addiction"] = { "ginseng", "herb", 45, true, false, false },
- ["hatred"] = { "ash", "herb", 46, true, true, false },
- ["agoraphobia"] = { "lobelia", "herb", 47, true, true, false },
- ["dissonance"] = { "goldenseal", "herb", 48, true, false, false },
- ["heartflutter"] = { "bloodroot", "herb", 49, true, false, false },
- ["rend"] = { "ginseng", "herb", 50, true, false, false },
- ["infested"] = { "goldenseal", "herb", 51, true, false, false },
- ["blighted"] = { "ash", "herb", 52, true, false, false },
- ["limp_veins"] = { "kelp", "herb", 59, true, false, true },
- ["commitment_fear"] = { "lobelia", "herb", 60, false, false, false },
- ["hubris"] = { "bellwort", "herb", 61, false, false, false },
- ["body_odor"] = { "ginseng", "herb", 62, false, false, false },
- ["baldness"] = { "kelp", "herb", 63, false, false, false },
- ["sadness"] = { "ash", "herb", 64, false, false, false },
- ["anorexia"] = { "epidermal to torso", "salve", 1, true, true, false },
- ["indifference"] = { "epidermal to head", "salve", 2, true, true, false },
- ["destroyed_throat"] = { "mending to head", "salve", 3, true, false, false },
- ["head_mangled"] = { "restoration to head", "salve", 4, false, false, false },
- ["head_bruised_critical"] = { "mending to head", "salve", 5, false, false, false },
- ["torso_bruised_critical"] = { "mending to torso", "salve", 6, false, false, false },
- ["right_leg_bruised_critical"] = { "mending to right leg", "salve", 7, false, false, false },
- ["left_leg_bruised_critical"] = { "mending to left leg", "salve", 8, false, false, false },
- ["right_arm_bruised_critical"] = { "mending to right arm", "salve", 9, false, false, false },
- ["left_arm_bruised_critical"] = { "mending to left arm", "salve", 10, false, false, false },
- ["right_leg_mangled"] = { "restoration to right leg", "salve", 11, false, false, false },
- ["left_leg_mangled"] = { "restoration to left leg", "salve", 12, false, false, false },
- ["right_arm_mangled"] = { "restoration to right arm", "salve", 13, false, false, false },
- ["left_arm_mangled"] = { "restoration to left arm", "salve", 14, false, false, false },
- ["right_leg_damaged"] = { "restoration to right leg", "salve", 15, false, false, false },
- ["left_leg_damaged"] = { "restoration to left leg", "salve", 16, false, false, false },
- ["right_arm_damaged"] = { "restoration to right arm", "salve", 17, false, false, false },
- ["left_arm_damaged"] = { "restoration to left arm", "salve", 18, false, false, false },
- ["frozen"] = { "caloric", "salve", 19, true, false, false },
- ["shivering"] = { "caloric", "salve", 20, true, false, false },
- ["ablaze"] = { "mending to body", "salve", 21, true, false, false },
- ["left_leg_broken"] = { "mending to left leg", "salve", 22, true, false, true },
- ["right_leg_broken"] = { "mending to right leg", "salve", 23, true, false, true },
- ["left_arm_broken"] = { "mending to left arm", "salve", 24, true, false, true },
- ["right_arm_broken"] = { "mending to right arm", "salve", 25, true, false, true },
- ["spinal_rip"] = { "restoration to torso", "salve", 26, false, false, false },
- ["head_bruised_moderate"] = { "mending to head", "salve", 27, false, false, false },
- ["torso_bruised_moderate"] = { "mending to torso", "salve", 28, false, false, false },
- ["right_leg_bruised_moderate"] = { "mending to right leg", "salve", 29, false, false, false },
- ["left_leg_bruised_moderate"] = { "mending to left leg", "salve", 30, false, false, false },
- ["right_arm_bruised_moderate"] = { "mending to right arm", "salve", 31, false, false, false },
- ["left_arm_bruised_moderate"] = { "mending to left arm", "salve", 32, false, false, false },
- ["head_damaged"] = { "restoration to head", "salve", 33, false, false, false },
- ["head_bruised"] = { "mending to head", "salve", 34, false, false, false },
- ["torso_bruised"] = { "mending to torso", "salve", 35, false, false, false },
- ["right_leg_bruised"] = { "mending to right leg", "salve", 36, false, false, false },
- ["left_leg_bruised"] = { "mending to left leg", "salve", 37, false, false, false },
- ["right_arm_bruised"] = { "mending to right arm", "salve", 38, false, false, false },
- ["left_arm_bruised"] = { "mending to left arm", "salve", 39, false, false, false },
- ["blurry_vision"] = { "epidermal to head", "salve", 40, true, false, false },
- ["insulation"] = { "caloric", "salve", 41, false, false, false },
- ["throatclaw"] = { "mending to head", "salve", 42, true, false, true },
- ["crippled_throat"] = { "mending to head", "salve", 43, true, false, true },
- ["stuttering"] = { "epidermal to head", "salve", 44, true, true, false },
- ["density"] = { "mass", "salve", 45, false, false, false },
- ["torso_mangled"] = { "restoration to torso", "salve", 46, false, false, false },
- ["torso_damaged"] = { "restoration to torso", "salve", 47, false, false, false },
- ["left_leg_prerestore"] = { "restoration to left leg", "salve", 48, false, false, false },
- ["right_leg_prerestore"] = { "restoration to right leg", "salve", 49, false, false, false },
- ["left_arm_prerestore"] = { "restoration to left arm", "salve", 50, false, false, false },
- ["right_arm_prerestore"] = { "restoration to right leg", "salve", 51, false, false, false },
- ["head_prerestore"] = { "restoration to head", "salve", 52, false, false, false },
- ["torso_prerestore"] = { "restoration to torso", "salve", 53, false, false, false },
- ["selarnia"] = { "mending to body", "salve", 54, true, false, false },
- ["aeon"] = { "elm", "pipe", 1, true, false, false },
- ["slickness"] = { "valerian", "pipe", 2, true, false, false },
- ["hellsight"] = { "elm", "pipe", 3, true, false, false },
- ["withering"] = { "elm", "pipe", 4, true, false, false },
- ["disfigurement"] = { "valerian", "pipe", 5, true, false, true },
- ["rebounding"] = { "skullcap", "pipe", 6, false, false, false },
- ["deadening"] = { "elm", "pipe", 7, true, false, false },
- ["voyria"] = { "immunity", "elixir", 1, false, false, false },
- ["levitation"] = { "levitation", "elixir", 2, false, false, false },
- ["venom_resistance"] = { "venom", "elixir", 3, false, false, false },
- ["writhe_impaled"] = { "writhe from impale", "writhe", 1, false, false, false },
- ["writhe_feed"] = { "writhe from feed", "writhe", 2, false, false, false },
- ["writhe_armpitlock"] = { "writhe from armpit-jawlock", "writhe", 3, false, false, false },
- ["writhe_thighlock"] = { "writhe from thigh-jawlock", "writhe", 4, false, false, false },
- ["writhe_necklock"] = { "writhe from neck-jawlock", "writhe", 5, false, false, false },
- ["writhe_transfix"] = { "writhe from transfix", "writhe", 6, false, false, false },
- ["writhe_ropes"] = { "writhe from ropes", "writhe", 7, false, false, false },
- ["writhe_bind"] = { "writhe from bind", "writhe", 8, false, false, false },
- ["writhe_web"] = { "writhe from web", "writhe", 9, false, false, false },
- ["writhe_vines"] = { "writhe from vines", "writhe", 10, false, false, false },
- ["mob_impaled"] = { "writhe from impale", "writhe", 11, false, false, false },
- ["idiocy"] = { "-", "other", 1, false, false, false },
- ["plodding"] = { "-", "other", 2, false, false, false },
- ["fear"] = { "compose", "other", 3, false, false, false },
- ["asleep"] = { "wake", "other", 4, false, false, false },
- ["stun"] = { "-", "other", 5, false, false, false },
- ["void"] = { "-", "other", 6, false, false, false },
- ["weakvoid"] = { "-", "other", 7, false, false, false },
- ["blackout"] = { "-", "other", 8, false, false, false },
- ["disrupted"] = { "concentrate", "other", 9, false, false, false },
- ["stormtouched"] = { "-", "other", 10, false, false, false },
- ["omen"] = { "-", "other", 11, false, false, false },
- ["vitalbane"] = { "-", "other", 12, false, false, false },
- ["shadowbrand"] = { "-", "other", 13, false, false, false },
- ["stonebrand"] = { "-", "other", 14, false, false, false },
- ["windbrand"] = { "-", "other", 15, false, false, false },
- ["spiritbrand"] = { "-", "other", 16, false, false, false },
- ["emberbrand"] = { "-", "other", 17, false, false, false },
- ["mistbrand"] = { "-", "other", 18, false, false, false },
- ["retardation"] = { "-", "other", 19, false, false, false },
- ["lifebane"] = { "-", "other", 20, false, false, false },
- ["premonition"] = { "-", "other", 21, false, true, false },
- ["vinethorns"] = { "-", "other", 22, false, false, false },
- ["fallen"] = { "-", "other", 23, false, false, false } }
- --[[ Run certain things on world open and close. ]]--
- function worldOpen()
- -- This just creates the windows and such for now.
- drawMap()
- drawAfflictions()
- end
- function worldClose()
- end
- --[[ This is what we run when a prompt pops up. This really needs to be as smooth as possible. :/ ]] --
- function onPrompt( name, line, wildcards, styles )
- -- First thing we do is rebuild the prompt to a more information friendly version.
- -- customPrompt( wildcards, styles )
- -- We grab GMCP data here from a plugin (as all OnPlugin...etc functions are only supported by plugins).
- require "json"
- vitals = json.decode( GetPluginVariable( plugin_GMCP, "gmcp_vitals" ) )
- -- Healing/reaction functions.
- if system == false then
- return
- end
- healVitals() -- Sip health/mana, and eat moss.
- cureAfflictions() -- Eat herbs, apply salves, or use things like focus.
- checkDefences() -- Check and see if defences like blindness and deafness are applied.
- executeBalanceQueue() -- Queued commands waiting for balance and equilibrium.
- -- autoBasher() -- Shitty autobasher. Really shitty.
- end
- function customPrompt( wildcards )
- if haveAffliction("blackout") or vitals == nil then
- ColourNote( "silver", "black", ":" )
- return
- end
- -- Health.
- local health = tonumber(wildcards[1])
- if health > vitals.maxhp * 0.75 then
- ColourTell( "green", "black", "H:" .. health .. " " )
- elseif health > vitals.maxhp * 0.25 then
- ColourTell( "yellow", "black", "H:" .. health .. " " )
- elseif health > 0 then
- ColourTell( "red", "black", "H:" .. health .. " " )
- else
- ColourTell( "silver", "black", "H:" .. health .. " " )
- end
- -- Health change.
- if tonumber(vitals.hp) > health then
- ColourTell( "red", "black", "<-" .. vitals.hp - health .. "> " )
- elseif tonumber(vitals.hp) < health then
- ColourTell( "lime", "black", "<" .. health - vitals.hp .. "> " )
- -- else
- -- ColourTell( "gray", "black", "<0> " )
- end
- -- Mana.
- local mana = tonumber(wildcards[2])
- if mana > vitals.maxmp * 0.75 then
- ColourTell( "green", "black", "M:" .. mana .. " " )
- elseif mana > vitals.maxmp * 0.25 then
- ColourTell( "yellow", "black", "M:" .. mana .. " " )
- elseif mana > 0 then
- ColourTell( "red", "black", "M:" .. mana .. " " )
- else
- ColourTell( "silver", "black", "M:" .. mana .. " " )
- end
- -- Mana change.
- if tonumber(vitals.mp) > mana then
- ColourTell( "red", "black", "<-" .. vitals.mp - mana .. "> " )
- elseif tonumber(vitals.mp) < mana then
- ColourTell( "lime", "black", "<" .. mana - vitals.mp .. "> " )
- -- else
- -- ColourTell( "gray", "black", " <0> " )
- end
- -- Blood.
- ColourTell( "red", "black", "B:" .. wildcards[3] .. "% " )
- -- Status.
- ColourNote( "silver", "black", "[" .. wildcards[4] .. "]" )
- end
- --[[ This'll handle afflictions, the main bulk of shit. ]]--
- function addAffliction( aff, secondary )
- if affliction[aff] == nil then
- ColourTell( "red", "black", "Unknown affliction: " )
- Note( aff )
- return
- end
- if haveAffliction(aff) then
- return
- end
- local t, prio = whatAfflictionTable( affliction[aff][2] ), 1
- for i, name in ipairs(t) do
- if affliction[aff][3] > affliction[name][3] then
- prio = prio + 1
- else
- break
- end
- end
- table.insert(t, prio, aff)
- -- Small hack fix to deal with things like fear in the mean time.
- if t == other and affliction[aff][1] ~= "-" then
- Send( affliction[aff][1] )
- end
- -- GUI element.
- drawAfflictions()
- end
- function removeAffliction( aff )
- if affliction[aff] == nil then
- ColourTell( "red", "black", "Unknown affliction: " )
- Note( aff )
- return
- end
- if not haveAffliction(aff) then
- return
- end
- local t, pos = whatAfflictionTable( affliction[aff][2] )
- for i, name in ipairs(t) do
- if aff == name then
- pos = i
- break
- end
- end
- table.remove(t, pos)
- -- GUI element.
- drawAfflictions()
- end
- function haveAffliction( aff )
- local aff_t = { herb, salve, pipe, elixir, writhe, other }
- for i, t in ipairs(aff_t) do
- for _, name in ipairs(t) do
- if aff == name then
- return true
- end
- end
- end
- return false
- end
- function venomlockWarning()
- -- Basic warnings for venomlocks!
- if vlock_warning > 0 then
- return
- end
- if ( haveAffliction("anorexia") or haveAffliction("indifference") or haveAffliction("destroyed_throat") ) and
- ( haveAffliction("slickness") or haveAffliction("earthrot") ) and
- haveAffliction("asthma") then
- if haveAffliction("paralysis") then
- Note( "+-------------------------------------------+" )
- Tell( "| " )
- ColourTell( "yellow", "black", "--*> " )
- ColourTell( "red", "black", "VENOM-LOCKED + PARALYSIS" )
- ColourTell( "yellow", "black", " <*--" )
- Note( " |" )
- Note( "| HOPE FOR LUCKY PURITY TICKS / TRY TUMBLE! |" )
- Note( "+-------------------------------------------+" )
- vlock_warning = 2
- else
- Note( "+-------------------------------------------+" )
- Note( "| !!! VENOM-LOCKED !!! |" )
- Note( "| YOU'VE STILL GOT A CHANCE / BLOODBOIL OUT |" )
- Note( "+-------------------------------------------+" )
- vlock_warning = 1
- end
- AddTimer( "reset_vlock_lvl", 0, 0, 10, "", 1061, "venomlockResetLvl" )
- end
- end
- function venomlockResetLvl()
- vlock_warning = 0
- end
- function cureAfflictionsHerbs()
- if #herb == 0 then
- return
- end
- if vitals.herb == "1" and sent_herb == false and
- not haveAffliction("anorexia") and
- not haveAffliction("indifference") and
- not haveAffliction("destroyed_throat") and
- #writhe == 0 then
- for i, name in ipairs(herb) do
- if ( name == "blighted" or name == "infested" ) and haveAffliction("premonition") then
- -- Do nothing.
- else
- sent_herb = true
- if haveAffliction("stupidity") then
- Send( "outc " .. affliction[name][1] )
- Send( "outc " .. affliction[name][1] )
- Send( "eat " .. affliction[name][1] )
- Send( "inc " .. affliction[name][1] )
- Send( "eat " .. affliction[name][1] )
- Send( "eat " .. affliction[name][1] )
- else
- Send( "outc " .. affliction[name][1] )
- Send( "eat " .. affliction[name][1] )
- end
- AddTimer( "herb_reset", 0, 0, resetDelay(), "", 1061, "resetHerb" )
- break
- end
- end
- end
- end
- function cureAfflictionsSalves()
- if #salve == 0 then
- return
- end
- if vitals.salve == "1" and sent_salve == false and
- not haveAffliction("slickness") and
- not haveAffliction("earthrot") then
- for i, name in ipairs(salve) do
- sent_salve = true
- if haveAffliction("stupidity") or haveAffliction("head_mangled") then
- Send( "apply " .. affliction[name][1] )
- Send( "apply " .. affliction[name][1] )
- else
- Send( "apply " .. affliction[name][1] )
- end
- AddTimer( "salve_reset", 0, 0, resetDelay(), "", 1061, "resetSalve" )
- break
- end
- end
- end
- function cureAfflictionsPipes()
- if #pipe == 0 then
- return
- end
- if vitals.pipe == "1" and sent_pipe == false and
- not haveAffliction("asthma") then
- for i, name in ipairs(pipe) do
- sent_pipe = true
- SSend( "smoke " .. affliction[name][1] )
- AddTimer( "pipe_reset", 0, 0, resetDelay(), "", 1061, "resetPipe" )
- break
- end
- end
- end
- function cureAfflictionsElixirs()
- if #elixir == 0 then
- return
- end
- if vitals.affelixir == "1" and sent_elixir == false and
- not haveAffliction("anorexia") and
- not haveAffliction("indifference") and
- not haveAffliction("destroyed_throat") then
- for i, name in ipairs(elixir) do
- sent_elixir = true
- SSend( "drink " .. affliction[name][1] )
- AddTimer( "aff_elixir_reset", 0, 0, resetDelay(), "", 1061, "resetAffElixir" )
- break
- end
- end
- end
- function cureAfflictionsWrithes()
- if #writhe == 0 then
- return
- end
- if vitals.writhing ~= "1" and sent_writhe == false then
- for i, name in ipairs(writhe) do
- if ( name == "writhe_impaled" or name == "writhe_feed" ) and vitals.balance == "0" then
- break
- end
- sent_writhe = true
- SSend( affliction[name][1] )
- AddTimer( "writhe_reset", 0, 0, resetDelay(), "", 1061, "resetWrithe" )
- break
- end
- end
- end
- function cureAfflictionsTree( force )
- --[[ Basically, we check and see if we have 2 or more afflictions in a curing tree before firing off the
- curing method. This way we know we won't use tree pointlessly, if we happen to have already sent off
- a command to cure an affliction via a herb/salve. ]]--
- local aff_t, n = { herb, salve }, { 0, 0 }
- local oktree = false
- for i, t in ipairs(aff_t) do
- for _, name in ipairs(t) do
- if affliction[name][4] == true then
- n[i] = n[i] + 1
- if n[i] == 2 then oktree = true break end
- end
- end
- end
- if unknown_afflictions == 0 and not oktree and not force then
- return
- end
- if vitals.tree == "1" and sent_tree == false and
- not haveAffliction("paralysis") and
- not ( haveAffliction("left_arm_broken") and haveAffliction("right_arm_broken") ) then
- sent_tree = true
- Send( "touch tree" )
- AddTimer( "reset_tree", 0, 0, resetDelay(), "", 1061, "resetTree" )
- end
- end
- function cureAfflictionsFocus( force )
- -- Same thing as above, but now it's three because we might have sent tree.
- local aff_t, n = { herb, salve }, { 0, 0 }
- local okfocus = false
- for i, t in ipairs(aff_t) do
- for _, name in ipairs(t) do
- if affliction[name][5] == true then
- n[i] = n[i] + 1
- if n[i] == 3 then okfocus = true break end
- end
- end
- end
- -- Premonition will cause focus to send as long as we have focus balance. Only way to cure it.
- if not haveAffliction("premonition") and not okfocus and not force then
- return
- end
- if vitals.focus == "1" and ( sent_tree == false or force ) and sent_focus == false and
- not haveAffliction("impatience") and
- tonumber(vitals.mp) >= vitals.maxmp / 2 then
- sent_focus = true
- Send( "focus" )
- AddTimer( "reset_focus", 0, 0, resetDelay(), "", 1061, "resetFocus" )
- end
- end
- function cureAfflictionsRenew( force )
- -- Like above, but now it's four because of focus as well.
- local aff_t, n = { herb, salve }, { 0, 0 }
- local okrenew = false
- for i, t in ipairs(aff_t) do
- for _, name in ipairs(t) do
- if affliction[name][4] == true then
- n[i] = n[i] + 1
- if n[i] == 4 then okrenew = true break end
- end
- end
- end
- if not okrenew and not force then
- return
- end
- if vitals.renew == "1" and ( sent_tree == false and sent_focus == false or force ) and sent_renew == false and
- vitals.balance == "1" and vitals.equilibrium == "1" and
- tonumber(vitals.mp) >= vitals.maxmp / 2 then
- sent_renew = true
- Send( "reconstitute" )
- AddTimer( "reset_renew", 0, 0, resetDelay(), "", 1061, "resetRenew" )
- end
- end
- function cureAfflictions()
- -- This is the beast function that calls all the curing functions!
- venomlockWarning()
- -- Dead.
- if vitals.hp == "0" then
- return
- end
- -- Incapable of action.
- if haveAffliction("stun") or haveAffliction("asleep") or haveAffliction("unconscious") then
- return
- end
- cureAfflictionsWrithes()
- -- Only writhes can fire with safety on, so channelled abilities can do their thing.
- if safe_only == true then
- return
- end
- cureAfflictionsHerbs()
- cureAfflictionsSalves()
- cureAfflictionsPipes()
- cureAfflictionsElixirs()
- cureAfflictionsTree()
- cureAfflictionsFocus()
- cureAfflictionsRenew()
- end
- function resetAfflictions()
- -- Resets all afflictions.
- herb = {}
- salve = {}
- pipe = {}
- elixir = {}
- writhe = {}
- other = {}
- healing = {}
- vlock_warning = 0
- -- GUI element.
- drawAfflictions()
- end
- function resetAfflictionsType( cat )
- -- If we need to reset a group of afflictions belonging to one of these categories.
- local category = {
- ["random"] = 4,
- ["mental"] = 5,
- ["physical"] = 6
- }
- if category[cat] == nil then
- return
- end
- local aff_t = { herb, salve, pipe, other }
- local list, key = {}, category[cat]
- for i, t in ipairs(aff_t) do
- for _, name in ipairs(t) do
- if affliction[name][key] == true then
- list[#list+1] = name
- end
- end
- end
- for i, name in ipairs(list) do
- removeAffliction(name)
- end
- end
- function resetBalances()
- sent_sip = false
- sent_moss = false
- sent_herb = false
- sent_salve = false
- sent_pipe = false
- sent_elixir = false
- sent_writhe = false
- sent_tree = false
- sent_focus = false
- sent_renew = false
- end
- function resetOnConsumePlant( plant )
- local consumable = {
- ["a bloodroot leaf"] = "bloodroot",
- ["some prickly ash bark"] = "ash",
- ["a goldenseal root"] = "goldenseal",
- ["a piece of kelp"] = "kelp",
- ["a lobelia seed"] = "lobelia",
- ["a ginseng root"] = "ginseng",
- ["a bellwort flower"] = "bellwort"
- }
- if consumable[plant] == nil then
- return
- end
- local list = {}
- for i, name in ipairs(herb) do
- if affliction[name][1] == consumable[plant] then
- list[#list+1] = name
- end
- end
- for i, name in ipairs(list) do
- removeAffliction(name)
- end
- end
- function resetOnApplySalve( app, bpart )
- local application = {
- ["an epidermal salve"] = { ["head"] = "epidermal to head",
- ["torso"] = "epidermal to torso" },
- ["a salve of mending"] = { ["head"] = "mending to head",
- ["torso"] = "mending to torso",
- ["body"] = "mending to body",
- ["left arm"] = "mending to left arm",
- ["right arm"] = "mending to right arm",
- ["left leg"] = "mending to left leg",
- ["right leg"] = "mending to right leg" }
- }
- if application[app][bpart] == nil then
- return
- end
- local list = {}
- for i, name in ipairs(salve) do
- if affliction[name][1] == application[app][bpart] then
- list[#list+1] = name
- end
- end
- for i, name in ipairs(list) do
- removeAffliction(name)
- end
- end
- function resetOnSmokePipe( plant )
- if plant ~= "valerian" and
- plant ~= "elm" then
- return
- end
- local list = {}
- for i, name in ipairs(pipe) do
- if affliction[name][1] == plant then
- list[#list+1] = name
- end
- end
- for i, name in ipairs(list) do
- removeAffliction(name)
- end
- end
- function resetOnEmptyWrithe()
- local list = {}
- for i, name in ipairs(writhe) do
- list[#list+1] = name
- end
- for i, name in ipairs(list) do
- removeAffliction(name)
- end
- end
- function resetHerb()
- sent_herb = false
- end
- function resetSalve()
- sent_salve = false
- end
- function resetPipe()
- sent_pipe = false
- end
- function resetAffElixir()
- sent_elixir = false
- end
- function resetWrithe()
- sent_writhe = false
- end
- function resetTree()
- sent_tree = false
- end
- function resetFocus()
- sent_focus = false
- end
- function resetRenew()
- sent_renew = false
- end
- --[[ Functions for AutoSipper and healing vitals ]]--
- function healVitals()
- if sipper == true and safe_only == false and vitals.hp ~= "0" and
- not haveAffliction("anorexia") and
- not haveAffliction("indifference") then
- if vitals.elixir == "1" and sent_sip == false then
- --[[ if tonumber(vitals.mp) <= vitals.maxmp * force_mana_threshold then
- sent_sip = true
- Send( "drink mana" )
- AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
- ]]--
- if tonumber(vitals.hp) <= vitals.maxhp * health_threshold then
- sent_sip = true
- Send( "drink health" )
- AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
- elseif tonumber(vitals.mp) <= vitals.maxmp * mana_threshold then
- sent_sip = true
- Send( "drink mana" )
- AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
- end
- end
- if vitals.moss == "1" and sent_moss == false and #writhe == 0 then
- if tonumber(vitals.hp) <= vitals.maxhp * moss_threshold or
- tonumber(vitals.mp) <= vitals.maxmp * moss_threshold or
- haveAffliction("idiocy") or
- haveAffliction("plodding") then
- sent_moss = true
- Send( "outc moss" )
- Send( "eat moss" )
- AddTimer( "moss_reset", 0, 0, resetDelay(), "", 1061, "resetMoss" )
- end
- end
- end
- end
- function resetElixir()
- sent_sip = false
- end
- function resetMoss()
- sent_moss = false
- end
- --[[ Queue for performing actions that require balance or equilibrium. ]]--
- function addBalanceQueue( cmd, bal, eq, wait, exe )
- if type(cmd) ~= "string" then
- ColourTell( "red", "black", "ERROR: " )
- Note( "addBalanceQueue(str,str,str,bool,bool) - 'cmd' is not a string." )
- return
- end
- if type(bal) ~= "string" and ( bal ~= "1" and bal ~= "0" ) then
- ColourTell( "red", "black", "ERROR: " )
- Note( "addBalanceQueue(str,str,str,bool,bool) - 'bal' is not a string, or is not \"1\" or \"0\"." )
- return
- end
- if type(eq) ~= "string" and ( eq ~= "1" and eq ~= "0" ) then
- ColourTell( "red", "black", "ERROR: " )
- Note( "addBalanceQueue(str,str,str,bool,bool) - 'eq' is not a string, or is not \"1\" or \"0\"." )
- return
- end
- if type(wait) ~= "boolean" then
- ColourTell( "red", "black", "ERROR: " )
- Note( "addBalanceQueue(str,str,str,bool,bool) - 'wait' is not a boolean." )
- return
- end
- if type(exe) ~= "boolean" then
- ColourTell( "red", "black", "ERROR: " )
- Note( "addBalanceQueue(str,str,str,bool,bool) - 'exe' is not a boolean." )
- return
- end
- queue[#queue+1] = { cmd, bal, eq, wait, exe }
- executeBalanceQueue()
- end
- function executeBalanceQueue()
- -- This handles queued commands, and can make sure we're on balance and such.
- if awaiting_balance_use == true then
- if vitals.balance == "0" or vitals.equilibrium == "0" then
- awaiting_balance_use = false
- DeleteTimer( "queue_reset" )
- else
- return
- end
- end
- if safe_only == true then
- return
- end
- local del = 0
- for i, name in ipairs(queue) do
- if vitals.balance == queue[i][2] and vitals.equilibrium == queue[i][3] then
- if queue[i][5] == true then
- Execute( queue[i][1] )
- else
- Send( queue[i][1] )
- end
- del = del + 1
- if queue[i][4] == true then
- awaiting_balance_use = true
- AddTimer( "queue_reset", 0, 0, 5, "", 1061, "resetQueue" )
- break
- end
- end
- end
- while del > 0 do
- table.remove(queue, 1)
- del = del - 1
- end
- end
- function clearQueue()
- queue = {}
- awaiting_balance_use = false
- end
- function resetQueue()
- awaiting_balance_use = false
- end
- --[[ Basic routine that'll be expanded later to deal with defences. ]]--
- function checkDefences()
- if stay_blind_deaf == true then
- if vitals.blind == "0" then
- addAffliction("blindness")
- end
- if vitals.deaf == "0" then
- addAffliction("deafness")
- end
- end
- end
- --[[ This is all the scripting for the GUI. For now it'll probably be tacky until I learn more about miniwindows. ]]--
- function drawMap( name, line, wildcards, styles )
- map[#map+1] = styles
- -- So basically we draw the map at the end once we have everything.
- if gui_elements == false then
- return
- end
- local win = GetPluginID() .. ":map"
- local font = "f"
- if not WindowInfo( win, 1 ) then
- WindowCreate( win, 0, 0, 0, 0, 6, 0, 0 )
- WindowFont( win, font, "FixedSys", 9 )
- end
- local font_height = WindowFontInfo( win, font, 1 )
- local window_width = 370 + 18
- local window_height = font_height * 26 + 10
- WindowCreate( win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB("black") )
- WindowRectOp( win, 5, 0, 0, 0, 0, 5, 15 + 0x1000 )
- local y = font_height / 2 + 5
- for i, styles in ipairs(map) do
- local x = 5 + 8
- for _, style in ipairs(styles) do
- x = x + WindowText( win, font, style.text, x, y, 0, 0, style.textcolour )
- end
- y = y + font_height
- end
- WindowShow( win, true )
- end
- function captureMap( name, line, wildcards, styles )
- map[#map+1] = styles
- end
- function drawAfflictions()
- if gui_elements == false then
- return
- end
- local win = GetPluginID() .. ":afflictions"
- local font = "f"
- if not WindowInfo( win, 1 ) then
- WindowCreate( win, 0, 0, 0, 0, 8, 0, 0 )
- WindowFont( win, font, "FixedSys", 9 )
- end
- local font_height = WindowFontInfo( win, font, 1 )
- local window_width = 370 + 18
- local window_height = font_height * 24 + 10
- WindowCreate( win, 0, 0, window_width, window_height, 8, 0, ColourNameToRGB("black") )
- -- WindowRectOp( win, 5, 0, 0, 0, 0, 5, 15 + 0x1000 )
- local y = font_height / 2 + 5
- local x = 13
- WindowText( win, font, "Afflictions:", x, y, 0, 0, ColourNameToRGB("red") )
- y = y + font_height
- local aff_t = { herb, salve, pipe, elixir, writhe, other }
- x = x + 10
- for i, t in ipairs(aff_t) do
- y = y + 3
- for _, name in ipairs(t) do
- WindowText( win, font, "* " .. name, x, y, 0, 0, whatAfflictionColour(t) )
- y = y + font_height
- if y >= font_height * 23 then
- y = font_height / 2 + 5 + font_height
- x = 224 + 5
- end
- end
- end
- WindowShow( win, true )
- end
- --[[ Utility functions sit below! They make life a lot easier. :) ]]--
- function SSend( command )
- -- Sends twice if you have stupidity, else it'll only send once.
- if haveAffliction("stupidity") then
- Send( command )
- end
- Send( command )
- end
- function ringVibes()
- -- Why AddTimer doesn't allow newline chars is beyond me. >:(
- Note( " +--------------------------+ " )
- Note( " | NEED TO RING VIBRATIONS! | " )
- Note( " +--------------------------+ " )
- end
- function whatAfflictionTable( name )
- -- Find the right affliction table.
- local list = {
- ["herb"] = herb,
- ["salve"] = salve,
- ["pipe"] = pipe,
- ["elixir"] = elixir,
- ["writhe"] = writhe,
- ["other"] = other
- }
- return list[name]
- end
- function whatAfflictionColour( t )
- -- What colour each affliction should be for drawing.
- if t == herb then
- return ColourNameToRGB("lime")
- elseif t == salve then
- return ColourNameToRGB("darkorange")
- elseif t == pipe then
- return ColourNameToRGB("blueviolet")
- elseif t == elixir then
- return ColourNameToRGB("dodgerblue")
- elseif t == writhe then
- return ColourNameToRGB("darkgray")
- elseif t == other then
- return ColourNameToRGB("yellow")
- end
- return ColourNameToRGB("white")
- end
- function roundNum( x )
- -- Rounding because Lua doesn't have one inbuilt.
- if x >= 0 then
- return math.floor( x + 0.5 )
- end
- return math.ceil( x - 0.5 )
- end
- function resetSafeOnly()
- -- Resets the safe_only variable so curing can begin kicking in again.
- ColourNote( "olive", "black", "-- Overriding safety --" )
- safe_only = false
- end
- function resetDelay()
- -- Aeon and Retardation delay input by 1.5 seconds, so we need to account for that.
- if haveAffliction("aeon") or haveAffliction("retardation") then
- return 2.5
- end
- return 1.2
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement