Пример #1
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;
    }