Beispiel #1
0
    //Requires an appropriate Raycaster component be on a camera in order to trigger.
    public void OnPointerClick(PointerEventData data)
    {
        //ensures that only the correct people look at each other's cards unless this is debug mode.
        if (FaceUp || owner.Bonds.Contains(this) || GameManager.instance.playtestMode)
        {
            CardReader.instance.DisplayCard(gameObject);
        }

        ContextMenu.instance.ClosePanel();


        if (FaceUp && owner == GameManager.instance.turnPlayer && !GameManager.instance.inCombat)
        {
            //pulls up the ContextMenu centered on the card when the card is clicked.
            ContextMenuDetails menuDetails = new ContextMenuDetails
            {
                rawPosition = Camera.main.WorldToScreenPoint(transform.position),
                //canAttack = false,
                //attackAction = () => { Debug.Log("Attack!"); },
                //canBond = true,
                //bondAction = () => { Debug.Log("Bond!"); },
                //canDeploy = false,
                //deployAction = () => { Debug.Log("Deploy!"); }, //owner.DeployToFrontLine(this);
                //canClassChange = false,
                //classChangeAction = () => { Debug.Log("Class Change!"); },
                //canLevelUp = false,
                //levelUpAction = () => { Debug.Log("Level Up!"); }
                //canEffect = false,
                //effectAction = () => { Debug.Log("Effect!");  }, //owner.LevelUp(this);
                //canMove = false,
                //moveAction = () => { Debug.Log("Move!"); } //owner.ReturnCardStackToHandFromField(this);
            };

            //If it's the main phase, this card is on the field, this card isn't tapped, it isn't the first turn, and there are other cards in its range then let it attack.
            if (GameManager.instance.CurrentPhase == CipherData.PhaseEnum.Action && Owner.FieldCards.Contains(this) && !Tapped &&
                (!GameManager.instance.FirstTurn || GameManager.instance.playtestMode) && AttackTargets.Count > 0)
            {
                menuDetails.canAttack    = true;
                menuDetails.attackAction = () => { Debug.Log("Attack!"); GameManager.instance.AimAttack(this); };
            }
            else
            {
                menuDetails.canAttack = false;
            }

            //If it's the bond phase, no other cards have been bonded, this card is in the hand, and it can be bonded then let it be bonded.
            if (GameManager.instance.CurrentPhase == CipherData.PhaseEnum.Bond && owner.Hand.Contains(this) && Bondable && (!GameManager.instance.cardBonded || GameManager.instance.playtestMode))
            {
                menuDetails.canBond    = true;
                menuDetails.bondAction = () => { owner.PlaceCardInBonds(this, owner.Hand, true); GameManager.instance.cardBonded = true; };
            }
            else
            {
                menuDetails.canBond = false;
            }

            //The following determines whether a card can be deployed, leveled up, or class changed. Start by assuming that none of those actions can occur.
            menuDetails.canDeploy      = false;
            menuDetails.canClassChange = false;
            menuDetails.canLevelUp     = false;

            //If it's the deployment phase, there is an appropriate color present in the bonds, and this card is in the hand, then it might be playable to the field.
            if (GameManager.instance.CurrentPhase == CipherData.PhaseEnum.Deployment && owner.AreCardColorsBonded(this) && owner.Hand.Contains(this))
            {
                int usableBonds = owner.Bonds.Count - GameManager.instance.bondDeployCount;

                //if the card is present on the field, it may be able to be leveled up or class changed or both, but not deployed.
                if (owner.FieldCards.Exists(x => x.CompareNames(this, true)))
                {
                    //Check if there are enough bonds for this card to be classChanged.
                    if (usableBonds >= PromotionCost && Promotable)
                    {
                        menuDetails.canClassChange    = true;
                        menuDetails.classChangeAction = () => { Debug.Log("Class Change!"); owner.PlayToFieldFromHand(this, true); };
                    }

                    //also check if there are enough bonds for this card to be leveled up
                    if (usableBonds >= DeploymentCost)
                    {
                        menuDetails.canLevelUp    = true;
                        menuDetails.levelUpAction = () => { Debug.Log("Level Up!"); owner.PlayToFieldFromHand(this, false); };
                    }
                }
                else    //The card is not present on the field, so this is a deployment if there are sufficient bonds.
                {
                    //Check if there are sufficent bonds to deploy this card.
                    if (usableBonds >= DeploymentCost)
                    {
                        menuDetails.canDeploy    = true;
                        menuDetails.deployAction = () => { Debug.Log("Deploy!"); owner.DeployToFieldFromHand(this); };
                    }
                }
            }

            //If it's the action phase, a skill's conditions are met, and the card is on the field, then start paying the cost to use the skill.
            if (GameManager.instance.CurrentPhase == CipherData.PhaseEnum.Action && CheckActionSkillConditions() && owner.FieldCards.Contains(this))
            {
                menuDetails.canEffect    = true;
                menuDetails.effectAction = () => { Debug.Log("Effect!"); PayActionSkillCost(); };
            }
            else
            {
                menuDetails.canEffect = false;
            }


            //If it's the action phase, the card is not already tapped, and the card is on the field, then let it be moved.
            //Also taps the card as part of the cost before moving.
            if (GameManager.instance.CurrentPhase == CipherData.PhaseEnum.Action && !Tapped && owner.FieldCards.Contains(this))
            {
                menuDetails.canMove    = true;
                menuDetails.moveAction = () => { Debug.Log("Move!"); Tap(); owner.MoveCard(this); };
            }
            else
            {
                menuDetails.canMove = false;
            }


            if (menuDetails.ShouldOpen)
            {
                ContextMenu.instance.PopUpMenu(menuDetails);
            }
        }
    }