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>(); }
public void LoadFromJSON(string jsonString) { var jsonObject = JObject.Parse(jsonString); m_vId = jsonObject["avatar_id"].ToObject <long>(); m_vToken = jsonObject["token"].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 DataSlot(null, 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); } }
public void LoadFromJSON(string jsonString) { var jsonObject = JObject.Parse(jsonString); this.UserId = jsonObject["avatar_id"].ToObject <long>(); this.HighID = jsonObject["id_high_int"].ToObject <int>(); this.LowID = jsonObject["id_low_int"].ToObject <int>(); this.UserToken = jsonObject["token"].ToObject <string>(); this.Region = jsonObject["region"].ToObject <string>(); this.IPAddress = jsonObject["IPAddress"].ToObject <string>(); this.m_vAccountCreationDate = jsonObject["avatar_creation_date"].ToObject <DateTime>(); this.AccountPrivileges = jsonObject["avatar_privilages"].ToObject <byte>(); this.AccountBanned = jsonObject["avatar_banned"].ToObject <bool>(); this.m_vActiveLayout = jsonObject["active_layout"].ToObject <int>(); this.LastTickSaved = jsonObject["last_tick_save"].ToObject <DateTime>(); this.m_vAndroid = jsonObject["android"].ToObject <bool>(); this.CurrentHomeId = jsonObject["current_home_id"].ToObject <long>(); this.AllianceId = 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>()); this.AvatarName = jsonObject["avatar_name"].ToObject <string>(); this.m_vAvatarLevel = jsonObject["avatar_level"].ToObject <int>(); this.m_vExperience = jsonObject["experience"].ToObject <int>(); this.m_vCurrentGems = jsonObject["current_gems"].ToObject <int>(); SetScore(jsonObject["score"].ToObject <int>()); this.m_vNameChangingLeft = jsonObject["nameChangesLeft"].ToObject <byte>(); this.m_vnameChosenByUser = jsonObject["nameChosenByUser"].ToObject <byte>(); this.m_vShieldTime = jsonObject["shield_time"].ToObject <int>(); this.m_vProtectionTime = jsonObject["protection_time"].ToObject <int>(); this.FacebookId = jsonObject["fb_id"].ToObject <string>(); this.FacebookToken = jsonObject["fb_token"].ToObject <string>(); this.GoogleId = jsonObject["gg_id"].ToObject <string>(); this.m_vReceived = jsonObject["troops_received"].ToObject <int>(); this.m_vDonated = jsonObject["troops_donated"].ToObject <int>(); this.GoogleToken = jsonObject["gg_token"].ToObject <string>(); this.TroopRequestMessage = jsonObject["rq_message"].ToObject <string>(); JArray jsonBookmarkedClan = (JArray)jsonObject["bookmark"]; foreach (JObject jobject in jsonBookmarkedClan) { JObject data = (JObject)jobject; BookmarkSlot ds = new BookmarkSlot(0); ds.Load(data); BookmarkedClan.Add(ds); } JArray jsonResources = (JArray)jsonObject["resources"]; foreach (JObject resource in jsonResources) { DataSlot ds = new DataSlot(null, 0); ds.Load(resource); GetResources().Add(ds); } JArray jsonUnits = (JArray)jsonObject["units"]; foreach (JObject unit in jsonUnits) { DataSlot ds = new DataSlot(null, 0); ds.Load(unit); m_vUnitCount.Add(ds); } JArray jsonSpells = (JArray)jsonObject["spells"]; foreach (JObject spell in jsonSpells) { DataSlot ds = new DataSlot(null, 0); ds.Load(spell); m_vSpellCount.Add(ds); } JArray jsonUnitLevels = (JArray)jsonObject["unit_upgrade_levels"]; foreach (JObject unitLevel in jsonUnitLevels) { DataSlot ds = new DataSlot(null, 0); ds.Load(unitLevel); m_vUnitUpgradeLevel.Add(ds); } JArray jsonSpellLevels = (JArray)jsonObject["spell_upgrade_levels"]; foreach (JObject data in jsonSpellLevels) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); m_vSpellUpgradeLevel.Add(ds); } JArray jsonHeroLevels = (JArray)jsonObject["hero_upgrade_levels"]; foreach (JObject data in jsonHeroLevels) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); m_vHeroUpgradeLevel.Add(ds); } JArray jsonHeroHealth = (JArray)jsonObject["hero_health"]; foreach (JObject data in jsonHeroHealth) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); m_vHeroHealth.Add(ds); } JArray jsonHeroState = (JArray)jsonObject["hero_state"]; foreach (JObject data in jsonHeroState) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); m_vHeroState.Add(ds); } JArray jsonAllianceUnits = (JArray)jsonObject["alliance_units"]; foreach (JObject data in jsonAllianceUnits) { DonationSlot ds = new DonationSlot(0, 0, 0, 0); ds.Load(data); AllianceUnits.Add(ds); } TutorialStepsCount = jsonObject["tutorial_step"].ToObject <uint>(); JArray jsonAchievementsProgress = (JArray)jsonObject["achievements_progress"]; foreach (JObject data in jsonAchievementsProgress) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); Achievements.Add(ds); } JArray jsonNpcStars = (JArray)jsonObject["npc_stars"]; foreach (JObject data in jsonNpcStars) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); NpcStars.Add(ds); } JArray jsonNpcLootedGold = (JArray)jsonObject["npc_looted_gold"]; foreach (JObject data in jsonNpcLootedGold) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); NpcLootedGold.Add(ds); } JArray jsonNpcLootedElixir = (JArray)jsonObject["npc_looted_elixir"]; foreach (JObject data in jsonNpcLootedElixir) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); NpcLootedElixir.Add(ds); } JArray jsonQuickTrain1 = (JArray)jsonObject["quick_train_1"]; foreach (JObject data in jsonQuickTrain1) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); QuickTrain1.Add(ds); } JArray jsonQuickTrain2 = (JArray)jsonObject["quick_train_2"]; foreach (JObject data in jsonQuickTrain2) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); QuickTrain2.Add(ds); } JArray jsonQuickTrain3 = (JArray)jsonObject["quick_train_3"]; foreach (JObject data in jsonQuickTrain3) { DataSlot ds = new DataSlot(null, 0); ds.Load(data); QuickTrain3.Add(ds); } m_vPremium = jsonObject["Premium"].ToObject <bool>(); }