Make Captures Upgradeable

This commit is contained in:
Mustafa Alperen Seki
2017-03-22 19:03:12 +02:00
committed by abcdefg30
parent 287290bbdf
commit f7983692ae
3 changed files with 40 additions and 18 deletions

View File

@@ -9,6 +9,8 @@
*/
#endregion
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
@@ -19,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Actor actor;
readonly Building building;
readonly Capturable capturable;
readonly CapturesInfo capturesInfo;
readonly Captures[] captures;
readonly Health health;
public CaptureActor(Actor self, Actor target)
@@ -27,7 +29,7 @@ namespace OpenRA.Mods.Common.Activities
{
actor = target;
building = actor.TraitOrDefault<Building>();
capturesInfo = self.Info.TraitInfo<CapturesInfo>();
captures = self.TraitsImplementing<Captures>().ToArray();
capturable = target.Trait<Capturable>();
health = actor.Trait<Health>();
}
@@ -50,9 +52,12 @@ namespace OpenRA.Mods.Common.Activities
if (building != null && building.Locked)
building.Unlock();
if (actor.IsDead || capturable.BeingCaptured)
var activeCaptures = captures.FirstOrDefault(c => !c.IsTraitDisabled);
if (actor.IsDead || capturable.BeingCaptured || activeCaptures == null)
return;
var capturesInfo = activeCaptures.Info;
var lowEnoughHealth = health.HP <= capturable.Info.CaptureThreshold * health.MaxHP / 100;
if (!capturesInfo.Sabotage || lowEnoughHealth || actor.Owner.NonCombatant)
{
@@ -82,5 +87,13 @@ namespace OpenRA.Mods.Common.Activities
self.Dispose();
});
}
public override Activity Tick(Actor self)
{
if (captures.All(c => c.IsTraitDisabled))
Cancel(self);
return base.Tick(self);
}
}
}