Пример #1
0
 public bool Use(BattleUnitsStack source, SkillTarget target)
 {
     return(target.Match(
                battle => Use(source, battle),
                army => Use(source, army),
                list => Use(source, list),
                stack => Use(source, stack)
                ));
 }
Пример #2
0
        public bool Attack(BattleUnitsStack target)
        {
            if (_state != BattleState.InGame)
            {
                return(false);
            }

            var source = GetCurrentStack();

            if (source.GetArmy() == target.GetArmy())
            {
                return(false);
            }

            var hitPoints = DamageUtils.CalcDamageHitPoints(source, target);

            // Fire before attack event
            var beforeAttackEventArgs = new BeforeAttackEventArgs(source, target, hitPoints);

            EventBus.OnBeforeAttack(this, beforeAttackEventArgs);
            if (beforeAttackEventArgs.Cancel)
            {
                return(false);
            }

            hitPoints = beforeAttackEventArgs.HitPoints;

            target.Damage(hitPoints);

            // Fire after attack event
            EventBus.OnAfterAttack(this, new AfterAttackEventArgs(source, target, hitPoints));

            if (target.IsAlive() && !target.IsAnswered())
            {
                var answerHitPoints = DamageUtils.CalcDamageHitPoints(target, source);

                // Fire before answer event
                var beforeAnswerEventArgs = new BeforeAnswerEventArgs(source, target, answerHitPoints);
                EventBus.OnBeforeAnswer(this, beforeAnswerEventArgs);

                if (!beforeAnswerEventArgs.Cancel)
                {
                    answerHitPoints = beforeAnswerEventArgs.HitPoints;

                    source.Damage(answerHitPoints);
                    target.SetAnswered(beforeAnswerEventArgs.IsAnswered);

                    // Fire after answer event
                    EventBus.OnAfterAnswer(this,
                                           new AfterAnswerEventArgs(source, target, hitPoints, beforeAnswerEventArgs.IsAnswered));
                }
            }

            NextTurn();

            return(true);
        }
Пример #3
0
        public void AddStack(BattleUnitsStack stack)
        {
            if (_stacks.Count == MaxBattleArmySize)
            {
                throw new ArgumentOutOfRangeException(nameof(_stacks), $"Maximum size of battle army is {MaxBattleArmySize}");
            }

            _stacks.Add(stack);
        }
Пример #4
0
 public virtual bool Use(BattleUnitsStack source, BattleUnitsStack target) => false;
Пример #5
0
 public virtual bool Use(BattleUnitsStack source, IList <BattleUnitsStack> targets) => false;
Пример #6
0
 public bool ContainsStack(BattleUnitsStack stack) => _stacks.Contains(stack);
Пример #7
0
 public bool RemoveStack(BattleUnitsStack stack) => _stacks.Remove(stack);