//00 00 02 24 20 41 6A 6B 00 00 00 01 00 00 02 1F 
        //00 00 00 17 00 9E 81 01 
        //01 
        //00 00 00 33
        //44 C3 A9 73 6F 6C C3 A9 2C 20 6E 6F 75 73 20 61 76 6F 6E 73 20 64 C3 A9 63 69 64 C3 A9 20 64 65 20 74 27 65 78 63 6C 75 72 65 20 64 75 20 63 6C 61 6E 2E 
        //00 00 01 E6

        public override void Execute(Level level)
        {
            Level targetAccount = ResourcesManager.GetPlayer(m_vAvatarId, true);
            if(targetAccount != null)
            {
                var targetAvatar = targetAccount.GetPlayerAvatar();
                var targetAllianceId = targetAvatar.GetAllianceId();
                var requesterAvatar = level.GetPlayerAvatar();
                var requesterAllianceId = requesterAvatar.GetAllianceId();
                if (requesterAllianceId > 0 && targetAllianceId == requesterAllianceId)
                {
                    Alliance alliance = ObjectManager.GetAlliance(requesterAllianceId);
                    var requesterMember = alliance.GetAllianceMember(requesterAvatar.GetId());
                    var targetMember = alliance.GetAllianceMember(m_vAvatarId);
                    if(targetMember.HasLowerRoleThan(requesterMember.GetRole()))
                    {
                        targetAvatar.SetAllianceId(0);
                        alliance.RemoveMember(m_vAvatarId);
                        //Now sending messages
                        if (ResourcesManager.IsPlayerOnline(targetAccount))
                        {
                            var leaveAllianceCommand = new LeaveAllianceCommand();
                            leaveAllianceCommand.SetAlliance(alliance);
                            leaveAllianceCommand.SetReason(2);//kick
                            var availableServerCommandMessage = new AvailableServerCommandMessage(targetAccount.GetClient());
                            availableServerCommandMessage.SetCommandId(2);
                            availableServerCommandMessage.SetCommand(leaveAllianceCommand);
                            PacketManager.ProcessOutgoingPacket(availableServerCommandMessage);

                            AllianceKickOutStreamEntry kickOutStreamEntry = new AllianceKickOutStreamEntry();
                            kickOutStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                            kickOutStreamEntry.SetAvatar(requesterAvatar);
                            kickOutStreamEntry.SetIsNew(0);
                            kickOutStreamEntry.SetAllianceId(alliance.GetAllianceId());
                            kickOutStreamEntry.SetAllianceBadgeData(alliance.GetAllianceBadgeData());
                            kickOutStreamEntry.SetAllianceName(alliance.GetAllianceName());
                            kickOutStreamEntry.SetMessage(m_vMessage);
                            var p = new AvatarStreamEntryMessage(targetAccount.GetClient());
                            p.SetAvatarStreamEntry(kickOutStreamEntry);
                            PacketManager.ProcessOutgoingPacket(p);
                        }

                        AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry();
                        eventStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                        eventStreamEntry.SetAvatar(targetAvatar);
                        eventStreamEntry.SetEventType(1);
                        eventStreamEntry.SetAvatarId(requesterAvatar.GetId());
                        eventStreamEntry.SetAvatarName(requesterAvatar.GetAvatarName());

                        alliance.AddChatMessage(eventStreamEntry);

                        foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                        {
                            if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == requesterAllianceId)
                            {
                                var p = new AllianceStreamEntryMessage(onlinePlayer.GetClient());
                                p.SetStreamEntry(eventStreamEntry);
                                PacketManager.ProcessOutgoingPacket(p);
                            }
                        }
                    }
                }
            }
        }
示例#2
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 member = new AllianceMemberEntry(id);
                var scorem = new Level(id);
                m_vScore = m_vScore + scorem.GetPlayerAvatar().GetScore();
                member.Load(jsonMember);
                m_vAllianceMembers.Add(id, member);
            }

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

                        case 2:
                            se = new ChatStreamEntry();
                            break;
                    }
                    se.Load(jsonMessage);
                    m_vChatMessages.Add(se);
                }
            }
        }
示例#3
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  = jsonMember["token"].ToObject <string>();
                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);
                }
            }
        }