Refactor AutoHeal.
This commit is contained in:
@@ -18,48 +18,21 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
class AutoHeal : INotifyIdle
|
class AutoHeal : INotifyIdle
|
||||||
{
|
{
|
||||||
bool NeedsNewTarget(Actor self)
|
public void TickIdle( Actor self )
|
||||||
{
|
{
|
||||||
var attack = self.Trait<AttackBase>();
|
var attack = self.Trait<AttackBase>();
|
||||||
var range = attack.GetMaximumRange();
|
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * attack.GetMaximumRange());
|
||||||
|
|
||||||
if (currentTarget == null || !currentTarget.IsInWorld)
|
var target = inRange
|
||||||
return true; // he's dead.
|
|
||||||
if( !Combat.IsInRange( self.CenterLocation, range, currentTarget ) )
|
|
||||||
return true; // wandered off faster than we could follow
|
|
||||||
|
|
||||||
if (currentTarget.GetDamageState() == DamageState.Undamaged)
|
|
||||||
return true; // fully healed
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Actor ChooseTarget(Actor self, float range)
|
|
||||||
{
|
|
||||||
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
|
|
||||||
var attack = self.Trait<AttackBase>();
|
|
||||||
|
|
||||||
return inRange
|
|
||||||
.Where(a => a != self && self.Owner.Stances[a.Owner] == Stance.Ally)
|
.Where(a => a != self && self.Owner.Stances[a.Owner] == Stance.Ally)
|
||||||
.Where(a => a.IsInWorld && !a.IsDead())
|
.Where(a => a.IsInWorld && !a.IsDead())
|
||||||
.Where(a => a.HasTrait<Health>() && a.GetDamageState() > DamageState.Undamaged)
|
.Where(a => a.HasTrait<Health>() && a.GetDamageState() > DamageState.Undamaged)
|
||||||
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
|
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
|
||||||
.OrderBy(a => (a.CenterLocation - self.CenterLocation).LengthSquared)
|
.OrderBy(a => (a.CenterLocation - self.CenterLocation).LengthSquared)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
}
|
|
||||||
|
if( target != null )
|
||||||
Actor currentTarget;
|
self.QueueActivity(self.Trait<AttackBase>().GetAttackActivity(self, Target.FromActor( target ), false ));
|
||||||
public void TickIdle( Actor self )
|
|
||||||
{
|
|
||||||
var attack = self.Trait<AttackBase>();
|
|
||||||
var range = attack.GetMaximumRange();
|
|
||||||
|
|
||||||
if (NeedsNewTarget(self))
|
|
||||||
{
|
|
||||||
var currentTarget = ChooseTarget(self, range);
|
|
||||||
if( currentTarget != null )
|
|
||||||
self.QueueActivity(self.Trait<AttackBase>().GetAttackActivity(self, Target.FromActor( currentTarget ), false ));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,10 +40,10 @@ namespace OpenRA.Mods.RA
|
|||||||
public void TickIdle( Actor self )
|
public void TickIdle( Actor self )
|
||||||
{
|
{
|
||||||
var attack = self.Trait<AttackBase>();
|
var attack = self.Trait<AttackBase>();
|
||||||
var currentTarget = attack.ScanForTarget(self, null);
|
var target = attack.ScanForTarget(self, null);
|
||||||
if( currentTarget != null )
|
if( target != null )
|
||||||
self.QueueActivity(attack.GetAttackActivity( self,
|
self.QueueActivity(attack.GetAttackActivity( self,
|
||||||
Target.FromActor(currentTarget),
|
Target.FromActor(target),
|
||||||
self.Info.Traits.Get<AutoTargetInfo>().AllowMovement
|
self.Info.Traits.Get<AutoTargetInfo>().AllowMovement
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user