예제 #1
0
    public void Fetch(TwinSpriteDelegate fetchDelegate)
    {
        // If no id, do nothing
        if (toyxId == null || toyxId.Length == 0)
        {
            Debug.Log("No toyxID, playing without toyx.");

            if (fetchDelegate != null)
            {
                fetchDelegate.Invoke(null);
            }
            return;
        }


        // No toyx, create session before
        if (toyx == null)
        {
            infoMessage += "Can't fetching, create session before.\n";
            return;
        }


        toyx.FetchInBackground(delegate(TwinSpriteError error) {
            if (error != null)
            {
                infoMessage += "Error fetching: " + error.message + "\nError code: " + error.errorCode + "\n";
            }
            else
            {
                infoMessage += "Feched: " + toyx + "\n";

                // Fill properties
                experience = toyx.GetInt(EXPERIENCE);
                gold       = toyx.GetInt(GOLD);
                level      = toyx.GetInt(LEVEL);
                weapon     = (WeaponType)toyx.GetInt(WEAPON);
            }

            if (fetchDelegate != null)
            {
                fetchDelegate.Invoke(error);
            }
        });
    }
    public void LoadPlayer(string toyxId, int player)
    {
        Debug.Log ("Creating P" + player + " session");

                Toyx toyx = new Toyx (toyxId);

                if (player == 1) {
                        _player1Loaded = false;
                        _player1Toyx = toyx;
                } else {
                        _player2Loaded = false;
                        _player2Toyx = toyx;
                }

                IntroGUIManager.Instance.ShowLoading ();

                toyx.CreateSessionInBackground (delegate(TwinSpriteError sessionError) {
                        if (sessionError != null) {
                                Debug.LogError ("Error creating P" + player + " session: " + sessionError.message);
                                _loadError = true;
                        } else {
                                Debug.Log ("P" + player + " session created successfully");
                                Debug.Log ("Fetching P" + player + " data");
                                toyx.FetchInBackground (delegate(TwinSpriteError fetchError) {
                                        if (fetchError != null) {
                                                Debug.LogError ("Error fetching P" + player + " data: " + fetchError.message);
                                                _loadError = true;
                                        } else {
                                                Debug.Log ("P" + player + " fetched successfully");
                                                if (player == 1) {
                                                        _player1Loaded = true;
                                                } else {
                                                        _player2Loaded = true;
                                                }
                                        }
                                });
                        }
                });
    }
예제 #3
0
    private void ParseToyx(string toyxId)
    {
        // If no id, do nothing
        if (toyxId == null || toyxId.Length == 0)
        {
            // remove spinner
            loadingBackground.SetActive(false);
            return;
        }


        if (Utils.HasInternetConnection())
        {
            //Fetch from internet
            // Make the toyx
            Toyx toyx = new Toyx(toyxId);

            toyx.CreateSessionInBackground(delegate(TwinSpriteError error1) {
                if (error1 != null)
                {
                    ShowPopup("Error creating session: " + error1.message + "\nError code: " + error1.errorCode);
                }
                else
                {
                    Debug.Log("Created session!!! now fetch it");

                    toyx.FetchInBackground(delegate(TwinSpriteError error2) {
                        if (error2 != null)
                        {
                            ShowPopup("Error fetching: " + error2.message + "\nError code: " + error2.errorCode);
                        }
                        else
                        {
                            Debug.Log("Fetched: " + toyx);

                            long modelID = toyx.GetToyxSnapshot().GetToyxModel().GetId();
                            int charges  = 0;
                            switch (modelID)
                            {
                            case FIREWAVE_MODEL_ID:
                                loadingBackground.SetActive(false); // remove spinner
                                charges = toyx.GetInt(SPECIAL_ATTACK_USES_ATTRIB);
                                UnlockSpecialButton(0, true, charges);
                                break;

                            case EARTHQUAKE_MODEL_ID:
                                loadingBackground.SetActive(false); // remove spinner
                                charges = toyx.GetInt(SPECIAL_ATTACK_USES_ATTRIB);
                                UnlockSpecialButton(1, true, charges);
                                break;

                            default:
                                ShowPopup("Toyx Model not compatible with bossfight powers");
                                break;
                            }
                        }
                    });
                }
            });
        }
        else
        {
            ShowPopup("Toyx Model not compatible with bossfight powers");
        }
    }