Skip to content

Commit

Permalink
Caching Projectile Damage Table
Browse files Browse the repository at this point in the history
  • Loading branch information
Stratege authored and shalkya committed Feb 29, 2020
1 parent f784164 commit a25bee3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lua/sim/weapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ Weapon = Class(moho.weapon_methods) {

end,

GetDamageTable = function(self)

GetDamageTableInternal = function(self)
local weaponBlueprint = self:GetBlueprint()
local damageTable = {}
damageTable.InitialDamageAmount = weaponBlueprint.InitialDamage or 0
Expand Down Expand Up @@ -346,6 +347,12 @@ Weapon = Class(moho.weapon_methods) {
return damageTable
end,

damageTableCache = false,
GetDamageTable = function(self)
if not self.damageTableCache then self.damageTableCache = self:GetDamageTableInternal() end
return self.damageTableCache
end,

CreateProjectileForWeapon = function(self, bone)
local proj = self:CreateProjectile(bone)
local damageTable = self:GetDamageTable()
Expand Down Expand Up @@ -461,10 +468,12 @@ Weapon = Class(moho.weapon_methods) {

AddDamageMod = function(self, dmgMod)
self.DamageMod = self.DamageMod + dmgMod
self.damageTableCache = false
end,

AddDamageRadiusMod = function(self, dmgRadMod)
self.DamageRadiusMod = self.DamageRadiusMod + (dmgRadMod or 0)
self.damageTableCache = false
end,

DoOnFireBuffs = function(self)
Expand All @@ -485,6 +494,7 @@ Weapon = Class(moho.weapon_methods) {
-- Error
error('ERROR: DisableBuff in weapon.lua does not have a buffname')
end
self.damageTableCache = false
end,

ReEnableBuff = function(self, buffname)
Expand All @@ -494,6 +504,7 @@ Weapon = Class(moho.weapon_methods) {
-- Error
error('ERROR: ReEnableBuff in weapon.lua does not have a buffname')
end
self.damageTableCache = false
end,

-- Method to mark weapon when parent unit gets loaded on to a transport unit
Expand Down

0 comments on commit a25bee3

Please sign in to comment.