Add INotifyAiming interface
And trigger notifications from Attack* traits.
This commit is contained in:
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public override abstract object Create(ActorInitializer init);
|
public override abstract object Create(ActorInitializer init);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class AttackBase : PausableConditionalTrait<AttackBaseInfo>, INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, ISync
|
public abstract class AttackBase : PausableConditionalTrait<AttackBaseInfo>, INotifyCreated, ITick, IIssueOrder, IResolveOrder, IOrderVoice, ISync
|
||||||
{
|
{
|
||||||
readonly string attackOrderName = "Attack";
|
readonly string attackOrderName = "Attack";
|
||||||
readonly string forceAttackOrderName = "ForceAttack";
|
readonly string forceAttackOrderName = "ForceAttack";
|
||||||
@@ -50,10 +50,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
protected IFacing facing;
|
protected IFacing facing;
|
||||||
protected Building building;
|
protected Building building;
|
||||||
protected IPositionable positionable;
|
protected IPositionable positionable;
|
||||||
|
protected INotifyAiming[] notifyAiming;
|
||||||
protected Func<IEnumerable<Armament>> getArmaments;
|
protected Func<IEnumerable<Armament>> getArmaments;
|
||||||
|
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
|
||||||
|
bool wasAiming;
|
||||||
|
|
||||||
public AttackBase(Actor self, AttackBaseInfo info)
|
public AttackBase(Actor self, AttackBaseInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
@@ -65,12 +68,30 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
facing = self.TraitOrDefault<IFacing>();
|
facing = self.TraitOrDefault<IFacing>();
|
||||||
building = self.TraitOrDefault<Building>();
|
building = self.TraitOrDefault<Building>();
|
||||||
positionable = self.TraitOrDefault<IPositionable>();
|
positionable = self.TraitOrDefault<IPositionable>();
|
||||||
|
notifyAiming = self.TraitsImplementing<INotifyAiming>().ToArray();
|
||||||
|
|
||||||
getArmaments = InitializeGetArmaments(self);
|
getArmaments = InitializeGetArmaments(self);
|
||||||
|
|
||||||
base.Created(self);
|
base.Created(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ITick.Tick(Actor self)
|
||||||
|
{
|
||||||
|
Tick(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (!wasAiming && IsAiming)
|
||||||
|
foreach (var n in notifyAiming)
|
||||||
|
n.StartedAiming(self, this);
|
||||||
|
else if (wasAiming && !IsAiming)
|
||||||
|
foreach (var n in notifyAiming)
|
||||||
|
n.StoppedAiming(self, this);
|
||||||
|
|
||||||
|
wasAiming = IsAiming;
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual Func<IEnumerable<Armament>> InitializeGetArmaments(Actor self)
|
protected virtual Func<IEnumerable<Armament>> InitializeGetArmaments(Actor self)
|
||||||
{
|
{
|
||||||
var armaments = self.TraitsImplementing<Armament>()
|
var armaments = self.TraitsImplementing<Armament>()
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public override object Create(ActorInitializer init) { return new AttackCharges(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new AttackCharges(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AttackCharges : AttackOmni, INotifyCreated, ITick, INotifyAttack, INotifySold
|
public class AttackCharges : AttackOmni, INotifyAttack, INotifySold
|
||||||
{
|
{
|
||||||
readonly AttackChargesInfo info;
|
readonly AttackChargesInfo info;
|
||||||
ConditionManager conditionManager;
|
ConditionManager conditionManager;
|
||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
base.Created(self);
|
base.Created(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
protected override void Tick(Actor self)
|
||||||
{
|
{
|
||||||
// Stop charging when we lose our target
|
// Stop charging when we lose our target
|
||||||
charging &= self.CurrentActivity is SetTarget;
|
charging &= self.CurrentActivity is SetTarget;
|
||||||
@@ -70,6 +70,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (ChargeLevel == 0 && conditionManager != null && chargingToken != ConditionManager.InvalidConditionToken)
|
if (ChargeLevel == 0 && conditionManager != null && chargingToken != ConditionManager.InvalidConditionToken)
|
||||||
chargingToken = conditionManager.RevokeCondition(self, chargingToken);
|
chargingToken = conditionManager.RevokeCondition(self, chargingToken);
|
||||||
|
|
||||||
|
base.Tick(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool CanAttack(Actor self, Target target)
|
protected override bool CanAttack(Actor self, Target target)
|
||||||
|
|||||||
@@ -22,19 +22,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public override object Create(ActorInitializer init) { return new AttackFollow(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new AttackFollow(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AttackFollow : AttackBase, ITick, INotifyOwnerChanged
|
public class AttackFollow : AttackBase, INotifyOwnerChanged
|
||||||
{
|
{
|
||||||
public Target Target { get; protected set; }
|
public Target Target { get; protected set; }
|
||||||
|
|
||||||
public AttackFollow(Actor self, AttackFollowInfo info)
|
public AttackFollow(Actor self, AttackFollowInfo info)
|
||||||
: base(self, info) { }
|
: base(self, info) { }
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
protected override void Tick(Actor self)
|
||||||
{
|
|
||||||
Tick(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Tick(Actor self)
|
|
||||||
{
|
{
|
||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled)
|
||||||
{
|
{
|
||||||
@@ -44,6 +39,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
DoAttack(self, Target);
|
DoAttack(self, Target);
|
||||||
IsAiming = Target.IsValidFor(self);
|
IsAiming = Target.IsValidFor(self);
|
||||||
|
|
||||||
|
base.Tick(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||||
|
|||||||
@@ -88,6 +88,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
void WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses);
|
void WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
public interface INotifyAiming
|
||||||
|
{
|
||||||
|
void StartedAiming(Actor self, AttackBase attack);
|
||||||
|
void StoppedAiming(Actor self, AttackBase attack);
|
||||||
|
}
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface INotifyAttack
|
public interface INotifyAttack
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user