add Util.RunActivity, and have Actor.Tick use it. fix medic autoheal

This commit is contained in:
Bob
2010-11-14 18:36:36 +13:00
parent d152d21338
commit 80e897abfb
16 changed files with 59 additions and 57 deletions

View File

@@ -27,31 +27,35 @@ namespace OpenRA.Mods.RA
class IdleHealActivity : Idle
{
Actor currentTarget;
IActivity inner;
public override IActivity Tick( Actor self )
{
if( NextActivity != null )
return NextActivity;
if( inner == null )
{
if( NextActivity != null )
return NextActivity;
var attack = self.Trait<AttackBase>();
var range = attack.GetMaximumRange();
var attack = self.Trait<AttackBase>();
var range = attack.GetMaximumRange();
if (NeedsNewTarget(self))
AttackTarget(self, ChooseTarget(self, range));
if (NeedsNewTarget(self))
{
currentTarget = ChooseTarget(self, range);
if( currentTarget != null )
inner = self.Trait<AttackBase>().GetAttackActivity(self, Target.FromActor( currentTarget ), false );
}
}
if( inner != null )
{
if( currentTarget.GetDamageState() == DamageState.Undamaged )
inner.Cancel( self );
inner = Util.RunActivity( self, inner );
}
return this;
}
void AttackTarget(Actor self, Actor target)
{
var attack = self.Trait<AttackBase>();
if (target != null)
attack.AttackTarget(Target.FromActor( target), false, true );
else
if (attack.IsAttacking)
self.CancelActivity();
}
bool NeedsNewTarget(Actor self)
{
var attack = self.Trait<AttackBase>();