Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Agatha:AddAff(affliction)
- if type(affliction) ~= "string" then return false end
- -- if the affliction is present in the dictionary, add it to all queues
- -- associated with its cure_types table.
- if self.Afflictions.aff_dict[affliction:lower()] then
- local aff = self.Afflictions.aff_dict[affliction:lower()]
- local duplicate_aff = false
- local cure_type = ""
- Agatha:Announce("|cffffffAffliction added: |cff0000" .. string.upper(affliction) .. "|cffffff.")
- for _,v in pairs(aff.cure_types) do
- cure_type = v
- if #self.Afflictions[cure_type.."_queue"] > 0 then
- for _,j in pairs(self.Afflictions[cure_type.."_queue"]) do
- if j.name == affliction then
- duplicate_aff = true
- end
- end
- if not duplicate_aff then
- for i,k in pairs(self.Afflictions[v.."_queue"]) do
- if aff.priority <= k.priority or i == #self.Afflictions[v.."_queue"] then
- table.insert(self.Afflictions[v.."_queue"], i, aff)
- break
- end
- end
- end
- else
- table.insert(self.Afflictions[cure_type.."_queue"], aff)
- end
- end
- end
- end
- function Agatha:RemAff(affliction)
- if type(affliction) ~= "string" then return false end
- -- if the affliction is present in the dictionary, remove it from all queues
- -- associated with its cure_types table.
- if self.Afflictions.aff_dict[affliction:lower()] then
- for k,v in pairs(self.Afflictions.aff_dict[affliction:lower()].cure_types) do
- for i,j in pairs(self.Afflictions[v.."_queue"]) do
- if j.name == affliction:lower() then table.remove(self.Afflictions[v.."_queue"], i) end
- end
- end
- Agatha:Announce("|cffffffAffliction removed: |c00ff00" .. string.upper(affliction) .. "|cffffff.")
- end
- end
- function Agatha:NewAff(name, ...)
- -- defines a new affliction and adds it to Agatha.afflictions.aff_dict["affname"]
- if type(name) ~= "string" then
- Agatha:Error("NewAff: invalid affliction name data type.")
- return false
- end
- if self.Afflictions.aff_dict[name:lower()] then
- Agatha:Announce("Duplicate affliction definition. Overwriting old definition.")
- end
- local args = {...}
- local aff = {
- name = name:lower(),
- herb_cure = "",
- salve_cure = "",
- pipe_cure = "",
- tincture_cure = "",
- slice_cure = "",
- poultice_cure = "",
- skills_cure = {},
- cure_types = {},
- bodypart = "",
- priority = ""
- }
- for _,v in pairs(args) do
- if type(v) == "string" then
- if self.Cure_dict.Concoctions.Herbs[v] then
- aff.herb_cure = v
- table.insert(aff.cure_types, "herb")
- elseif self.Cure_dict.Concoctions.Salves[v] then
- aff.salve_cure = v
- table.insert(aff.cure_types, "salve")
- elseif self.Cure_dict.Concoctions.Smoked[v] then
- aff.pipe_cure = v
- table.insert(aff.cure_types, "smoked")
- elseif self.Cure_dict.Reanimation.Slices[v] then
- aff.slice_cure = v
- table.insert(aff.cure_types, "slice")
- elseif self.Cure_dict.Reanimation.Poultices[v] then
- aff.poultice_cure = v
- table.insert(aff.cure_types, "poultice")
- elseif self.Cure_dict.Reanimation.Tinctures[v] then
- aff.tincture_cure = v
- table.insert(aff.cure_types, "tincture")
- elseif self.Cure_dict.Skills[v] then
- aff.skills_cure = v
- table.insert(aff.cure_types, "skill")
- elseif self.Cure_dict.Bodyparts[v] then
- aff.bodypart = v
- else Agatha:Error("Agatha:NewAff: Invalid argument type in affliction definition.");return false
- end
- elseif type(v) == "function" then
- aff.priority = v
- else
- Agatha:Error("Agatha:NewAff: Invalid argument type in affliction definition.");return false
- end
- end
- if not aff.priority then aff.priority = function() return 1 end end
- self.Afflictions.aff_dict[name:lower()] = aff
- Agatha:Announce("Affliction successfully added to the dictionary: " .. name .. ".")
- Save()
- return true
- end
- function Agatha:CureNextAff(afftype)
- if type(afftype) ~= "string" then
- Agatha:Error("Agatha:CureNextAff: invalid type.")
- return false
- end
- local aff_queue = self.Afflictions[afftype.."_queue"]
- local cure_command
- if afftype == "herb" or type == "slice" then cure_command = "eat"
- elseif afftype == "salve" then cure_command = "apply"
- elseif afftype == "pipe" then cure_command = "smoke"
- elseif afftype == "poultice" then cure_command = "press"
- elseif afftype == "tincture" then cure_command = "inject"
- end
- if aff_queue then
- if #aff_queue > 0 then
- if self.Status.Balances[afftype.."_bal"] and not self.Status.Balances["try_"..afftype] then
- self.Status.Balances["try_"..afftype] = true
- if cure_command == "eat" then cure_command = "outc " .. self.Afflictions.aff_dict[aff_queue[1].name][afftype.."_cure"] .. ";eat" end
- cure_command = cure_command .. " " .. self.Afflictions.aff_dict[aff_queue[1].name][afftype.."_cure"]
- if aff_queue[1].bodypart ~= "" and aff_queue[1].bodypart ~= "skin" then cure_command = cure_command .. " to " .. aff_queue[1].bodypart end
- send(cure_command)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement