public sealed override void HandleAccept(Controller controller)
        {
            IModel  model  = controller.Model;
            IGame   game   = model.CurrentGameBox.CurrentGame;
            IPlayer sender = model.GetPlayer(senderId);

            if (sender != null && sender.Guid != Guid.Empty && boardId != -1)
            {
                IBoard board = game.GetBoardById(boardId);
                if (board != null)
                {
                    IStack         stackBeingDropped = board.GetStackFromZOrder(zOrder);
                    ITerrainClone  pieceBeingDropped = (ITerrainClone)stackBeingDropped.Pieces[0];
                    CommandContext context           = new CommandContext(stackBeingDropped.Board, stackBeingDropped.BoundingBox);
                    model.CommandManager.ExecuteCommandSequence(
                        context, context,
                        new DragDropTerrainIntoHandCommand(model, sender.Guid, stackBeingDropped, insertionIndex));
                }
            }

            if (sender != null)
            {
                sender.StackBeingDragged = null;
            }
        }
        /// <summary>Rollback the previous cancellation of this command.</summary>
        public override void Redo()
        {
            preventConflict(stackBefore, stackAfter);

            // does the hand already contain an identical clone?
            IPlayerHand playerHand = model.CurrentGameBox.CurrentGame.GetPlayerHand(playerGuid);

            for (int i = 0; i < playerHand.Count; ++i)
            {
                ITerrainClone handPiece = stackAfter.Pieces[i] as ITerrainClone;
                if (handPiece != null && handPiece.Prototype == piece.Prototype)
                {
                    // yes -> don't redo ordering of the hand, it's not transactional
                    model.AnimationManager.LaunchAnimationSequence(
                        new MoveToFrontOfBoardAnimation(stackBefore, boardBefore),
                        new MoveStackToHandAnimation(stackBefore),
                        new RemoveTerrainAnimation(stackBefore));
                    return;
                }
            }
            // add the piece
            model.AnimationManager.LaunchAnimationSequence(
                new MoveToFrontOfBoardAnimation(stackBefore, boardBefore),
                new MoveStackToHandAnimation(stackBefore),
                (stackBefore == stackAfter ?
                 (IAnimation) new FillPlayerHandAnimation(playerGuid, stackBefore) :
                 (IAnimation) new MergeStacksAnimation(stackAfter, stackBefore, insertionIndex)));
        }
        /// <summary>Execute this command.</summary>
        public override void Do()
        {
            preventConflict(stackBefore, stackAfter);

            boardBefore         = stackBefore.Board;
            positionBefore      = stackBefore.Position;
            piece               = (ITerrainClone)stackBefore.Pieces[0];
            zOrderBefore        = ((Board)boardBefore).GetZOrder(stackBefore);
            rotationAngleBefore = piece.RotationAngle;
            sideBefore          = piece.Side;

            // does the hand already contain an identical clone?
            IPlayerHand playerHand = model.CurrentGameBox.CurrentGame.GetPlayerHand(playerGuid);

            for (int i = 0; i < playerHand.Count; ++i)
            {
                ITerrainClone handPiece = stackAfter.Pieces[i] as ITerrainClone;
                if (handPiece != null && handPiece.Prototype == piece.Prototype)
                {
                    // yes -> simply move the piece to the new insertion index
                    if (playerGuid == model.ThisPlayer.Guid)
                    {
                        model.AnimationManager.LaunchAnimationSequence(
                            new RemoveTerrainAnimation(stackBefore),
                            new RearrangePlayerHandAnimation(playerHand, i, insertionIndex));
                    }
                    else
                    {
                        model.AnimationManager.LaunchAnimationSequence(
                            new MoveToFrontOfBoardAnimation(stackBefore, boardBefore),
                            new MoveStackToHandAnimation(stackBefore),
                            new RemoveTerrainAnimation(stackBefore),
                            new RearrangePlayerHandAnimation(playerHand, i, insertionIndex));
                    }
                    return;
                }
            }
            // add the piece
            if (playerGuid == model.ThisPlayer.Guid)
            {
                model.AnimationManager.LaunchAnimationSequence(
                    (stackBefore == stackAfter ?
                     (IAnimation) new FillPlayerHandAnimation(playerGuid, stackBefore) :
                     (IAnimation) new MergeStacksAnimation(stackAfter, stackBefore, insertionIndex)));
            }
            else
            {
                model.AnimationManager.LaunchAnimationSequence(
                    new MoveToFrontOfBoardAnimation(stackBefore, boardBefore),
                    new MoveStackToHandAnimation(stackBefore),
                    (stackBefore == stackAfter ?
                     (IAnimation) new FillPlayerHandAnimation(playerGuid, stackBefore) :
                     (IAnimation) new MergeStacksAnimation(stackAfter, stackBefore, insertionIndex)));
            }
        }
示例#4
0
        /// <summary>Execute this command.</summary>
        public override void Do()
        {
            preventConflict(stackBefore, stackAfter);

            PlayerHand playerHand = (PlayerHand)model.CurrentGameBox.CurrentGame.GetPlayerHand(playerGuid);

            insertionIndex = (playerHand != null ? playerHand.Count : 0);

            boardBefore         = stackBefore.Board;
            positionBefore      = stackBefore.Position;
            piece               = (ITerrainClone)stackBefore.Pieces[0];
            zOrderBefore        = ((Board)boardBefore).GetZOrder(stackBefore);
            rotationAngleBefore = piece.RotationAngle;
            sideBefore          = piece.Side;

            List <IAnimation> animations = new List <IAnimation>(4);

            if (playerHand == null)
            {
                animations.Add(new AddPlayerHandAnimation(playerGuid));
            }

            animations.Add(new MoveToFrontOfBoardAnimation(stackBefore, boardBefore));
            animations.Add(new MoveStackToHandAnimation(stackBefore));

            if (playerHand != null)
            {
                // does the hand already contain an identical clone?
                for (int i = 0; i < playerHand.Count; ++i)
                {
                    ITerrainClone handPiece = stackAfter.Pieces[i] as ITerrainClone;
                    if (handPiece != null && handPiece.Prototype == piece.Prototype)
                    {
                        // yes -> simply move the piece to the new insertion index
                        animations.Add(new RemoveTerrainAnimation(stackBefore));
                        animations.Add(new RearrangePlayerHandAnimation(playerHand, i, insertionIndex));
                        model.AnimationManager.LaunchAnimationSequence(animations.ToArray());
                        return;
                    }
                }
            }
            // add the piece
            if (stackBefore == stackAfter)
            {
                animations.Add(new FillPlayerHandAnimation(playerGuid, stackBefore));
            }
            else
            {
                animations.Add(new MergeStacksAnimation(stackAfter, stackBefore, insertionIndex));
            }
            model.AnimationManager.LaunchAnimationSequence(animations.ToArray());
        }
示例#5
0
        public sealed override void HandleAccept(Controller controller)
        {
            IModel  model  = controller.Model;
            IGame   game   = model.CurrentGameBox.CurrentGame;
            IPlayer sender = model.GetPlayer(senderId);

            // is the terrain in the player's hand?
            if (boardId != -1)
            {
                // no
                IBoard board = game.GetBoardById(boardId);
                if (board != null)
                {
                    IStack stackBeingDropped = board.GetStackFromZOrder(zOrder);
                    IBoard visibleBoard      = model.CurrentGameBox.CurrentGame.VisibleBoard;
                    if (board == visibleBoard)
                    {
                        model.CommandManager.ExecuteCommandSequence(
                            new CommandContext(visibleBoard, stackBeingDropped.BoundingBox),
                            new CommandContext(visibleBoard),
                            new DragDropStackCommand(model, stackBeingDropped, newPosition));
                    }
                    else
                    {
                        model.CommandManager.ExecuteCommandSequence(
                            new CommandContext(stackBeingDropped.Board, stackBeingDropped.BoundingBox),
                            new CommandContext(visibleBoard),
                            new DragDropStackFromOtherBoardCommand(model, stackBeingDropped, visibleBoard, newPosition));
                    }
                }
                if (sender != null)
                {
                    sender.StackBeingDragged = null;
                }
            }
            else
            {
                // yes, in the hand
                if (sender != null && sender.Guid != Guid.Empty)
                {
                    IPlayerHand playerHand = game.GetPlayerHand(sender.Guid);
                    if (playerHand != null && playerHand.Count > zOrder)
                    {
                        ITerrainClone piece = (ITerrainClone)playerHand.Pieces[zOrder];
                        model.CommandManager.ExecuteCommandSequence(
                            new CloneTerrainFromHandCommand(model, sender.Guid, piece, newPosition));
                    }
                    sender.PieceBeingDragged = null;
                }
            }
        }
示例#6
0
        public sealed override void HandleAccept(Controller controller)
        {
            IModel  model  = controller.Model;
            IGame   game   = model.CurrentGameBox.CurrentGame;
            IPlayer sender = model.GetPlayer(senderId);

            // is the terrain in the player's hand?
            if (boardId != -1)
            {
                // no
                IBoard board = game.GetBoardById(boardId);
                if (board != null)
                {
                    IStack         stack   = board.GetStackFromZOrder(zOrder);
                    CommandContext context = new CommandContext(board, stack.BoundingBox);
                    model.CommandManager.ExecuteCommandSequence(
                        context, context,
                        new RemoveTerrainCommand(model, stack));
                }
                if (sender != null)
                {
                    sender.StackBeingDragged = null;
                }
            }
            else
            {
                // yes, in the hand
                if (sender != null && sender.Guid != Guid.Empty)
                {
                    IPlayerHand playerHand = game.GetPlayerHand(sender.Guid);
                    if (playerHand != null && playerHand.Count > zOrder)
                    {
                        ITerrainClone piece = (ITerrainClone)playerHand.Pieces[zOrder];
                        model.CommandManager.ExecuteCommandSequence(
                            new RemoveTerrainFromHandCommand(model, sender.Guid, piece));
                    }
                }
                if (sender != null)
                {
                    sender.PieceBeingDragged = null;
                }
            }
        }
示例#7
0
        /// <summary>Rollback the previous cancellation of this command.</summary>
        public override void Redo()
        {
            preventConflict(stackBefore, stackAfter);

            PlayerHand playerHand = (PlayerHand)model.CurrentGameBox.CurrentGame.GetPlayerHand(playerGuid);

            List <IAnimation> animations = new List <IAnimation>(4);

            if (playerHand == null)
            {
                animations.Add(new AddPlayerHandAnimation(playerGuid));
            }

            animations.Add(new MoveToFrontOfBoardAnimation(stackBefore, boardBefore));
            animations.Add(new MoveStackToHandAnimation(stackBefore));

            if (playerHand != null)
            {
                // does the hand already contain an identical clone?
                for (int i = 0; i < playerHand.Count; ++i)
                {
                    ITerrainClone handPiece = stackAfter.Pieces[i] as ITerrainClone;
                    if (handPiece != null && handPiece.Prototype == piece.Prototype)
                    {
                        // yes -> don't redo ordering of the hand, it's not transactional
                        animations.Add(new RemoveTerrainAnimation(stackBefore));
                        model.AnimationManager.LaunchAnimationSequence(animations.ToArray());
                        return;
                    }
                }
            }
            // add the piece
            if (stackBefore == stackAfter)
            {
                animations.Add(new FillPlayerHandAnimation(playerGuid, stackBefore));
            }
            else
            {
                animations.Add(new MergeStacksAnimation(stackAfter, stackBefore, insertionIndex));
            }
            model.AnimationManager.LaunchAnimationSequence(animations.ToArray());
        }
示例#8
0
        /// <summary>Execute this command.</summary>
        public override void Do()
        {
            if (stackAfter != null)
            {
                preventConflict(stackBefore, stackAfter);
            }
            else
            {
                preventConflict(stackBefore);
            }

            PlayerHand playerHand = (PlayerHand)model.CurrentGameBox.CurrentGame.GetPlayerHand(playerGuid);

            insertionIndex = (playerHand != null ? playerHand.Count : 0);

            List <IAnimation> animations = new List <IAnimation>(4);

            if (playerHand == null)
            {
                animations.Add(new AddPlayerHandAnimation(playerGuid));
            }

            if (piece is ITerrainPrototype)
            {
                if (stackAfter != null)
                {
                    preventConflict(stackAfter);
                    // does the hand already contain an identical clone?
                    for (int i = 0; i < stackAfter.Pieces.Length; ++i)
                    {
                        ITerrainClone handPiece = stackAfter.Pieces[i] as ITerrainClone;
                        if (handPiece != null && handPiece.Prototype == piece)
                        {
                            // yes -> simply move the piece to the new insertion index
                            animations.Add(new RearrangePlayerHandAnimation(playerHand, i, insertionIndex));
                            model.AnimationManager.LaunchAnimationSequence(animations.ToArray());
                            return;
                        }
                    }
                }
                // add the piece
                clone       = new TerrainClone((TerrainPrototype)piece);
                stackBefore = clone.Stack;
                sideBefore  = piece.Side;
            }
            else
            {
                sideBefore = piece.Side;
                animations.Add(new DetachStacksAnimation(new IStack[] { stackBefore }, new Side[] { sideBefore }));
            }
            animations.Add(new MoveToFrontOfBoardAnimation(stackBefore, piece.CounterSection.CounterSheet));
            animations.Add(new MoveStackToHandAnimation(stackBefore));
            if (stackAfter == null)
            {
                animations.Add(new FillPlayerHandAnimation(playerGuid, stackBefore));
            }
            else
            {
                animations.Add(new MergeStacksAnimation(stackAfter, stackBefore, insertionIndex));
            }
            model.AnimationManager.LaunchAnimationSequence(animations.ToArray());
        }