Example #1
0
        protected virtual void OnInviteAccept(PlayerMobile pm)
        {
            if (pm == null || pm.Deleted || !IsOnline(pm))
            {
                return;
            }

            if (!IsQueued(pm))
            {
                pm.SendMessage("You are not queued for {0}", Name);
                return;
            }

            if (IsParticipant(pm))
            {
                pm.SendMessage("You are already participating in {0}", Name);
                return;
            }

            if (InOtherBattle(pm))
            {
                pm.SendMessage("You cannot join {0} while you are in another battle.", Name);
                return;
            }

            if (IsFull)
            {
                pm.SendMessage("The battle is full, you will be sent an invite if someone leaves.");
                return;
            }

            PvPTeam team = Queue[pm];

            if (team == null || team.Deleted)             // Assume AutoAssign is true
            {
                if (Teams.Count == 1)
                {
                    team = Teams[0];
                }
                else if (AutoAssign)                 // Make sure AutoAssign is true
                {
                    team = GetAutoAssignTeam(pm);
                }
            }

            if (team == null || team.Deleted)             // Fallback to most empty, or random team
            {
                team = GetMostEmptyTeam();

                if (team == null || team.Deleted)
                {
                    team = GetRandomTeam();
                }
            }

            if (team == null || team.Deleted)
            {
                pm.SendMessage("The team you've chosen seems to have vanished in the void, sorry about that.");
                Queue.Remove(pm);
                return;
            }

            if (team.IsFull)
            {
                pm.SendMessage("The team you've chosen is full, you will be sent an invite if someone leaves.");
                return;
            }

            Queue.Remove(pm);
            team.AddMember(pm, true);
            SendSound(pm, Options.Sounds.InviteAccept);
        }