Removed RenderUnit

Used this opportunity to unhardcode several sandworm-related sequences.
This commit is contained in:
reaperrr
2015-06-23 21:49:57 +02:00
parent 76aaafe37c
commit 2be06e610a
8 changed files with 54 additions and 69 deletions

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.D2k.Activities
readonly Target target;
readonly Sandworm sandworm;
readonly WeaponInfo weapon;
readonly RenderUnit renderUnit;
readonly WithSpriteBody withSpriteBody;
readonly RadarPings radarPings;
readonly AttackSwallow swallow;
readonly IPositionable positionable;
@@ -44,11 +44,11 @@ namespace OpenRA.Mods.D2k.Activities
sandworm = self.Trait<Sandworm>();
positionable = self.Trait<Mobile>();
swallow = self.Trait<AttackSwallow>();
renderUnit = self.Trait<RenderUnit>();
withSpriteBody = self.Trait<WithSpriteBody>();
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
countdown = swallow.Info.AttackTime;
renderUnit.DefaultAnimation.ReplaceAnim("burrowed");
withSpriteBody.DefaultAnimation.ReplaceAnim(sandworm.Info.BurrowedSequence);
stance = AttackState.Burrowed;
location = target.Actor.Location;
}
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.D2k.Activities
// List because IEnumerable gets evaluated too late.
void PlayAttack(Actor self, WPos attackPosition, List<Player> affectedPlayers)
{
renderUnit.PlayCustomAnim(self, "mouth");
withSpriteBody.PlayCustomAnimation(self, sandworm.Info.MouthSequence);
Sound.Play(swallow.Info.WormAttackSound, self.CenterPosition);
Game.RunAfterDelay(1000, () =>
@@ -142,7 +142,7 @@ namespace OpenRA.Mods.D2k.Activities
self.World.AddFrameEndTask(w => self.Kill(self));
}
else
renderUnit.DefaultAnimation.ReplaceAnim("idle");
withSpriteBody.DefaultAnimation.ReplaceAnim(sandworm.Info.IdleSequence);
return NextActivity;
}
@@ -156,7 +156,7 @@ namespace OpenRA.Mods.D2k.Activities
if (!WormAttack(self))
{
renderUnit.DefaultAnimation.ReplaceAnim("idle");
withSpriteBody.DefaultAnimation.ReplaceAnim(sandworm.Info.IdleSequence);
return NextActivity;
}

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.D2k.Traits
{
class SandwormInfo : WandersInfo, Requires<MobileInfo>, Requires<RenderUnitInfo>, Requires<AttackBaseInfo>
class SandwormInfo : WandersInfo, Requires<MobileInfo>, Requires<WithSpriteBodyInfo>, Requires<AttackBaseInfo>
{
[Desc("Time between rescanning for targets (in ticks).")]
public readonly int TargetRescanInterval = 32;
@@ -30,7 +30,13 @@ namespace OpenRA.Mods.D2k.Traits
public readonly int ChanceToDisappear = 80;
[Desc("Name of the sequence that is used when the actor is idle or moving (not attacking).")]
public readonly string IdleSequence = "idle";
[SequenceReference] public readonly string IdleSequence = "idle";
[Desc("Name of the sequence that is used when the actor is attacking.")]
[SequenceReference] public readonly string MouthSequence = "mouth";
[Desc("Name of the sequence that is used when the actor is burrowed.")]
[SequenceReference] public readonly string BurrowedSequence = "burrowed";
public override object Create(ActorInitializer init) { return new Sandworm(init.Self, this); }
}
@@ -41,7 +47,7 @@ namespace OpenRA.Mods.D2k.Traits
readonly WormManager manager;
readonly Lazy<Mobile> mobile;
readonly Lazy<RenderUnit> renderUnit;
readonly Lazy<WithSpriteBody> withSpriteBody;
readonly Lazy<AttackBase> attackTrait;
public bool IsMovingTowardTarget { get; private set; }
@@ -55,15 +61,15 @@ namespace OpenRA.Mods.D2k.Traits
{
Info = info;
mobile = Exts.Lazy(self.Trait<Mobile>);
renderUnit = Exts.Lazy(self.Trait<RenderUnit>);
withSpriteBody = Exts.Lazy(self.Trait<WithSpriteBody>);
attackTrait = Exts.Lazy(self.Trait<AttackBase>);
manager = self.World.WorldActor.Trait<WormManager>();
}
public override void OnBecomingIdle(Actor self)
{
if (renderUnit.Value.DefaultAnimation.CurrentSequence.Name != Info.IdleSequence)
renderUnit.Value.DefaultAnimation.PlayRepeating("idle");
if (withSpriteBody.Value.DefaultAnimation.CurrentSequence.Name != Info.IdleSequence)
withSpriteBody.Value.DefaultAnimation.PlayRepeating(Info.IdleSequence);
base.OnBecomingIdle(self);
}