Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. function Agatha:AddAff(affliction)
  2. if type(affliction) ~= "string" then return false end
  3.  
  4. -- if the affliction is present in the dictionary, add it to all queues
  5. -- associated with its cure_types table.
  6.  
  7. if self.Afflictions.aff_dict[affliction:lower()] then
  8.  
  9. local aff = self.Afflictions.aff_dict[affliction:lower()]
  10. local duplicate_aff = false
  11. local cure_type = ""
  12. Agatha:Announce("|cffffffAffliction added: |cff0000" .. string.upper(affliction) .. "|cffffff.")
  13. for _,v in pairs(aff.cure_types) do
  14.  
  15. cure_type = v
  16.  
  17. if #self.Afflictions[cure_type.."_queue"] > 0 then
  18. for _,j in pairs(self.Afflictions[cure_type.."_queue"]) do
  19. if j.name == affliction then
  20. duplicate_aff = true
  21. end
  22. end
  23.  
  24. if not duplicate_aff then
  25. for i,k in pairs(self.Afflictions[v.."_queue"]) do
  26. if aff.priority <= k.priority or i == #self.Afflictions[v.."_queue"] then
  27. table.insert(self.Afflictions[v.."_queue"], i, aff)
  28. break
  29. end
  30. end
  31. end
  32. else
  33. table.insert(self.Afflictions[cure_type.."_queue"], aff)
  34. end
  35. end
  36. end
  37. end
  38.  
  39. function Agatha:RemAff(affliction)
  40. if type(affliction) ~= "string" then return false end
  41.  
  42. -- if the affliction is present in the dictionary, remove it from all queues
  43. -- associated with its cure_types table.
  44.  
  45. if self.Afflictions.aff_dict[affliction:lower()] then
  46. for k,v in pairs(self.Afflictions.aff_dict[affliction:lower()].cure_types) do
  47. for i,j in pairs(self.Afflictions[v.."_queue"]) do
  48. if j.name == affliction:lower() then table.remove(self.Afflictions[v.."_queue"], i) end
  49. end
  50. end
  51. Agatha:Announce("|cffffffAffliction removed: |c00ff00" .. string.upper(affliction) .. "|cffffff.")
  52. end
  53. end
  54.  
  55. function Agatha:NewAff(name, ...)
  56. -- defines a new affliction and adds it to Agatha.afflictions.aff_dict["affname"]
  57.  
  58. if type(name) ~= "string" then
  59. Agatha:Error("NewAff: invalid affliction name data type.")
  60. return false
  61. end
  62.  
  63. if self.Afflictions.aff_dict[name:lower()] then
  64. Agatha:Announce("Duplicate affliction definition. Overwriting old definition.")
  65. end
  66.  
  67. local args = {...}
  68. local aff = {
  69. name = name:lower(),
  70. herb_cure = "",
  71. salve_cure = "",
  72. pipe_cure = "",
  73. tincture_cure = "",
  74. slice_cure = "",
  75. poultice_cure = "",
  76. skills_cure = {},
  77. cure_types = {},
  78. bodypart = "",
  79. priority = ""
  80. }
  81.  
  82. for _,v in pairs(args) do
  83. if type(v) == "string" then
  84. if self.Cure_dict.Concoctions.Herbs[v] then
  85. aff.herb_cure = v
  86. table.insert(aff.cure_types, "herb")
  87. elseif self.Cure_dict.Concoctions.Salves[v] then
  88. aff.salve_cure = v
  89. table.insert(aff.cure_types, "salve")
  90. elseif self.Cure_dict.Concoctions.Smoked[v] then
  91. aff.pipe_cure = v
  92. table.insert(aff.cure_types, "smoked")
  93. elseif self.Cure_dict.Reanimation.Slices[v] then
  94. aff.slice_cure = v
  95. table.insert(aff.cure_types, "slice")
  96. elseif self.Cure_dict.Reanimation.Poultices[v] then
  97. aff.poultice_cure = v
  98. table.insert(aff.cure_types, "poultice")
  99. elseif self.Cure_dict.Reanimation.Tinctures[v] then
  100. aff.tincture_cure = v
  101. table.insert(aff.cure_types, "tincture")
  102. elseif self.Cure_dict.Skills[v] then
  103. aff.skills_cure = v
  104. table.insert(aff.cure_types, "skill")
  105. elseif self.Cure_dict.Bodyparts[v] then
  106. aff.bodypart = v
  107. else Agatha:Error("Agatha:NewAff: Invalid argument type in affliction definition.");return false
  108. end
  109. elseif type(v) == "function" then
  110. aff.priority = v
  111. else
  112. Agatha:Error("Agatha:NewAff: Invalid argument type in affliction definition.");return false
  113. end
  114. end
  115. if not aff.priority then aff.priority = function() return 1 end end
  116. self.Afflictions.aff_dict[name:lower()] = aff
  117. Agatha:Announce("Affliction successfully added to the dictionary: " .. name .. ".")
  118. Save()
  119. return true
  120.  
  121. end
  122.  
  123. function Agatha:CureNextAff(afftype)
  124.  
  125. if type(afftype) ~= "string" then
  126. Agatha:Error("Agatha:CureNextAff: invalid type.")
  127. return false
  128. end
  129.  
  130. local aff_queue = self.Afflictions[afftype.."_queue"]
  131. local cure_command
  132.  
  133. if afftype == "herb" or type == "slice" then cure_command = "eat"
  134. elseif afftype == "salve" then cure_command = "apply"
  135. elseif afftype == "pipe" then cure_command = "smoke"
  136. elseif afftype == "poultice" then cure_command = "press"
  137. elseif afftype == "tincture" then cure_command = "inject"
  138. end
  139.  
  140. if aff_queue then
  141. if #aff_queue > 0 then
  142. if self.Status.Balances[afftype.."_bal"] and not self.Status.Balances["try_"..afftype] then
  143. self.Status.Balances["try_"..afftype] = true
  144. if cure_command == "eat" then cure_command = "outc " .. self.Afflictions.aff_dict[aff_queue[1].name][afftype.."_cure"] .. ";eat" end
  145. cure_command = cure_command .. " " .. self.Afflictions.aff_dict[aff_queue[1].name][afftype.."_cure"]
  146. if aff_queue[1].bodypart ~= "" and aff_queue[1].bodypart ~= "skin" then cure_command = cure_command .. " to " .. aff_queue[1].bodypart end
  147. send(cure_command)
  148. end
  149. end
  150. end
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement