Cleaned up DamageWarhead

Reordered methods and fixed access modifiers. Also removed unused using statements from warheads.
This commit is contained in:
Pavel Penev
2020-05-23 23:20:42 +03:00
committed by abcdefg30
parent 7a0e55a02a
commit f0578a75f4
12 changed files with 23 additions and 34 deletions

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Effects;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits;

View File

@@ -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<Armor>()
.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<Armor>()
.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);
}
}

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;

View File

@@ -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

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;

View File

@@ -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<DebugVisualizations>();
if (debugVis != null && debugVis.CombatGeometry)

View File

@@ -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;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Primitives;
using OpenRA.Traits;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Mods.D2k.Traits;