You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.1 KiB

-------------------------------------------------------------------------------
---------------------------------- NAMESPACE ----------------------------------
-------------------------------------------------------------------------------
local ADDON_NAME, ns = ...
local Class = ns.Class
-------------------------------------------------------------------------------
--------------------------------- REQUIREMENT ---------------------------------
-------------------------------------------------------------------------------
--[[
Base class for all node requirements.
text (string): Requirement text
--]]
local Requirement = Class('Requirement', nil, { text = UNKNOWN })
function Requirement:GetText() return self.text end
function Requirement:IsMet() return false end
-------------------------------------------------------------------------------
---------------------------------- CURRENCY -----------------------------------
-------------------------------------------------------------------------------
local Currency = Class('Currency', Requirement)
function Currency:Initialize(id, count)
self.id, self.count = id, count
self.text = string.format('{currency:%d} x%d', self.id, self.count)
end
function Currency:IsMet()
local info = C_CurrencyInfo.GetCurrencyInfo(self.id)
return info and info.quantity >= self.count
end
-------------------------------------------------------------------------------
------------------------------- GARRISON TALENT -------------------------------
-------------------------------------------------------------------------------
local GarrisonTalent = Class('GarrisonTalent', Requirement)
function GarrisonTalent:Initialize(id, text)
self.id, self.text = id, text
end
function GarrisonTalent:GetText()
local info = C_Garrison.GetTalentInfo(self.id)
return self.text:format(info.name)
end
function GarrisonTalent:IsMet()
local info = C_Garrison.GetTalentInfo(self.id)
return info and info.researched
end
-------------------------------------------------------------------------------
------------------------------------ ITEM -------------------------------------
-------------------------------------------------------------------------------
local function IterateBagSlots()
local bag, slot, slots = nil, 1, 1
return function ()
if bag == nil or slot == slots then
repeat
bag = (bag or -1) + 1
slot = 1
slots = GetContainerNumSlots(bag)
until slots > 0 or bag > 4
if bag > 4 then return end
else
slot = slot + 1
end
return bag, slot
end
end
-------------------------------------------------------------------------------
local Item = Class('Item', Requirement)
function Item:Initialize(id, count)
self.id, self.count = id, count
self.text = string.format('{item:%d}', self.id)
if self.count and self.count > 1 then
self.text = self.text..' x'..self.count
end
end
function Item:IsMet()
for bag, slot in IterateBagSlots() do
if GetContainerItemID(bag, slot) == self.id then
if self.count and self.count > 1 then
return select(2, GetContainerItemInfo(bag, slot)) >= self.count
else return true end
end
end
return false
end
-------------------------------------------------------------------------------
------------------------------------ SPELL ------------------------------------
-------------------------------------------------------------------------------
local Spell = Class('Spell', Requirement)
function Spell:Initialize(id)
self.id = id
self.text = string.format('{spell:%d}', self.id)
end
function Spell:IsMet()
for i = 1, 255 do
local buff = select(10, UnitAura('player', i, 'HELPFUL'))
local debuff = select(10, UnitAura('player', i, 'HARMFUL'))
if buff == self.id or debuff == self.id then return true end
end
return false
end
-------------------------------------------------------------------------------
ns.requirement = {
Currency=Currency,
GarrisonTalent=GarrisonTalent,
Item=Item,
Requirement=Requirement,
Spell=Spell
}