コード例 #1
0
    public void FetchIfNeeded(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.FetchIfNeededInBackground(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);
            }
        });
    }
コード例 #2
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");
        }
    }
コード例 #3
0
    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;
    }