Ejemplo n.º 1
0
        public override void Load(JObject jsonObject)
        {
            ID              = jsonObject["rid"].ToObject <int>();
            m_vMaxTroop     = jsonObject["max_troops"].ToObject <int>();
            m_vMaxSpell     = jsonObject["max_spells"].ToObject <int>();
            m_vDonatedTroop = jsonObject["donated_troops"].ToObject <int>();
            m_vDonatedSpell = jsonObject["donated_spell"].ToObject <int>();
            JArray jsonDonaterID = (JArray)jsonObject["donater_list"];

            foreach (JToken jToken in jsonDonaterID)
            {
                JObject      data = (JObject)jToken;
                BookmarkSlot di   = new BookmarkSlot(0);
                di.Load(data);
                m_vDonatorList.Add(di);
            }
            JArray jsonDonatedUnit = (JArray)jsonObject["donated_unit"];

            foreach (JToken jToken in jsonDonatedUnit)
            {
                JObject      data = (JObject)jToken;
                DonationSlot ds   = new DonationSlot(0, 0, 0, 0);
                ds.Load(data);
                m_vUnitDonation.Add(ds);
            }
            m_vMessage = jsonObject["message"].ToObject <string>();
        }
Ejemplo n.º 2
0
 public override void Load(JObject jsonObject)
 {
     base.Load(jsonObject);
     ID              = jsonObject["rid"].ToObject <int>();
     m_vMaxTroop     = jsonObject["max_troops"].ToObject <int>();
     m_vMaxSpell     = jsonObject["max_spells"].ToObject <int>();
     m_vDonatedTroop = jsonObject["donated_troops"].ToObject <int>();
     m_vDonatedSpell = jsonObject["donated_spell"].ToObject <int>();
     using (IEnumerator <JToken> enumerator = ((JArray)jsonObject["donater_list"]).GetEnumerator())
     {
         while (((IEnumerator)enumerator).MoveNext())
         {
             JObject      current      = (JObject)enumerator.Current;
             BookmarkSlot bookmarkSlot = new BookmarkSlot(0L);
             bookmarkSlot.Load(current);
             this.m_vDonatorList.Add(bookmarkSlot);
         }
     }
     using (IEnumerator <JToken> enumerator = ((JArray)jsonObject["donated_unit"]).GetEnumerator())
     {
         while (((IEnumerator)enumerator).MoveNext())
         {
             JObject      current      = (JObject)enumerator.Current;
             DonationSlot donationSlot = new DonationSlot(0L, 0, 0, 0);
             donationSlot.Load(current);
             this.m_vUnitDonation.Add(donationSlot);
         }
     }
     m_vMessage = jsonObject["message"].ToObject <string>();
 }
Ejemplo n.º 3
0
        public override byte[] Encode()
        {
            var data = new List <byte>();

            data.AddRange(((IEnumerable <byte>)base.Encode()));
            data.AddInt32(ID);
            data.AddInt32(m_vMaxTroop);
            data.AddInt32(m_vMaxSpell);
            data.AddInt32(m_vDonatedTroop);
            data.AddInt32(m_vDonatedSpell);
            data.AddInt32(m_vDonatorList.Count);
            for (int index1 = 0; index1 < m_vDonatorList.Count; index1++)
            {
                foreach (DonationSlot donationSlot1 in m_vUnitDonation)
                {
                    DonationSlot i             = donationSlot1;
                    DonationSlot donationSlot2 = m_vUnitDonation.Find((Predicate <DonationSlot>)(t =>
                    {
                        if (t.DonatorID == i.DonatorID)
                        {
                            return(t.UnitLevel == i.UnitLevel);
                        }
                        return(false);
                    }));
                    data.AddInt64(donationSlot2.DonatorID);
                    data.AddInt32(donationSlot2.Count);

                    for (int index2 = 0; index2 < i.Count - 1; ++index2)
                    {
                        data.AddInt32(donationSlot2.ID);
                        data.AddInt32(donationSlot2.UnitLevel - 1);
                    }
                    data.AddInt32(donationSlot2.ID);
                    data.AddInt32(donationSlot2.UnitLevel);
                }
            }
            if (string.IsNullOrEmpty(m_vMessage))
            {
                data.Add((byte)0);
            }
            else
            {
                data.Add((byte)1);
                data.AddString(m_vMessage);
            }
            data.AddInt32(m_vUnitDonation.Count);
            foreach (DonationSlot donationSlot in m_vUnitDonation)
            {
                data.AddInt32(donationSlot.ID);
                data.AddInt32(donationSlot.Count);
                data.AddInt32(donationSlot.UnitLevel);
            }
            return(data.ToArray());
        }
Ejemplo n.º 4
0
        public void AddDonatedTroop(long did, int id, int value, int level)
        {
            DonationSlot e = m_vUnitDonation.Find(t => t.ID == id && t.UnitLevel == level);

            if (e != null)
            {
                int i = m_vUnitDonation.IndexOf(e);
                e.Count            = e.Count + value;
                m_vUnitDonation[i] = e;
            }
            else
            {
                DonationSlot ds = new DonationSlot(did, id, value, level);
                m_vUnitDonation.Add(ds);
            }
        }
Ejemplo n.º 5
0
        public void AddAllianceTroop(long did, int id, int value, int level)
        {
            DonationSlot e = AllianceUnits.Find(t => t.ID == id && t.DonatorID == did && t.UnitLevel == level);

            if (e != null)
            {
                int i = AllianceUnits.IndexOf(e);
                e.Count          = e.Count + value;
                AllianceUnits[i] = e;
            }
            else
            {
                DonationSlot ds = new DonationSlot(did, id, value, level);
                AllianceUnits.Add(ds);
            }
        }
Ejemplo n.º 6
0
        public override byte[] Encode()
        {
            List <byte> data = new List <byte>();

            data.AddRange(base.Encode());
            data.AddInt32(ID);              // ID
            data.AddInt32(m_vMaxTroop);     // Max Troops
            data.AddInt32(m_vMaxSpell);     // Max Spells
            data.AddInt32(m_vDonatedTroop); // Donated Troops
            data.AddInt32(m_vDonatedSpell); // Donated Spells
            data.AddInt32(m_vDonatorList.Count);
            for (int d = 0; d < m_vDonatorList.Count; d++)
            {
                foreach (DonationSlot i in m_vUnitDonation) // Components
                {
                    DonationSlot tp = m_vUnitDonation.Find(t => t.DonatorID == i.DonatorID && t.UnitLevel == i.UnitLevel);
                    data.AddInt64(tp.DonatorID);
                    data.AddInt32(tp.Count);
                    for (int a = 0; a < i.Count - 1; a++)
                    {
                        data.AddInt32(tp.ID);
                        data.AddInt32(tp.UnitLevel - 1);
                    }
                    data.AddInt32(tp.ID);
                    data.AddInt32(tp.UnitLevel);
                }
            }
            if (string.IsNullOrEmpty(m_vMessage))
            {
                data.Add(0);
            }
            else
            {
                data.Add(1);
                data.AddString(m_vMessage);
            }
            data.AddInt32(m_vUnitDonation.Count);       // Components Count
            foreach (DonationSlot i in m_vUnitDonation) // Components
            {
                data.AddInt32(i.ID);
                data.AddInt32(i.Count);
                data.AddInt32(i.UnitLevel);
            }
            return(data.ToArray());
        }
Ejemplo n.º 7
0
        public void AddDonatedTroop(long did, int id, int value, int level)
        {
            m_vDonatedTroop = m_vDonatedTroop + ((CombatItemData)CSVManager.DataTables.GetDataById(id)).GetHousingSpace();
            DonationSlot e = m_vUnitDonation.Find(t => t.ID == id && t.UnitLevel == level);

            if (e != null)
            {
                // Troops already exist.
                int i = m_vUnitDonation.IndexOf(e);
                e.Count            = e.Count + value;
                m_vUnitDonation[i] = e;
            }
            else
            {
                DonationSlot ds = new DonationSlot(did, id, value, level);
                m_vUnitDonation.Add(ds);
            }
        }
Ejemplo n.º 8
0
        public void AddDonatedTroop(long did, int id, int value, int level)
        {
            DonationSlot donationSlot = m_vUnitDonation.Find((Predicate <DonationSlot>)(t =>
            {
                if (t.ID == id)
                {
                    return(t.UnitLevel == level);
                }
                return(false);
            }));

            if (donationSlot != null)
            {
                int index = m_vUnitDonation.IndexOf(donationSlot);
                donationSlot.Count          = donationSlot.Count + value;
                this.m_vUnitDonation[index] = donationSlot;
            }
            else
            {
                this.m_vUnitDonation.Add(new DonationSlot(did, id, value, level));
            }
        }
Ejemplo n.º 9
0
        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>();
        }