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.

167 lines
5.7 KiB

5 years ago
-------------------------------------------------------------------------------
---------------------------------- NAMESPACE ----------------------------------
-------------------------------------------------------------------------------
local ADDON_NAME, ns = ...
local Class = ns.Class
-------------------------------------------------------------------------------
--------------------------------- REQUIREMENT ---------------------------------
-------------------------------------------------------------------------------
--[[
Base class for all node requirements.
text (string): Requirement text
--]]
4 years ago
local Requirement = Class('Requirement', nil, {text = UNKNOWN})
5 years ago
function Requirement:GetText() return self.text end
function Requirement:IsMet() return false end
4 years ago
-------------------------------------------------------------------------------
--------------------------------- ACHIEVEMENT ---------------------------------
-------------------------------------------------------------------------------
local Achievement = Class('Achievement', Requirement)
function Achievement:Initialize(id)
self.id = id
self.text = string.format('{achievement:%d}', self.id)
end
function Achievement:IsMet()
local _, _, _, completed = GetAchievementInfo(self.id)
return completed
end
5 years ago
-------------------------------------------------------------------------------
---------------------------------- 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)
4 years ago
function GarrisonTalent:Initialize(id, text) self.id, self.text = id, text end
5 years ago
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
4 years ago
self.text = self.text .. ' x' .. self.count
5 years ago
end
end
4 years ago
function Item:IsMet() return ns.PlayerHasItem(self.id, self.count) end
-------------------------------------------------------------------------------
------------------------------------ QUEST ------------------------------------
-------------------------------------------------------------------------------
local Quest = Class('Quest', Requirement)
function Quest:Initialize(id) self.id = id end
function Quest:GetText() return C_QuestLog.GetTitleForQuestID(self.id) end
function Quest:IsMet() return C_QuestLog.IsQuestFlaggedCompleted(self.id) end
-------------------------------------------------------------------------------
--------------------------------- REPUTATION ----------------------------------
-------------------------------------------------------------------------------
local Reputation = Class('Reputation', Requirement)
-- @todo will cause problems when requiring lower / negative reputations. Maybe add comparison as optional parameter with default value '>='.
function Reputation:Initialize(id, level) self.id, self.level = id, level end
function Reputation:GetText()
local name = GetFactionInfoByID(self.id)
local level = GetText('FACTION_STANDING_LABEL' .. self.level)
return string.format(name .. ' (' .. level .. ')')
end
function Reputation:IsMet()
local _, _, standingID = GetFactionInfoByID(self.id)
return standingID >= self.level
5 years ago
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,
4 years ago
IsMet = function()
return C_PvP.IsWarModeActive() or C_PvP.IsWarModeDesired()
end
5 years ago
})()
-------------------------------------------------------------------------------
ns.requirement = {
4 years ago
Achievement = Achievement,
Currency = Currency,
GarrisonTalent = GarrisonTalent,
Item = Item,
Quest = Quest,
Reputation = Reputation,
Requirement = Requirement,
Spell = Spell,
WarMode = WarMode
5 years ago
}