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

            m_vAllianceId        = jsonObject["alliance_id"].ToObject <long>();
            m_vAllianceName      = jsonObject["alliance_name"].ToObject <string>();
            m_vAllianceBadgeData = jsonObject["alliance_badge"].ToObject <int>();
            m_vAllianceType      = jsonObject["alliance_type"].ToObject <int>();
            if (jsonObject["required_score"] != null)
            {
                m_vRequiredScore = jsonObject["required_score"].ToObject <int>();
            }
            // m_vScore = jsonObject["score"].ToObject<int>();
            m_vAllianceDescription = jsonObject["description"].ToObject <string>();
            m_vAllianceExperience  = jsonObject["alliance_experience"].ToObject <int>();
            m_vAllianceLevel       = jsonObject["alliance_level"].ToObject <int>();
            if (jsonObject["won_wars"] != null)
            {
                m_vWonWars = jsonObject["won_wars"].ToObject <int>();
            }
            if (jsonObject["lost_wars"] != null)
            {
                m_vLostWars = jsonObject["lost_wars"].ToObject <int>();
            }
            if (jsonObject["draw_wars"] != null)
            {
                m_vDrawWars = jsonObject["draw_wars"].ToObject <int>();
            }
            if (jsonObject["war_frequency"] != null)
            {
                m_vWarFrequency = jsonObject["war_frequency"].ToObject <int>();
            }
            if (jsonObject["alliance_origin"] != null)
            {
                m_vAllianceOrigin = jsonObject["alliance_origin"].ToObject <int>();
            }

            var jsonMembers = (JArray)jsonObject["members"];

            foreach (JObject jsonMember in jsonMembers)
            {
                var id     = jsonMember["avatar_id"].ToObject <long>();
                var token  = UCS.Core.ResourcesManager.GetPlayer(id).GetPlayerAvatar().GetUserToken();
                var member = new AllianceMemberEntry(id);
                var scorem = new Level(id, token);
                m_vScore = m_vScore + scorem.GetPlayerAvatar().GetScore();
                member.Load(jsonMember);
                m_vAllianceMembers.Add(id, member);
            }
            m_vScore = m_vScore / 2;

            var jsonMessages = (JArray)jsonObject["chatMessages"];

            if (jsonMessages != null)
            {
                foreach (JObject jsonMessage in jsonMessages)
                {
                    var se = new StreamEntry();
                    switch (jsonMessage["type"].ToObject <int>())
                    {
                    case 1:
                        se = new TroopRequestStreamEntry();
                        break;

                    case 2:
                        se = new ChatStreamEntry();
                        break;

                    case 3:
                        se = new InvitationStreamEntry();
                        break;

                    case 4:
                        se = new AllianceEventStreamEntry();
                        break;

                    case 5:
                        se = new ShareStreamEntry();
                        break;
                    }
                    se.Load(jsonMessage);
                    m_vChatMessages.Add(se);
                }
            }
        }
示例#2
0
        public void LoadFromJSON(string jsonString)
        {
            JObject jObject = JObject.Parse(jsonString);

            this.m_vAllianceId        = jObject["alliance_id"].ToObject <long>();
            this.m_vAllianceName      = jObject["alliance_name"].ToObject <string>();
            this.m_vAllianceBadgeData = jObject["alliance_badge"].ToObject <int>();
            this.m_vAllianceType      = jObject["alliance_type"].ToObject <int>();
            if (jObject["required_score"] != null)
            {
                this.m_vRequiredScore = jObject["required_score"].ToObject <int>();
            }
            this.m_vAllianceDescription = jObject["description"].ToObject <string>();
            this.m_vAllianceExperience  = jObject["alliance_experience"].ToObject <int>();
            this.m_vAllianceLevel       = jObject["alliance_level"].ToObject <int>();
            if (jObject["won_wars"] != null)
            {
                this.m_vWonWars = jObject["won_wars"].ToObject <int>();
            }
            if (jObject["lost_wars"] != null)
            {
                this.m_vLostWars = jObject["lost_wars"].ToObject <int>();
            }
            if (jObject["draw_wars"] != null)
            {
                this.m_vDrawWars = jObject["draw_wars"].ToObject <int>();
            }
            if (jObject["war_frequency"] != null)
            {
                this.m_vWarFrequency = jObject["war_frequency"].ToObject <int>();
            }
            if (jObject["alliance_origin"] != null)
            {
                this.m_vAllianceOrigin = jObject["alliance_origin"].ToObject <int>();
            }
            using (IEnumerator <JToken> enumerator = ((JArray)jObject["members"]).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    JObject             jObject2            = (JObject)enumerator.Current;
                    long                num                 = jObject2["avatar_id"].ToObject <long>();
                    AllianceMemberEntry allianceMemberEntry = new AllianceMemberEntry(num);
                    Level               level               = new Level(num);
                    this.m_vScore += level.GetPlayerAvatar().GetScore();
                    allianceMemberEntry.Load(jObject2);
                    this.m_vAllianceMembers.Add(num, allianceMemberEntry);
                }
            }
            this.m_vScore /= 2;
            JArray jArray = (JArray)jObject["chatMessages"];

            if (jArray != null)
            {
                using (IEnumerator <JToken> enumerator = jArray.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        JObject     jObject3    = (JObject)enumerator.Current;
                        StreamEntry streamEntry = new StreamEntry();
                        switch (jObject3["type"].ToObject <int>())
                        {
                        case 1:
                            streamEntry = new TroopRequestStreamEntry();
                            break;

                        case 2:
                            streamEntry = new ChatStreamEntry();
                            break;

                        case 3:
                            streamEntry = new InvitationStreamEntry();
                            break;

                        case 4:
                            streamEntry = new AllianceEventStreamEntry();
                            break;

                        case 5:
                            streamEntry = new ShareStreamEntry();
                            break;
                        }
                        streamEntry.Load(jObject3);
                        this.m_vChatMessages.Add(streamEntry);
                    }
                }
            }
        }