Implement enter behaviour for Infiltrates plus other cleanups.
This commit is contained in:
@@ -18,19 +18,17 @@ namespace OpenRA.Mods.RA.Activities
|
||||
class Infiltrate : Enter
|
||||
{
|
||||
readonly Actor target;
|
||||
|
||||
readonly Stance validStances;
|
||||
readonly Cloak cloak;
|
||||
readonly string notification;
|
||||
|
||||
readonly Infiltrates infiltrates;
|
||||
|
||||
public Infiltrate(Actor self, Actor target)
|
||||
: base(self, target, EnterBehaviour.Dispose)
|
||||
public Infiltrate(Actor self, Actor target, EnterBehaviour enterBehaviour, Stance validStances, string notification)
|
||||
: base(self, target, enterBehaviour)
|
||||
{
|
||||
this.target = target;
|
||||
|
||||
this.validStances = validStances;
|
||||
this.notification = notification;
|
||||
cloak = self.TraitOrDefault<Cloak>();
|
||||
|
||||
infiltrates = self.TraitOrDefault<Infiltrates>();
|
||||
}
|
||||
|
||||
protected override void OnInside(Actor self)
|
||||
@@ -39,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return;
|
||||
|
||||
var stance = self.Owner.Stances[target.Owner];
|
||||
if (!infiltrates.Info.ValidStances.HasStance(stance))
|
||||
if (!validStances.HasStance(stance))
|
||||
return;
|
||||
|
||||
if (cloak != null && cloak.Info.UncloakOnInfiltrate)
|
||||
@@ -48,10 +46,9 @@ namespace OpenRA.Mods.RA.Activities
|
||||
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())
|
||||
t.Infiltrated(target, self);
|
||||
|
||||
self.Dispose();
|
||||
|
||||
if (target.Info.HasTraitInfo<BuildingInfo>())
|
||||
Game.Sound.PlayToPlayer(self.Owner, "bldginf1.aud");
|
||||
if (!string.IsNullOrEmpty(notification))
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
|
||||
notification, self.Owner.Faction.InternalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,29 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Ability")]
|
||||
public class InfiltrateProperties : ScriptActorProperties
|
||||
public class InfiltrateProperties : ScriptActorProperties, Requires<InfiltratesInfo>
|
||||
{
|
||||
readonly InfiltratesInfo info;
|
||||
|
||||
public InfiltrateProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{ }
|
||||
{
|
||||
info = Self.Info.TraitInfo<InfiltratesInfo>();
|
||||
}
|
||||
|
||||
[Desc("Infiltrate the target actor.")]
|
||||
public void Infiltrate(Actor target)
|
||||
{
|
||||
Self.QueueActivity(new Infiltrate(Self, target));
|
||||
Self.QueueActivity(new Infiltrate(Self, target, info.EnterBehaviour, info.ValidStances, info.Notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
@@ -27,21 +28,28 @@ namespace OpenRA.Mods.RA.Traits
|
||||
[Desc("What diplomatic stances can be infiltrated by this actor.")]
|
||||
public readonly Stance ValidStances = Stance.Neutral | Stance.Enemy;
|
||||
|
||||
[Desc("Behaviour when entering the structure.",
|
||||
"Possible values are Exit, Suicide, Dispose.")]
|
||||
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Dispose;
|
||||
|
||||
[Desc("Notification to play when a building is infiltrated.")]
|
||||
public readonly string Notification = "BuildingInfiltrated";
|
||||
|
||||
public object Create(ActorInitializer init) { return new Infiltrates(this); }
|
||||
}
|
||||
|
||||
class Infiltrates : IIssueOrder, IResolveOrder, IOrderVoice
|
||||
{
|
||||
public readonly InfiltratesInfo Info;
|
||||
readonly InfiltratesInfo info;
|
||||
|
||||
public Infiltrates(InfiltratesInfo info)
|
||||
{
|
||||
Info = info;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get { yield return new InfiltrationOrderTargeter(Info); }
|
||||
get { yield return new InfiltrationOrderTargeter(info); }
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
@@ -79,13 +87,13 @@ namespace OpenRA.Mods.RA.Traits
|
||||
else
|
||||
targetTypes = order.TargetActor.GetEnabledTargetTypes();
|
||||
|
||||
return Info.Types.Overlaps(targetTypes);
|
||||
return info.Types.Overlaps(targetTypes);
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return order.OrderString == "Infiltrate" && IsValidOrder(self, order)
|
||||
? Info.Voice : null;
|
||||
? info.Voice : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
@@ -95,14 +103,14 @@ namespace OpenRA.Mods.RA.Traits
|
||||
|
||||
var target = self.ResolveFrozenActorOrder(order, Color.Red);
|
||||
if (target.Type != TargetType.Actor
|
||||
|| !Info.Types.Overlaps(target.Actor.GetAllTargetTypes()))
|
||||
|| !info.Types.Overlaps(target.Actor.GetAllTargetTypes()))
|
||||
return;
|
||||
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(target, Color.Red);
|
||||
self.QueueActivity(new Infiltrate(self, target.Actor));
|
||||
self.QueueActivity(new Infiltrate(self, target.Actor, info.EnterBehaviour, info.ValidStances, info.Notification));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user