Beispiel #1
0
 public void AddChatMessage(StreamEntry.StreamEntry message)
 {
     while (m_vChatMessages.Count >= m_vMaxChatMessagesNumber)
     {
         m_vChatMessages.RemoveAt(0);
     }
     m_vChatMessages.Add(message);
 }
        public void AddChatMessage(UCS.Logic.StreamEntry.StreamEntry message)
        {
            if (this.m_vChatMessages.Count >= 30)
            {
                this.m_vChatMessages.RemoveAt(0);
            }

            this.m_vChatMessages.Add(message);
        }
Beispiel #3
0
        public override void Execute(Level level)
        {
            ChallangeCommand challangeCommand = this;

            try
            {
                ClientAvatar         player   = level.GetPlayerAvatar();
                Alliance             alliance = ObjectManager.GetAlliance(player.GetAllianceId());
                ChallengeStreamEntry cm       = new ChallengeStreamEntry();
                cm.SetMessage(challangeCommand.Message);
                cm.SetSenderId(player.GetId());
                cm.SetSenderName(player.GetAvatarName());
                cm.SetSenderLevel(player.GetAvatarLevel());
                ChallengeStreamEntry challengeStreamEntry = cm;
                int allianceRole = player.GetAllianceRole();
                challengeStreamEntry.SetSenderRole(allianceRole);
                challengeStreamEntry = (ChallengeStreamEntry)null;
                cm.SetId(alliance.GetChatMessages().Count + 1);
                cm.SetSenderLeagueId(player.GetLeagueId());
                alliance.AddChatMessage((UCS.Logic.StreamEntry.StreamEntry)cm);
                UCS.Logic.StreamEntry.StreamEntry      s = alliance.GetChatMessages().Find((Predicate <UCS.Logic.StreamEntry.StreamEntry>)(c => c.GetStreamEntryType() == 12));
                List <AllianceMemberEntry> .Enumerator enumerator;
                if (s != null)
                {
                    alliance.GetChatMessages().RemoveAll((Predicate <UCS.Logic.StreamEntry.StreamEntry>)(t => t == s));
                    foreach (AllianceMemberEntry allianceMember in alliance.GetAllianceMembers())
                    {
                        Level player1 = ResourcesManager.GetPlayer(allianceMember.GetAvatarId(), false);
                        if (player1.GetClient() != null)
                        {
                            new AllianceStreamEntryRemovedMessage(player1.GetClient(), s.GetId()).Send();
                        }
                    }
                    enumerator = new List <AllianceMemberEntry> .Enumerator();
                }
                foreach (AllianceMemberEntry allianceMember in alliance.GetAllianceMembers())
                {
                    Level player1 = ResourcesManager.GetPlayer(allianceMember.GetAvatarId(), false);
                    if (player1.GetClient() != null)
                    {
                        AllianceStreamEntryMessage Message = new AllianceStreamEntryMessage(player1.GetClient());
                        ChallengeStreamEntry       challengeStreamEntry1 = cm;
                        Message.SetStreamEntry((UCS.Logic.StreamEntry.StreamEntry)challengeStreamEntry1);
                        Message.Send();
                    }
                }
                enumerator = new List <AllianceMemberEntry> .Enumerator();

                player   = (ClientAvatar)null;
                alliance = (Alliance)null;
                cm       = (ChallengeStreamEntry)null;
            }
            catch (Exception ex)
            {
            }
        }
        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>();
            m_vRequiredScore       = jsonObject["required_score"].ToObject <int>();
            m_vAllianceDescription = jsonObject["description"].ToObject <string>();
            m_vAllianceExperience  = jsonObject["alliance_experience"].ToObject <int>();
            m_vAllianceLevel       = jsonObject["alliance_level"].ToObject <int>();
            m_vWarLogPublic        = jsonObject["war_log_public"].ToObject <byte>();
            m_vFriendlyWar         = jsonObject["friendly_war"].ToObject <byte>();
            m_vWonWars             = jsonObject["won_wars"].ToObject <int>();
            m_vLostWars            = jsonObject["lost_wars"].ToObject <int>();
            m_vDrawWars            = jsonObject["draw_wars"].ToObject <int>();
            m_vWarFrequency        = jsonObject["war_frequency"].ToObject <int>();
            m_vAllianceOrigin      = jsonObject["alliance_origin"].ToObject <int>();

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

            foreach (var jToken in jsonMembers)
            {
                var jsonMember = (JObject)jToken;

                var id     = jsonMember["avatar_id"].ToObject <long>();
                var player = ResourcesManager.GetPlayer(id);
                var member = new AllianceMemberEntry(id);

                m_vScore = m_vScore + player.GetPlayerAvatar().GetScore();

                member.Load(jsonMember);
                m_vAllianceMembers.Add(id, member);
            }
            m_vScore = m_vScore / 2;

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

            if (jsonMessages != null)
            {
                foreach (JToken jToken in jsonMessages)
                {
                    JObject jsonMessage        = (JObject)jToken;
                    StreamEntry.StreamEntry se = new StreamEntry.StreamEntry();
                    if (jsonMessage["type"].ToObject <int>() == 1)
                    {
                        se = new TroopRequestStreamEntry();
                    }
                    else if (jsonMessage["type"].ToObject <int>() == 2)
                    {
                        se = new ChatStreamEntry();
                    }
                    else if (jsonMessage["type"].ToObject <int>() == 3)
                    {
                        se = new InvitationStreamEntry();
                    }
                    else if (jsonMessage["type"].ToObject <int>() == 4)
                    {
                        se = new AllianceEventStreamEntry();
                    }
                    else if (jsonMessage["type"].ToObject <int>() == 5)
                    {
                        se = new ShareStreamEntry();
                    }
                    se.Load(jsonMessage);
                    m_vChatMessages.Add(se);
                }
            }
        }
Beispiel #5
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>();
            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>();
            m_vWonWars             = jsonObject["won_wars"].ToObject <int>();
            m_vLostWars            = jsonObject["lost_wars"].ToObject <int>();
            m_vDrawWars            = jsonObject["draw_wars"].ToObject <int>();
            m_vWarFrequency        = jsonObject["war_frequency"].ToObject <int>();
            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 pl     = ResourcesManager.GetPlayer(id);
                var member = new AllianceMemberEntry(id);
                m_vScore = m_vScore + pl.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.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);
                }
            }
        }