categorize traits better
This commit is contained in:
15
OpenRa.Game/Traits/Modifiers/BelowUnits.cs
Normal file
15
OpenRa.Game/Traits/Modifiers/BelowUnits.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class BelowUnitsInfo : StatelessTraitInfo<BelowUnits> { }
|
||||
|
||||
class BelowUnits : IRenderModifier
|
||||
{
|
||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||
{
|
||||
return r.Select(a => a.WithZOffset(-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
63
OpenRa.Game/Traits/Modifiers/Cloak.cs
Normal file
63
OpenRa.Game/Traits/Modifiers/Cloak.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRa.Graphics;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class CloakInfo : ITraitInfo
|
||||
{
|
||||
public readonly float CloakDelay = 1.2f; // Seconds
|
||||
public readonly string CloakSound = "ironcur9.aud";
|
||||
public readonly string UncloakSound = "ironcur9.aud";
|
||||
public object Create(Actor self) { return new Cloak(self); }
|
||||
}
|
||||
|
||||
class Cloak : IRenderModifier, INotifyAttack, ITick
|
||||
{
|
||||
[Sync]
|
||||
int remainingUncloakTime = 2; /* setup for initial cloak */
|
||||
|
||||
Actor self;
|
||||
public Cloak(Actor self)
|
||||
{
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
public void Attacking(Actor self)
|
||||
{
|
||||
if (remainingUncloakTime <= 0)
|
||||
OnCloak();
|
||||
|
||||
remainingUncloakTime = (int)(self.Info.Traits.Get<CloakInfo>().CloakDelay * 25);
|
||||
}
|
||||
|
||||
public IEnumerable<Renderable>
|
||||
ModifyRender(Actor self, IEnumerable<Renderable> rs)
|
||||
{
|
||||
if (remainingUncloakTime > 0)
|
||||
return rs;
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
return rs.Select(a => a.WithPalette("shadow"));
|
||||
else
|
||||
return new Renderable[] { };
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (remainingUncloakTime > 0)
|
||||
if (--remainingUncloakTime <= 0)
|
||||
OnUncloak();
|
||||
}
|
||||
|
||||
void OnCloak()
|
||||
{
|
||||
Sound.Play(self.Info.Traits.Get<CloakInfo>().CloakSound);
|
||||
}
|
||||
|
||||
void OnUncloak()
|
||||
{
|
||||
Sound.Play(self.Info.Traits.Get<CloakInfo>().UncloakSound);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
OpenRa.Game/Traits/Modifiers/InvisibleToOthers.cs
Normal file
15
OpenRa.Game/Traits/Modifiers/InvisibleToOthers.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class InvisibleToOthersInfo : StatelessTraitInfo<InvisibleToOthers> { }
|
||||
|
||||
class InvisibleToOthers : IRenderModifier
|
||||
{
|
||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||
{
|
||||
return self.World.LocalPlayer == self.Owner
|
||||
? r : new Renderable[] { };
|
||||
}
|
||||
}
|
||||
}
|
||||
24
OpenRa.Game/Traits/Modifiers/WithShadow.cs
Normal file
24
OpenRa.Game/Traits/Modifiers/WithShadow.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Graphics;
|
||||
|
||||
namespace OpenRa.Traits
|
||||
{
|
||||
class WithShadowInfo : StatelessTraitInfo<WithShadow> {}
|
||||
|
||||
class WithShadow : IRenderModifier
|
||||
{
|
||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||
{
|
||||
var unit = self.traits.Get<Unit>();
|
||||
|
||||
var shadowSprites = r.Select(a => a.WithPalette("shadow"));
|
||||
var flyingSprites = (unit.Altitude <= 0) ? r
|
||||
: r.Select(a => a.WithPos(a.Pos - new float2(0, unit.Altitude)).WithZOffset(3));
|
||||
|
||||
return shadowSprites.Concat(flyingSprites);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user