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.
117 lines
3.8 KiB
117 lines
3.8 KiB
|
5 years ago
|
-------------------------------------------------------------------------------
|
||
|
|
---------------------------------- 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 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()
|
||
|
|
return ns.PlayerHasItem(self.id, self.count)
|
||
|
|
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
|
||
|
|
|
||
|
|
-------------------------------------------------------------------------------
|
||
|
|
----------------------------------- WAR MODE ----------------------------------
|
||
|
|
-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
local WarMode = Class('WarMode', Requirement, {
|
||
|
|
text = PVP_LABEL_WAR_MODE,
|
||
|
|
IsMet = function () return C_PvP.IsWarModeActive() or C_PvP.IsWarModeDesired() end
|
||
|
|
})()
|
||
|
|
|
||
|
|
-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
ns.requirement = {
|
||
|
|
Currency=Currency,
|
||
|
|
GarrisonTalent=GarrisonTalent,
|
||
|
|
Item=Item,
|
||
|
|
Requirement=Requirement,
|
||
|
|
Spell=Spell,
|
||
|
|
WarMode=WarMode
|
||
|
|
}
|