private void onSelectTarget(TargetModel c)
 {
     view.setDragEnabled(true);
 }
 private void onStartTarget(TargetModel m)
 {
     view.setDragEnabled(false);
 }
 private void onUpdateTarget(TargetModel model)
 {
     updateSelectHighlights(model);
 }
 private void updateSelectHighlights(TargetModel model)
 {
     view.toggleTileFlags(null, TileHighlightStatus.TargetTile, true);
     if (model != null && model.area != null)
     {
         if (model.selectedPosition.HasValue)
         {
             List<Tile> tiles = null;
             switch (model.area.areaType) {
                 case AreaType.Square:
                     tiles = mapService.GetKingTilesInRadius(model.selectedPosition.Value, selectingArea.area.size).Values.ToList();
                     break;
                 case AreaType.Cross:
                     tiles = mapService.GetCrossTiles(model.selectedPosition.Value, selectingArea.area.size).Values.ToList();
                     break;
                 case AreaType.Line:
                     tiles = mapService.GetKingTilesInRadius(model.selectedPosition.Value, 1).Values.ToList();
                     break;
                 case AreaType.Row:
                     tiles = mapService.GetCrossTiles(model.selectedPosition.Value, 1).Values.ToList();
                     break;
                 case AreaType.Diagonal:
                     tiles = mapService.GetDiagonalTilesInRadius(model.selectedPosition.Value, 1).Values.ToList();
                     break;
             }
             view.toggleTileFlags(tiles, TileHighlightStatus.TargetTile, true);
         }
         else
         {
             view.toggleTileFlags(map.tileList, TileHighlightStatus.TargetTile, true);
         }
     }
 }
 private void onSelectTarget(TargetModel card)
 {
     setAttackRangeTiles(null);
     selectingArea = null;
     updateSelectHighlights(null);
 }
 private void onStartTarget(TargetModel model)
 {
     //see if there are any areas to show
     var area = model.area;
     if (model.area != null)
     {
         selectingArea = model;
         if(area.areaTiles.Count > 0){
             var tiles = map.getTilesByPosition(area.areaTiles.Select(t => t.Vector2).ToList());
             setAttackRangeTiles(tiles, true);
         }
     }
     updateSelectHighlights(model);
 }
 private void onSelectedTarget(TargetModel targetModel)
 {
     activateCard.Dispatch(new ActivateModel() {
         cardActivated = targetModel.targetingCard,
         position = targetModel.cardDeployPosition != null ?
             targetModel.cardDeployPosition.position :
             targetModel.selectedPosition,
         pivotPosition = targetModel.selectedPivotPosition,
         optionalTarget = targetModel.selectedPiece,
         chooseCardTemplateId = chooseModel == null ? null : chooseModel.chosenTemplateId
     });
     startTargetModel = null;
     chooseModel = null;
 }
Beispiel #8
0
 private void onTargetSelected(TargetModel c)
 {
     disableTargetCandidate();
 }
        private void onActivate(GameObject activated)
        {
            if (activated == null || draggedCard == null)
            {
                cardSelected.Dispatch(null);
                return;
            }

            if (activated.CompareTag("Tile"))
            {
                //check for appropriate resources
                if (draggedCard.cost > playerResources.resources[draggedCard.playerId])
                {
                    message.Dispatch(new MessageModel() { message = "Not enough energy to play!" }, new SocketKey(turns.currentTurnClientId, "game"));
                    return;
                }

                var gameTile = map.tiles.Get(activated.transform.position.ToTileCoordinates());

                if (draggedCard.isChoose(possibleActions))
                {
                    chooseModel = new ChooseModel()
                    {
                        choosingCard = draggedCard,
                        cardDeployPosition = gameTile,
                        choices = possibleActions.GetChoiceCards(draggedCard.playerId, draggedCard.id)
                    };
                    debug.Log("Starting choose");
                    startChoose.Dispatch(chooseModel);
                }
                else if (draggedCard.needsTargeting(possibleActions))
                {
                    var targets = possibleActions.GetActionsForCard(turns.currentPlayerId, draggedCard.id);
                    var area = possibleActions.GetAreasForCard(turns.currentPlayerId, draggedCard.id);

                    var selectedPosition = (area != null && area.centerPosition != null) ? area.centerPosition.Vector2 : (Vector2?)null;
                    if (area != null && area.selfCentered)
                    {
                        selectedPosition = gameTile.position;
                    }
                    var pivotPosition = (area != null && area.pivotPosition != null) ? area.pivotPosition.Vector2 : (Vector2?)null;

                    //record state we need to maintain for subsequent clicks then dispatch the start target
                    startTargetModel = new TargetModel()
                    {
                        targetingCard = draggedCard,
                        cardDeployPosition = gameTile,
                        targets = targets,
                        area = area,
                        selectedPosition = selectedPosition,
                        selectedPivotPosition = pivotPosition
                    };

                    //delay sending off the start select target signal till the card deselected event has cleared
                    Invoke("StartSelectTargets", 0.10f);
                }
                else
                {
                    activateCard.Dispatch(new ActivateModel()
                    {
                        cardActivated = draggedCard,
                        position = gameTile.position,
                        optionalTarget = null
                    });
                }
            }
        }
        private void onClick(GameObject clickedObject, Vector3 point)
        {
            if (clickedObject != null)
            {
                if (clickedObject.CompareTag("Card"))
                {
                    var cardView = clickedObject.GetComponent<CardView>();

                    //Choose card interactions
                    if (chooseModel != null && cardView.card.tags.Contains(Constants.chooseCardTag))
                    {
                        chooseModel.chosenTemplateId = cardView.card.cardTemplateId;
                        cardChosen.Dispatch(chooseModel);
                        if (chooseModel.chooseFulfilled)
                        {
                            activateCard.Dispatch(new ActivateModel()
                            {
                                cardActivated = chooseModel.choosingCard,
                                optionalTarget = null,
                                position = chooseModel.cardDeployPosition.position,
                                pivotPosition = null,
                                chooseCardTemplateId = chooseModel.chosenTemplateId
                            });
                            chooseModel = null;
                        }
                        else
                        {
                            var selected = chooseModel.choices.choices
                                .FirstOrDefault(x => x.cardTemplateId == chooseModel.chosenTemplateId.Value);
                            //if the choice isn't fulfilled yet it must mean it needs targets
                            startTargetModel = new TargetModel()
                            {
                                targetingCard = chooseModel.choosingCard,
                                cardDeployPosition = chooseModel.cardDeployPosition,
                                targets = selected.targets,
                                area = null // not supported yet
                            };
                            Invoke("StartSelectTargets", 0.10f);
                            return;
                        }
                        return;
                    }

                    if (cardView.card.isSpell)
                    {
                        var targets = possibleActions.GetActionsForCard(turns.currentPlayerId, cardView.card.id);
                        var area = possibleActions.GetAreasForCard(turns.currentPlayerId, cardView.card.id);
                        if (targets != null || area != null)
                        {
                            startTargetModel = new TargetModel()
                            {
                                targetingCard = cardView.card,
                                cardDeployPosition = null,
                                targets = targets,
                                area = area
                            };
                            Invoke("StartSelectTargets", 0.10f);
                            return;
                        }
                    }

                    draggedCard = cardView.card;
                    pieceSelected.Dispatch(null);
                    cardSelected.Dispatch(new CardSelectedModel() { card = draggedCard, point = point });
                }
            }
            else
            {
                draggedCard = null;
                cardSelected.Dispatch(null);

                //only cancel if we're not targeting with a choose
                if (startTargetModel == null)
                {
                    if (chooseModel != null)
                    {
                        cancelChoose.Dispatch(chooseModel);
                    }
                    chooseModel = null;
                }
            }
        }
Beispiel #11
0
 private void onStartTarget(TargetModel model)
 {
     cardTarget = model;
 }
Beispiel #12
0
        private void onClick(ClickModel clickModel)
        {
            if (clickModel.clickedObject != null)
            {
                if (clickModel.piece)
                {
                    var pieceView = clickModel.piece;
                    pieceDragging.Dispatch(clickModel.isUp ? null : pieceView.piece);
                    if (cardTarget != null)
                    {
                        debug.Log("Selected target");
                        cardTarget.selectedPiece = pieceView.piece;

                        var continueTarget = updateTarget(map.tiles.Get(pieceView.piece.tilePosition));

                        if (continueTarget && cardTarget.targetFulfilled)
                        {
                            selectTarget.Dispatch(cardTarget);
                            cardTarget = null;
                            pieceSelected.Dispatch(null);
                        }
                    }
                    else if (abilityTarget != null)
                    {
                        debug.Log("Selected ability target");
                        selectAbilityTarget.Dispatch(abilityTarget, pieceView.piece);
                        abilityTarget = null;
                        pieceSelected.Dispatch(null);
                    }
                    else if (pieceView.piece.currentPlayerHasControl && !clickModel.isUp)
                    {
                        pieceSelected.Dispatch(pieceView.piece);
                    }
                    else
                    {
                        if (
                            selectedPiece != null
                            && selectedPiece.id != pieceView.piece.id
                            && selectedPiece.attackCount < selectedPiece.maxAttacks
                            && selectedPiece.attack > 0
                            && !FlagsHelper.IsSet(selectedPiece.statuses, Statuses.Paralyze)
                            && !FlagsHelper.IsSet(selectedPiece.statuses, Statuses.CantAttack)
                            && !FlagsHelper.IsSet(pieceView.piece.statuses, Statuses.Cloak)
                            && mapService.isHeightPassable(
                                  mapService.Tile(selectedPiece.tilePosition),
                                  mapService.Tile(pieceView.piece.tilePosition)
                               )
                            )
                        {
                            attackPiece.Dispatch(new AttackPieceModel()
                            {
                                attackingPieceId = selectedPiece.id,
                                targetPieceId = pieceView.piece.id
                            });
                            pieceSelected.Dispatch(null);
                        }
                    }
                    return;
                }

                //selected should never be null but check anyways
                if (selectedPiece != null && selectedPiece.playerId == turns.currentPlayerId) {
                    if (clickModel.clickedObject.CompareTag("RotateSouth"))
                    {
                        rotatePiece.Dispatch(new RotatePieceModel(selectedPiece.id, Direction.South));
                    }
                    if (clickModel.clickedObject.CompareTag("RotateWest"))
                    {
                        rotatePiece.Dispatch(new RotatePieceModel(selectedPiece.id, Direction.West));
                    }
                    if (clickModel.clickedObject.CompareTag("RotateNorth"))
                    {
                        rotatePiece.Dispatch(new RotatePieceModel(selectedPiece.id, Direction.North));
                    }
                    if (clickModel.clickedObject.CompareTag("RotateEast"))
                    {
                        rotatePiece.Dispatch(new RotatePieceModel(selectedPiece.id, Direction.East));
                    }
                }

                if (clickModel.tile != null)
                {
                    var gameTile = clickModel.tile;

                    if (cardTarget != null && cardTarget.area != null)
                    {
                        if (cardTarget.area.areaTiles != null && cardTarget.area.areaTiles.Count > 0)
                        {
                            //verify tile selected is in area
                            if (!cardTarget.area.areaTiles.Contains(gameTile.position.ToPositionModel()))
                            {
                                debug.Log("Cancelling target for outside area");
                                cancelSelectTarget.Dispatch(cardTarget.targetingCard);
                                return;
                            }
                        }

                        var continueTargeting = updateTarget(gameTile);

                        if (continueTargeting && cardTarget.targetFulfilled)
                        {
                            selectTarget.Dispatch(cardTarget);
                            cardTarget = null;
                        }
                    } else if (
                        FlagsHelper.IsSet(gameTile.highlightStatus, TileHighlightStatus.Movable)
                        && selectedPiece != null
                        && !FlagsHelper.IsSet(selectedPiece.statuses, Statuses.Paralyze)
                        && !FlagsHelper.IsSet(selectedPiece.statuses, Statuses.CantAttack)
                        && !FlagsHelper.IsSet(selectedPiece.statuses, Statuses.Root)
                        )
                    {
                        movePiece.Dispatch(selectedPiece, gameTile);
                        pieceSelected.Dispatch(null);
                    }
                }
            }
            else
            {
                pieceSelected.Dispatch(null);
                pieceDragging.Dispatch(null);
                if (cardTarget != null)
                {
                    debug.Log("Cancelling targeting");
                    cancelSelectTarget.Dispatch(cardTarget.targetingCard);
                    cardTarget = null;
                }
                else if (abilityTarget != null)
                {
                    debug.Log("Cancelling targeting");
                    cancelSelectAbilityTarget.Dispatch(abilityTarget.targetingPiece);
                    abilityTarget = null;
                }
            }

            if (clickModel.isUp)
            {
                pieceDragging.Dispatch(null);
            }
        }
Beispiel #13
0
 private void onCancelTarget(CardModel card)
 {
     cardTarget = null;
 }
Beispiel #14
0
 private void onSelectTarget(TargetModel card)
 {
     view.disable();
 }
 private void onTargetCancel(CardModel card)
 {
     startTargetModel = null;
     if (chooseModel != null)
     {
         debug.Log("Cancelling choose from target cancel");
         cancelChoose.Dispatch(chooseModel);
     }
     chooseModel = null;
     cardSelected.Dispatch(null);
 }
Beispiel #16
0
        private void onStartTarget(TargetModel model)
        {
            if (model.targetingCard != null && model.cardDeployPosition != null)
            {
                view.worldPoint(model.cardDeployPosition.gameObject.transform);
            }
            else if (model.targetingCard.isSpell)
            {
                var area = possibleActions.GetAreasForCard(turns.currentPlayerId, model.targetingCard.id);
                //don't point for untargeted spells
                if (model.targets == null && area == null) { return; }

                view.rectTransform(model.targetingCard.gameObject);
            }
            else
            {
                view.disable();
            }
        }
Beispiel #17
0
 private void onStartSelectTarget(TargetModel model)
 {
     if (model.targets != null )
     {
         var selected = pieces.Pieces.Where(p => model.targets.targetPieceIds.Contains(p.id));
         foreach (var piece in selected)
         {
             piece.pieceView.targetCandidate = true;
         }
     }
 }