示例#1
0
        public void LoadFromJSON(string jsonString)
        {
            var jsonObject = JObject.Parse(jsonString);

            m_vId            = jsonObject["avatar_id"].ToObject <long>();
            m_vToken         = jsonObject["token"].ToObject <string>();
            m_vRegion        = jsonObject["region"].ToObject <string>();
            m_vCurrentHomeId = jsonObject["current_home_id"].ToObject <long>();
            m_vAllianceId    = jsonObject["alliance_id"].ToObject <long>();
            SetAllianceCastleLevel(jsonObject["alliance_castle_level"].ToObject <int>());
            SetAllianceCastleTotalCapacity(jsonObject["alliance_castle_total_capacity"].ToObject <int>());
            SetAllianceCastleUsedCapacity(jsonObject["alliance_castle_used_capacity"].ToObject <int>());
            SetTownHallLevel(jsonObject["townhall_level"].ToObject <int>());
            m_vAvatarName  = jsonObject["avatar_name"].ToObject <string>();
            m_vAvatarLevel = jsonObject["avatar_level"].ToObject <int>();
            m_vExperience  = jsonObject["experience"].ToObject <int>();
            m_vCurrentGems = jsonObject["current_gems"].ToObject <int>();
            SetScore(jsonObject["score"].ToObject <int>());
            m_vNameChangingLeft = jsonObject["nameChangesLeft"].ToObject <byte>();
            m_vnameChosenByUser = jsonObject["nameChosenByUser"].ToObject <byte>();

            /*JArray jsonMaxResources = (JArray)jsonObject["max_resources"];
             * foreach (JObject resource in jsonMaxResources)
             * {
             *  var ds = new DataSlot(null, 0);
             *  ds.Load(resource);
             *  m_vResourceCaps.Add(ds);
             * }*/

            var jsonResources = (JArray)jsonObject["resources"];

            foreach (JObject resource in jsonResources)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(resource);
                GetResources().Add(ds);
            }

            var jsonUnits = (JArray)jsonObject["units"];

            foreach (JObject unit in jsonUnits)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(unit);
                m_vUnitCount.Add(ds);
            }

            var jsonSpells = (JArray)jsonObject["spells"];

            foreach (JObject spell in jsonSpells)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(spell);
                m_vSpellCount.Add(ds);
            }

            var jsonUnitLevels = (JArray)jsonObject["unit_upgrade_levels"];

            foreach (JObject unitLevel in jsonUnitLevels)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(unitLevel);
                m_vUnitUpgradeLevel.Add(ds);
            }

            var jsonSpellLevels = (JArray)jsonObject["spell_upgrade_levels"];

            foreach (JObject data in jsonSpellLevels)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                m_vSpellUpgradeLevel.Add(ds);
            }

            var jsonHeroLevels = (JArray)jsonObject["hero_upgrade_levels"];

            foreach (JObject data in jsonHeroLevels)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                m_vHeroUpgradeLevel.Add(ds);
            }

            var jsonHeroHealth = (JArray)jsonObject["hero_health"];

            foreach (JObject data in jsonHeroHealth)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                m_vHeroHealth.Add(ds);
            }

            var jsonHeroState = (JArray)jsonObject["hero_state"];

            foreach (JObject data in jsonHeroState)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                m_vHeroState.Add(ds);
            }

            var jsonAllianceUnits = (JArray)jsonObject["alliance_units"];

            foreach (JObject data in jsonAllianceUnits)
            {
                var ds = new TroopDataSlot(null, 0, 0);
                ds.Load(data);
                AllianceUnits.Add(ds);
            }
            TutorialStepsCount = jsonObject["tutorial_step"].ToObject <uint>();

            /*
             * JArray jsonUnlockedAchievements = (JArray)jsonObject["unlocked_achievements"];
             * foreach (JObject data in jsonUnlockedAchievements)
             * {
             *  var ds = new DataSlot(null, 0);
             *  ds.Load(data);
             *  AchievementsUnlocked.Add(ds);
             * }
             */

            var jsonAchievementsProgress = (JArray)jsonObject["achievements_progress"];

            foreach (JObject data in jsonAchievementsProgress)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                Achievements.Add(ds);
            }

            var jsonNpcStars = (JArray)jsonObject["npc_stars"];

            foreach (JObject data in jsonNpcStars)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                NpcStars.Add(ds);
            }

            var jsonNpcLootedGold = (JArray)jsonObject["npc_looted_gold"];

            foreach (JObject data in jsonNpcLootedGold)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                NpcLootedGold.Add(ds);
            }

            var jsonNpcLootedElixir = (JArray)jsonObject["npc_looted_elixir"];

            foreach (JObject data in jsonNpcLootedElixir)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                NpcLootedElixir.Add(ds);
            }
        }
示例#2
0
        public void LoadFromJson(string jsonString)
        {
            var jsonObject = JObject.Parse(jsonString);

            m_vId                  = jsonObject["avatar_id"].ToObject <long>();
            m_vHighInt             = jsonObject["id_high_int"].ToObject <int>();
            m_vLowInt              = jsonObject["id_low_int"].ToObject <int>();
            m_vToken               = jsonObject["token"].ToObject <string>();
            m_vRegion              = jsonObject["region"].ToObject <string>();
            m_vAccountCreationDate = jsonObject["avatar_creation_date"].ToObject <DateTime>();
            m_vActiveLayout        = jsonObject["active_layout"].ToObject <int>();
            m_vAndroid             = jsonObject["android"].ToObject <bool>();
            m_vCurrentHomeId       = jsonObject["current_home_id"].ToObject <long>();
            m_vAllianceId          = jsonObject["alliance_id"].ToObject <long>();
            SetAllianceCastleLevel(jsonObject["alliance_castle_level"].ToObject <int>());
            SetAllianceCastleTotalCapacity(jsonObject["alliance_castle_total_capacity"].ToObject <int>());
            SetAllianceCastleUsedCapacity(jsonObject["alliance_castle_used_capacity"].ToObject <int>());
            SetTownHallLevel(jsonObject["townhall_level"].ToObject <int>());
            m_vAvatarName  = jsonObject["avatar_name"].ToObject <string>();
            m_vAvatarLevel = jsonObject["avatar_level"].ToObject <int>();
            m_vExperience  = jsonObject["experience"].ToObject <int>();
            m_vCurrentGems = jsonObject["current_gems"].ToObject <int>();
            SetScore(jsonObject["score"].ToObject <int>());
            m_vNameChangingLeft = jsonObject["nameChangesLeft"].ToObject <byte>();
            m_vnameChosenByUser = jsonObject["nameChosenByUser"].ToObject <byte>();

            var jsonBookmarkedClan = (JArray)jsonObject["bookmark"];

            foreach (JObject jobject in jsonBookmarkedClan)
            {
                var data = (JObject)jobject;
                var ds   = new BookmarkSlot(0);
                ds.Load(data);
                BookmarkedClan.Add(ds);
            }

            var jsonResources = (JArray)jsonObject["resources"];

            foreach (JObject resource in jsonResources)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(resource);
                GetResources().Add(ds);
            }

            var jsonUnits = (JArray)jsonObject["units"];

            foreach (JObject unit in jsonUnits)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(unit);
                m_vUnitCount.Add(ds);
            }

            var jsonSpells = (JArray)jsonObject["spells"];

            foreach (JObject spell in jsonSpells)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(spell);
                m_vSpellCount.Add(ds);
            }

            var jsonUnitLevels = (JArray)jsonObject["unit_upgrade_levels"];

            foreach (JObject unitLevel in jsonUnitLevels)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(unitLevel);
                m_vUnitUpgradeLevel.Add(ds);
            }

            var jsonSpellLevels = (JArray)jsonObject["spell_upgrade_levels"];

            foreach (JObject data in jsonSpellLevels)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                m_vSpellUpgradeLevel.Add(ds);
            }

            var jsonHeroLevels = (JArray)jsonObject["hero_upgrade_levels"];

            foreach (JObject data in jsonHeroLevels)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                m_vHeroUpgradeLevel.Add(ds);
            }

            var jsonHeroHealth = (JArray)jsonObject["hero_health"];

            foreach (JObject data in jsonHeroHealth)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                m_vHeroHealth.Add(ds);
            }

            var jsonHeroState = (JArray)jsonObject["hero_state"];

            foreach (JObject data in jsonHeroState)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                m_vHeroState.Add(ds);
            }

            var jsonAllianceUnits = (JArray)jsonObject["alliance_units"];

            foreach (JObject data in jsonAllianceUnits)
            {
                var ds = new TroopDataSlot(null, 0, 0);
                ds.Load(data);
                AllianceUnits.Add(ds);
            }
            TutorialStepsCount = jsonObject["tutorial_step"].ToObject <uint>();

            var jsonAchievementsProgress = (JArray)jsonObject["achievements_progress"];

            foreach (JObject data in jsonAchievementsProgress)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                Achievements.Add(ds);
            }

            var jsonNpcStars = (JArray)jsonObject["npc_stars"];

            foreach (JObject data in jsonNpcStars)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                NpcStars.Add(ds);
            }

            var jsonNpcLootedGold = (JArray)jsonObject["npc_looted_gold"];

            foreach (JObject data in jsonNpcLootedGold)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                NpcLootedGold.Add(ds);
            }

            var jsonNpcLootedElixir = (JArray)jsonObject["npc_looted_elixir"];

            foreach (JObject data in jsonNpcLootedElixir)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                NpcLootedElixir.Add(ds);
            }
            var jsonQuickTrain1 = (JArray)jsonObject["quick_train_1"];

            foreach (JObject data in jsonQuickTrain1)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                QuickTrain1.Add(ds);
            }
            var jsonQuickTrain2 = (JArray)jsonObject["quick_train_2"];

            foreach (JObject data in jsonQuickTrain2)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                QuickTrain2.Add(ds);
            }
            var jsonQuickTrain3 = (JArray)jsonObject["quick_train_3"];

            foreach (JObject data in jsonQuickTrain3)
            {
                var ds = new DataSlot(null, 0);
                ds.Load(data);
                QuickTrain3.Add(ds);
            }
            m_vPremium = jsonObject["Premium"].ToObject <bool>();
        }