Exemple #1
0
    void OnMouseUp()
    {
        GlobalScript.ourCursorScript.myCardScript = null;

        //store handscript because it's not free
        HandScript handScript = myHandScript;

        PlayerScript playerScript = handScript.myOwningPlayer;

        //check if card is main player's
        if (null != handScript && playerScript == GlobalScript.ourGlobalScript.myMainPlayerScript)
        {
            //card must be over 20% of the screen to be used
            //Debug.Log(Input.mousePosition.y / Screen.height);
            if (Input.mousePosition.y / Screen.height > .2f)
            {
                Message message = playerScript.ToMessage();

                //raycast terrain
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, GlobalScript.ourCursorScript.myRayLength))
                {
                    message.myObject.myPosition = hit.point;
                }

                //raycast units
                if (Physics.Raycast(ray, out hit, GlobalScript.ourCursorScript.myRayLength, 1 << 9))
                {
                    UnitScript unitScript = hit.transform.GetComponent <UnitScript>();

                    if (unitScript)
                    {
                        message.myObject = unitScript.ToTerm();
                    }
                }

                //get cost of card
                int manaCost = CostMana(message);
                int goldCost = CostGold(message);

                //if player has enough
                if (manaCost <= playerScript.myMana)
                {
                    if (goldCost <= playerScript.myGold)
                    {
                        //pay cost
                        playerScript
                        .SubMana(manaCost)
                        .SubGold(goldCost)
                        .AddDebt(CostDebt(message))
                        .AddOverload(CostOverload(message));

                        handScript.RemoveCard(this, false);

                        playerScript.ActivateCard(this, message);

                        Destroy(gameObject);
                    }
                    else
                    {
                        Debug.Log("Card: " + gameObject.name + " uses " + goldCost + " gold.");
                    }
                }
                else
                {
                    Debug.Log("Card: " + gameObject.name + " uses " + manaCost + " mana.");
                }

                return;
            }

            myPosition.Reset(transform.localPosition).Animate(myHandScript.CardPosition(this), .2f);

            myRotation.Reset(transform.localRotation).Animate(myHandScript.CardRotation(this), .2f);
        }
    }