Item emmy lua docs

main
4n0n 2 years ago
parent c91a522b6b
commit ca82648393
  1. 59
      src/Item/Item.lua

@ -31,16 +31,20 @@ function Item:__index(k)
end end
-- Equals -- Equals
---@param other Item
---@return boolean
function Item:__eq(other) function Item:__eq(other)
return self:GetID() == other:GetID() return self:GetID() == other:GetID()
end end
-- tostring -- tostring
---@return string
function Item:__tostring() function Item:__tostring()
return "Bastion.__Item(" .. self:GetID() .. ")" .. " - " .. self:GetName() return "Bastion.__Item(" .. self:GetID() .. ")" .. " - " .. self:GetName()
end end
-- Constructor -- Constructor
---@param id number
function Item:New(id) function Item:New(id)
local self = setmetatable({}, Item) local self = setmetatable({}, Item)
@ -57,47 +61,58 @@ function Item:New(id)
end end
-- Get the Items id -- Get the Items id
---@return number
function Item:GetID() function Item:GetID()
return self.ItemID return self.ItemID
end end
-- Get the Items name -- Get the Items name
---@return string
function Item:GetName() function Item:GetName()
return GetItemInfo(self:GetID()) return GetItemInfo(self:GetID())
end end
-- Get the Items icon -- Get the Items icon
---@return number
function Item:GetIcon() function Item:GetIcon()
return select(3, GetItemInfo(self:GetID())) return select(3, GetItemInfo(self:GetID()))
end end
-- Get the Items cooldown -- Get the Items cooldown
---@return number
function Item:GetCooldown() function Item:GetCooldown()
return select(2, C_Container.GetItemCooldown(self:GetID())) return select(2, C_Container.GetItemCooldown(self:GetID()))
end end
-- Return the Usable function -- Return the Usable function
---@return function | boolean
function Item:GetUsableFunction() function Item:GetUsableFunction()
return self.UsableIfFunc return self.UsableIfFunc
end end
-- Return the preUse function -- Return the preUse function
---@return function | boolean
function Item:GetPreUseFunction() function Item:GetPreUseFunction()
return self.PreUseFunc return self.PreUseFunc
end end
-- Get the on Use func -- Get the on Use func
---@return function | boolean
function Item:GetOnUseFunction() function Item:GetOnUseFunction()
return self.OnUseFunc return self.OnUseFunc
end end
-- Get the Items cooldown remaining -- Get the Items cooldown remaining
---@return number
function Item:GetCooldownRemaining() function Item:GetCooldownRemaining()
local start, duration = C_Container.GetItemCooldown(self:GetID()) local start, duration = C_Container.GetItemCooldown(self:GetID())
return start + duration - GetTime() return start + duration - GetTime()
end end
-- Use the Item -- Use the Item
---@param unit Unit
---@param condition string
---@return boolean
function Item:Use(unit, condition) function Item:Use(unit, condition)
if condition and not self:EvaluateCondition(condition) then if condition and not self:EvaluateCondition(condition) then
return false return false
@ -127,46 +142,56 @@ function Item:Use(unit, condition)
if self:GetOnUseFunction() then if self:GetOnUseFunction() then
self:GetOnUseFunction()(self) self:GetOnUseFunction()(self)
end end
return true
end end
-- Last use attempt -- Last use attempt
---@return number
function Item:GetLastUseAttempt() function Item:GetLastUseAttempt()
return self.lastUseAttempt return self.lastUseAttempt
end end
-- Time since last attepmt -- Time since last attepmt
---@return number
function Item:GetTimeSinceLastUseAttempt() function Item:GetTimeSinceLastUseAttempt()
return GetTime() - self:GetLastUseAttempt() return GetTime() - self:GetLastUseAttempt()
end end
-- Check if the Item is known -- Check if the Item is known
---@return boolean
function Item:IsEquipped() function Item:IsEquipped()
return IsEquippedItem(self:GetID()) return IsEquippedItem(self:GetID())
end end
-- Check if the Item is on cooldown -- Check if the Item is on cooldown
---@return boolean
function Item:IsOnCooldown() function Item:IsOnCooldown()
return select(2, C_Container.GetItemCooldown(self:GetID())) > 0 return select(2, C_Container.GetItemCooldown(self:GetID())) > 0
end end
-- Check if the Item is usable -- Check if the Item is usable
---@return boolean
function Item:IsUsable() function Item:IsUsable()
local usable, noMana = IsUsableItem(self:GetID()) local usable, noMana = IsUsableItem(self:GetID())
return usable or usableExcludes[self:GetID()] return usable or usableExcludes[self:GetID()]
end end
-- Check if the Item is Usable -- Check if the Item is Usable
---@return boolean
function Item:IsEquippedAndUsable() function Item:IsEquippedAndUsable()
return ((self:IsEquippable() and self:IsEquipped()) or return ((self:IsEquippable() and self:IsEquipped()) or
(not self:IsEquippable() and self:IsUsable())) and not self:IsOnCooldown() (not self:IsEquippable() and self:IsUsable())) and not self:IsOnCooldown()
end end
-- Is equippable -- Is equippable
---@return boolean
function Item:IsEquippable() function Item:IsEquippable()
return IsEquippableItem(self:GetID()) return IsEquippableItem(self:GetID())
end end
-- Check if the Item is Usable -- Check if the Item is Usable
---@return boolean
function Item:Usable() function Item:Usable()
if self:GetUsableFunction() then if self:GetUsableFunction() then
return self:GetUsableFunction()(self) return self:GetUsableFunction()(self)
@ -177,6 +202,7 @@ end
-- Set a script to check if the Item is Usable -- Set a script to check if the Item is Usable
---@param func fun(self:Item):boolean ---@param func fun(self:Item):boolean
---@return Item
function Item:UsableIf(func) function Item:UsableIf(func)
self.UsableIfFunc = func self.UsableIfFunc = func
return self return self
@ -184,6 +210,7 @@ end
-- Set a script to run before the Item has been Use -- Set a script to run before the Item has been Use
---@param func fun(self:Item) ---@param func fun(self:Item)
---@return Item
function Item:PreUse(func) function Item:PreUse(func)
self.PreUseFunc = func self.PreUseFunc = func
return self return self
@ -191,17 +218,23 @@ end
-- Set a script to run after the Item has been Use -- Set a script to run after the Item has been Use
---@param func fun(self:Item) ---@param func fun(self:Item)
---@return Item
function Item:OnUse(func) function Item:OnUse(func)
self.OnUseFunc = func self.OnUseFunc = func
return self return self
end end
-- Get was looking -- Get was looking
---@return boolean
function Item:GetWasLooking() function Item:GetWasLooking()
return self.wasLooking return self.wasLooking
end end
-- Click the Item -- Click the Item
---@param x number
---@param y number
---@param z number
---@return boolean
function Item:Click(x, y, z) function Item:Click(x, y, z)
if type(x) == 'table' then if type(x) == 'table' then
x, y, z = x.x, x.y, x.z x, y, z = x.x, x.y, x.z
@ -218,6 +251,8 @@ function Item:Click(x, y, z)
end end
-- Check if the Item is Usable and Use it -- Check if the Item is Usable and Use it
---@param unit Unit
---@return boolean
function Item:Call(unit) function Item:Call(unit)
if self:Usable() then if self:Usable() then
self:Use(unit) self:Use(unit)
@ -227,6 +262,8 @@ function Item:Call(unit)
end end
-- Check if the Item is in range of the unit -- Check if the Item is in range of the unit
---@param unit Unit
---@return boolean
function Item:IsInRange(unit) function Item:IsInRange(unit)
local name, rank, icon, UseTime, Itemmin, Itemmax, ItemID = GetItemInfo(self:GetID()) local name, rank, icon, UseTime, Itemmin, Itemmax, ItemID = GetItemInfo(self:GetID())
@ -263,11 +300,13 @@ function Item:IsInRange(unit)
end end
-- Get the last use time -- Get the last use time
---@return number
function Item:GetLastUseTime() function Item:GetLastUseTime()
return Bastion.SpellBook:GetSpell(self:GetID()):GetLastCastTime() return Bastion.SpellBook:GetSpell(self:GetID()):GetLastCastTime()
end end
-- Get time since last use -- Get time since last use
---@return number
function Item:GetTimeSinceLastUse() function Item:GetTimeSinceLastUse()
if not self:GetLastUseTime() then if not self:GetLastUseTime() then
return math.huge return math.huge
@ -276,11 +315,13 @@ function Item:GetTimeSinceLastUse()
end end
-- Get the Items charges -- Get the Items charges
---@return number
function Item:GetCharges() function Item:GetCharges()
return GetItemCharges(self:GetID()) return GetItemCharges(self:GetID())
end end
-- Get the Items charges remaining -- Get the Items charges remaining
---@return number
function Item:GetChargesRemaining() function Item:GetChargesRemaining()
local charges, maxCharges, start, duration = GetItemCharges(self:GetID()) local charges, maxCharges, start, duration = GetItemCharges(self:GetID())
return charges return charges
@ -289,6 +330,7 @@ end
-- Create a condition for the Item -- Create a condition for the Item
---@param name string ---@param name string
---@param func fun(self:Item) ---@param func fun(self:Item)
---@return Item
function Item:Condition(name, func) function Item:Condition(name, func)
self.conditions[name] = { self.conditions[name] = {
func = func func = func
@ -297,6 +339,8 @@ function Item:Condition(name, func)
end end
-- Get a condition for the Item -- Get a condition for the Item
---@param name string
---@return function | nil
function Item:GetCondition(name) function Item:GetCondition(name)
local condition = self.conditions[name] local condition = self.conditions[name]
if condition then if condition then
@ -307,6 +351,8 @@ function Item:GetCondition(name)
end end
-- Evaluate a condition for the Item -- Evaluate a condition for the Item
---@param name string
---@return boolean
function Item:EvaluateCondition(name) function Item:EvaluateCondition(name)
local condition = self:GetCondition(name) local condition = self:GetCondition(name)
if condition then if condition then
@ -317,6 +363,8 @@ function Item:EvaluateCondition(name)
end end
-- Check if the Item has a condition -- Check if the Item has a condition
---@param name string
---@return boolean
function Item:HasCondition(name) function Item:HasCondition(name)
local condition = self:GetCondition(name) local condition = self:GetCondition(name)
if condition then if condition then
@ -327,17 +375,21 @@ function Item:HasCondition(name)
end end
-- Set the Items target -- Set the Items target
---@param unit Unit
---@return Item
function Item:SetTarget(unit) function Item:SetTarget(unit)
self.target = unit self.target = unit
return self return self
end end
-- Get the Items target -- Get the Items target
---@return Unit | nil
function Item:GetTarget() function Item:GetTarget()
return self.target return self.target
end end
-- IsMagicDispel -- IsMagicDispel
---@return boolean
function Item:IsMagicDispel() function Item:IsMagicDispel()
return ({ return ({
[88423] = true [88423] = true
@ -345,6 +397,7 @@ function Item:IsMagicDispel()
end end
-- IsCurseDispel -- IsCurseDispel
---@return boolean
function Item:IsCurseDispel() function Item:IsCurseDispel()
return ({ return ({
[88423] = true [88423] = true
@ -352,6 +405,7 @@ function Item:IsCurseDispel()
end end
-- IsPoisonDispel -- IsPoisonDispel
---@return boolean
function Item:IsPoisonDispel() function Item:IsPoisonDispel()
return ({ return ({
[88423] = true [88423] = true
@ -359,16 +413,21 @@ function Item:IsPoisonDispel()
end end
-- IsDiseaseDispel -- IsDiseaseDispel
---@return boolean
function Item:IsDiseaseDispel() function Item:IsDiseaseDispel()
return ({ return ({
})[self:GetID()] })[self:GetID()]
end end
---@param item Item
---@return boolean
function Item:IsItem(item) function Item:IsItem(item)
return self:GetID() == item:GetID() return self:GetID() == item:GetID()
end end
-- Get the Items spell
---@return Spell | nil
function Item:GetSpell() function Item:GetSpell()
if self.spellID then if self.spellID then
return Bastion.SpellBook:GetSpell(self.spellID) return Bastion.SpellBook:GetSpell(self.spellID)

Loading…
Cancel
Save