Capture changes - Engis now capture from outside. Added classic (legacy) capturable traits.

This commit is contained in:
Curtis Shmyr
2013-06-11 20:44:06 -06:00
parent d898899de7
commit 6a1b37b5b7
12 changed files with 391 additions and 109 deletions

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -9,47 +9,75 @@
#endregion
using System.Linq;
using OpenRA.Mods.RA.Move;
using OpenRA.Traits;
using OpenRA.Effects;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Mods.RA.Activities
{
class CaptureActor : Activity
{
Actor target;
Target target;
public CaptureActor(Actor target) { this.target = target; }
public CaptureActor(Target target) { this.target = target; }
public override Activity Tick(Actor self)
{
if (IsCanceled)
return NextActivity;
if (target == null || !target.IsInWorld || target.IsDead())
return NextActivity;
if (target.Owner == self.Owner)
if (!target.IsValid)
return NextActivity;
var capturesInfo = self.Info.Traits.Get<CapturesInfo>();
var health = target.Trait<Health>();
int damage = health.MaxHP / 4;
var capturable = target.Actor.Trait<Capturable>();
// Need to be next to building, TODO: stop capture when going away
var mobile = self.Trait<Mobile>();
var nearest = target.OccupiesSpace.NearestCellTo(mobile.toCell);
if ((nearest - mobile.toCell).LengthSquared > 2)
return Util.SequenceActivities(new MoveAdjacentTo(Target.FromActor(target)), this);
if (!capturesInfo.Sabotage || (capturesInfo.Sabotage && health.DamageState == DamageState.Heavy))
if (IsCanceled || !self.IsInWorld || self.IsDead())
{
if (!target.Trait<Capturable>().BeginCapture(target, self))
return NextActivity;
if (capturable.CaptureInProgress)
capturable.EndCapture();
return NextActivity;
}
var mobile = self.Trait<Mobile>();
var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.toCell);
if ((nearest - mobile.toCell).LengthSquared > 2)
return Util.SequenceActivities(new MoveAdjacentTo(target), this);
if (!capturable.CaptureInProgress)
capturable.BeginCapture(self);
else
target.InflictDamage(self, damage, null);
{
if (capturable.Captor != self) return NextActivity;
if (capturesInfo != null && capturesInfo.WastedAfterwards)
self.World.AddFrameEndTask(w => self.Destroy());
if (capturable.CaptureProgressTime % 25 == 0)
{
self.World.Add(new FlashTarget(target.Actor)); // TODO: building should flash captor's color
self.World.Add(new FlashTarget(self));
}
if (capturable.CaptureProgressTime == capturable.Info.CaptureCompleteTime * 25)
{
var capturesInfo = self.Info.Traits.Get<CapturesInfo>();
self.World.AddFrameEndTask(w =>
{
var oldOwner = target.Actor.Owner;
target.Actor.ChangeOwner(self.Owner);
foreach (var t in target.Actor.TraitsImplementing<INotifyCapture>())
t.OnCapture(target.Actor, self, oldOwner, self.Owner);
foreach (var t in self.World.ActorsWithTrait<INotifyOtherCaptured>())
t.Trait.OnActorCaptured(t.Actor, target.Actor, self, oldOwner, self.Owner);
capturable.EndCapture();
if (capturesInfo != null && capturesInfo.ConsumeActor)
self.Destroy();
});
}
}
return this;
}
}

View File

@@ -0,0 +1,70 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Traits;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Mods.RA.Activities
{
class LegacyCaptureActor : Activity
{
Target target;
public LegacyCaptureActor(Target target) { this.target = target; }
public override Activity Tick(Actor self)
{
if (IsCanceled)
return NextActivity;
if (!target.IsValid)
return NextActivity;
var b = target.Actor.TraitOrDefault<Building>();
if (b != null && b.Locked)
return NextActivity;
var capturesInfo = self.Info.Traits.Get<LegacyCapturesInfo>();
var capturableInfo = target.Actor.Info.Traits.Get<LegacyCapturableInfo>();
var health = target.Actor.Trait<Health>();
var lowEnoughHealth = health.HP <= capturableInfo.CaptureThreshold * health.MaxHP;
self.World.AddFrameEndTask(w =>
{
if (!capturesInfo.Sabotage || lowEnoughHealth || target.Actor.Owner.NonCombatant)
{
var oldOwner = target.Actor.Owner;
target.Actor.ChangeOwner(self.Owner);
foreach (var t in self.TraitsImplementing<INotifyCapture>())
t.OnCapture(target.Actor, self, oldOwner, self.Owner);
foreach (var t in self.World.ActorsWithTrait<INotifyOtherCaptured>())
t.Trait.OnActorCaptured(t.Actor, target.Actor, self, oldOwner, self.Owner);
if (b != null && b.Locked)
b.Unlock();
}
else
{
int damage = (int)(health.MaxHP * capturesInfo.SabotageHPRemoval);
target.Actor.InflictDamage(self, damage, null);
}
self.Destroy();
});
return this;
}
}
}