示例#1
0
        internal override async void Process()
        {
            try
            {
                var targetAccount = await ResourcesManager.GetPlayer(m_vAvatarId);

                if (targetAccount != null)
                {
                    var targetAvatar        = targetAccount.Avatar;
                    var targetAllianceId    = targetAvatar.AllianceId;
                    var requesterAvatar     = this.Device.Player.Avatar;
                    var requesterAllianceId = requesterAvatar.AllianceId;
                    if (requesterAllianceId > 0 && targetAllianceId == requesterAllianceId)
                    {
                        var alliance        = ObjectManager.GetAlliance(requesterAllianceId);
                        var requesterMember = alliance.m_vAllianceMembers[requesterAvatar.UserId];
                        var targetMember    = alliance.m_vAllianceMembers[m_vAvatarId];
                        if (targetMember.HasLowerRoleThan(requesterMember.Role))
                        {
                            targetAvatar.AllianceId = 0;
                            alliance.RemoveMember(m_vAvatarId);
                            if (ResourcesManager.IsPlayerOnline(targetAccount))
                            {
                                var leaveAllianceCommand = new LeavedAllianceCommand(this.Device);
                                leaveAllianceCommand.SetAlliance(alliance);
                                leaveAllianceCommand.SetReason(2); //Kick
                                new AvailableServerCommandMessage(targetAccount.Client, leaveAllianceCommand.Handle()).Send();

                                var kickOutStreamEntry = new AllianceKickOutStreamEntry();
                                kickOutStreamEntry.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                                kickOutStreamEntry.SetSender(requesterAvatar);
                                kickOutStreamEntry.IsNew = 2;
                                kickOutStreamEntry.SetAllianceId(alliance.m_vAllianceId);
                                kickOutStreamEntry.SetAllianceBadgeData(alliance.m_vAllianceBadgeData);
                                kickOutStreamEntry.SetAllianceName(alliance.m_vAllianceName);
                                kickOutStreamEntry.SetMessage(m_vMessage);

                                var p = new AvatarStreamEntryMessage(targetAccount.Client);
                                p.SetAvatarStreamEntry(kickOutStreamEntry);
                                p.Send();
                            }

                            var eventStreamEntry = new AllianceEventStreamEntry();
                            eventStreamEntry.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                            eventStreamEntry.SetSender(targetAvatar);
                            eventStreamEntry.m_vAvatarName = this.Device.Player.Avatar.AvatarName;
                            eventStreamEntry.EventType     = 1;
                            alliance.AddChatMessage(eventStreamEntry);

                            foreach (AllianceMemberEntry op in alliance.GetAllianceMembers())
                            {
                                Level alliancemembers = await ResourcesManager.GetPlayer(op.AvatarId);

                                if (alliancemembers.Client != null)
                                {
                                    new AllianceStreamEntryMessage(alliancemembers.Client)
                                    {
                                        StreamEntry = eventStreamEntry
                                    }.Send();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        internal override async void Process()
        {
            try
            {
                ClientAvatar avatar   = this.Device.Player.Avatar;
                Alliance     alliance = ObjectManager.GetAlliance(avatar.AllianceId);

                if (await avatar.GetAllianceRole() == 2 && alliance.GetAllianceMembers().Count > 1)
                {
                    List <AllianceMemberEntry> members = alliance.GetAllianceMembers();
                    foreach (AllianceMemberEntry player in members.Where(player => player.Role >= 3))
                    {
                        player.Role = 2;

                        if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.AvatarId)))
                        {
                            Level l = await ResourcesManager.GetPlayer(player.AvatarId);

                            AllianceRoleUpdateCommand c = new AllianceRoleUpdateCommand(l.Client);
                            c.SetAlliance(alliance);
                            c.SetRole(2);
                            c.Tick(l);

                            new AvailableServerCommandMessage(l.Client, c.Handle()).Send();
                        }
                        done = true;
                        break;
                    }
                    if (!done)
                    {
                        int    count = alliance.GetAllianceMembers().Count;
                        Random rnd   = new Random();
                        int    id    = rnd.Next(1, count);
                        while (id != this.Device.Player.Avatar.UserId)
                        {
                            id = rnd.Next(1, count);
                        }
                        int loop = 0;
                        foreach (AllianceMemberEntry player in members)
                        {
                            loop++;
                            if (loop == id)
                            {
                                player.Role = 2;
                                if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.AvatarId)))
                                {
                                    Level l2 = await ResourcesManager.GetPlayer(player.AvatarId);

                                    AllianceRoleUpdateCommand e = new AllianceRoleUpdateCommand(l2.Client);
                                    e.SetAlliance(alliance);
                                    e.SetRole(2);
                                    e.Tick(l2);

                                    new AvailableServerCommandMessage(l2.Client, e.Handle()).Send();
                                }
                                break;
                            }
                        }
                    }
                }
                LeavedAllianceCommand a = new LeavedAllianceCommand(this.Device);
                a.SetAlliance(alliance);
                a.SetReason(1);

                new AvailableServerCommandMessage(Device, a.Handle()).Send();

                alliance.RemoveMember(avatar.UserId);
                avatar.AllianceId = 0;

                if (alliance.GetAllianceMembers().Count > 0)
                {
                    AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry();
                    eventStreamEntry.ID = alliance.m_vChatMessages.Count + 1;
                    eventStreamEntry.SetSender(avatar);
                    eventStreamEntry.EventType = 4;
                    alliance.AddChatMessage(eventStreamEntry);
                    foreach (Level onlinePlayer in ResourcesManager.m_vOnlinePlayers)
                    {
                        if (onlinePlayer.Avatar.AllianceId == alliance.m_vAllianceId)
                        {
                            new AllianceStreamEntryMessage(onlinePlayer.Client)
                            {
                                StreamEntry = eventStreamEntry
                            }.Send();
                        }
                    }
                }
                else
                {
                    Resources.DatabaseManager.RemoveAlliance(alliance);
                }
                new LeaveAllianceOkMessage(Device, alliance).Send();
            } catch (Exception) { }
        }