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