forked from Bastion/Bastion
parent
cd029208e3
commit
40f77a11e4
@ -0,0 +1,56 @@ |
||||
---@type Tinkr |
||||
local Tinkr, |
||||
---@class Bastion |
||||
Bastion = ... |
||||
|
||||
---@class Bastion.APLActor2.Table.Base |
||||
---@field parentAPL Bastion.APL |
||||
---@field index number |
||||
|
||||
-- Create an APL actor for the APL class |
||||
---@class Bastion.APLActor2 |
||||
---@field traits Bastion.APLTrait[] |
||||
---@field table Bastion.APLActor2.Table.Base |
||||
---@field executor fun(self: Bastion.APLActor2): boolean |
||||
local APLActor = {} |
||||
APLActor.__index = APLActor |
||||
|
||||
---@param type string |
||||
function APLActor:New(type) |
||||
---@class Bastion.APLActor2 |
||||
local self = setmetatable({ |
||||
type = type, |
||||
enabled = true, |
||||
traits = {}, |
||||
table = {}, |
||||
executor = function() return false end |
||||
}, APLActor) |
||||
return self |
||||
end |
||||
|
||||
---@param ... any |
||||
function APLActor:GetName(...) |
||||
local paramStrings = type(...) ~= "nil" and table.concat({ ... }, "-") or "" |
||||
return string.format("[%s]%s", self.type, paramStrings) |
||||
end |
||||
|
||||
-- Add a trait to the APL actor |
||||
---@param ... Bastion.APLTrait |
||||
---@return Bastion.APLActor2 |
||||
function APLActor:AddTraits(...) |
||||
for _, trait in ipairs({ ... }) do |
||||
table.insert(self.traits, trait) |
||||
end |
||||
|
||||
return self |
||||
end |
||||
|
||||
-- Get the actor |
||||
---@return Bastion.APLActor2.Table.Base |
||||
function APLActor:GetActorTable() |
||||
return self.table |
||||
end |
||||
|
||||
function APLActor:SetExecutor(executor) |
||||
self.executor = executor |
||||
end |
@ -0,0 +1,6 @@ |
||||
---@type Tinkr |
||||
local Tinkr, |
||||
---@class Bastion |
||||
Bastion = ... |
||||
|
||||
---@class Bastion.APL.SpellActor |
@ -0,0 +1,61 @@ |
||||
---@type Tinkr |
||||
local Tinkr, |
||||
---@class Bastion |
||||
Bastion = ... |
||||
|
||||
---@class Bastion.Missile : Tinkr.Missile |
||||
local Missile = { |
||||
} |
||||
|
||||
function Missile:__index(k) |
||||
if k == "_missile" then |
||||
return rawget(self, k) |
||||
end |
||||
|
||||
local response = rawget(self._missile, k) |
||||
|
||||
return response ~= nil and response or rawget(self, k) |
||||
end |
||||
|
||||
---@param missile Tinkr.Missile |
||||
function Missile:New(missile) |
||||
---@class Bastion.Missile |
||||
local self = setmetatable({ |
||||
_missile = missile |
||||
}, Missile) |
||||
return self |
||||
end |
||||
|
||||
function Missile:GetSourceUnit() |
||||
return Bastion.UnitManager:Get(self.source) |
||||
end |
||||
|
||||
function Missile:GetTargetUnit() |
||||
return Bastion.UnitManager:Get(self.target) |
||||
end |
||||
|
||||
function Missile:GetCurrentVector() |
||||
return Bastion.Vector3:New(self.cx, self.cy, self.cz) |
||||
end |
||||
|
||||
function Missile:GetHitVector() |
||||
return Bastion.Vector3:New(self.hx, self.hy, self.hz) |
||||
end |
||||
|
||||
function Missile:GetInitialVector() |
||||
return Bastion.Vector3:New(self.ix, self.iy, self.iz) |
||||
end |
||||
|
||||
function Missile:GetModelVector() |
||||
return Bastion.Vector3:New(self.mx, self.my, self.mz) |
||||
end |
||||
|
||||
function Missile:GetPVector() |
||||
return Bastion.Vector3:New(self.px, self.py, self.pz) |
||||
end |
||||
|
||||
function Missile:GetUVector() |
||||
return Bastion.Vector3:New(self.ux, self.uy, self.uz) |
||||
end |
||||
|
||||
Bastion.Missile = Missile |
@ -0,0 +1,137 @@ |
||||
---@type Tinkr |
||||
local Tinkr, |
||||
---@class Bastion |
||||
Bastion = ... |
||||
|
||||
---@class Bastion.MissileManager.TrackingParams |
||||
---@field source? Bastion.Unit |
||||
---@field target? Bastion.Unit |
||||
---@field spellId? number |
||||
---@field spellVisualId? number |
||||
---@field callback fun(self: Bastion.Missile) |
||||
|
||||
---@class Bastion.MissileManager |
||||
---@field _lists table<string, {list: Bastion.List, cb:fun(missile: Tinkr.Missile): any}> |
||||
---@field trackingParams Bastion.MissileManager.TrackingParams[] |
||||
---@field missiles Tinkr.Missile[] |
||||
local MissileManager = {} |
||||
MissileManager.__index = MissileManager |
||||
|
||||
function MissileManager:New() |
||||
---@class Bastion.MissileManager |
||||
local self = setmetatable({}, MissileManager) |
||||
self.missiles = {} |
||||
self._lists = {} |
||||
self.trackedMissiles = Bastion.List:New() |
||||
self.allMissiles = Bastion.List:New() |
||||
self.trackingParams = {} |
||||
return self |
||||
end |
||||
|
||||
-- Register a custom list with a callback |
||||
---@param name string |
||||
---@param cb fun(missile: Tinkr.Missile): boolean | any |
||||
---@return Bastion.List | false |
||||
function MissileManager:RegisterList(name, cb) |
||||
if self._lists[name] then |
||||
return false |
||||
end |
||||
|
||||
self._lists[name] = { |
||||
list = Bastion.List:New(), |
||||
cb = cb, |
||||
} |
||||
|
||||
return self._lists[name].list |
||||
end |
||||
|
||||
-- reset custom lists |
||||
---@return nil |
||||
function MissileManager:ResetLists() |
||||
for _, list in pairs(self._lists) do |
||||
list.list:clear() |
||||
end |
||||
end |
||||
|
||||
function MissileManager:Reset() |
||||
self.missiles = {} |
||||
|
||||
self.trackedMissiles:clear() |
||||
self.allMissiles:clear() |
||||
self:ResetLists() |
||||
end |
||||
|
||||
-- Refresh custom lists |
||||
---@param missile Tinkr.Missile |
||||
---@return nil |
||||
function MissileManager:EnumLists(missile) |
||||
for _, list in pairs(self._lists) do |
||||
local r = list.cb(missile) |
||||
if r then |
||||
list.list:push(r) |
||||
end |
||||
end |
||||
end |
||||
|
||||
---@param params Bastion.MissileManager.TrackingParams |
||||
function MissileManager:TrackMissile(params) |
||||
table.insert(self.trackingParams, params) |
||||
end |
||||
|
||||
---@param missileObj Bastion.Missile |
||||
function MissileManager:EnumTrackingParams(missileObj) |
||||
local tracked = false |
||||
for i, trackingParam in ipairs(self.trackingParams) do |
||||
if (not trackingParam.source or missileObj:GetSourceUnit():IsUnit(trackingParam.source)) and |
||||
(not trackingParam.target or missileObj:GetTargetUnit():IsUnit(trackingParam.target)) and |
||||
(not trackingParam.spellId or missileObj._missile.spellId == trackingParam.spellId) and |
||||
(not trackingParam.spellVisualId or missileObj._missile.spellVisualId == trackingParam.spellVisualId) |
||||
then |
||||
tracked = true |
||||
trackingParam.callback(missileObj) |
||||
end |
||||
end |
||||
return tracked |
||||
end |
||||
|
||||
-- Get a list |
||||
---@param name string |
||||
---@return Bastion.List |
||||
function MissileManager:GetList(name) |
||||
return self._lists[name].list |
||||
end |
||||
|
||||
function MissileManager:Refresh() |
||||
self:Reset() |
||||
|
||||
local missiles = Missiles() |
||||
if type(missiles) == "table" then |
||||
for _, missile in ipairs(missiles) do |
||||
table.insert(self.missiles, missile) |
||||
self:EnumLists(missile) |
||||
local missileObj = Bastion.Missile:New(missile) |
||||
self.allMissiles:push(missileObj) |
||||
if self:EnumTrackingParams(missileObj) then |
||||
self.trackedMissiles:push(missileObj) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
---@param params { source?: Bastion.Unit, target?: Bastion.Unit, spellId?: number, spellVisualId?: number } |
||||
function MissileManager:GetMissiles(params) |
||||
---@type Bastion.Missile[] |
||||
local missiles = {} |
||||
for _, missile in ipairs(self.trackedMissiles) do |
||||
if (not params.source or missile:GetSourceUnit():IsUnit(params.source)) and |
||||
(not params.target or missile:GetTargetUnit():IsUnit(params.target)) and |
||||
(not params.spellId or missile._missile.spellId == params.spellId) and |
||||
(not params.spellVisualId or missile._missile.spellVisualId == params.spellVisualId) |
||||
then |
||||
table.insert(missiles, missile) |
||||
end |
||||
end |
||||
return missiles |
||||
end |
||||
|
||||
Bastion.MissileManager = MissileManager:New() |
Loading…
Reference in new issue