Don't crash on multiple Attack* traits

This is important for actors that use upgrades to switch between attack types.
This commit is contained in:
Pavel Penev
2016-02-13 18:46:42 +02:00
parent 65942ecfbf
commit 07947179cd
2 changed files with 48 additions and 17 deletions

View File

@@ -27,17 +27,15 @@ namespace OpenRA.Mods.Common.Traits
public class CombatDebugOverlay : IPostRender, INotifyDamage, INotifyCreated
{
readonly DeveloperMode devMode;
readonly HealthInfo healthInfo;
readonly Lazy<BodyOrientation> coords;
IBlocksProjectiles[] allBlockers;
Lazy<AttackBase> attack;
Lazy<BodyOrientation> coords;
public CombatDebugOverlay(Actor self)
{
healthInfo = self.Info.TraitInfoOrDefault<HealthInfo>();
attack = Exts.Lazy(() => self.TraitOrDefault<AttackBase>());
coords = Exts.Lazy(() => self.Trait<BodyOrientation>());
coords = Exts.Lazy(self.Trait<BodyOrientation>);
var localPlayer = self.World.LocalPlayer;
devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;
@@ -71,14 +69,16 @@ namespace OpenRA.Mods.Common.Traits
TargetLineRenderable.DrawTargetMarker(wr, hc, hb);
}
// No armaments to draw
if (attack.Value == null)
return;
foreach (var attack in self.TraitsImplementing<AttackBase>().Where(x => !x.IsTraitDisabled))
DrawArmaments(self, attack, wr, wcr, iz);
}
void DrawArmaments(Actor self, AttackBase attack, WorldRenderer wr, RgbaColorRenderer wcr, float iz)
{
var c = Color.White;
// Fire ports on garrisonable structures
var garrison = attack.Value as AttackGarrisoned;
var garrison = attack as AttackGarrisoned;
if (garrison != null)
{
var bodyOrientation = coords.Value.QuantizeOrientation(self, self.Orientation);
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Traits
return;
}
foreach (var a in attack.Value.Armaments)
foreach (var a in attack.Armaments)
{
foreach (var b in a.Barrels)
{