Make Transforms a PausableConditionalTrait.
This commit is contained in:
committed by
Paul Chote
parent
3d4095cffd
commit
1a947907d3
@@ -17,7 +17,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Actor becomes a specified actor type when this trait is triggered.")]
|
[Desc("Actor becomes a specified actor type when this trait is triggered.")]
|
||||||
public class TransformsInfo : ITraitInfo
|
public class TransformsInfo : PausableConditionalTraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Actor to transform into."), ActorReference, FieldLoader.Require]
|
[Desc("Actor to transform into."), ActorReference, FieldLoader.Require]
|
||||||
public readonly string IntoActor = null;
|
public readonly string IntoActor = null;
|
||||||
@@ -48,42 +48,48 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
[VoiceReference] public readonly string Voice = "Action";
|
[VoiceReference] public readonly string Voice = "Action";
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new Transforms(init, this); }
|
public override object Create(ActorInitializer init) { return new Transforms(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Transforms : IIssueOrder, IResolveOrder, IOrderVoice, IIssueDeployOrder
|
public class Transforms : PausableConditionalTrait<TransformsInfo>, IIssueOrder, IResolveOrder, IOrderVoice, IIssueDeployOrder
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly TransformsInfo info;
|
|
||||||
readonly BuildingInfo buildingInfo;
|
readonly BuildingInfo buildingInfo;
|
||||||
readonly string faction;
|
readonly string faction;
|
||||||
|
|
||||||
public Transforms(ActorInitializer init, TransformsInfo info)
|
public Transforms(ActorInitializer init, TransformsInfo info)
|
||||||
|
: base(info)
|
||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
this.info = info;
|
|
||||||
buildingInfo = self.World.Map.Rules.Actors[info.IntoActor].TraitInfoOrDefault<BuildingInfo>();
|
buildingInfo = self.World.Map.Rules.Actors[info.IntoActor].TraitInfoOrDefault<BuildingInfo>();
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string VoicePhraseForOrder(Actor self, Order order)
|
public string VoicePhraseForOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
return (order.OrderString == "DeployTransform") ? info.Voice : null;
|
return (order.OrderString == "DeployTransform") ? Info.Voice : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanDeploy()
|
public bool CanDeploy()
|
||||||
{
|
{
|
||||||
|
if (IsTraitPaused || IsTraitDisabled)
|
||||||
|
return false;
|
||||||
|
|
||||||
var building = self.TraitOrDefault<Building>();
|
var building = self.TraitOrDefault<Building>();
|
||||||
if (building != null && building.Locked)
|
if (building != null && building.Locked)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return buildingInfo == null || self.World.CanPlaceBuilding(info.IntoActor, buildingInfo, self.Location + info.Offset, self);
|
return buildingInfo == null || self.World.CanPlaceBuilding(Info.IntoActor, buildingInfo, self.Location + Info.Offset, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IOrderTargeter> Orders
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
{
|
{
|
||||||
get { yield return new DeployOrderTargeter("DeployTransform", 5,
|
get
|
||||||
() => CanDeploy() ? info.DeployCursor : info.DeployBlockedCursor); }
|
{
|
||||||
|
if (!IsTraitDisabled)
|
||||||
|
yield return new DeployOrderTargeter("DeployTransform", 5,
|
||||||
|
() => CanDeploy() ? Info.DeployCursor : Info.DeployBlockedCursor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||||
@@ -105,10 +111,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
// Only play the "Cannot deploy here" audio
|
// Only play the "Cannot deploy here" audio
|
||||||
// for non-queued orders
|
// for non-queued orders
|
||||||
foreach (var s in info.NoTransformSounds)
|
foreach (var s in Info.NoTransformSounds)
|
||||||
Game.Sound.PlayToPlayer(SoundType.World, self.Owner, s);
|
Game.Sound.PlayToPlayer(SoundType.World, self.Owner, s);
|
||||||
|
|
||||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.NoTransformNotification, self.Owner.Faction.InternalName);
|
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Info.NoTransformNotification, self.Owner.Faction.InternalName);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -116,19 +122,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!queued)
|
if (!queued)
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
|
|
||||||
self.QueueActivity(new Transform(self, info.IntoActor)
|
self.QueueActivity(new Transform(self, Info.IntoActor)
|
||||||
{
|
{
|
||||||
Offset = info.Offset,
|
Offset = Info.Offset,
|
||||||
Facing = info.Facing,
|
Facing = Info.Facing,
|
||||||
Sounds = info.TransformSounds,
|
Sounds = Info.TransformSounds,
|
||||||
Notification = info.TransformNotification,
|
Notification = Info.TransformNotification,
|
||||||
Faction = faction
|
Faction = faction
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString == "DeployTransform")
|
if (order.OrderString == "DeployTransform" && !IsTraitPaused && !IsTraitDisabled)
|
||||||
DeployTransform(order.Queued);
|
DeployTransform(order.Queued);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user