예제 #1
0
        internal override void Handle()
        {
            Alliance alliance = Alliances.Get(this.Connection.Avatar.Alliance.Identifier);

            if (alliance != null)
            {
                AllianceMember member = alliance.Members.Find(m => m.Identifier == this.MemberID);
                AllianceMember sender = alliance.Members.Find(m => m.Identifier == this.Connection.Avatar.Identifier);

                alliance.AddEntry(new StreamEntry(member, sender, ChangeAllianceMemberRoleMessage.IsHigherRoleThan(this.Role, member.Role) ? StreamEntry.StreamEvent.Promoted : StreamEntry.StreamEvent.Demoted));
                member.Role = this.Role;

                if (this.Role == (int)Alliance.Role.Leader)
                {
                    sender.Role = (int)Alliance.Role.CoLeader;
                    alliance.AddEntry(new StreamEntry(sender, sender, StreamEntry.StreamEvent.Demoted));
                }

                Alliances.Save(alliance);

                new AvailableServerCommandMessage(this.Connection, new LogicChangeAllianceRoleCommand(this.Connection)
                {
                    Role = (Alliance.Role) this.Role
                }).Send();
            }
        }
예제 #2
0
        internal override void Handle()
        {
            Alliance alliance = Alliances.Get(this.AllianceID);

            if (alliance != null)
            {
                if (!alliance.Members.Contains(alliance.Members.Find(member => member.Identifier == this.Connection.Avatar.Identifier)))
                {
                    AllianceMember member = new AllianceMember(this.Connection.Avatar, Alliance.Role.Member);
                    alliance.Members.Add(member);

                    this.Connection.Avatar.ClanHighID = alliance.HighID;
                    this.Connection.Avatar.ClanLowID  = alliance.LowID;

                    this.Connection.Avatar.Save();

                    Alliances.Save(alliance);

                    new AvailableServerCommandMessage(this.Connection, new LogicChangeAllianceRoleCommand(this.Connection)
                    {
                        Role = Alliance.Role.Member
                    }).Send();

                    new AvailableServerCommandMessage(this.Connection, new LogicJoinAllianceCommand(this.Connection)).Send();

                    new AllianceStreamMessage(this.Connection).Send();
                    alliance.AddEntry(new StreamEntry(member, member, StreamEntry.StreamEvent.Joined));

                    this.Connection.Avatar.Save();
                }
            }
        }
예제 #3
0
        internal override void Handle()
        {
            LogicClientAvatar avatar   = this.Connection.Avatar;
            Alliance          alliance = avatar.Alliance;

            if (alliance != null)
            {
                AllianceMember member = alliance.Members.Find(m => m.Identifier == avatar.Identifier);

                avatar.ClanHighID = 0;
                avatar.ClanLowID  = 0;

                avatar.Save();

                if (alliance.Members.Size == 0)
                {
                    Alliances.Delete(alliance);
                }
                else
                {
                    if (member.Role == (int)Alliance.Role.Leader)
                    {
                        LeaveAllianceMessage.FindNewLeader(alliance, member);
                    }
                }

                new AvailableServerCommandMessage(this.Connection, new LogicLeaveAllianceCommand(this.Connection, alliance.Identifier)).Send();
                alliance.AddEntry(new StreamEntry(member, member, StreamEntry.StreamEvent.Left));

                alliance.Members.Remove(member);

                Alliances.Save(alliance);
            }
        }
예제 #4
0
        private static void FindNewLeader(Alliance alliance, AllianceMember member)
        {
            LogicClientAvatar avatar = Avatars.Get(member.Identifier);

            AllianceMember      newLeader = alliance.Members.Find(member => member.Role == (int)Alliance.Role.CoLeader);
            const Alliance.Role newRole   = Alliance.Role.Leader;

            if (newLeader != null)
            {
                newLeader.Role = (int)newRole;
            }
            else
            {
                newLeader = alliance.Members.Find(member => member.Role == (int)Alliance.Role.Admin);

                if (newLeader != null)
                {
                    newLeader.Role = (int)newRole;
                }
                else
                {
                    newLeader = alliance.Members[Loader.Random.Rand(alliance.Members.Count)];

                    if (newLeader != null)
                    {
                        newLeader.Role = (int)newRole;
                    }
                }
            }

            alliance.AddEntry(new StreamEntry(member, member, StreamEntry.StreamEvent.Demoted));
            alliance.AddEntry(new StreamEntry(newLeader, member, StreamEntry.StreamEvent.Promoted));

            avatar.Save();
            Avatars.Get(newLeader.Identifier).Save();

            new AvailableServerCommandMessage(avatar.Connection, new LogicChangeAllianceRoleCommand(avatar.Connection)
            {
                Role = newRole
            }).Send();
        }