Demolishable, trivial optimization.
This commit is contained in:
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public override object Create(ActorInitializer init) { return new Demolishable(this); }
|
public override object Create(ActorInitializer init) { return new Demolishable(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Demolishable : ConditionalTrait<DemolishableInfo>, IDemolishable, ITick
|
public class Demolishable : ConditionalTrait<DemolishableInfo>, IDemolishable, ITick, INotifyOwnerChanged
|
||||||
{
|
{
|
||||||
class DemolishAction
|
class DemolishAction
|
||||||
{
|
{
|
||||||
@@ -48,10 +48,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
readonly List<DemolishAction> actions = new List<DemolishAction>();
|
readonly List<DemolishAction> actions = new List<DemolishAction>();
|
||||||
readonly List<DemolishAction> removeActions = new List<DemolishAction>();
|
readonly List<DemolishAction> removeActions = new List<DemolishAction>();
|
||||||
|
IDamageModifier[] damageModifiers;
|
||||||
|
|
||||||
public Demolishable(DemolishableInfo info)
|
public Demolishable(DemolishableInfo info)
|
||||||
: base(info) { }
|
: base(info) { }
|
||||||
|
|
||||||
|
protected override void Created(Actor self)
|
||||||
|
{
|
||||||
|
damageModifiers = self.TraitsImplementing<IDamageModifier>()
|
||||||
|
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>()).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
|
{
|
||||||
|
damageModifiers = self.TraitsImplementing<IDamageModifier>()
|
||||||
|
.Concat(newOwner.PlayerActor.TraitsImplementing<IDamageModifier>()).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
bool IDemolishable.IsValidTarget(Actor self, Actor saboteur)
|
bool IDemolishable.IsValidTarget(Actor self, Actor saboteur)
|
||||||
{
|
{
|
||||||
return !IsTraitDisabled;
|
return !IsTraitDisabled;
|
||||||
@@ -68,18 +81,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled || actions.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var a in actions)
|
foreach (var a in actions)
|
||||||
{
|
{
|
||||||
if (a.Delay-- <= 0)
|
if (a.Delay-- <= 0)
|
||||||
{
|
{
|
||||||
var modifiers = self.TraitsImplementing<IDamageModifier>()
|
if (Util.ApplyPercentageModifiers(100, damageModifiers.Select(t => t.GetDamageModifier(self, null))) > 0)
|
||||||
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
|
|
||||||
.Select(t => t.GetDamageModifier(self, null));
|
|
||||||
|
|
||||||
if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
|
|
||||||
self.Kill(a.Saboteur, a.DamageTypes);
|
self.Kill(a.Saboteur, a.DamageTypes);
|
||||||
else if (a.Token != Actor.InvalidConditionToken)
|
else if (a.Token != Actor.InvalidConditionToken)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user