Exemplo n.º 1
0
        public bool initiateMovementAction(CardInstance card, Square square)
        {
            if (!gameManager.isPlayerTurn(card.owner))
            {
                return(false);
            }
            if (square.boardLocation != BoardLocationEnum.board)
            {
                return(false);   //must move to square on board
            }
            ActionTargetingInfo tInfo = new ActionTargetingInfo {
                player        = card.owner,
                sourceCard    = card,
                targetSquares = new List <Square> {
                    square
                }
            };

            for (int i = 0; i < card.movementActions.Count; i++)
            {
                if (card.movementActions[i].execute(0, tInfo))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public override bool isValidTarget(float d, ActionTargetingInfo targetInfo)
        {
            ActionTargetingInfo tInfo = (targetInfo ?? defaultTargetingInfo);

            if (tInfo.targetSquares.Count != 1)
            {
                return(false);
            }

            Square sourceSquare = tInfo.sourceCard.square;
            Square targetSquare = tInfo.targetSquares[0];

            if (tInfo.targetSquares.Count != 1)
            {
                return(false);
            }
            if (targetSquare == null || tInfo.sourceCard == null || sourceSquare == null)
            {
                return(false);
            }
            if (tInfo.sourceCard.owner == null || tInfo.player == null || tInfo.sourceCard.owner != tInfo.player)
            {
                return(false);
            }

            //target must be unoccupied
            if (targetSquare.isOccupied())
            {
                return(false);
            }

            if (sourceSquare.boardLocation != BoardLocationEnum.board)
            {
                return(false);
            }
            if (Math.Abs(sourceSquare.col - targetSquare.col) != Math.Abs(sourceSquare.row - targetSquare.row))
            {
                return(false);
            }
            if (sourceSquare.col == targetSquare.col && sourceSquare.row == targetSquare.row)
            {
                return(false);
            }

            int rowDir = (targetSquare.row - sourceSquare.row) / Math.Abs(targetSquare.row - sourceSquare.row);
            int colDir = (targetSquare.col - sourceSquare.col) / Math.Abs(targetSquare.col - sourceSquare.col);

            for (int diff = 1; diff < Math.Abs(sourceSquare.col - targetSquare.col); diff++)
            {
                int row = sourceSquare.row + diff * rowDir;
                int col = sourceSquare.col + diff * colDir;

                if (tInfo.sourceCard.boardManager.squares[col][row].isOccupied())
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public override bool isValidTarget(float d, ActionTargetingInfo targetInfo = null)
        {
            ActionTargetingInfo tInfo = (targetInfo == null ? defaultTargetingInfo : targetInfo);

            if (tInfo == null || tInfo.player == null)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public override bool execute(float d, ActionTargetingInfo targetInfo = null)
        {
            if (!isValidTarget(d, targetInfo))
            {
                return(false);
            }

            ActionTargetingInfo tInfo = (targetInfo ?? defaultTargetingInfo);

            tInfo.sourceCard.boardManager.moveCardToSquare(tInfo.sourceCard, tInfo.targetSquares[0]);

            return(true);
        }
Exemplo n.º 5
0
        public override bool execute(float d, ActionTargetingInfo targetInfo)
        {
            if (!isValidTarget(d, targetInfo))
            {
                return(false);
            }

            PointerEventData pointerData = new PointerEventData(EventSystem.current)
            {
                position = Input.mousePosition
            };

            IClickable c = null;

            List <RaycastResult> results = new List <RaycastResult>();

            EventSystem.current.RaycastAll(pointerData, results);
            foreach (RaycastResult r in results)
            {
                c = r.gameObject.GetComponentInParent <IClickable>();
                if (c != null)
                {
                    break;
                }
            }

            if (c == null)
            {
                RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
                if (hit)
                {
                    c = hit.collider.GetComponentInParent <IClickable>();
                }
                //c = GameObject.Find(hit.collider.gameObject.name).GetComponentInParent<IClickable>();
            }

            if (screenManager != null)
            {
                screenManager.onMouseEvent(c, (targetInfo == null ? defaultTargetingInfo.player : targetInfo.player));
            }

            return(true);
        }
Exemplo n.º 6
0
        public override bool execute(float d, ActionTargetingInfo targetInfo)
        {
            if (!isValidTarget(d, targetInfo))
            {
                return(false);
            }

            ActionTargetingInfo tInfo = (targetInfo ?? defaultTargetingInfo);

            if (tInfo.sourceCard == null || tInfo.targetSquares.Count < 1 || tInfo.targetSquares[0].cards.Count != 1 || tInfo.targetSquares[0].cards[0] == null)
            {
                return(false);
            }

            if (tInfo.sourceCard.fight(tInfo.targetSquares[0].cards[0]) && !tInfo.sourceCard.isDead)
            {
                tInfo.sourceCard.boardManager.moveCardToSquare(tInfo.sourceCard, tInfo.targetSquares[0]);
            }

            return(true);
        }
Exemplo n.º 7
0
        public override bool isValidTarget(float d, ActionTargetingInfo targetInfo = null)
        {
            ActionTargetingInfo tInfo = (targetInfo ?? defaultTargetingInfo);

            if (tInfo.targetSquares.Count != 1)
            {
                return(false);
            }
            if (tInfo.targetSquares[0] == null || tInfo.sourceCard == null || tInfo.sourceCard.square == null)
            {
                return(false);
            }
            if (tInfo.sourceCard.owner == null || tInfo.player == null || tInfo.sourceCard.owner != tInfo.player)
            {
                return(false);
            }

            //target must be unoccupied
            if (tInfo.targetSquares[0].cards.Count != 0)
            {
                return(false);
            }

            if (tInfo.sourceCard.square.boardLocation != BoardLocationEnum.player1Hand && tInfo.sourceCard.square.boardLocation != BoardLocationEnum.player2Hand)    //doesn't check which hand it is, because assumes that's handled in game manager (and by correctly assigning owners)
            {
                return(false);
            }

            if (tInfo.sourceCard.square.boardLocation == BoardLocationEnum.player1Hand && tInfo.targetSquares[0].row >= tInfo.sourceCard.boardManager.squares[0].Count / 2)
            {
                return(false);
            }
            if (tInfo.sourceCard.square.boardLocation == BoardLocationEnum.player2Hand && tInfo.targetSquares[0].row < (tInfo.sourceCard.boardManager.squares[0].Count - tInfo.sourceCard.boardManager.squares[0].Count / 2))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        public void highlightValidSquares(CardInstance card, BoardActionEnum actionType)
        {
            ActionTargetingInfo targetInfo = new ActionTargetingInfo {
                player        = card.owner,
                sourceCard    = card,
                targetSquares = new List <Square> {
                    squares[0][0]
                }
            };

            for (int i = 0; i < squares.Count; i++)
            {
                for (int j = 0; j < squares[i].Count; j++)
                {
                    targetInfo.targetSquares[0] = squares[i][j];
                    if (card.isValidActionTarget(targetInfo, actionType))
                    {
                        ((ScreenSquare)squares[i][j]).setHighlight(true);
                    }
                }
            }
        }
Exemplo n.º 9
0
 public abstract bool isValidTarget(float d, ActionTargetingInfo targetInfo = null);
Exemplo n.º 10
0
 public abstract bool execute(float d, ActionTargetingInfo targetInfo       = null);
Exemplo n.º 11
0
 public Action()
 {
     defaultTargetingInfo = new ActionTargetingInfo();
 }