32 lines
1.1 KiB
Lua
32 lines
1.1 KiB
Lua
--- @alias ImpactType "physic"|"magic"
|
|
|
|
--- Представляет из себя некое "взаимодействие", которое мы должны применить к персонажу в зависимости от контекста,
|
|
--- например, нанести урон.
|
|
--- @class Impact
|
|
--- @field intensity integer
|
|
--- @field impactType ImpactType
|
|
local impact = {}
|
|
impact.__index = impact
|
|
|
|
--- @param other Impact
|
|
function impact:__add(other)
|
|
assert(self.impactType == other.impactType, "Impact types not equals each other!")
|
|
local newImpact = Impact(self.intensity + other.intensity, self.impactType)
|
|
return newImpact
|
|
end
|
|
|
|
--- @param other Impact
|
|
function impact:__sub(other)
|
|
assert(self.impactType == other.impactType, "Impact types not equals each other!")
|
|
local newImpact = Impact(self.intensity - other.intensity, self.impactType)
|
|
return newImpact
|
|
end
|
|
|
|
--- @param intensity integer
|
|
--- @param impactType ImpactType
|
|
function Impact(intensity, impactType)
|
|
return setmetatable({ intensity = intensity, impactType = impactType }, impact)
|
|
end
|
|
|
|
return Impact
|