Exemple #1
0
        /// <summary>
        /// Removes a player from the raid.
        /// </summary>
        /// <param name="player">Player to remove.</param>
        /// <returns>RaidRemove with raid group and list of invited users.</returns>
        public override RaidRemoveResult RemovePlayer(SocketGuildUser player)
        {
            RaidRemoveResult returnValue = new RaidRemoveResult(Global.NOT_IN_RAID, new List <SocketGuildUser>());

            int groupNum = IsInRaid(player);

            if (groupNum == InviteListNumber)
            {
                Invite.Remove(player);
            }
            else if (groupNum == MuleGroupNumber)
            {
                Mules.RemovePlayer(player);
                foreach (RaidGroup group in Groups)
                {
                    returnValue.Users.AddRange(group.RemovePlayer(player));
                }
                foreach (SocketGuildUser invite in returnValue.Users)
                {
                    Invite.Add(invite);
                }
                return(returnValue);
            }
            else if (groupNum != Global.NOT_IN_RAID)
            {
                RaidGroup foundGroup = Groups.ElementAt(groupNum);
                foundGroup.RemovePlayer(player);
            }
            return(returnValue);
        }
Exemple #2
0
        /// <summary>
        /// Removes a player from the raid.
        /// </summary>
        /// <param name="player">Player to remove.</param>
        /// <returns>RaidRemove with raid group and list of invited users.</returns>
        public override RaidRemoveResult RemovePlayer(SocketGuildUser player)
        {
            RaidRemoveResult returnValue = new RaidRemoveResult(Global.NOT_IN_RAID, new List <SocketGuildUser>());

            int group = IsInRaid(player);

            if (group == InviteListNumber)
            {
                Invite.Remove(player);
            }
            else
            {
                if (group != Global.NOT_IN_RAID)
                {
                    RaidGroup foundGroup            = Groups.ElementAt(group);
                    List <SocketGuildUser> tempList = foundGroup.RemovePlayer(player);
                    foreach (SocketGuildUser invite in tempList)
                    {
                        returnValue.Users.Add(invite);
                        Invite.Add(invite);
                    }
                }
            }
            return(returnValue);
        }
Exemple #3
0
        /// <summary>
        /// Marks a player as ready in the raid.
        /// </summary>
        /// <param name="player">Player to mark ready.</param>
        /// <returns>Group number the player is in, else NotInRaid.</returns>
        public int MarkPlayerReady(SocketGuildUser player)
        {
            int groupNum = IsInRaid(player, false);

            if (groupNum != Global.NOT_IN_RAID && groupNum != InviteListNumber)
            {
                RaidGroup group = Groups.ElementAt(groupNum);
                return((group.MarkPlayerReady(player) && group.AllPlayersReady()) ? groupNum : Global.NOT_IN_RAID);
            }
            return(Global.NOT_IN_RAID);
        }
Exemple #4
0
        /// <summary>
        /// Attempts to split the raid group.
        /// </summary>
        /// <returns>A new raid group if the raid can be split, else null.</returns>
        public RaidGroup SplitGroup()
        {
            RaidGroup newGroup = new RaidGroup(PlayerLimit, InviteLimit);

            foreach (KeyValuePair <SocketGuildUser, int> player in Attending)
            {
                if ((newGroup.TotalPlayers() + player.Value) <= PlayerLimit / 2)
                {
                    newGroup.Attending.Add(player.Key, player.Value);

                    foreach (KeyValuePair <SocketGuildUser, SocketGuildUser> invite in Invited)
                    {
                        if (invite.Value.Equals(player.Key))
                        {
                            newGroup.InvitePlayer(invite.Key, invite.Value);
                        }
                    }
                }
            }

            if (newGroup.TotalPlayers() < PlayerLimit / 2)
            {
                foreach (KeyValuePair <SocketGuildUser, int> player in Ready)
                {
                    if (newGroup.TotalPlayers() < PlayerLimit / 2)
                    {
                        newGroup.Ready.Add(player.Key, player.Value);
                        foreach (KeyValuePair <SocketGuildUser, SocketGuildUser> invite in Invited)
                        {
                            if (invite.Value.Equals(player.Key))
                            {
                                newGroup.InvitePlayer(invite.Key, invite.Value);
                            }
                        }
                    }
                }
            }

            foreach (SocketGuildUser player in newGroup.Attending.Keys)
            {
                Attending.Remove(player);
            }
            foreach (SocketGuildUser player in newGroup.Ready.Keys)
            {
                Ready.Remove(player);
            }
            foreach (SocketGuildUser player in newGroup.Invited.Keys)
            {
                Invited.Remove(player);
            }
            return(newGroup);
        }
Exemple #5
0
 /// <summary>
 /// Merges this group and another group.
 /// </summary>
 /// <param name="group">Group to merge with this group.</param>
 public void MergeGroup(RaidGroup group)
 {
     if (!group.Equals(this) &&
         group.TotalPlayers() != 0 && TotalPlayers() != 0 &&
         (group.TotalPlayers() + TotalPlayers()) <= PlayerLimit)
     {
         Attending = Attending.Union(group.Attending).ToDictionary(k => k.Key, v => v.Value);
         Ready     = Ready.Union(group.Ready).ToDictionary(k => k.Key, v => v.Value);
         Invited   = Invited.Union(group.Invited).ToDictionary(k => k.Key, v => v.Value);
         group.Attending.Clear();
         group.Ready.Clear();
         group.Invited.Clear();
     }
 }
Exemple #6
0
        /// <summary>
        /// Adds a player to a raid.
        /// The player will not be added if splitting the group brings the number of
        /// raid groups over the group limit.
        /// </summary>
        /// <param name="player">Player to add.</param>
        /// <param name="partySize">Number of accounts the player is bringing. Should always be 1.</param>
        /// <param name="invitedBy">Who invited the user.</param>
        /// <returns>True if the user was added, otherwise false.</returns>
        public override bool AddPlayer(SocketGuildUser player, int partySize, SocketGuildUser invitedBy = null)
        {
            if (invitedBy == null)
            {
                if (IsInRaid(player) == Global.NOT_IN_RAID && Mules.GetAttendingCount() < Global.LIMIT_RAID_MULE_MULE)
                {
                    Mules.AddPlayer(player, partySize, Global.NO_ADD_VALUE);
                    return(true);
                }
            }
            else // is invite
            {
                int group = FindSmallestGroup();
                Groups.ElementAt(group).InvitePlayer(player, invitedBy);
                Invite.Remove(player);

                bool shouldSplit = Groups.ElementAt(group).ShouldSplit();

                if (shouldSplit && Groups.Count < RaidGroupLimit)
                {
                    RaidGroup newGroup = Groups.ElementAt(group).SplitGroup();
                    Groups.Add(newGroup);
                    CheckMergeGroups();
                    return(true);
                }
                else if (!shouldSplit)
                {
                    CheckMergeGroups();
                    return(true);
                }

                Groups.ElementAt(group).RemovePlayer(player);
                Invite.Add(player);
            }
            return(false);
        }
Exemple #7
0
 /// <summary>
 /// Creates a new raid.
 /// </summary>
 /// <param name="tier">Tier of the raid.</param>
 /// <param name="time">When the raid starts.</param>
 /// <param name="location">Where the raid is.</param>
 /// <param name="boss">Name of the raid boss.</param>
 public RaidMule(short tier, string time, string location, string boss = null) :
     base(Global.LIMIT_RAID_MULE_GROUP, Global.LIMIT_RAID_MULE_INVITE, Global.LIMIT_RAID_MULE_INVITE, tier, time, location, boss)
 {
     Mules = new RaidGroup(Global.LIMIT_RAID_MULE_MULE, 0);
 }
Exemple #8
0
        /// <summary>
        /// Adds a player to a raid.
        /// The player will not be added if splitting the group brings the number of
        /// raid groups over the group limit.
        /// </summary>
        /// <param name="player">Player to add.</param>
        /// <param name="partySize">Number of accounts the player is bringing.</param>
        /// <param name="invitedBy">Who invited the player.</param>
        /// <returns>True if the player was added, otherwise false.</returns>
        public override bool AddPlayer(SocketGuildUser player, int partySize, SocketGuildUser invitedBy = null)
        {
            int group;

            if (invitedBy == null) // Add in person
            {
                group = IsInRaid(player);
                if (group == Global.NOT_IN_RAID)
                {
                    group = FindSmallestGroup();
                }
                if (group != InviteListNumber)
                {
                    Groups.ElementAt(group).AddPlayer(player, partySize, Global.NO_ADD_VALUE);
                }
                else
                {
                    return(false);
                }
            }
            else if (player.Equals(invitedBy)) // Remote
            {
                group = IsInRaid(player);
                if (group == Global.NOT_IN_RAID)
                {
                    group = FindSmallestGroup();
                }
                if (group != InviteListNumber)
                {
                    Groups.ElementAt(group).AddPlayer(player, Global.NO_ADD_VALUE, partySize);
                }
                else
                {
                    return(false);
                }
            }
            else // accept invite
            {
                group = IsInRaid(invitedBy);
                if (group != Global.NOT_IN_RAID)
                {
                    Groups.ElementAt(group).InvitePlayer(player, invitedBy);
                    Invite.Remove(player);
                }
                else if (player.Equals(invitedBy))
                {
                    group = FindSmallestGroup();
                    Groups.ElementAt(group).InvitePlayer(player, invitedBy);
                }
                else
                {
                    return(false);
                }
            }

            bool shouldSplit = Groups.ElementAt(group).ShouldSplit();

            if (shouldSplit && Groups.Count < RaidGroupLimit)
            {
                RaidGroup newGroup = Groups.ElementAt(group).SplitGroup();
                Groups.Add(newGroup);
                CheckMergeGroups();
                return(true);
            }
            else if (!shouldSplit)
            {
                CheckMergeGroups();
                return(true);
            }

            Groups.ElementAt(group).RemovePlayer(player);
            if (invitedBy != null)
            {
                Invite.Add(player);
            }
            return(false);
        }