Rewrite Leap activity to be more robust.
The dog will now always leap to the target subcell (even if the target dies or moves), and will kill whatever happens to be in the target cell when it lands.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.RA.Move;
|
using OpenRA.Mods.RA.Move;
|
||||||
using OpenRA.Mods.RA.Render;
|
using OpenRA.Mods.RA.Render;
|
||||||
@@ -17,16 +18,29 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
{
|
{
|
||||||
class Leap : Activity
|
class Leap : Activity
|
||||||
{
|
{
|
||||||
Target target;
|
Mobile mobile;
|
||||||
PPos initialLocation;
|
|
||||||
|
PPos from;
|
||||||
|
PPos to;
|
||||||
|
|
||||||
int moveFraction;
|
int moveFraction;
|
||||||
const int delay = 6;
|
const int length = 6;
|
||||||
|
|
||||||
public Leap(Actor self, Target target)
|
public Leap(Actor self, Target target)
|
||||||
{
|
{
|
||||||
this.target = target;
|
if (!target.IsActor)
|
||||||
initialLocation = (PPos) self.Trait<Mobile>().PxPosition;
|
throw new InvalidOperationException("Leap requires a target actor");
|
||||||
|
|
||||||
|
var targetMobile = target.Actor.TraitOrDefault<Mobile>();
|
||||||
|
if (targetMobile == null)
|
||||||
|
throw new InvalidOperationException("Leap requires a target actor with the Mobile trait");
|
||||||
|
|
||||||
|
mobile = self.Trait<Mobile>();
|
||||||
|
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, targetMobile.fromCell, targetMobile.fromSubCell);
|
||||||
|
mobile.IsMoving = true;
|
||||||
|
|
||||||
|
from = self.CenterLocation;
|
||||||
|
to = Util.CenterOfCell(targetMobile.fromCell) + MobileInfo.SubCellOffsets[targetMobile.fromSubCell];
|
||||||
|
|
||||||
self.Trait<RenderInfantry>().Attacking(self, target);
|
self.Trait<RenderInfantry>().Attacking(self, target);
|
||||||
Sound.Play("dogg5p.aud", self.CenterLocation);
|
Sound.Play("dogg5p.aud", self.CenterLocation);
|
||||||
@@ -34,23 +48,18 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if( moveFraction == 0 && IsCanceled ) return NextActivity;
|
if (moveFraction == 0 && IsCanceled)
|
||||||
if (!target.IsValid) return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
self.Trait<AttackLeap>().IsLeaping = true;
|
mobile.AdjustPxPosition(self, PPos.Lerp(from, to, moveFraction++, length - 1));
|
||||||
var mobile = self.Trait<Mobile>();
|
if (moveFraction >= length)
|
||||||
++moveFraction;
|
|
||||||
|
|
||||||
mobile.PxPosition = PPos.Lerp(initialLocation, target.PxPosition, moveFraction, delay);
|
|
||||||
|
|
||||||
if (moveFraction >= delay)
|
|
||||||
{
|
{
|
||||||
self.TraitsImplementing<IMove>().FirstOrDefault()
|
mobile.SetLocation(mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell);
|
||||||
.SetPosition(self, target.CenterLocation.ToCPos());
|
mobile.FinishedMoving(self);
|
||||||
|
mobile.IsMoving = false;
|
||||||
|
|
||||||
if (target.IsActor)
|
// Kill whatever else is in our new cell
|
||||||
target.Actor.Kill(self);
|
self.World.ActorMap.GetUnitsAt(mobile.toCell, mobile.toSubCell).Except(new []{self}).Do(a => a.Kill(self));
|
||||||
self.Trait<AttackLeap>().IsLeaping = false;
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
class AttackLeap : AttackFrontal, ISync
|
class AttackLeap : AttackFrontal, ISync
|
||||||
{
|
{
|
||||||
[Sync] internal bool IsLeaping;
|
|
||||||
|
|
||||||
public AttackLeap(Actor self, AttackLeapInfo info)
|
public AttackLeap(Actor self, AttackLeapInfo info)
|
||||||
: base(self, info) {}
|
: base(self, info) {}
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,9 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub)
|
public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub)
|
||||||
{
|
{
|
||||||
if (fromCell == from && toCell == to) return;
|
if (fromCell == from && toCell == to && fromSubCell == fromSub && toSubCell == toSub)
|
||||||
|
return;
|
||||||
|
|
||||||
RemoveInfluence();
|
RemoveInfluence();
|
||||||
__fromCell = from;
|
__fromCell = from;
|
||||||
__toCell = to;
|
__toCell = to;
|
||||||
|
|||||||
Reference in New Issue
Block a user