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

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

        // Make the toyx
        toyxId = id;
        toyx   = new Toyx(id);

        toyx.CreateSessionInBackground(delegate(TwinSpriteError error) {
            if (error != null)
            {
                infoMessage += "Error creating session: " + error.message + "\nError code: " + error.errorCode + "\n";
            }
            else
            {
                infoMessage += "Created session!!!\n";
            }

            if (createSessionDelegate != null)
            {
                createSessionDelegate.Invoke(error);
            }
        });
    }
예제 #2
0
    public void Get()
    {
        // Get toyx in background
        ToyxQuery.GetInBackground(toyxId, delegate(Toyx newToyx, TwinSpriteError error) {
            if (error != null)
            {
                infoMessage = "Error fetching: " + error.message + "\nError code: " + error.errorCode;
            }
            else
            {
                infoMessage = "Feched: " + toyx;
                toyx        = newToyx;
            }

            guiEnabled = true;
        });
    }
예제 #3
0
    public void CreateSession()
    {
        // Create session with toyx id
        CreateSessionRequest.CreateSessionInBackground(toyxId, delegate(Toyx newToyx, TwinSpriteError error) {
            if (error != null)
            {
                infoMessage = "Error creating session: " + error.message + "\nError code: " + error.errorCode;
            }
            else
            {
                infoMessage = "Created session!!!";
                toyx        = newToyx;
            }

            guiEnabled = true;
        });
    }
    public void CreateSession(string id, TwinSpriteDelegate createSessionDelegate)
    {
        // Make the toyx
        toyxId = id;
        toyx = new Toyx(id);

        toyx.CreateSessionInBackground(delegate(TwinSpriteError error) {
            if (error != null) {
                infoMessage += "Error creating session: "+error.message+"\nError code: " +error.errorCode+"\n";
            } else {
                infoMessage += "Created session!!!\n";
            }

            if (createSessionDelegate != null) {
                createSessionDelegate.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;
                                                }
                                        }
                                });
                        }
                });
    }
예제 #6
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");
        }
    }
    private Player GetPlayer(Toyx toyx)
    {
        Player player = new Player ();
                player.Model = toyx.GetToyxSnapshot ().GetToyxModel ().GetId ();
                Debug.Log ("modlel.id:" + player.Model);
                player.Health = toyx.GetInt (MainConstants.HEALTH_TOYX_ATTR);
                Debug.Log ("health:" + player.Health.ToString ());
                player.Strength = toyx.GetInt (MainConstants.STRENGTH_TOYX_ATTR);
                Debug.Log ("strength:" + player.Strength);
                string abilitiesAsStr = toyx.GetString (MainConstants.ABILITIES_TOYX_ATTR);
                Debug.Log ("abilities:" + abilitiesAsStr);
                abilitiesAsStr = abilitiesAsStr.Replace (" ", "");
                string[] abilityKeys = abilitiesAsStr.Split (',');

                foreach (string key in abilityKeys) {
                        Ability ability = new Ability ();
                        ability.Name = toyx.GetString (MainConstants.ABILITIES_TOYX_ATTR + MainConstants.ABILITIES_FIELD_DELIMITER + key + MainConstants.ABILITIES_FIELD_DELIMITER + MainConstants.NAME_SUFFIX_TOYX_ATTR);
                        ability.Value = toyx.GetInt (MainConstants.ABILITIES_TOYX_ATTR + MainConstants.ABILITIES_FIELD_DELIMITER + key + MainConstants.ABILITIES_FIELD_DELIMITER + MainConstants.VALUE_SUFFIX_TOYX_ATTR);
                        ability.Count = toyx.GetInt (MainConstants.ABILITIES_TOYX_ATTR + MainConstants.ABILITIES_FIELD_DELIMITER + key + MainConstants.ABILITIES_FIELD_DELIMITER + MainConstants.COUNT_SUFFIX_TOYX_ATTR);
                        player.AbilityKeys.Add (key);
                        player.Abilities.Add (key, ability);
                }

                return player;
    }