Refactored Health usage to IHealth.
This commit is contained in:
@@ -38,6 +38,11 @@ namespace OpenRA.Traits
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DamageType { DamageType() { } }
|
public sealed class DamageType { DamageType() { } }
|
||||||
|
|
||||||
|
public interface IHealthInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
int MaxHP { get; }
|
||||||
|
}
|
||||||
|
|
||||||
public interface IHealth
|
public interface IHealth
|
||||||
{
|
{
|
||||||
DamageState DamageState { get; }
|
DamageState DamageState { get; }
|
||||||
|
|||||||
@@ -188,10 +188,10 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
var sumOfHp = 0;
|
var sumOfHp = 0;
|
||||||
foreach (var a in actors)
|
foreach (var a in actors)
|
||||||
{
|
{
|
||||||
if (a.Info.HasTraitInfo<HealthInfo>())
|
if (a.Info.HasTraitInfo<IHealthInfo>())
|
||||||
{
|
{
|
||||||
sumOfMaxHp += a.Trait<Health>().MaxHP;
|
sumOfMaxHp += a.Trait<IHealth>().MaxHP;
|
||||||
sumOfHp += a.Trait<Health>().HP;
|
sumOfHp += a.Trait<IHealth>().HP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0;
|
return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0;
|
||||||
|
|
||||||
case DecisionMetric.Health:
|
case DecisionMetric.Health:
|
||||||
var health = a.TraitOrDefault<Health>();
|
var health = a.TraitOrDefault<IHealth>();
|
||||||
|
|
||||||
if (health == null)
|
if (health == null)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -193,8 +193,8 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0;
|
return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0;
|
||||||
|
|
||||||
case DecisionMetric.Health:
|
case DecisionMetric.Health:
|
||||||
var healthInfo = fa.Info.TraitInfoOrDefault<HealthInfo>();
|
var healthInfo = fa.Info.TraitInfoOrDefault<IHealthInfo>();
|
||||||
return (healthInfo != null) ? fa.HP * Attractiveness / healthInfo.HP : 0;
|
return (healthInfo != null) ? fa.HP * Attractiveness / healthInfo.MaxHP : 0;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return Attractiveness;
|
return Attractiveness;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
readonly Building building;
|
readonly Building building;
|
||||||
readonly Capturable capturable;
|
readonly Capturable capturable;
|
||||||
readonly Captures[] captures;
|
readonly Captures[] captures;
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
|
|
||||||
public CaptureActor(Actor self, Actor target)
|
public CaptureActor(Actor self, Actor target)
|
||||||
: base(self, target, EnterBehaviour.Dispose)
|
: base(self, target, EnterBehaviour.Dispose)
|
||||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
building = actor.TraitOrDefault<Building>();
|
building = actor.TraitOrDefault<Building>();
|
||||||
captures = self.TraitsImplementing<Captures>().ToArray();
|
captures = self.TraitsImplementing<Captures>().ToArray();
|
||||||
capturable = target.Trait<Capturable>();
|
capturable = target.Trait<Capturable>();
|
||||||
health = actor.Trait<Health>();
|
health = actor.Trait<IHealth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool CanReserve(Actor self)
|
protected override bool CanReserve(Actor self)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class Repair : Activity
|
public class Repair : Activity
|
||||||
{
|
{
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
readonly RepairsUnits[] allRepairsUnits;
|
readonly RepairsUnits[] allRepairsUnits;
|
||||||
readonly Target host;
|
readonly Target host;
|
||||||
readonly WDist closeEnough;
|
readonly WDist closeEnough;
|
||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
this.host = Target.FromActor(host);
|
this.host = Target.FromActor(host);
|
||||||
this.closeEnough = closeEnough;
|
this.closeEnough = closeEnough;
|
||||||
allRepairsUnits = host.TraitsImplementing<RepairsUnits>().ToArray();
|
allRepairsUnits = host.TraitsImplementing<RepairsUnits>().ToArray();
|
||||||
health = self.TraitOrDefault<Health>();
|
health = self.TraitOrDefault<IHealth>();
|
||||||
repairable = self.TraitOrDefault<Repairable>();
|
repairable = self.TraitOrDefault<Repairable>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
class RepairBuilding : Enter
|
class RepairBuilding : Enter
|
||||||
{
|
{
|
||||||
readonly Actor target;
|
readonly Actor target;
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
readonly Stance validStances;
|
readonly Stance validStances;
|
||||||
|
|
||||||
public RepairBuilding(Actor self, Actor target, EnterBehaviour enterBehaviour, Stance validStances)
|
public RepairBuilding(Actor self, Actor target, EnterBehaviour enterBehaviour, Stance validStances)
|
||||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.validStances = validStances;
|
this.validStances = validStances;
|
||||||
health = target.Trait<Health>();
|
health = target.Trait<IHealth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool CanReserve(Actor self)
|
protected override bool CanReserve(Actor self)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
class Sell : Activity
|
class Sell : Activity
|
||||||
{
|
{
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
readonly SellableInfo sellableInfo;
|
readonly SellableInfo sellableInfo;
|
||||||
readonly PlayerResources playerResources;
|
readonly PlayerResources playerResources;
|
||||||
bool showTicks;
|
bool showTicks;
|
||||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
public Sell(Actor self, bool showTicks)
|
public Sell(Actor self, bool showTicks)
|
||||||
{
|
{
|
||||||
this.showTicks = showTicks;
|
this.showTicks = showTicks;
|
||||||
health = self.TraitOrDefault<Health>();
|
health = self.TraitOrDefault<IHealth>();
|
||||||
sellableInfo = self.Info.TraitInfo<SellableInfo>();
|
sellableInfo = self.Info.TraitInfo<SellableInfo>();
|
||||||
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
|
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||||
IsInterruptible = false;
|
IsInterruptible = false;
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (Faction != null)
|
if (Faction != null)
|
||||||
init.Add(new FactionInit(Faction));
|
init.Add(new FactionInit(Faction));
|
||||||
|
|
||||||
var health = self.TraitOrDefault<Health>();
|
var health = self.TraitOrDefault<IHealth>();
|
||||||
if (health != null)
|
if (health != null)
|
||||||
{
|
{
|
||||||
// Cast to long to avoid overflow when multiplying by the health
|
// Cast to long to avoid overflow when multiplying by the health
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
{
|
{
|
||||||
foreach (var actorInfo in rules.Actors)
|
foreach (var actorInfo in rules.Actors)
|
||||||
{
|
{
|
||||||
var health = actorInfo.Value.TraitInfoOrDefault<HealthInfo>();
|
var health = actorInfo.Value.TraitInfoOrDefault<IHealthInfo>();
|
||||||
if (health == null)
|
if (health == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Scripting
|
namespace OpenRA.Mods.Common.Scripting
|
||||||
{
|
{
|
||||||
[ScriptPropertyGroup("General")]
|
[ScriptPropertyGroup("General")]
|
||||||
public class HealthProperties : ScriptActorProperties, Requires<HealthInfo>
|
public class HealthProperties : ScriptActorProperties, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
Health health;
|
IHealth health;
|
||||||
public HealthProperties(ScriptContext context, Actor self)
|
public HealthProperties(ScriptContext context, Actor self)
|
||||||
: base(context, self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Current health of the actor.")]
|
[Desc("Current health of the actor.")]
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Bridge actor that can't be passed underneath.")]
|
[Desc("Bridge actor that can't be passed underneath.")]
|
||||||
class GroundLevelBridgeInfo : ITraitInfo, IRulesetLoaded, Requires<BuildingInfo>, Requires<HealthInfo>
|
class GroundLevelBridgeInfo : ITraitInfo, IRulesetLoaded, Requires<BuildingInfo>, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
public readonly string TerrainType = "Bridge";
|
public readonly string TerrainType = "Bridge";
|
||||||
|
|
||||||
@@ -53,13 +53,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly BridgeLayer bridgeLayer;
|
readonly BridgeLayer bridgeLayer;
|
||||||
readonly IEnumerable<CPos> cells;
|
readonly IEnumerable<CPos> cells;
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
|
|
||||||
public GroundLevelBridge(Actor self, GroundLevelBridgeInfo info)
|
public GroundLevelBridge(Actor self, GroundLevelBridgeInfo info)
|
||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
this.self = self;
|
this.self = self;
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
|
|
||||||
bridgeLayer = self.World.WorldActor.Trait<BridgeLayer>();
|
bridgeLayer = self.World.WorldActor.Trait<BridgeLayer>();
|
||||||
var buildingInfo = self.Info.TraitInfo<BuildingInfo>();
|
var buildingInfo = self.Info.TraitInfo<BuildingInfo>();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Building can be repaired by the repair button.")]
|
[Desc("Building can be repaired by the repair button.")]
|
||||||
public class RepairableBuildingInfo : ConditionalTraitInfo, Requires<HealthInfo>
|
public class RepairableBuildingInfo : ConditionalTraitInfo, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
[Desc("Cost to fully repair the actor as a percent of its value.")]
|
[Desc("Cost to fully repair the actor as a percent of its value.")]
|
||||||
public readonly int RepairPercent = 20;
|
public readonly int RepairPercent = 20;
|
||||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public class RepairableBuilding : ConditionalTrait<RepairableBuildingInfo>, ITick
|
public class RepairableBuilding : ConditionalTrait<RepairableBuildingInfo>, ITick
|
||||||
{
|
{
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
readonly Predicate<Player> isNotActiveAlly;
|
readonly Predicate<Player> isNotActiveAlly;
|
||||||
readonly Stack<int> repairTokens = new Stack<int>();
|
readonly Stack<int> repairTokens = new Stack<int>();
|
||||||
ConditionManager conditionManager;
|
ConditionManager conditionManager;
|
||||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public RepairableBuilding(Actor self, RepairableBuildingInfo info)
|
public RepairableBuilding(Actor self, RepairableBuildingInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
isNotActiveAlly = player => player.WinState != WinState.Undefined || player.Stances[self.Owner] != Stance.Ally;
|
isNotActiveAlly = player => player.WinState != WinState.Undefined || player.Stances[self.Owner] != Stance.Ally;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var health = target.Trait<Health>();
|
var health = target.Trait<IHealth>();
|
||||||
|
|
||||||
// Cast to long to avoid overflow when multiplying by the health
|
// Cast to long to avoid overflow when multiplying by the health
|
||||||
var lowEnoughHealth = health.HP <= (int)(c.Info.CaptureThreshold * (long)health.MaxHP / 100);
|
var lowEnoughHealth = health.HP <= (int)(c.Info.CaptureThreshold * (long)health.MaxHP / 100);
|
||||||
@@ -130,10 +130,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var health = target.Info.TraitInfoOrDefault<HealthInfo>();
|
var health = target.Info.TraitInfoOrDefault<IHealthInfo>();
|
||||||
|
|
||||||
// Cast to long to avoid overflow when multiplying by the health
|
// Cast to long to avoid overflow when multiplying by the health
|
||||||
var lowEnoughHealth = target.HP <= (int)(c.CaptureThreshold * (long)health.HP / 100);
|
var lowEnoughHealth = target.HP <= (int)(c.CaptureThreshold * (long)health.MaxHP / 100);
|
||||||
|
|
||||||
cursor = !capturesInfo.Sabotage || lowEnoughHealth || target.Owner.NonCombatant
|
cursor = !capturesInfo.Sabotage || lowEnoughHealth || target.Owner.NonCombatant
|
||||||
? capturesInfo.EnterCursor : capturesInfo.SabotageCursor;
|
? capturesInfo.EnterCursor : capturesInfo.SabotageCursor;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
static readonly WVec TargetPosVLine = new WVec(128, 0, 0);
|
static readonly WVec TargetPosVLine = new WVec(128, 0, 0);
|
||||||
|
|
||||||
readonly DebugVisualizations debugVis;
|
readonly DebugVisualizations debugVis;
|
||||||
readonly HealthInfo healthInfo;
|
readonly IHealthInfo healthInfo;
|
||||||
readonly Lazy<BodyOrientation> coords;
|
readonly Lazy<BodyOrientation> coords;
|
||||||
|
|
||||||
HitShape[] shapes;
|
HitShape[] shapes;
|
||||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public CombatDebugOverlay(Actor self)
|
public CombatDebugOverlay(Actor self)
|
||||||
{
|
{
|
||||||
healthInfo = self.Info.TraitInfoOrDefault<HealthInfo>();
|
healthInfo = self.Info.TraitInfoOrDefault<IHealthInfo>();
|
||||||
coords = Exts.Lazy(self.Trait<BodyOrientation>);
|
coords = Exts.Lazy(self.Trait<BodyOrientation>);
|
||||||
|
|
||||||
debugVis = self.World.WorldActor.TraitOrDefault<DebugVisualizations>();
|
debugVis = self.World.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (healthInfo == null)
|
if (healthInfo == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var maxHP = healthInfo.HP > 0 ? healthInfo.HP : 1;
|
var maxHP = healthInfo.MaxHP > 0 ? healthInfo.MaxHP : 1;
|
||||||
var damageText = "{0} ({1}%)".F(-e.Damage.Value, e.Damage.Value * 100 / maxHP);
|
var damageText = "{0} ({1}%)".F(-e.Damage.Value, e.Damage.Value * 100 / maxHP);
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, damageText, 30)));
|
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, damageText, 30)));
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Applies a condition to the actor at specified damage states.")]
|
[Desc("Applies a condition to the actor at specified damage states.")]
|
||||||
public class GrantConditionOnDamageStateInfo : ITraitInfo, Requires<HealthInfo>
|
public class GrantConditionOnDamageStateInfo : ITraitInfo, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
[FieldLoader.Require]
|
[FieldLoader.Require]
|
||||||
[GrantedConditionReference]
|
[GrantedConditionReference]
|
||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class GrantConditionOnDamageState : INotifyDamageStateChanged, INotifyCreated
|
public class GrantConditionOnDamageState : INotifyDamageStateChanged, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly GrantConditionOnDamageStateInfo info;
|
readonly GrantConditionOnDamageStateInfo info;
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
|
|
||||||
ConditionManager conditionManager;
|
ConditionManager conditionManager;
|
||||||
int conditionToken = ConditionManager.InvalidConditionToken;
|
int conditionToken = ConditionManager.InvalidConditionToken;
|
||||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public GrantConditionOnDamageState(Actor self, GrantConditionOnDamageStateInfo info)
|
public GrantConditionOnDamageState(Actor self, GrantConditionOnDamageStateInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public override void Activate(Actor collector)
|
public override void Activate(Actor collector)
|
||||||
{
|
{
|
||||||
foreach (var healable in collector.World.ActorsWithTrait<Health>().Where(tp => tp.Actor.Owner == collector.Owner))
|
foreach (var healable in collector.World.ActorsWithTrait<IHealth>().Where(tp => tp.Actor.Owner == collector.Owner))
|
||||||
if (!healable.Trait.IsDead)
|
if (!healable.Trait.IsDead)
|
||||||
healable.Trait.InflictDamage(healable.Actor, healable.Actor, new Damage(-(healable.Trait.MaxHP - healable.Trait.HP)), true);
|
healable.Trait.InflictDamage(healable.Actor, healable.Actor, new Damage(-(healable.Trait.MaxHP - healable.Trait.HP)), true);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("This actor receives damage from the given weapon when on the specified terrain type.")]
|
[Desc("This actor receives damage from the given weapon when on the specified terrain type.")]
|
||||||
class DamagedByTerrainInfo : ConditionalTraitInfo, Requires<HealthInfo>
|
class DamagedByTerrainInfo : ConditionalTraitInfo, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
[Desc("Amount of damage received per DamageInterval ticks.")]
|
[Desc("Amount of damage received per DamageInterval ticks.")]
|
||||||
[FieldLoader.Require] public readonly int Damage = 0;
|
[FieldLoader.Require] public readonly int Damage = 0;
|
||||||
@@ -41,14 +41,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
class DamagedByTerrain : ConditionalTrait<DamagedByTerrainInfo>, ITick, ISync, INotifyAddedToWorld
|
class DamagedByTerrain : ConditionalTrait<DamagedByTerrainInfo>, ITick, ISync, INotifyAddedToWorld
|
||||||
{
|
{
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
|
|
||||||
[Sync] int damageTicks;
|
[Sync] int damageTicks;
|
||||||
[Sync] int damageThreshold;
|
[Sync] int damageThreshold;
|
||||||
|
|
||||||
public DamagedByTerrain(Actor self, DamagedByTerrainInfo info) : base(info)
|
public DamagedByTerrain(Actor self, DamagedByTerrainInfo info) : base(info)
|
||||||
{
|
{
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public enum DamageSource { Self, Killer }
|
public enum DamageSource { Self, Killer }
|
||||||
|
|
||||||
[Desc("This actor explodes when killed.")]
|
[Desc("This actor explodes when killed.")]
|
||||||
public class ExplodesInfo : ConditionalTraitInfo, Requires<HealthInfo>
|
public class ExplodesInfo : ConditionalTraitInfo, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
[WeaponReference, FieldLoader.Require, Desc("Default weapon to use for explosion if ammo/payload is loaded.")]
|
[WeaponReference, FieldLoader.Require, Desc("Default weapon to use for explosion if ammo/payload is loaded.")]
|
||||||
public readonly string Weapon = null;
|
public readonly string Weapon = null;
|
||||||
@@ -81,13 +81,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public class Explodes : ConditionalTrait<ExplodesInfo>, INotifyKilled, INotifyDamage, INotifyCreated
|
public class Explodes : ConditionalTrait<ExplodesInfo>, INotifyKilled, INotifyDamage, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
BuildingInfo buildingInfo;
|
BuildingInfo buildingInfo;
|
||||||
|
|
||||||
public Explodes(ExplodesInfo info, Actor self)
|
public Explodes(ExplodesInfo info, Actor self)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("This actor triggers an explosion on itself when transitioning to a specific damage state.")]
|
[Desc("This actor triggers an explosion on itself when transitioning to a specific damage state.")]
|
||||||
public class ExplosionOnDamageTransitionInfo : ITraitInfo, IRulesetLoaded, Requires<HealthInfo>
|
public class ExplosionOnDamageTransitionInfo : ITraitInfo, IRulesetLoaded, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
[WeaponReference, FieldLoader.Require, Desc("Weapon to use for explosion.")]
|
[WeaponReference, FieldLoader.Require, Desc("Weapon to use for explosion.")]
|
||||||
public readonly string Weapon = null;
|
public readonly string Weapon = null;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
public class HealthInfo : ITraitInfo, UsesInit<HealthInit>, IRulesetLoaded
|
public class HealthInfo : IHealthInfo, UsesInit<HealthInit>, IRulesetLoaded
|
||||||
{
|
{
|
||||||
[Desc("HitPoints")]
|
[Desc("HitPoints")]
|
||||||
public readonly int HP = 0;
|
public readonly int HP = 0;
|
||||||
@@ -30,6 +30,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!ai.HasTraitInfo<HitShapeInfo>())
|
if (!ai.HasTraitInfo<HitShapeInfo>())
|
||||||
throw new YamlException("Actors with Health need at least one HitShape trait!");
|
throw new YamlException("Actors with Health need at least one HitShape trait!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int IHealthInfo.MaxHP { get { return HP; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Health : IHealth, ISync, ITick, INotifyCreated, INotifyOwnerChanged
|
public class Health : IHealth, ISync, ITick, INotifyCreated, INotifyOwnerChanged
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (conditionManager != null && !string.IsNullOrEmpty(Info.GrantsCondition))
|
if (conditionManager != null && !string.IsNullOrEmpty(Info.GrantsCondition))
|
||||||
conditionManager.GrantCondition(self, Info.GrantsCondition);
|
conditionManager.GrantCondition(self, Info.GrantsCondition);
|
||||||
|
|
||||||
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
if (Info.RemoveInstead || !self.Info.HasTraitInfo<IHealthInfo>())
|
||||||
self.Dispose();
|
self.Dispose();
|
||||||
else
|
else
|
||||||
self.Kill(self, Info.DamageTypes);
|
self.Kill(self, Info.DamageTypes);
|
||||||
|
|||||||
@@ -14,20 +14,20 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Scale power amount with the current health.")]
|
[Desc("Scale power amount with the current health.")]
|
||||||
public class ScalePowerWithHealthInfo : ITraitInfo, Requires<PowerInfo>, Requires<HealthInfo>
|
public class ScalePowerWithHealthInfo : ITraitInfo, Requires<PowerInfo>, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
public object Create(ActorInitializer init) { return new ScalePowerWithHealth(init.Self); }
|
public object Create(ActorInitializer init) { return new ScalePowerWithHealth(init.Self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ScalePowerWithHealth : IPowerModifier, INotifyDamage, INotifyOwnerChanged
|
public class ScalePowerWithHealth : IPowerModifier, INotifyDamage, INotifyOwnerChanged
|
||||||
{
|
{
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
PowerManager power;
|
PowerManager power;
|
||||||
|
|
||||||
public ScalePowerWithHealth(Actor self)
|
public ScalePowerWithHealth(Actor self)
|
||||||
{
|
{
|
||||||
power = self.Owner.PlayerActor.Trait<PowerManager>();
|
power = self.Owner.PlayerActor.Trait<PowerManager>();
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int IPowerModifier.GetPowerModifier()
|
int IPowerModifier.GetPowerModifier()
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("This actor can be sent to a structure for repairs.")]
|
[Desc("This actor can be sent to a structure for repairs.")]
|
||||||
class RepairableInfo : ITraitInfo, Requires<HealthInfo>, Requires<IMoveInfo>
|
class RepairableInfo : ITraitInfo, Requires<IHealthInfo>, Requires<IMoveInfo>
|
||||||
{
|
{
|
||||||
public readonly HashSet<string> RepairBuildings = new HashSet<string> { "fix" };
|
public readonly HashSet<string> RepairBuildings = new HashSet<string> { "fix" };
|
||||||
|
|
||||||
@@ -35,14 +35,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
class Repairable : IIssueOrder, IResolveOrder, IOrderVoice
|
class Repairable : IIssueOrder, IResolveOrder, IOrderVoice
|
||||||
{
|
{
|
||||||
public readonly RepairableInfo Info;
|
public readonly RepairableInfo Info;
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
readonly IMove movement;
|
readonly IMove movement;
|
||||||
readonly AmmoPool[] ammoPools;
|
readonly AmmoPool[] ammoPools;
|
||||||
|
|
||||||
public Repairable(Actor self, RepairableInfo info)
|
public Repairable(Actor self, RepairableInfo info)
|
||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
movement = self.Trait<IMove>();
|
movement = self.Trait<IMove>();
|
||||||
ammoPools = self.TraitsImplementing<AmmoPool>().ToArray();
|
ammoPools = self.TraitsImplementing<AmmoPool>().ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
class RepairableNearInfo : ITraitInfo, Requires<HealthInfo>, Requires<IMoveInfo>
|
class RepairableNearInfo : ITraitInfo, Requires<IHealthInfo>, Requires<IMoveInfo>
|
||||||
{
|
{
|
||||||
[ActorReference] public readonly HashSet<string> Buildings = new HashSet<string> { "spen", "syrd" };
|
[ActorReference] public readonly HashSet<string> Buildings = new HashSet<string> { "spen", "syrd" };
|
||||||
public readonly WDist CloseEnough = WDist.FromCells(4);
|
public readonly WDist CloseEnough = WDist.FromCells(4);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Attach this to actors which should be able to regenerate their health points.")]
|
[Desc("Attach this to actors which should be able to regenerate their health points.")]
|
||||||
class SelfHealingInfo : ConditionalTraitInfo, Requires<HealthInfo>
|
class SelfHealingInfo : ConditionalTraitInfo, Requires<IHealthInfo>
|
||||||
{
|
{
|
||||||
[Desc("Absolute amount of health points added in each step.")]
|
[Desc("Absolute amount of health points added in each step.")]
|
||||||
public readonly int Step = 5;
|
public readonly int Step = 5;
|
||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
class SelfHealing : ConditionalTrait<SelfHealingInfo>, ITick, INotifyDamage
|
class SelfHealing : ConditionalTrait<SelfHealingInfo>, ITick, INotifyDamage
|
||||||
{
|
{
|
||||||
readonly Health health;
|
readonly IHealth health;
|
||||||
|
|
||||||
[Sync] int ticks;
|
[Sync] int ticks;
|
||||||
[Sync] int damageTicks;
|
[Sync] int damageTicks;
|
||||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public SelfHealing(Actor self, SelfHealingInfo info)
|
public SelfHealing(Actor self, SelfHealingInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
health = self.Trait<Health>();
|
health = self.Trait<IHealth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class Sellable : ConditionalTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo
|
public class Sellable : ConditionalTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly Lazy<Health> health;
|
readonly Lazy<IHealth> health;
|
||||||
readonly SellableInfo info;
|
readonly SellableInfo info;
|
||||||
|
|
||||||
public Sellable(Actor self, SellableInfo info)
|
public Sellable(Actor self, SellableInfo info)
|
||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
|
health = Exts.Lazy(() => self.TraitOrDefault<IHealth>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();
|
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();
|
||||||
var cost = csv != null ? csv.Value : (valued != null ? valued.Cost : 0);
|
var cost = csv != null ? csv.Value : (valued != null ? valued.Cost : 0);
|
||||||
|
|
||||||
var health = self.TraitOrDefault<Health>();
|
var health = self.TraitOrDefault<IHealth>();
|
||||||
var dudesValue = Info.ValuePercent * cost / 100;
|
var dudesValue = Info.ValuePercent * cost / 100;
|
||||||
if (health != null)
|
if (health != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Warheads
|
|||||||
if (!AffectsParent && victim == firedBy)
|
if (!AffectsParent && victim == firedBy)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!victim.Info.HasTraitInfo<HealthInfo>())
|
if (!victim.Info.HasTraitInfo<IHealthInfo>())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If the impact position is within any HitShape, we have a direct hit
|
// If the impact position is within any HitShape, we have a direct hit
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ namespace OpenRA.Mods.Common.Warheads
|
|||||||
if (!IsValidAgainst(victim, firedBy))
|
if (!IsValidAgainst(victim, firedBy))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var healthInfo = victim.Info.TraitInfoOrDefault<HealthInfo>();
|
var healthInfo = victim.Info.TraitInfoOrDefault<IHealthInfo>();
|
||||||
if (healthInfo == null)
|
if (healthInfo == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Damage is measured as a percentage of the target health
|
// Damage is measured as a percentage of the target health
|
||||||
var damage = Util.ApplyPercentageModifiers(healthInfo.HP, damageModifiers.Append(Damage, DamageVersus(victim)));
|
var damage = Util.ApplyPercentageModifiers(healthInfo.MaxHP, damageModifiers.Append(Damage, DamageVersus(victim)));
|
||||||
victim.InflictDamage(firedBy, new Damage(damage, DamageTypes));
|
victim.InflictDamage(firedBy, new Damage(damage, DamageTypes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Warheads
|
|||||||
foreach (var victim in hitActors)
|
foreach (var victim in hitActors)
|
||||||
{
|
{
|
||||||
// Cannot be damaged without a Health trait
|
// Cannot be damaged without a Health trait
|
||||||
var healthInfo = victim.Info.TraitInfoOrDefault<HealthInfo>();
|
var healthInfo = victim.Info.TraitInfoOrDefault<IHealthInfo>();
|
||||||
if (healthInfo == null)
|
if (healthInfo == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user