Make demolition conditional
This commit is contained in:
committed by
Matthias Mailänder
parent
eb897d755e
commit
043e6f662f
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.Mods.Common.Activities;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Scripting;
|
using OpenRA.Scripting;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -19,12 +19,12 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
[ScriptPropertyGroup("Combat")]
|
[ScriptPropertyGroup("Combat")]
|
||||||
public class DemolitionProperties : ScriptActorProperties, Requires<IMoveInfo>, Requires<DemolitionInfo>
|
public class DemolitionProperties : ScriptActorProperties, Requires<IMoveInfo>, Requires<DemolitionInfo>
|
||||||
{
|
{
|
||||||
readonly DemolitionInfo info;
|
readonly Demolition[] demolitions;
|
||||||
|
|
||||||
public DemolitionProperties(ScriptContext context, Actor self)
|
public DemolitionProperties(ScriptContext context, Actor self)
|
||||||
: base(context, self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
info = Self.Info.TraitInfo<DemolitionInfo>();
|
demolitions = Self.TraitsImplementing<Demolition>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
@@ -32,8 +32,9 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
public void Demolish(Actor target)
|
public void Demolish(Actor target)
|
||||||
{
|
{
|
||||||
// NB: Scripted actions get no visible targetlines.
|
// NB: Scripted actions get no visible targetlines.
|
||||||
Self.QueueActivity(new Demolish(Self, Target.FromActor(target), info.EnterBehaviour, info.DetonationDelay,
|
var demolition = demolitions.FirstEnabledTraitOrDefault();
|
||||||
info.Flashes, info.FlashesDelay, info.FlashInterval, info.DamageTypes, null));
|
if (demolition != null)
|
||||||
|
Self.QueueActivity(demolition.GetDemolishActivity(Self, Target.FromActor(target), null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
class DemolitionInfo : TraitInfo
|
class DemolitionInfo : ConditionalTraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Delay to demolish the target once the explosive device is planted. " +
|
[Desc("Delay to demolish the target once the explosive device is planted. " +
|
||||||
"Measured in game ticks. Default is 1.8 seconds.")]
|
"Measured in game ticks. Default is 1.8 seconds.")]
|
||||||
@@ -57,23 +57,25 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public override object Create(ActorInitializer init) { return new Demolition(this); }
|
public override object Create(ActorInitializer init) { return new Demolition(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Demolition : IIssueOrder, IResolveOrder, IOrderVoice
|
class Demolition : ConditionalTrait<DemolitionInfo>, IIssueOrder, IResolveOrder, IOrderVoice
|
||||||
{
|
{
|
||||||
readonly DemolitionInfo info;
|
|
||||||
|
|
||||||
public Demolition(DemolitionInfo info)
|
public Demolition(DemolitionInfo info)
|
||||||
{
|
: base(info) { }
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<IOrderTargeter> Orders
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
{
|
{
|
||||||
get { yield return new DemolitionOrderTargeter(info); }
|
get
|
||||||
|
{
|
||||||
|
if (IsTraitDisabled)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
yield return new DemolitionOrderTargeter(Info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
|
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
|
||||||
{
|
{
|
||||||
if (order.OrderID != "C4")
|
if (order.OrderID != "C4" || IsTraitDisabled)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new Order(order.OrderID, self, target, queued);
|
return new Order(order.OrderID, self, target, queued);
|
||||||
@@ -81,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString != "C4")
|
if (order.OrderString != "C4" || IsTraitDisabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (order.Target.Type == TargetType.Actor)
|
if (order.Target.Type == TargetType.Actor)
|
||||||
@@ -91,15 +93,22 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.QueueActivity(order.Queued, new Demolish(self, order.Target, info.EnterBehaviour, info.DetonationDelay,
|
self.QueueActivity(order.Queued, GetDemolishActivity(self, order.Target, Info.TargetLineColor));
|
||||||
info.Flashes, info.FlashesDelay, info.FlashInterval, info.DamageTypes, info.TargetLineColor));
|
|
||||||
|
|
||||||
self.ShowTargetLines();
|
self.ShowTargetLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Demolish GetDemolishActivity(Actor self, Target target, Color? targetLineColor)
|
||||||
|
{
|
||||||
|
return new Demolish(self, target, Info.EnterBehaviour, Info.DetonationDelay, Info.Flashes,
|
||||||
|
Info.FlashesDelay, Info.FlashInterval, Info.DamageTypes, targetLineColor);
|
||||||
|
}
|
||||||
|
|
||||||
public string VoicePhraseForOrder(Actor self, Order order)
|
public string VoicePhraseForOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
return order.OrderString == "C4" ? info.Voice : null;
|
if (IsTraitDisabled)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return order.OrderString == "C4" ? Info.Voice : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DemolitionOrderTargeter : UnitOrderTargeter
|
class DemolitionOrderTargeter : UnitOrderTargeter
|
||||||
|
|||||||
Reference in New Issue
Block a user