Example #1
0
        protected MultiTurnSelection[] CopyMultiTurnSelectionArray(IList <HumanFighter> fighters)
        {
            int numFighters = fighters.Count;

            MultiTurnSelection[] copy = new MultiTurnSelection[numFighters];

            for (var j = 0; j < numFighters; ++j)
            {
                copy[j] = _multiTurnSelections.FirstOrDefault(mts => mts != null && mts.Owner == fighters[j]);
            }

            return(copy);
        }
Example #2
0
        /// <summary>
        /// Given a particular array of MultiTurnSelections, an index, and the moveOwner, either returns null (no multiTurn move for the given fighter),
        /// or returns the appropriate BattleMoveWithTarget, and updates the selectionArray
        /// </summary>
        /// <param name="moveOwner"></param>
        /// <param name="selectionArray"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        protected BattleMoveWithTarget FindAndProcessMultiTurnMove(IFighter moveOwner, MultiTurnSelection[] selectionArray, int index)
        {
            BattleMoveWithTarget ret = null;

            MultiTurnSelection multiTurnSelection = selectionArray.FirstOrDefault(mts => mts != null && mts.Owner == moveOwner);

            if (multiTurnSelection != null)
            {
                var multiTurnIndex = multiTurnSelection.Index;
                var move           = multiTurnSelection.Move.Moves[multiTurnIndex];
                var target         = (move.TargetType == TargetType.Self) ? moveOwner : multiTurnSelection.Target;

                ret = new BattleMoveWithTarget(move, target, moveOwner);

                multiTurnSelection.IncrementIndex();

                if (multiTurnSelection.Index >= multiTurnSelection.Move.Moves.Count)
                {
                    selectionArray[index] = null;
                }
            }

            return(ret);
        }
Example #3
0
        public virtual List <BattleMoveWithTarget> GetInputs(IList <HumanFighter> fighters, List <MenuAction> specialMenuActions = null)
        {
            BuildMenus(fighters, specialMenuActions);

            var length = _menus.Count;
            var ret    = new List <BattleMoveWithTarget>(new BattleMoveWithTarget[length]);

            for (var i = 0; i < length;)
            {
                IFighter fighter = _menus[i].Owner;

                BattleMoveWithTarget multiTurnmove = FindAndProcessMultiTurnMove(fighter, _multiTurnSelections, i);

                if (multiTurnmove != null)
                {
                    ret[i] = multiTurnmove;
                    ++i;
                }
                else
                {
                    var menuSelection = _menus[i].GetInput();

                    switch (menuSelection.Description)
                    {
                    case "run":
                        OnRun(new RanEventArgs());
                        for (var j = 0; j < length; ++j)
                        {
                            ret[j] = null;
                        }
                        i = length;
                        break;

                    case "back":
                        --i;
                        break;

                    default:

                        var multiTurn = menuSelection.Move as MultiTurnBattleMove;
                        if (multiTurn != null)
                        {
                            _multiTurnSelections[i] = new MultiTurnSelection(fighter, multiTurn, 1,
                                                                             menuSelection.Target);

                            var move = multiTurn.Moves[0];

                            var target = move.TargetType == TargetType.Self ? fighter : menuSelection.Target;

                            ret[i] = new BattleMoveWithTarget(move, target, fighter);
                        }
                        else
                        {
                            ret[i] = menuSelection.Convert(fighter);
                        }

                        ++i;
                        break;
                    }
                }
            }

            return(ret);
        }