Ejemplo n.º 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)
                ));
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 public virtual bool Use(BattleUnitsStack source, BattleUnitsStack target) => false;
Ejemplo n.º 5
0
 public virtual bool Use(BattleUnitsStack source, IList <BattleUnitsStack> targets) => false;
Ejemplo n.º 6
0
 public bool ContainsStack(BattleUnitsStack stack) => _stacks.Contains(stack);
Ejemplo n.º 7
0
 public bool RemoveStack(BattleUnitsStack stack) => _stacks.Remove(stack);