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

Revert FiringState OnLostTarget working through HaltFire #6289

Merged
Merged
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
3 changes: 3 additions & 0 deletions changelog/snippets/fix.6289.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- (#6289) Fix Ythotha lightning storm not attacking the ground or allies.

- (#6289) Fix `AttackGroundTries` not firing on the last shot for most weapons.
50 changes: 43 additions & 7 deletions lua/sim/weapons/DefaultProjectileWeapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1111,16 +1111,14 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
unit.Trash:Add(ForkThread(self.DisabledWhileReloadingThread, self, 1 / rof))
end

local hasTarget = self:WeaponHasTarget()

-- Deal with the rack firing sequence
if self.CurrentRackSalvoNumber > rackBoneCount then
self.CurrentRackSalvoNumber = 1
if bp.RackSalvoReloadTime > 0 then
ChangeState(self, self.RackSalvoReloadState)
elseif bp.RackSalvoChargeTime > 0 then
ChangeState(self, self.IdleState)
elseif countedProjectile or not hasTarget then
elseif countedProjectile then
if bp.WeaponUnpacks then
ChangeState(self, self.WeaponPackingState)
else
Expand All @@ -1129,7 +1127,7 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
else
ChangeState(self, self.RackSalvoFireReadyState)
end
elseif countedProjectile or not hasTarget then
elseif countedProjectile then
if bp.WeaponUnpacks then
ChangeState(self, self.WeaponPackingState)
else
Expand All @@ -1141,7 +1139,39 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
end,

OnLostTarget = function(self)
self.HaltFireOrdered = true
-- Override the default OnLostTarget but not inherited ones
-- the inherited ones are needed for beam weapons to stop firing: https://github.com/FAForever/fa/pull/4863
-- and for ythotha storm to not instantly stop firing: https://github.com/FAForever/fa/pull/5291
local baseOnLostTarget = self.__base.OnLostTarget
if baseOnLostTarget ~= DefaultProjectileWeapon.OnLostTarget then
baseOnLostTarget(self)
else
local unit = self.unit
if unit then
unit:OnLostTarget(self)
end
Weapon.OnLostTarget(self)

-- Some weapons look too ridiculous shooting into the air, so stop them from firing
-- stopping firing will cause the last shot of AttackGroundTries to not fire
local bp = self.Blueprint
if bp.WeaponUnpacks then
-- since we're stopping firing anyway, also prevent skipping the reload state here
if bp.RackSalvoReloadTime > 0 then
self.CurrentRackSalvoNumber = 1
ChangeState(self, self.RackSalvoReloadState)
else
ChangeState(self, self.WeaponPackingState)
end
elseif bp.MuzzleChargeDelay > 0.5 then
if bp.RackSalvoReloadTime > 0 then
self.CurrentRackSalvoNumber = 1
ChangeState(self, self.RackSalvoReloadState)
else
ChangeState(self, self.IdleState)
end
end
end
end,

-- Set a bool so we won't fire if the target reticle is moved
Expand Down Expand Up @@ -1169,9 +1199,8 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
if notExclusive then
unit:SetBusy(false)
end
self.ReloadEndTime = GetGameTick() + MATH_IRound(bp.RackSalvoReloadTime * 10)

WaitSeconds(bp.RackSalvoReloadTime)
self.ReloadEndTime = nil

self:WaitForAndDestroyManips()

Expand All @@ -1196,6 +1225,13 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
end,

OnLostTarget = function(self)
-- Override default OnLostTarget to prevent bypassing reload time by switching to idle state immediately
local unit = self.unit
if unit then
unit:OnLostTarget(self)
end

Weapon.OnLostTarget(self)
end,
},

Expand Down