From ca512196daa35ede9c47ea3d74c42d073c6af430 Mon Sep 17 00:00:00 2001 From: dnqbob Date: Sun, 26 May 2024 08:47:23 +0800 Subject: [PATCH] BackFireShrapnel: fix crash on beam weapon and code simplify --- .../Warheads/BackFireShrapnelWarhead.cs | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/OpenRA.Mods.AS/Warheads/BackFireShrapnelWarhead.cs b/OpenRA.Mods.AS/Warheads/BackFireShrapnelWarhead.cs index 8d4aa9dbdc03..0c599ead92a0 100644 --- a/OpenRA.Mods.AS/Warheads/BackFireShrapnelWarhead.cs +++ b/OpenRA.Mods.AS/Warheads/BackFireShrapnelWarhead.cs @@ -9,9 +9,7 @@ #endregion using System; -using System.Linq; using OpenRA.GameRules; -using OpenRA.Mods.Common.Traits; using OpenRA.Traits; namespace OpenRA.Mods.AS.Warheads @@ -24,8 +22,6 @@ public class BackFireShrapnelWarhead : WarheadAS, IRulesetLoaded [Desc("Has to be defined in weapons.yaml as well.")] public readonly string Weapon = null; - public readonly string WeaponName = "primary"; - WeaponInfo weapon; public void RulesetLoaded(Ruleset rules, WeaponInfo info) @@ -44,33 +40,28 @@ public override void DoImpact(in Target target, WarheadArgs args) var shrapnelTarget = Target.Invalid; shrapnelTarget = Target.FromActor(firedBy); + var sourcepos = target.CenterPosition; + var facing = (shrapnelTarget.CenterPosition - sourcepos).Yaw; if (shrapnelTarget.Type != TargetType.Invalid) { var pargs = new ProjectileArgs { Weapon = weapon, - Facing = (shrapnelTarget.CenterPosition - target.CenterPosition).Yaw, + Facing = facing, + CurrentMuzzleFacing = () => facing, - DamageModifiers = !firedBy.IsDead - ? firedBy.TraitsImplementing() - .Select(a => a.GetFirepowerModifier(WeaponName)).ToArray() - : Array.Empty(), + DamageModifiers = args.DamageModifiers, - InaccuracyModifiers = !firedBy.IsDead - ? firedBy.TraitsImplementing() - .Select(a => a.GetInaccuracyModifier()).ToArray() - : Array.Empty(), + InaccuracyModifiers = Array.Empty(), - RangeModifiers = !firedBy.IsDead - ? firedBy.TraitsImplementing() - .Select(a => a.GetRangeModifier()).ToArray() - : Array.Empty(), + RangeModifiers = Array.Empty(), - Source = target.CenterPosition, + Source = sourcepos, + CurrentSource = () => sourcepos, SourceActor = firedBy, GuidedTarget = shrapnelTarget, - PassiveTarget = shrapnelTarget.CenterPosition + PassiveTarget = shrapnelTarget.CenterPosition, }; if (pargs.Weapon.Projectile != null) @@ -81,9 +72,8 @@ public override void DoImpact(in Target target, WarheadArgs args) if (pargs.Weapon.Report != null && pargs.Weapon.Report.Length > 0) { - var pos = target.CenterPosition; - if (pargs.Weapon.AudibleThroughFog || (!firedBy.World.ShroudObscures(pos) && !firedBy.World.FogObscures(pos))) - Game.Sound.Play(SoundType.World, pargs.Weapon.Report, firedBy.World, pos, null, pargs.Weapon.SoundVolume); + if (pargs.Weapon.AudibleThroughFog || (!firedBy.World.ShroudObscures(sourcepos) && !firedBy.World.FogObscures(sourcepos))) + Game.Sound.Play(SoundType.World, pargs.Weapon.Report, firedBy.World, sourcepos, null, pargs.Weapon.SoundVolume); } } }