Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix excess projectiles in the same tick impacting entities that die that tick #6532

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/snippets/fix.6532.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6532) Fix excess projectiles impacting entities that die in the same tick. For example, 6 tactical missiles impacting a shield at the same time, despite only 3 being needed to bring down the shield.
14 changes: 14 additions & 0 deletions lua/shield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ end
---@field ImpactMeshBp string
---@field SkipAttachmentCheck boolean
---@field AbsorptionTypeDamageTypeToMulti table<DamageType, number>
---@field DisallowCollisions boolean
Shield = ClassShield(moho.shield_methods, Entity) {

RemainEnabledWhenAttached = false,
Expand Down Expand Up @@ -187,6 +188,7 @@ Shield = ClassShield(moho.shield_methods, Entity) {
self.PassOverkillDamage = spec.PassOverkillDamage
self.ImpactMeshBp = spec.ImpactMesh
self.SkipAttachmentCheck = spec.SkipAttachmentCheck
self.DisallowCollisions = false

if spec.ImpactEffects ~= '' then
self.ImpactEffects = EffectTemplate[spec.ImpactEffects]
Expand Down Expand Up @@ -340,6 +342,7 @@ Shield = ClassShield(moho.shield_methods, Entity) {

-- change state if we're enabled
if self.Enabled then
self.DisallowCollisions = true
ChangeState(self, self.EnergyDrainedState)
end
end,
Expand All @@ -350,6 +353,7 @@ Shield = ClassShield(moho.shield_methods, Entity) {

-- change state if we're enabled
if self.Enabled then
self.DisallowCollisions = false
ChangeState(self, self.OnState)
end
end,
Expand Down Expand Up @@ -576,6 +580,7 @@ Shield = ClassShield(moho.shield_methods, Entity) {

-- if we have no health, collapse
if EntityGetHealth(self) <= 0 then
self.DisallowCollisions = true
ChangeState(self, self.DamageDrainedState)
-- otherwise, attempt to regenerate
else
Expand Down Expand Up @@ -682,6 +687,10 @@ Shield = ClassShield(moho.shield_methods, Entity) {
-- @param other The projectile we're checking the collision with
OnCollisionCheck = function(self, other)

if self.DisallowCollisions then
return false
end

-- special logic when it is a projectile to simulate air crashes
if other.CrashingAirplaneShieldCollisionLogic then
if other.ShieldImpacted then
Expand Down Expand Up @@ -723,6 +732,10 @@ Shield = ClassShield(moho.shield_methods, Entity) {
-- @param firingWeapon The weapon the beam originates from that we're checking the collision with
OnCollisionCheckWeapon = function(self, firingWeapon)

if self.DisallowCollisions then
return false
end

-- if we're allied, check if we allow that type of collision
if self.Army == firingWeapon.Army or IsAlly(self.Army, firingWeapon.Army) then
return firingWeapon.Blueprint.CollideFriendly
Expand Down Expand Up @@ -917,6 +930,7 @@ Shield = ClassShield(moho.shield_methods, Entity) {
self.RegenThreadStartTick = GetGameTick() + 10 * self.RegenStartTime

-- back to the regular onstate
self.DisallowCollisions = false
ChangeState(self, self.OnState)
end,

Expand Down
8 changes: 7 additions & 1 deletion lua/sim/Projectile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,15 @@ Projectile = ClassProjectile(ProjectileMethods, DebugProjectileComponent) {

--- Called by the engine when the projectile impacts something
---@param self Projectile
---@param targetType string
---@param targetType ImpactType
---@param targetEntity Unit | Prop
OnImpact = function(self, targetType, targetEntity)
-- Since collision is checked before impacts are run, collision changes caused by impacts need to be checked by impacts
-- For example, a shield will first tell every projectile that it can collide with it, and then only afterwards will
-- HP be drained from the shield, and collisions turned off due to the shield being down. The same applies for units.
if targetEntity.DisallowCollisions then
return
end

-- localize information for performance
local position = self:GetPosition()
Expand Down
Loading