Example #1
0
    public void Setup(int id, CosmicAPI api)
    {
        this.id = id;
        origin  = api.GetCard(id);

        isMinion = origin.type == CardType.Minion;

        minionTitle.gameObject.SetActive(isMinion);
        spellTitle.gameObject.SetActive(!isMinion);

        mask.sprite  = isMinion ? minionMask : spellMask;
        frame.sprite = isMinion ? minionCard : spellCard;

        descriptionText.text = origin.description;
        elementText.text     = origin.element.ToString().ToUpper();

        image.sprite = origin.image;

        if (!isMinion)
        {
            hpText.gameObject.SetActive(false);
            damageText.gameObject.SetActive(false);
            spellTitle.text = origin.name;
        }
        else
        {
            minionTitle.text = origin.name;
        }

        hp     = origin.hp;
        damage = origin.damage;
        mana   = origin.cost;

        UpdateCardValues();
    }
Example #2
0
    void Start()
    {
        api.OnLogin += () => {
            GameObject.Find("LoggedInStatus").GetComponent <Text>().text = "Logged in as " + api.GetMe().username;
            wrongPasswordWarning.gameObject.SetActive(false);
            usernameInput.text = api.GetMe().username;
            passwordInput.text = "";
        };

        api.OnConnected += () => {
            Task.Run(async() => {
                for (; ;)
                {
                    await Task.Delay(400);
                    api.Ping();
                }
            });
        };

        api.OnDisconnected += () => {
            GameObject.Find("LoggedInStatus").GetComponent <Text>().text = "Disconnected, trying to relogin";
        };

        api.OnPing += (int ping) => {
            pingText.text = "Ping: " + ping + "ms";
        };

        loginButton.onClick.AddListener(() => {
            api.Login(usernameInput.text, passwordInput.text);
        });

        api.OnLoginFail += () => {
            wrongPasswordWarning.gameObject.SetActive(true);
        };

        api.OnGameStart += () => {
            Debug.Log("New game started!");
        };

        api.OnOpponentCard += () => {
            Debug.Log("Opponent drew a card");
        };

        api.OnCard += (cardId) => {
            Card       card       = api.GetCard(cardId);
            GameObject cardObject = api.InstantiateWorldCard(cardId, cardHand);
            cardObject.transform.position = new Vector3(handIndex * 2, 0, 0) + cardObject.transform.position;
            handIndex++;
        };

        api.OnTurn += (attackingPlayer) => {
            string attackingPlayerName = "Opponent is";
            if (attackingPlayer == api.GetMe().id)
            {
                attackingPlayerName = "You are";
            }
            Debug.Log("New round (" + api.GetGame().round + ") starting! " + attackingPlayerName + " attacking!");
        };

        api.OnUpdate += () => {
            Game   game = api.GetGame();
            Player me   = api.GetPlayer();
            stats.text =
                "Mana: " + me.manaLeft + "/" + me.totalMana + "\n" +
                "Round: " + game.round + "\n" +
                "Attacking: " + (me.turn ? "You" : "Opponent") + "\n" +
                "Opponent cards: " + api.GetOpponent().cards.Length;
        };
    }