From f0578a75f4f80e36fd55eddc552112b8fb95a056 Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Sat, 23 May 2020 23:20:42 +0300 Subject: [PATCH] Cleaned up DamageWarhead Reordered methods and fixed access modifiers. Also removed unused using statements from warheads. --- .../Warheads/ChangeOwnerWarhead.cs | 1 - .../Warheads/CreateEffectWarhead.cs | 1 - .../Warheads/CreateResourceWarhead.cs | 1 - OpenRA.Mods.Common/Warheads/DamageWarhead.cs | 42 +++++++++---------- .../Warheads/DestroyResourceWarhead.cs | 1 - .../Warheads/FireClusterWarhead.cs | 1 - .../Warheads/GrantExternalConditionWarhead.cs | 1 - .../Warheads/HealthPercentageDamageWarhead.cs | 1 - .../Warheads/SpreadDamageWarhead.cs | 3 +- .../Warheads/TargetDamageWarhead.cs | 3 +- OpenRA.Mods.Common/Warheads/Warhead.cs | 1 - .../Warheads/DamagesConcreteWarhead.cs | 1 - 12 files changed, 23 insertions(+), 34 deletions(-) diff --git a/OpenRA.Mods.Common/Warheads/ChangeOwnerWarhead.cs b/OpenRA.Mods.Common/Warheads/ChangeOwnerWarhead.cs index b94a767a36..3d0acbd1ee 100644 --- a/OpenRA.Mods.Common/Warheads/ChangeOwnerWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/ChangeOwnerWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; diff --git a/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs b/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs index 5b9666ee3f..50b11b49ac 100644 --- a/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; using OpenRA.Mods.Common.Effects; diff --git a/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs b/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs index e44a33f649..aa73775823 100644 --- a/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; diff --git a/OpenRA.Mods.Common/Warheads/DamageWarhead.cs b/OpenRA.Mods.Common/Warheads/DamageWarhead.cs index 70065bc5a1..7a74a733cc 100644 --- a/OpenRA.Mods.Common/Warheads/DamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/DamageWarhead.cs @@ -38,26 +38,6 @@ namespace OpenRA.Mods.Common.Warheads return base.IsValidAgainst(victim, firedBy); } - public virtual int DamageVersus(Actor victim, HitShape shape, WarheadArgs args) - { - // If no Versus values are defined, DamageVersus would return 100 anyway, so we might as well do that early. - if (Versus.Count == 0) - return 100; - - var armor = victim.TraitsImplementing() - .Where(a => !a.IsTraitDisabled && a.Info.Type != null && Versus.ContainsKey(a.Info.Type) && - (shape.Info.ArmorTypes.IsEmpty || shape.Info.ArmorTypes.Contains(a.Info.Type))) - .Select(a => Versus[a.Info.Type]); - - return Util.ApplyPercentageModifiers(100, armor); - } - - protected virtual void InflictDamage(Actor victim, Actor firedBy, HitShape shape, WarheadArgs args) - { - var damage = Util.ApplyPercentageModifiers(Damage, args.DamageModifiers.Append(DamageVersus(victim, shape, args))); - victim.InflictDamage(firedBy, new Damage(damage, DamageTypes)); - } - public override void DoImpact(Target target, WarheadArgs args) { var firedBy = args.SourceActor; @@ -83,6 +63,26 @@ namespace OpenRA.Mods.Common.Warheads DoImpact(target.CenterPosition, firedBy, args); } - public abstract void DoImpact(WPos pos, Actor firedBy, WarheadArgs args); + protected virtual int DamageVersus(Actor victim, HitShape shape, WarheadArgs args) + { + // If no Versus values are defined, DamageVersus would return 100 anyway, so we might as well do that early. + if (Versus.Count == 0) + return 100; + + var armor = victim.TraitsImplementing() + .Where(a => !a.IsTraitDisabled && a.Info.Type != null && Versus.ContainsKey(a.Info.Type) && + (shape.Info.ArmorTypes.IsEmpty || shape.Info.ArmorTypes.Contains(a.Info.Type))) + .Select(a => Versus[a.Info.Type]); + + return Util.ApplyPercentageModifiers(100, armor); + } + + protected virtual void InflictDamage(Actor victim, Actor firedBy, HitShape shape, WarheadArgs args) + { + var damage = Util.ApplyPercentageModifiers(Damage, args.DamageModifiers.Append(DamageVersus(victim, shape, args))); + victim.InflictDamage(firedBy, new Damage(damage, DamageTypes)); + } + + protected abstract void DoImpact(WPos pos, Actor firedBy, WarheadArgs args); } } diff --git a/OpenRA.Mods.Common/Warheads/DestroyResourceWarhead.cs b/OpenRA.Mods.Common/Warheads/DestroyResourceWarhead.cs index 9856cff5a0..84372fbf12 100644 --- a/OpenRA.Mods.Common/Warheads/DestroyResourceWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/DestroyResourceWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; diff --git a/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs b/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs index 8af98cdab1..137a6c348f 100644 --- a/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs @@ -12,7 +12,6 @@ using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; -using OpenRA.Mods.Common.Traits; using OpenRA.Traits; namespace OpenRA.Mods.Common.Warheads diff --git a/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs b/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs index e26dd23f73..381f80cdda 100644 --- a/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; diff --git a/OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs b/OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs index ee54e4ff05..cf293dab55 100644 --- a/OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; diff --git a/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs b/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs index 9424a29ec8..697d6ca13c 100644 --- a/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; @@ -44,7 +43,7 @@ namespace OpenRA.Mods.Common.Warheads Range = Exts.MakeArray(Falloff.Length, i => i * Spread); } - public override void DoImpact(WPos pos, Actor firedBy, WarheadArgs args) + protected override void DoImpact(WPos pos, Actor firedBy, WarheadArgs args) { var debugVis = firedBy.World.WorldActor.TraitOrDefault(); if (debugVis != null && debugVis.CombatGeometry) diff --git a/OpenRA.Mods.Common/Warheads/TargetDamageWarhead.cs b/OpenRA.Mods.Common/Warheads/TargetDamageWarhead.cs index 81e2d2fd68..fc6b26f575 100644 --- a/OpenRA.Mods.Common/Warheads/TargetDamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/TargetDamageWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; @@ -23,7 +22,7 @@ namespace OpenRA.Mods.Common.Warheads [Desc("Damage will be applied to actors in this area. A value of zero means only targeted actor will be damaged.")] public readonly WDist Spread = WDist.Zero; - public override void DoImpact(WPos pos, Actor firedBy, WarheadArgs args) + protected override void DoImpact(WPos pos, Actor firedBy, WarheadArgs args) { if (Spread == WDist.Zero) return; diff --git a/OpenRA.Mods.Common/Warheads/Warhead.cs b/OpenRA.Mods.Common/Warheads/Warhead.cs index b991d33610..804bded878 100644 --- a/OpenRA.Mods.Common/Warheads/Warhead.cs +++ b/OpenRA.Mods.Common/Warheads/Warhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using OpenRA.GameRules; using OpenRA.Primitives; using OpenRA.Traits; diff --git a/OpenRA.Mods.D2k/Warheads/DamagesConcreteWarhead.cs b/OpenRA.Mods.D2k/Warheads/DamagesConcreteWarhead.cs index 098dc061f6..d9e5cd36b5 100644 --- a/OpenRA.Mods.D2k/Warheads/DamagesConcreteWarhead.cs +++ b/OpenRA.Mods.D2k/Warheads/DamagesConcreteWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using OpenRA.GameRules; using OpenRA.Mods.Common.Warheads; using OpenRA.Mods.D2k.Traits;