Port Infiltrate to the new Enter activity.
This commit is contained in:
committed by
Oliver Brakmann
parent
e9c3216048
commit
a17608a24e
@@ -9,9 +9,9 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Cnc.Traits;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
@@ -19,34 +19,51 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Activities
|
||||
{
|
||||
class Infiltrate : LegacyEnter
|
||||
class Infiltrate : Enter
|
||||
{
|
||||
readonly Actor target;
|
||||
readonly Infiltrates infiltrates;
|
||||
readonly INotifyInfiltration[] notifiers;
|
||||
Actor enterActor;
|
||||
|
||||
public Infiltrate(Actor self, Actor target, Infiltrates infiltrate)
|
||||
: base(self, target, infiltrate.Info.EnterBehaviour, targetLineColor: Color.Red)
|
||||
public Infiltrate(Actor self, Target target, Infiltrates infiltrates)
|
||||
: base(self, target, Color.Red)
|
||||
{
|
||||
this.target = target;
|
||||
infiltrates = infiltrate;
|
||||
this.infiltrates = infiltrates;
|
||||
notifiers = self.TraitsImplementing<INotifyInfiltration>().ToArray();
|
||||
}
|
||||
|
||||
protected override void OnInside(Actor self)
|
||||
protected override void TickInner(Actor self, Target target, bool targetIsDeadOrHiddenActor)
|
||||
{
|
||||
if (target.IsDead)
|
||||
return;
|
||||
if (infiltrates.IsTraitDisabled)
|
||||
Cancel(self, true);
|
||||
}
|
||||
|
||||
var stance = self.Owner.Stances[target.Owner];
|
||||
if (!infiltrates.Info.ValidStances.HasStance(stance))
|
||||
protected override bool TryStartEnter(Actor self, Actor targetActor)
|
||||
{
|
||||
// Make sure we can still demolish the target before entering
|
||||
// (but not before, because this may stop the actor in the middle of nowhere)
|
||||
if (!infiltrates.CanInfiltrateTarget(self, Target.FromActor(targetActor)))
|
||||
{
|
||||
Cancel(self, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
enterActor = targetActor;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnEnterComplete(Actor self, Actor targetActor)
|
||||
{
|
||||
// Make sure the target hasn't changed while entering
|
||||
// OnEnterComplete is only called if targetActor is alive
|
||||
if (targetActor != enterActor || !infiltrates.CanInfiltrateTarget(self, Target.FromActor(targetActor)))
|
||||
return;
|
||||
|
||||
foreach (var ini in notifiers)
|
||||
ini.Infiltrating(self);
|
||||
|
||||
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())
|
||||
t.Infiltrated(target, self, infiltrates.Info.Types);
|
||||
foreach (var t in targetActor.TraitsImplementing<INotifyInfiltrated>())
|
||||
t.Infiltrated(targetActor, self, infiltrates.Info.Types);
|
||||
|
||||
var exp = self.Owner.PlayerActor.TraitOrDefault<PlayerExperience>();
|
||||
if (exp != null)
|
||||
@@ -55,14 +72,11 @@ namespace OpenRA.Mods.Cnc.Activities
|
||||
if (!string.IsNullOrEmpty(infiltrates.Info.Notification))
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
|
||||
infiltrates.Info.Notification, self.Owner.Faction.InternalName);
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (infiltrates.IsTraitDisabled)
|
||||
Cancel(self);
|
||||
|
||||
return base.Tick(self);
|
||||
if (infiltrates.Info.EnterBehaviour == EnterBehaviour.Dispose)
|
||||
self.Dispose();
|
||||
else if (infiltrates.Info.EnterBehaviour == EnterBehaviour.Suicide)
|
||||
self.Kill(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user