Reimplement demolition lock using conditions.

This commit is contained in:
Paul Chote
2018-10-27 17:09:30 +00:00
committed by abcdefg30
parent 0901a7d9de
commit 18b84750aa
25 changed files with 239 additions and 71 deletions

View File

@@ -10,6 +10,7 @@
#endregion
using System.Linq;
using OpenRA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -43,14 +44,26 @@ namespace OpenRA.Mods.Common.Traits
Bridge.Do((b, d) => b.Repair(repairer, d, () => repairDirections--));
}
public void Demolish(Actor self, Actor saboteur)
{
Bridge.Do((b, d) => b.Demolish(saboteur, d));
}
public bool IsValidTarget(Actor self, Actor saboteur)
bool IDemolishable.IsValidTarget(Actor self, Actor saboteur)
{
return BridgeDamageState != DamageState.Dead;
}
void IDemolishable.Demolish(Actor self, Actor saboteur, int delay)
{
// TODO: Handle using ITick
self.World.Add(new DelayedAction(delay, () =>
{
if (self.IsDead)
return;
var modifiers = self.TraitsImplementing<IDamageModifier>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
.Select(t => t.GetDamageModifier(self, null));
if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
Bridge.Do((b, d) => b.Demolish(saboteur, d));
}));
}
}
}