Add an INotifyKilled interface, which is what most things that used INotifyDamaged actually cared about.

This commit is contained in:
Paul Chote
2011-04-16 10:58:35 +12:00
parent d9fc84b55e
commit 1c2574f4f4
22 changed files with 135 additions and 185 deletions

View File

@@ -14,27 +14,24 @@ namespace OpenRA.Mods.RA
{
class GivesExperienceInfo : TraitInfo<GivesExperience> { public readonly int Experience = -1; }
class GivesExperience : INotifyDamage
class GivesExperience : INotifyKilled
{
public void Damaged(Actor self, AttackInfo e)
public void Killed(Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
{
// Prevent TK from giving exp
if (e.Attacker == null || e.Attacker.Destroyed || e.Attacker.Owner.Stances[ self.Owner ] == Stance.Ally )
return;
// Prevent TK from giving exp
if (e.Attacker == null || e.Attacker.Destroyed || e.Attacker.Owner.Stances[ self.Owner ] == Stance.Ally )
return;
var info = self.Info.Traits.Get<GivesExperienceInfo>();
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
var info = self.Info.Traits.Get<GivesExperienceInfo>();
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
var exp = info.Experience >= 0
? info.Experience
: valued != null ? valued.Cost : 0;
var exp = info.Experience >= 0
? info.Experience
: valued != null ? valued.Cost : 0;
var killer = e.Attacker.TraitOrDefault<GainsExperience>();
if (killer != null)
killer.GiveExperience(exp);
}
var killer = e.Attacker.TraitOrDefault<GainsExperience>();
if (killer != null)
killer.GiveExperience(exp);
}
}
}