Update Full Recharge time.

main
ck 1 year ago
parent d69fd5d46a
commit 6fd60c6a4f
  1. 2
      src/Cache/Cache.lua
  2. 12
      src/Cacheable/Cacheable.lua
  3. 7
      src/Spell/Spell.lua
  4. 7
      src/UnitManager/UnitManager.lua
  5. 35
      src/_bastion.lua

@ -19,7 +19,7 @@ function Cache:Set(key, value, duration)
self.cache[key] = { self.cache[key] = {
value = value, value = value,
duration = duration, duration = duration,
time = GetTime() time = GetTime(),
} }
end end

@ -1,11 +1,10 @@
---@types Tinkr, Bastion ---@type Tinkr, Bastion
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
-- Define a Cacheable class -- Define a Cacheable class
---@class Cacheable<V>: { value: V, cache: Cache, callback?: fun(): V }
---@class Cacheable ---@class Cacheable
---@field cache? Cache
---@field callback? fun():any
---@field value any
local Cacheable = { local Cacheable = {
cache = nil, cache = nil,
callback = nil, callback = nil,
@ -40,10 +39,9 @@ function Cacheable:__tostring()
end end
-- Create -- Create
---@generic V: Cacheable, V ---@generic V : Cacheable, V
---@param value V ---@param value `V`
---@param cb fun(): V ---@param cb fun(): V
---@return V
function Cacheable:New(value, cb) function Cacheable:New(value, cb)
local self = setmetatable({}, Cacheable) local self = setmetatable({}, Cacheable)

@ -127,11 +127,8 @@ function Spell:GetFullRechargeTime()
return 0 return 0
end end
if charges == 0 then local totalChargeTime = ((maxCharges - charges) * chargeDuration) - ((chargeStart + chargeDuration) - GetTime())
return start + duration - GetTime() return totalChargeTime
end
return chargeStart + chargeDuration - GetTime()
end end
-- Return the castable function -- Return the castable function

@ -5,7 +5,7 @@ local ObjectManager = Tinkr.Util.ObjectManager
local Unit = Bastion.Unit local Unit = Bastion.Unit
---@class CacheableUnit : Cacheable, Unit ---@class CacheableUnit<U> : Cacheable<U>
-- Create a new UnitManager class -- Create a new UnitManager class
---@class UnitManager : { [UnitId]: Unit } ---@class UnitManager : { [UnitId]: Unit }
@ -122,16 +122,14 @@ end
-- Create a custom unit and cache it for .5 seconds -- Create a custom unit and cache it for .5 seconds
---@param token string ---@param token string
---@param cb fun(): Unit ---@param cb fun(): Unit
---@return CacheableUnit ---@return Cacheable<Unit>
function UnitManager:CreateCustomUnit(token, cb) function UnitManager:CreateCustomUnit(token, cb)
local unit = cb() local unit = cb()
---@type CacheableUnit
local cachedUnit = Bastion.Cacheable:New(unit, cb) local cachedUnit = Bastion.Cacheable:New(unit, cb)
if unit == nil then if unit == nil then
error("UnitManager:CreateCustomUnit - Invalid unit: " .. token) error("UnitManager:CreateCustomUnit - Invalid unit: " .. token)
end end
if self.customUnits[token] == nil then if self.customUnits[token] == nil then
self.customUnits[token] = { self.customUnits[token] = {
unit = cachedUnit, unit = cachedUnit,
@ -140,7 +138,6 @@ function UnitManager:CreateCustomUnit(token, cb)
end end
self.cache:Set(token, cachedUnit, 0.5) self.cache:Set(token, cachedUnit, 0.5)
return cachedUnit return cachedUnit
end end

@ -82,7 +82,9 @@ local function LoadThird()
end end
end end
---@return any ... ---@generic V
---@param class `V`
---@return V ...
function Bastion.require(class) function Bastion.require(class)
-- return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) -- return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion)
return Bastion:Require("~/src/" .. class .. "/" .. class) return Bastion:Require("~/src/" .. class .. "/" .. class)
@ -90,62 +92,37 @@ end
Bastion.Globals = {} Bastion.Globals = {}
---@type ClassMagic
Bastion.ClassMagic = Bastion.require("ClassMagic") Bastion.ClassMagic = Bastion.require("ClassMagic")
---@type List
Bastion.List = Bastion.require("List") Bastion.List = Bastion.require("List")
---@type Library
Bastion.Library = Bastion.require("Library") Bastion.Library = Bastion.require("Library")
---@type NotificationsList, Notification ---@type NotificationsList, Notification
Bastion.NotificationsList, Bastion.Notification = Bastion.require("NotificationsList") Bastion.NotificationsList, Bastion.Notification = Bastion.require("NotificationsList")
---@type Vector3
Bastion.Vector3 = Bastion.require("Vector3") Bastion.Vector3 = Bastion.require("Vector3")
---@type Sequencer
Bastion.Sequencer = Bastion.require("Sequencer") Bastion.Sequencer = Bastion.require("Sequencer")
---@type Command
Bastion.Command = Bastion.require("Command") Bastion.Command = Bastion.require("Command")
---@type Cache
Bastion.Cache = Bastion.require("Cache") Bastion.Cache = Bastion.require("Cache")
---@type Cacheable
Bastion.Cacheable = Bastion.require("Cacheable") Bastion.Cacheable = Bastion.require("Cacheable")
---@type Refreshable
Bastion.Refreshable = Bastion.require("Refreshable") Bastion.Refreshable = Bastion.require("Refreshable")
---@type Unit
Bastion.Unit = Bastion.require("Unit") Bastion.Unit = Bastion.require("Unit")
---@type Aura
Bastion.Aura = Bastion.require("Aura") Bastion.Aura = Bastion.require("Aura")
---@type APL, APLActor, APLTrait ---@type APL, APLActor, APLTrait
Bastion.APL, Bastion.APLActor, Bastion.APLTrait = Bastion.require("APL") Bastion.APL, Bastion.APLActor, Bastion.APLTrait = Bastion.require("APL")
---@type Module
Bastion.Module = Bastion.require("Module") Bastion.Module = Bastion.require("Module")
---@type UnitManager
Bastion.UnitManager = Bastion.require("UnitManager"):New() Bastion.UnitManager = Bastion.require("UnitManager"):New()
---@type ObjectManager
Bastion.ObjectManager = Bastion.require("ObjectManager"):New() Bastion.ObjectManager = Bastion.require("ObjectManager"):New()
---@type EventManager
Bastion.EventManager = Bastion.require("EventManager") Bastion.EventManager = Bastion.require("EventManager")
Bastion.Globals.EventManager = Bastion.EventManager:New() Bastion.Globals.EventManager = Bastion.EventManager:New()
---@type Spell
Bastion.Spell = Bastion.require("Spell") Bastion.Spell = Bastion.require("Spell")
---@type SpellBook
Bastion.SpellBook = Bastion.require("SpellBook") Bastion.SpellBook = Bastion.require("SpellBook")
Bastion.Globals.SpellBook = Bastion.SpellBook:New() Bastion.Globals.SpellBook = Bastion.SpellBook:New()
---@type Item
Bastion.Item = Bastion.require("Item") Bastion.Item = Bastion.require("Item")
---@type ItemBook
Bastion.ItemBook = Bastion.require("ItemBook") Bastion.ItemBook = Bastion.require("ItemBook")
Bastion.Globals.ItemBook = Bastion.ItemBook:New() Bastion.Globals.ItemBook = Bastion.ItemBook:New()
---@type AuraTable
Bastion.AuraTable = Bastion.require("AuraTable") Bastion.AuraTable = Bastion.require("AuraTable")
---@type Class
Bastion.Class = Bastion.require("Class") Bastion.Class = Bastion.require("Class")
---@type Timer
Bastion.Timer = Bastion.require("Timer") Bastion.Timer = Bastion.require("Timer")
---@type Timer
Bastion.CombatTimer = Bastion.Timer:New("combat") Bastion.CombatTimer = Bastion.Timer:New("combat")
---@type MythicPlusUtils
Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New() Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New()
---@type NotificationsList
Bastion.Notifications = Bastion.NotificationsList:New() Bastion.Notifications = Bastion.NotificationsList:New()
local LIBRARIES = {} local LIBRARIES = {}
@ -317,11 +294,7 @@ Command:Register("dumpspells", "Dump spells to a file", function()
if spellID then if spellID then
spellName = spellName:gsub("[%W%s]", "") spellName = spellName:gsub("[%W%s]", "")
WriteFile( WriteFile("bastion-" .. UnitClass("player") .. "-" .. rand .. ".lua", "local " .. spellName .. " = Bastion.Globals.SpellBook:GetSpell(" .. spellID .. ")\n", true)
"bastion-" .. UnitClass("player") .. "-" .. rand .. ".lua",
"local " .. spellName .. " = Bastion.Globals.SpellBook:GetSpell(" .. spellID .. ")\n",
true
)
end end
i = i + 1 i = i + 1
end end

Loading…
Cancel
Save