Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Dat System Created by: Kikon
- 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.
- Requirements:
- CONFIG MAPVIEW ON
- CONFIG AFFLICTION_VIEW FULL
- CONFIG COMBATMESSAGES ON
- --]]
- require "json.decode" -- JSON decoder.
- require "worlds.database" -- Pull in databases for afflictions and defences.
- require "worlds.afftracker" -- Affliction tracker module.
- -- Definitions.
- local AFF_CURE = 1
- local AFF_CURE_AUX = 2
- local AFF_TYPE = 3
- local AFF_PRIORITY = 4
- local AFF_RANDOM_CURE = 5
- local AFF_MENTAL_CURE = 6
- local AFF_PHYS_CURE = 7
- local DEF_COMMAND = 1
- local DEF_CLASS = 2
- local DEF_BALANCE = 3
- local DEF_EQUIL = 4
- local DEF_AUTO_AP = 5
- local QU_COMMAND = 1
- local QU_BALANCE = 2
- local QU_EQUIL = 3
- local QU_EXECUTE = 4
- -- 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).
- plugin_GMCP = "54bd8f89ff91b21ea6e3e07f" -- Plugin ID for GMCP.
- plugin_G15Display = "21b1c9f780b8984e2e1450fa" -- Plugin ID for G15 Display.
- -- Balance queue for queuing up various commands.
- local queue = {} -- Table for balance queue.
- local reset_queue = false -- Freezing queue for short period of time.
- -- Healing for vitals (health, mana, etc) and related stuff.
- local vitals = nil -- Vitals table that we receive from GMCP.
- local old_vitals = nil -- Old vitals table from the previous prompt.
- sipper = true -- Switch for sipping health/mana.
- use_moss = true -- Switch for eating moss.
- local sent_sip = false -- Attempting to sip for health/mana.
- local sent_moss = false -- Attempting to eat moss.
- -- Healing for afflictions (salves, pipes, etc) and related stuff.
- local herb = {} -- Table for current herbal afflictions.
- local salve = {} -- Table for current salve afflictions.
- local pipe = {} -- Table for current pipe afflictions.
- local elixir = {} -- Table for current elixir afflictions.
- local writhe = {} -- Table for current writhe afflictions.
- local other = {} -- Table for current afflictions that don't fall into the above.
- local limb_damage = {} -- Table for limb damage counters.
- local unknown_afflictions = 0 -- Counter for amount of hidden afflictions.
- local vlock_warning = 0 -- Levelled warning system for when a venom-lock is achieved.
- last_pipe = "" -- Last pipe we smoked.
- local hidden_check = false -- Check for hidden afflictions.
- 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.
- local defence = {} -- Defence table.
- apply_defences = true -- Applies a defence if stripped, as long as its allowed.
- stay_blind_deaf = true -- Automatic application of bayberry and hawthorn.
- stay_insomniac = true -- Automatic use of insomnia to prevent sleep.
- stay_standing = true -- Stay standing at all times.
- use_prerestore = true -- Automatic use of pre-restoring to heal limb damage.
- auto_parry = false -- Automatic use of parrying. Will parry most strategic limb.
- stay_massed = false -- Automatic mass application on fade.
- stay_rebounded = false -- Automatic application of skullcap aura.
- -- 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.
- local map = {} -- Captured line styles of MAP for replication to a miniwindow.
- --[[ Run certain things on world open and close. ]]--
- function worldOpen()
- -- Create the miniwindows so the screen doesn't appear blank.
- local top, height, left, width = 350, 10, 1090, 860
- MoveWorldWindow( top, height, left, width )
- drawMap()
- drawAfflictions()
- end
- function worldDisconnect()
- -- Wipe temporary variables.
- SetVariable( "replicate", "n/a" )
- end
- --[[ This is what we run when a prompt pops up. This really needs to be as smooth as possible! ]] --
- function onPrompt()
- -- Let's make sure GMCP has setup our vitals table first.
- if vitals == nil then
- return
- end
- -- Check/detection functions.
- detectHiddenAffs() -- Detection of certain hidden afflictions.
- checkBlindDeaf() -- Check and see if blindness and deafness are applied.
- if system == false or vitals.hp == "0" then
- return
- end
- venomlockWarning() -- Are we venom locked? This is a problem!
- if haveAffliction("stun") or haveAffliction("asleep") or haveAffliction("unconscious") then
- return
- end
- -- Healing/reaction functions.
- healVitals() -- Sip health/mana, and eat moss.
- cureAfflictions() -- Eat herbs, apply salves, or use things like focus.
- applyDefences() -- Apply queued defences for activation.
- executeBalanceQueue() -- Queued commands waiting for balance and equilibrium.
- 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
- ]]--
- --[[ Functions for calling by GMCP plugin. ]]--
- function GMCP_Vitals()
- -- Plugin ID is GMCP.xml, didn't want to make an extra call to global table.
- local params = GetPluginVariable( "54bd8f89ff91b21ea6e3e07f", "vitals" )
- old_vitals = vitals
- vitals = json.decode(params)
- end
- function GMCP_Login()
- local login = GetPluginVariable( plugin_GMCP, "name" )
- login = json.decode(login)
- SetVariable( "name", login.name )
- if login.name == "Kikon" then
- SetVariable( "mount", "moonfire" )
- SetVariable( "pack", "200024" )
- SetVariable( "pipe_elm", "133451" )
- SetVariable( "pipe_skullcap", "132883" )
- SetVariable( "pipe_valerian", "133245" )
- SetVariable( "bow", "bow137961" )
- SetVariable( "shield", "shield112317" )
- SetVariable( "staff", "staff47088" )
- elseif login.name == "Torlin" then
- SetVariable( "mount", "201447" )
- SetVariable( "pipe_elm", "79880" )
- SetVariable( "pipe_skullcap", "36261" )
- SetVariable( "pipe_valerian", "79880" )
- end
- end
- function GMCP_Comm()
- local msg = GetPluginVariable( plugin_GMCP, "comm" )
- msg = json.decode(msg)
- if msg.channel == "tell" and msg.talker ~= GetVariable("name") then
- Sound( "c:/windows/media/notify.wav" )
- end
- end
- --[[ This'll handle afflictions, the main bulk of shit. ]]--
- function addAffliction( aff, secondary )
- if affDB[aff] == nil then
- ColourTell( "red", "black", "Unknown affliction: " )
- Note( aff )
- return
- end
- if haveAffliction(aff) then
- return
- end
- -- If the affliction comes from a secondary source, then we need to know.
- if secondary == true then
- decreaseHiddenAffs()
- end
- -- Add affliction to corresponding table.
- local t = whatAfflictionTable( affDB[aff][AFF_TYPE] )
- local priority = affDB[aff][AFF_PRIORITY]
- local pos = 0
- for i, name in ipairs(t) do
- if priority < affDB[name][AFF_PRIORITY] then
- break
- end
- pos = i
- end
- table.insert( t, pos+1, aff )
- -- Small hack fix to deal with things like fear in the mean time.
- if t == other and affDB[aff][AFF_CURE] ~= "-" and system == true then
- Send( affDB[aff][AFF_CURE] )
- end
- -- GUI element.
- drawAfflictions()
- end
- function removeAffliction( aff, confirmed )
- if affDB[aff] == nil then
- ColourTell( "red", "black", "Unknown affliction: " )
- Note( aff )
- return
- end
- if not haveAffliction(aff) then
- if confirmed == true then
- decreaseHiddenAffs()
- end
- return
- end
- -- Remove affliction from corresponding table.
- local t = whatAfflictionTable( affDB[aff][AFF_TYPE] )
- local pos
- 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 increaseHiddenAffs()
- unknown_afflictions = unknown_afflictions + 1
- hidden_check = true
- -- GUI element.
- drawAfflictions()
- end
- function decreaseHiddenAffs()
- if unknown_afflictions == 0 then
- return
- end
- unknown_afflictions = unknown_afflictions - 1
- -- GUI element.
- drawAfflictions()
- end
- function detectHiddenAffs()
- if hidden_check == false then
- return
- end
- hidden_check = false
- -- Do we have recklessness?
- if vitals.hp == vitals.maxhp and old_vitals.hp < vitals.maxhp and
- vitals.mp == vitals.maxmp and old_vitals.mp < vitals.maxmp then
- addAffliction( "recklessness", true )
- end
- end
- function venomlockWarning()
- -- Basic warnings for venomlocks!
- if ( haveAffliction("anorexia") or haveAffliction("indifference") or haveAffliction("destroyed_throat") ) and
- ( haveAffliction("slickness") or haveAffliction("earthrot") ) and
- haveAffliction("asthma") then
- if haveAffliction("paralysis") and vlock_warning < 2 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
- elseif vlock_warning < 1 then
- 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
- local cure = affDB[name][AFF_CURE]
- if haveAffliction("stupidity") then
- Send( "eat " .. cure )
- end
- Send( "outc " .. cure )
- Send( "eat " .. cure )
- 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
- local cure = affDB[name][AFF_CURE]
- if haveAffliction("stupidity") or haveAffliction("head_mangled") then
- Send( "apply " .. cure )
- end
- Send( "apply " .. cure )
- 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
- local cure = affDB[name][AFF_CURE]
- last_pipe = cure
- SSend( "smoke " .. cure )
- 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 " .. affDB[name][AFF_CURE] )
- 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( affDB[name][AFF_CURE] )
- AddTimer( "writhe_reset", 0, 0, resetDelay(), "", 1061, "resetWrithe" )
- break
- end
- end
- end
- function cureAfflictionsTree( force )
- -- We want to make sure we have at least two afflictions, in case one is being cured by normal means.
- local aff_t = { herb, salve }
- local oktree = false
- for i, t in ipairs(aff_t) do
- local n = 0
- for _, name in ipairs(t) do
- if affDB[name][AFF_RANDOM_CURE] == true then
- n = n + 1
- if n == 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
- ( sent_focus == false and sent_renew == false or force ) and
- not haveAffliction("paralysis") and
- not haveAffliction("paresis") 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 we're making sure that we have afflictions that are focusable.
- local aff_t = { herb, salve }
- local okfocus = false
- for i, t in ipairs(aff_t) do
- local n = 0
- for _, name in ipairs(t) do
- if affDB[name][AFF_MENTAL_CURE] == true then
- n = n + 1
- if n == 2 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_focus == false ) and
- ( sent_tree == false and sent_renew == false or force ) and
- not haveAffliction("impatience") and
- tonumber(vitals.mp) >= vitals.maxmp * 0.5 then
- sent_focus = true
- Send( "focus" )
- AddTimer( "reset_focus", 0, 0, resetDelay(), "", 1061, "resetFocus" )
- end
- end
- function cureAfflictionsRenew( force )
- -- Reconstitute (renew) waits for three afflictions, since it's unique in that it'll work through anything. Save it!
- local aff_t = { herb, salve }
- local okrenew = false
- for i, t in ipairs(aff_t) do
- local n = 0
- for _, name in ipairs(t) do
- if affDB[name][AFF_RANDOM_CURE] == true then
- n = n + 1
- if n == 3 then okrenew = true break end
- end
- end
- end
- if unknown_afflictions < 3 and not okrenew and not force then
- return
- end
- if ( vitals.renew == "1" and sent_renew == false ) and
- ( sent_tree == false and sent_focus == false or force ) and
- vitals.balance == "1" and vitals.equilibrium == "1" and
- tonumber(vitals.mp) >= vitals.maxmp * 0.5 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!
- 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 = {}
- unknown_afflictions = 0
- vlock_warning = 0
- -- GUI element.
- drawAfflictions()
- end
- function resetAfflictionsType( kind )
- -- If we need to reset a group of afflictions belonging to one of these categories.
- local category = {
- ["random"] = AFF_RANDOM_CURE,
- ["mental"] = AFF_MENTAL_CURE,
- ["physical"] = AFF_PHYS_CURE
- }
- local key = category[kind]
- if key == nil then
- return
- end
- local aff_t = { herb, salve, pipe, other }
- local list = {}
- for i, t in ipairs(aff_t) do
- for _, name in ipairs(t) do
- if affDB[name][key] == true then
- list[#list+1] = name
- end
- end
- end
- for i, name in ipairs(list) do
- removeAffliction(name)
- end
- if key == AFF_RANDOM_CURE then
- unknown_afflictions = 0
- drawAfflictions()
- 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",
- ["a lung slice"] = "lung",
- ["a bladder slice"] = "bladder",
- ["a liver slice"] = "liver",
- ["an eyeball slice"] = "eyeball",
- ["a testis slice"] = "testis",
- ["an ovary slice"] = "ovary",
- ["a castorite gland slice"] = "castorite"
- }
- local cure = consumable[plant]
- if cure == nil then
- return
- end
- local list = {}
- for i, name in ipairs(herb) do
- if affDB[name][AFF_CURE] == cure 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" },
- ["an oculi poultice"] = { ["head"] = "oculi to head",
- ["torso"] = "ocull to torso" },
- ["an orbis poultice"] = { ["head"] = "orbis to head",
- ["torso"] = "orbis to torso",
- ["body"] = "orbis to body",
- ["left arm"] = "orbis to left arm",
- ["right arm"] = "orbis to right arm",
- ["left leg"] = "orbis to left leg",
- ["right leg"] = "orbis to right leg" }
- }
- if application[app] == nil then
- return
- end
- local cure = application[app][bpart]
- if cure == nil then
- return
- end
- local list = {}
- for i, name in ipairs(salve) do
- if affDB[name][AFF_CURE] == cure 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" and
- plant ~= "antispasmadic" and
- plant ~= "demulcent" then
- return
- end
- local list = {}
- for i, name in ipairs(pipe) do
- if affDB[name][AFF_CURE] == 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 dealing with pre-restoration and parry. ]]--
- function increaseLimbDamage( limb, dmg )
- -- Increases the limb damage value of a limb, and deals with pre-restore.
- local result = ( limb_damage[limb] or 0 ) + dmg
- if result > 100 then
- result = 100
- end
- if use_prerestore == true and result >= 15 then
- addAffliction( limb:gsub(" ","_") .. "_prerestore" )
- end
- limb_damage[limb] = result
- end
- function decreaseLimbDamage( limb, dmg )
- -- Decreases the limb damage value of a limb, and clears pre-restore.
- local result = ( limb_damage[limb] or 0 ) - dmg
- if result < 0 then
- result = 0
- end
- if use_prerestore == true and result < 15 then
- removeAffliction( limb:gsub(" ","_") .. "_prerestore" )
- end
- limb_damage[limb] = result
- end
- function setLimbDamage( limb, dmg )
- -- Sometimes we need to set a specific limb to a value.
- if not dmg then
- return
- end
- if dmg > 100 then
- dmg = 100
- end
- if dmg < 0 then
- dmg = 0
- end
- if use_prerestore == true then
- if dmg >= 15 then
- addAffliction( limb:gsub(" ","_") .. "_prerestore" )
- else
- removeAffliction( limb:gsub(" ","_") .. "_prerestore" )
- end
- end
- limb_damage[limb] = dmg
- end
- --[[
- function handlePreRestore()
- if use_prerestore == false then
- return
- end
- for limb, dmg in pairs(limb_damage) do
- local affname = limb:gsub( " ", "_" )
- if haveAffliction( affname .. "_damaged" ) then
- removeAffliction( affname .. "_prerestore" )
- else
- if dmg >= 20.00 then
- addAffliction( affname .. "_prerestore" )
- else
- removeAffliction( affname .. "_prerestore" )
- end
- end
- end
- end
- ]]--
- function displayLimbDamage()
- -- Basic display.
- for k, dmg in pairs(limb_damage) do
- Tell( k .. ": " )
- Note( dmg )
- end
- end
- function resetLimbDamage()
- limb_damage = {}
- removeAffliction("head_prerestore")
- removeAffliction("torso_prerestore")
- removeAffliction("left_arm_prerestore")
- removeAffliction("right_arm_prerestore")
- removeAffliction("left_leg_prerestore")
- removeAffliction("right_leg_prerestore")
- end
- function shiftParry( limb )
- if auto_parry == false then
- return
- end
- end
- function resetParry()
- end
- --[[ Functions for AutoSipper and healing vitals ]]--
- function displayVitals()
- -- Because this table is pretty useful to see, I don't even use 90% of it.
- for k, v in pairs(vitals) do
- print(k,v)
- end
- end
- function healVitals()
- if sipper == false or safe_only == true then
- return
- end
- if haveAffliction("anorexia") or haveAffliction("indifference") then
- return
- end
- -- TODO: Add a special forced mana threshold toggle when being targeted by an ability like angel sap.
- 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 * 0.82 or haveAffliction("blackout") then
- sent_sip = true
- Send( "drink health" )
- AddTimer( "elixir_reset", 0, 0, resetDelay(), "", 1061, "resetElixir" )
- elseif tonumber(vitals.mp) <= vitals.maxmp * 0.85 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 * 0.65 or
- tonumber(vitals.mp) <= vitals.maxmp * 0.65 or
- haveAffliction("idiocy") or
- haveAffliction("plodding") or
- haveAffliction("blackout") then
- sent_moss = true
- Send( "outc moss" )
- Send( "eat moss" )
- AddTimer( "moss_reset", 0, 0, resetDelay(), "", 1061, "resetMoss" )
- end
- end
- end
- function resetElixir()
- sent_sip = false
- end
- function resetMoss()
- sent_moss = false
- end
- --[[ Functions to deal with wielded items and the sort. ]]--
- function unwieldLeft()
- if vitals.wield_left ~= "" then
- local weapon = string.match(vitals.wield_left,"%a+")
- if weapon == "shield" or
- weapon == "bow" then
- Send( "unwield " .. vitals.wield_left )
- Send( "wear " .. vitals.wield_left )
- else
- Send( "secure " .. vitals.wield_left )
- Send( "unwield " .. vitals.wield_left )
- end
- end
- end
- function unwieldRight()
- if vitals.wield_right ~= "" then
- local weapon = string.match(vitals.wield_right,"%a+")
- if weapon == "shield" or
- weapon == "bow" then
- Send( "unwield " .. vitals.wield_right )
- Send( "wear " .. vitals.wield_right )
- else
- Send( "secure " .. vitals.wield_right )
- Send( "unwield " .. vitals.wield_right )
- end
- end
- end
- function wieldWeapon( item, hand )
- if item == nil then
- return
- end
- if hand == "left" and vitals.wield_left ~= item then
- unwieldLeft()
- Send( "wield " .. item .. " left" )
- elseif hand == "right" and vitals.wield_right ~= item then
- unwieldRight()
- Send( "wield " .. item .. " right" )
- elseif hand == "both" and vitals.wield_left ~= item then
- unwieldLeft()
- unwieldRight()
- Send( "wield " .. item )
- end
- end
- --[[ Queue for performing actions that require balance or equilibrium. ]]--
- function addBalanceQueue( cmd, bal, eq, exe, t_rmvl )
- if not cmd then
- ColourTell( "red", "black", "ERROR: " )
- Note( "No command supplied for balance queue." )
- end
- if type(bal) ~= "boolean" then
- bal = false
- end
- if type(eq) ~= "boolean" then
- eq = false
- end
- if type(exe) ~= "boolean" then
- exe = false
- end
- if type(t_rmvl) ~= "boolean" then
- t_rmvl = false
- end
- queue[#queue+1] = { cmd, bal, eq, exe, t_rmvl }
- executeBalanceQueue()
- end
- function executeBalanceQueue()
- -- This handles queued commands, and can make sure we're on balance and such.
- if #queue == 0 or sent_queue == true or safe_only == true then
- return
- end
- if ( vitals.balance == "1" or not queue[1][QU_BALANCE] ) and
- ( vitals.equilibrium == "1" or not queue[1][QU_EQUIL] ) then
- sent_queue = true
- local func = queue[1][QU_EXECUTE] and Execute or Send
- local t = queue[1][QU_COMMAND]
- if type(t) == "table" then
- for i, cmd in ipairs(t) do
- func (cmd)
- end
- else
- func (t)
- end
- AddTimer( "queue_reset", 0, 0, 1.5, "", 1061, "resetQueue" )
- table.remove( queue, 1 )
- end
- end
- function clearQueue()
- queue = {}
- sent_queue = false
- end
- function resetQueue()
- sent_queue = false
- end
- --[[ Basic routine that'll be expanded later to deal with defences. ]]--
- function lostDefence( def )
- -- When we lose a defence, we queue it for re-application/tracking.
- if defDB[def] == nil then
- return
- end
- if queuedDefence(def) then
- return
- end
- defence[#defence+1] = def
- end
- function gainedDefence( def )
- -- We regained a defence, wipe it from our queue. It isn't important anymore.
- if defDB[def] == nil then
- return
- end
- if not queuedDefence(def) then
- return
- end
- local pos
- for i, name in ipairs(defence) do
- if def == name then
- pos = i
- break
- end
- end
- table.remove( defence, pos )
- end
- function queuedDefence( def )
- -- Is a defence already queued/tracked as being lost?
- for i, name in ipairs(defence) do
- if def == name then
- return true
- end
- end
- return false
- end
- function applyDefences()
- -- We want to go through and see what we need to re-apply, if it's been set to automatically do so.
- if #defence == 0 or sent_defence == true or safe_only == true or apply_defences == false then
- return
- end
- for i, def in ipairs(defence) do
- if defDB[def][DEF_AUTO_AP] and
- ( vitals.balance == "1" or not defDB[def][DEF_BALANCE] ) and
- ( vitals.equilibrium == "1" or not defDB[def][DEF_EQUIL] ) then
- sent_defence = true
- local t = defDB[def][DEF_COMMAND]
- -- Commands can be supplied as an array for multi-command defences.
- if type(t) == "table" then
- for i, cmd in ipairs(t) do
- Send(cmd)
- end
- else
- Send(t)
- end
- AddTimer( "defence_reset", 0, 0, resetDelay(), "", 1061, "resetDefence" )
- break
- end
- end
- end
- function displayDefences()
- ColourNote( "yellow", "black", "Missing defences:" )
- if #defence == 0 then
- Note( "none" )
- return
- end
- for k, def in ipairs(defence) do
- Tell( k .. ") " .. def .. ": \"" )
- local cmd = defDB[def][DEF_COMMAND]
- if type(cmd) == "table" then
- Note( table.concat( cmd, ";" ) .. "\"" )
- else
- Note( cmd .. "\"" )
- end
- end
- end
- function clearDefences()
- defence = {}
- sent_defence = false
- end
- function resetDefence()
- sent_defence = false
- end
- function checkBlindDeaf()
- 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 * 0.5 + 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 clearMap()
- map = {}
- 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 * 0.5 + 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
- if #t > 0 then y = y + 5 end
- for _, name in ipairs(t) do
- WindowText( win, font, "* " .. name, x, y, 0, 0, whatAfflictionColour(t) )
- y = y + font_height
- if y >= font_height * 20 then
- y = font_height * 1.5 + 5
- x = 224 + 5
- end
- end
- end
- if unknown_afflictions > 0 then
- y = y + 5
- local clr = ColourNameToRGB("blueviolet")
- if unknown_afflictions >= 4 then
- clr = ColourNameToRGB("fuchsia")
- end
- WindowText( win, font, "* unknown afflict (x" .. unknown_afflictions .. ")", x, y, 0, 0, clr )
- 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("cyan")
- elseif t == elixir then
- return ColourNameToRGB("dodgerblue")
- elseif t == writhe then
- return ColourNameToRGB("red")
- elseif t == other then
- return ColourNameToRGB("yellow")
- end
- return ColourNameToRGB("white")
- end
- function whatAfflictionColour2( t )
- -- A variation of the above.
- if t == "herb" then
- return "lime"
- elseif t == "salve" then
- return "darkorange"
- elseif t == "pipe" then
- return "cyan"
- elseif t == "elixir" then
- return "dodgerblue"
- elseif t == "writhe" then
- return "red"
- elseif t == "other" then
- return "yellow"
- end
- return "white"
- end
- --[[
- function limbToBodypartKey( limb )
- -- Convert a limb name into it's corresponding key.
- local list = {
- ["head"] = BP_HEAD,
- ["torso"] = BP_TORSO,
- ["left arm"] = BP_LEFT_ARM,
- ["right arm"] = BP_RIGHT_ARM,
- ["left leg"] = BP_LEFT_LEG,
- ["right leg"] = BP_RIGHT_LEG
- }
- if list[limb] == nil then
- return
- end
- return list[limb]
- end
- function bodypartKeyToLimb( key )
- local list = {
- [BP_HEAD] = "head",
- [BP_TORSO] = "torso",
- [BP_LEFT_ARM] = "left arm",
- [BP_RIGHT_ARM] = "right arm",
- [BP_LEFT_LEG] = "left arm",
- [BP_RIGHT_LEG] = "right arm"
- }
- if list[key] == nil then
- return
- end
- return list[key]
- 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 splitString( str )
- -- Converts a string list into a table.
- local t = {}
- str = str:gsub( " and ", " " )
- str:gsub( "(%w+)", function(c) table.insert( t, c ) end )
- return t
- 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(name)
- -- 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