cleanup InflictDamage a bit
This commit is contained in:
@@ -77,12 +77,13 @@ namespace OpenRA.Traits
|
|||||||
var oldState = this.DamageState;
|
var oldState = this.DamageState;
|
||||||
|
|
||||||
/* apply the damage modifiers, if we have any. */
|
/* apply the damage modifiers, if we have any. */
|
||||||
var modifier = (float)self.TraitsImplementing<IDamageModifier>().Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
|
var modifier = (float)self.TraitsImplementing<IDamageModifier>()
|
||||||
|
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
|
||||||
.Select(t => t.GetDamageModifier(attacker, warhead)).Product();
|
.Select(t => t.GetDamageModifier(attacker, warhead)).Product();
|
||||||
|
|
||||||
damage = (int)(damage * modifier);
|
damage = (int)(damage * modifier);
|
||||||
|
hp = Exts.Clamp(hp - damage, 0, MaxHP);
|
||||||
|
|
||||||
hp -= damage;
|
|
||||||
var ai = new AttackInfo
|
var ai = new AttackInfo
|
||||||
{
|
{
|
||||||
Attacker = attacker,
|
Attacker = attacker,
|
||||||
@@ -91,8 +92,6 @@ namespace OpenRA.Traits
|
|||||||
PreviousDamageState = oldState,
|
PreviousDamageState = oldState,
|
||||||
DamageStateChanged = this.DamageState != oldState,
|
DamageStateChanged = this.DamageState != oldState,
|
||||||
Warhead = warhead,
|
Warhead = warhead,
|
||||||
PreviousHealth = hp + damage < 0 ? 0 : hp + damage,
|
|
||||||
Health = hp
|
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var nd in self.TraitsImplementing<INotifyDamage>()
|
foreach (var nd in self.TraitsImplementing<INotifyDamage>()
|
||||||
@@ -104,10 +103,8 @@ namespace OpenRA.Traits
|
|||||||
.Concat(attacker.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
|
.Concat(attacker.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
|
||||||
nd.AppliedDamage(attacker, self, ai);
|
nd.AppliedDamage(attacker, self, ai);
|
||||||
|
|
||||||
if (hp <= 0)
|
if (hp == 0)
|
||||||
{
|
{
|
||||||
hp = 0;
|
|
||||||
|
|
||||||
attacker.Owner.Kills++;
|
attacker.Owner.Kills++;
|
||||||
self.Owner.Deaths++;
|
self.Owner.Deaths++;
|
||||||
|
|
||||||
@@ -116,8 +113,6 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
Log.Write("debug", "{0} #{1} killed by {2} #{3}", self.Info.Name, self.ActorID, attacker.Info.Name, attacker.ActorID);
|
Log.Write("debug", "{0} #{1} killed by {2} #{3}", self.Info.Name, self.ActorID, attacker.Info.Name, attacker.ActorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hp > MaxHP) hp = MaxHP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
|
|||||||
@@ -6,15 +6,15 @@
|
|||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
* see COPYING.
|
* see COPYING.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Drawing;
|
using System.Collections.Generic;
|
||||||
using OpenRA.FileFormats;
|
using System.Drawing;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.GameRules;
|
||||||
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
@@ -31,8 +31,6 @@ namespace OpenRA.Traits
|
|||||||
public DamageState DamageState;
|
public DamageState DamageState;
|
||||||
public DamageState PreviousDamageState;
|
public DamageState PreviousDamageState;
|
||||||
public bool DamageStateChanged;
|
public bool DamageStateChanged;
|
||||||
public int PreviousHealth;
|
|
||||||
public int Health;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ITick { void Tick(Actor self); }
|
public interface ITick { void Tick(Actor self); }
|
||||||
|
|||||||
Reference in New Issue
Block a user