additional checks to avoid giving dead actors a rank sign

closes #4134
This commit is contained in:
Matthias Mailänder
2013-11-17 15:20:13 +01:00
parent 5d3987dee3
commit 8a13cd6c6a
4 changed files with 16 additions and 13 deletions

View File

@@ -170,7 +170,8 @@ namespace OpenRA.Traits
{ {
public static bool IsDead(this Actor self) public static bool IsDead(this Actor self)
{ {
if (self.Destroyed) return true; if (self.Destroyed)
return true;
var health = self.TraitOrDefault<Health>(); var health = self.TraitOrDefault<Health>();
return (health == null) ? false : health.IsDead; return (health == null) ? false : health.IsDead;
@@ -178,7 +179,8 @@ namespace OpenRA.Traits
public static DamageState GetDamageState(this Actor self) public static DamageState GetDamageState(this Actor self)
{ {
if (self.Destroyed) return DamageState.Dead; if (self.Destroyed)
return DamageState.Dead;
var health = self.TraitOrDefault<Health>(); var health = self.TraitOrDefault<Health>();
return (health == null) ? DamageState.Undamaged : health.DamageState; return (health == null) ? DamageState.Undamaged : health.DamageState;

View File

@@ -181,7 +181,7 @@ namespace OpenRA
public void Add(IEffect b) { effects.Add(b); } public void Add(IEffect b) { effects.Add(b); }
public void Remove(IEffect b) { effects.Remove(b); } public void Remove(IEffect b) { effects.Remove(b); }
public void AddFrameEndTask( Action<World> a ) { frameEndActions.Enqueue( a ); } public void AddFrameEndTask(Action<World> a) { frameEndActions.Enqueue(a); }
public event Action<Actor> ActorAdded = _ => { }; public event Action<Actor> ActorAdded = _ => { };
public event Action<Actor> ActorRemoved = _ => { }; public event Action<Actor> ActorRemoved = _ => { };

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Effects namespace OpenRA.Mods.RA.Effects
{ {
@@ -18,20 +19,19 @@ namespace OpenRA.Mods.RA.Effects
{ {
Actor self; Actor self;
Animation anim = new Animation("rank"); Animation anim = new Animation("rank");
GainsExperience xp;
public Rank(Actor self) public Rank(Actor self)
{ {
this.self = self; this.self = self;
xp = self.Trait<GainsExperience>(); var xp = self.Trait<GainsExperience>();
anim.PlayRepeating("rank"); anim.PlayRepeating("rank");
anim.PlayFetchIndex("rank", () => xp.Level - 1); anim.PlayFetchIndex("rank", () => xp.Level == 0 ? 0 : xp.Level - 1);
} }
public void Tick(World world) public void Tick(World world)
{ {
if (self.Destroyed) if (self.IsDead())
world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
else else
anim.Tick(); anim.Tick();
@@ -42,10 +42,7 @@ namespace OpenRA.Mods.RA.Effects
if (!self.IsInWorld) if (!self.IsInWorld)
yield break; yield break;
if (self.Destroyed) if (self.IsDead())
yield break;
if (xp.Level < 1)
yield break; yield break;
if (!self.Owner.IsAlliedWith(self.World.RenderPlayer)) if (!self.Owner.IsAlliedWith(self.World.RenderPlayer))

View File

@@ -76,8 +76,12 @@ namespace OpenRA.Mods.RA
Sound.PlayNotification(self.Owner, "Sounds", "LevelUp", self.Owner.Country.Race); Sound.PlayNotification(self.Owner, "Sounds", "LevelUp", self.Owner.Country.Race);
self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup"))); self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup")));
if (Level == 1 && !self.Destroyed) if (Level == 1)
self.World.AddFrameEndTask(w => w.Add(new Rank(self))); self.World.AddFrameEndTask(w =>
{
if (!self.IsDead())
w.Add(new Rank(self));
});
} }
} }