Example #1
0
 private async Task OneAttackAsync(BattleBase unit, Army enemy)
 {
     while (unit.IsAlive() && enemy.IsAlive())
     {
         var one = enemy.FindOne();
         if (one != null)
         {
             await unit.AttackAsync(one);
         }
     }
 }
Example #2
0
        public void ResetEnemyTarget(BattleBase enemy)
        {
            if (_enemy == enemy)
            {
                return;
            }

            if (HasAttackTarget)
            {
                StopAttack();
            }
            ResetTarget(enemy);
        }
Example #3
0
        public void AttackOnce(BattleBase enemy = null)
        {
            if (enemy != null)
            {
                ResetEnemyTarget(enemy);
            }

            if (HasAttackTarget)
            {
                HurtEnemy(_enemy);
                if (_enemy.IsAlive() == false)
                {
                    ClearTarget();
                }
            }
        }
Example #4
0
        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();
        }
Example #5
0
        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);
                }
            }
        }
Example #6
0
 private void HurtEnemy(BattleBase enemy)
 {
     enemy.GotHurt(NoArmorHurt + CalNormalHurt(enemy.Armor));
 }
Example #7
0
 private void ClearTarget()
 {
     lock (_mutex) _enemy = null;
 }
Example #8
0
 private void ResetTarget(BattleBase enemy)
 {
     lock (_mutex) _enemy = enemy;
 }