Update power on damage
This commit is contained in:
@@ -45,6 +45,8 @@ namespace OpenRA.Traits
|
|||||||
[Sync]
|
[Sync]
|
||||||
readonly int2 topLeft;
|
readonly int2 topLeft;
|
||||||
|
|
||||||
|
readonly PowerManager PlayerPower;
|
||||||
|
|
||||||
public bool Disabled
|
public bool Disabled
|
||||||
{
|
{
|
||||||
get { return self.TraitsImplementing<IDisable>().Any(t => t.Disabled); }
|
get { return self.TraitsImplementing<IDisable>().Any(t => t.Disabled); }
|
||||||
@@ -57,6 +59,8 @@ namespace OpenRA.Traits
|
|||||||
Info = self.Info.Traits.Get<BuildingInfo>();
|
Info = self.Info.Traits.Get<BuildingInfo>();
|
||||||
self.CenterLocation = Game.CellSize
|
self.CenterLocation = Game.CellSize
|
||||||
* ((float2)topLeft + .5f * (float2)Info.Dimensions);
|
* ((float2)topLeft + .5f * (float2)Info.Dimensions);
|
||||||
|
|
||||||
|
PlayerPower = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetPowerUsage()
|
public int GetPowerUsage()
|
||||||
@@ -78,6 +82,19 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
public void Damaged(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
|
// Power plants lose power with damage
|
||||||
|
if (Info.Power > 0)
|
||||||
|
{
|
||||||
|
var modifier = self
|
||||||
|
.TraitsImplementing<IPowerModifier>()
|
||||||
|
.Select(t => t.GetPowerModifier())
|
||||||
|
.Product();
|
||||||
|
|
||||||
|
var health = self.TraitOrDefault<Health>();
|
||||||
|
var healthFraction = (health == null) ? 1f : health.HPFraction;
|
||||||
|
PlayerPower.UpdateActor(self, (int)(modifier * healthFraction * Info.Power));
|
||||||
|
}
|
||||||
|
|
||||||
if (e.DamageState == DamageState.Dead)
|
if (e.DamageState == DamageState.Dead)
|
||||||
{
|
{
|
||||||
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(10, self.CenterLocation, 1);
|
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(10, self.CenterLocation, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user