private async Task OneAttackAsync(BattleBase unit, Army enemy) { while (unit.IsAlive() && enemy.IsAlive()) { var one = enemy.FindOne(); if (one != null) { await unit.AttackAsync(one); } } }
public void ResetEnemyTarget(BattleBase enemy) { if (_enemy == enemy) { return; } if (HasAttackTarget) { StopAttack(); } ResetTarget(enemy); }
public void AttackOnce(BattleBase enemy = null) { if (enemy != null) { ResetEnemyTarget(enemy); } if (HasAttackTarget) { HurtEnemy(_enemy); if (_enemy.IsAlive() == false) { ClearTarget(); } } }
public async Task AttackAsync(BattleBase enemy) { ResetEnemyTarget(enemy); var token = _source.Token; while (IsAlive() && enemy.IsAlive()) { if (token != null) { token.ThrowIfCancellationRequested(); } HurtEnemy(enemy); await Task.Delay((int)(AttackInterval * 1000)); } ClearTarget(); }
private void OnUnitDead(object sender, DateTime dateTime) { BattleBase one = sender as BattleBase; if (one != null) { UnitDeadEvent?.Invoke(this, one); lock (_mutex) { if (_battleUnits.Contains(one)) { _battleUnits.Remove(one); one.DeadEvent -= OnUnitDead; } } if (!IsAlive()) { DeadEvent?.Invoke(this, dateTime); } } }
private void HurtEnemy(BattleBase enemy) { enemy.GotHurt(NoArmorHurt + CalNormalHurt(enemy.Armor)); }
private void ClearTarget() { lock (_mutex) _enemy = null; }
private void ResetTarget(BattleBase enemy) { lock (_mutex) _enemy = enemy; }