Пример #1
0
        /// <summary>
        /// Make sure that Battleground.HasQueue is true before calling this method.
        /// Adds the given set of Characters to this team's queue.
        /// Will invite immediately if there are enough open slots and
        /// <see cref="WCell.RealmServer.Battlegrounds.Battleground.IsAddingPlayers"/> is true.
        /// </summary>
        /// <param name="chrs"></param>
        public BattlegroundRelation Enqueue(ICharacterSet chrs)
        {
            _battleground.EnsureContext();

            var relation     = new BattlegroundRelation(Queue, chrs);
            var shouldInvite = _battleground.IsAddingPlayers && chrs.CharacterCount <= OpenPlayerSlotCount;

            if (!shouldInvite)
            {
                Queue.Enqueue(relation);
            }
            else
            {
                ReservedSlots      += chrs.CharacterCount;
                relation.IsEnqueued = false;
            }

            chrs.ForeachCharacter(chr => chr.ExecuteInContext(() =>
            {
                var index = chr.Battlegrounds.AddRelation(relation);
                if (shouldInvite)
                {
                    chr.Battlegrounds.InviteTo(this, index, relation);
                }
            }));

            return(relation);
        }
Пример #2
0
        /// <summary>
        /// Make sure that Battleground.HasQueue is true before calling this method.
        /// Adds the given set of Characters to this team's queue.
        /// Will invite immediately if there are enough open slots and
        /// <see cref="P:WCell.RealmServer.Battlegrounds.Battleground.IsAddingPlayers" /> is true.
        /// </summary>
        /// <param name="chrs"></param>
        public BattlegroundRelation Enqueue(ICharacterSet chrs)
        {
            this._battleground.EnsureContext();
            BattlegroundRelation relation = new BattlegroundRelation(this.Queue, chrs);
            bool shouldInvite             = this._battleground.IsAddingPlayers && chrs.CharacterCount <= this.OpenPlayerSlotCount;

            if (!shouldInvite)
            {
                this.Queue.Enqueue(relation);
            }
            else
            {
                this.ReservedSlots += chrs.CharacterCount;
                relation.IsEnqueued = false;
            }

            chrs.ForeachCharacter((Action <Character>)(chr => chr.ExecuteInContext((Action)(() =>
            {
                int queueIndex = chr.Battlegrounds.AddRelation(relation);
                if (!shouldInvite)
                {
                    return;
                }
                chr.Battlegrounds.InviteTo(this, queueIndex, relation);
            }))));
            return(relation);
        }
Пример #3
0
        private void RemoveUnlocked(BattlegroundRelation relation)
        {
            var node = PendingRequests.First;

            while (node != null)
            {
                if (node.Value == relation)
                {
                    m_chrCount -= relation.Characters.CharacterCount;

                    var next = node.Next;
                    relation.IsEnqueued = false;
                    PendingRequests.Remove(node);
                    node = next;

                    if (node == null)
                    {
                        // was the last node
                        break;
                    }

                    // next node already selected
                    continue;
                }
                node = node.Next;
            }
        }
Пример #4
0
        private int Dequeue(int amount, Battleground bg, LinkedListNode <BattlegroundRelation> node)
        {
            BattlegroundTeam team = bg.GetTeam(this.Side);
            int num = 0;

            do
            {
                BattlegroundRelation battlegroundRelation = node.Value;
                if (battlegroundRelation.Count <= amount)
                {
                    this.m_chrCount -= battlegroundRelation.Characters.CharacterCount;
                    num             += team.Invite(battlegroundRelation.Characters);
                    battlegroundRelation.IsEnqueued = false;
                    LinkedListNode <BattlegroundRelation> next = node.Next;
                    this.PendingRequests.Remove(node);
                    node = next;
                    if (node == null)
                    {
                        break;
                    }
                }
            } while ((node = node.Next) != null && num <= amount);

            return(num);
        }
Пример #5
0
        public override BattlegroundRelation Enqueue(ICharacterSet chrs)
        {
            BattlegroundRelation battlegroundRelation = base.Enqueue(chrs);

            ((GlobalBattlegroundQueue)this.ParentQueue).CheckBGCreation();
            return(battlegroundRelation);
        }
Пример #6
0
        /// <summary>Enqueues the given Character(s) for the given side</summary>
        public BattlegroundRelation Enqueue(ICharacterSet chrs, BattlegroundSide side)
        {
            BattlegroundTeamQueue teamQueue = this.GetTeamQueue(side);
            BattlegroundRelation  request   = new BattlegroundRelation(teamQueue, chrs);

            teamQueue.Enqueue(request);
            return(request);
        }
Пример #7
0
        /// <summary>
        /// Enqueues the given Character(s) for the given side
        /// </summary>
        public BattlegroundRelation Enqueue(ICharacterSet chrs, BattlegroundSide side)
        {
            var queue   = GetTeamQueue(side);
            var request = new BattlegroundRelation(queue, chrs);

            queue.Enqueue(request);

            return(request);
        }
Пример #8
0
        public virtual BattlegroundRelation Enqueue(ICharacterSet chrs)
        {
            BattlegroundRelation request = new BattlegroundRelation(this, chrs);

            chrs.ForeachCharacter((Action <Character>)(chr =>
                                                       chr.ExecuteInContext((Action)(() => chr.Battlegrounds.AddRelation(request)))));
            this.Enqueue(request);
            return(request);
        }
Пример #9
0
        public bool IsEnqueuedFor(BattlegroundId bgId)
        {
            BattlegroundRelation relation = this.GetRelation(bgId);

            if (relation != null)
            {
                return(relation.IsEnqueued);
            }
            return(false);
        }
Пример #10
0
        public int GetIndex(BattlegroundRelation request)
        {
            BattlegroundQueue parentQueue = request.Queue.ParentQueue;

            if (parentQueue != null)
            {
                return(this.GetIndex(parentQueue.Template.Id));
            }
            return(0);
        }
Пример #11
0
        public int GetIndex(BattlegroundRelation request)
        {
            var queue = request.Queue.ParentQueue;

            if (queue != null)
            {
                return(GetIndex(queue.Template.Id));
            }

            return(0);
        }
Пример #12
0
 /// <summary>Cancel all relations</summary>
 public void CancelAllRelations()
 {
     for (int index = 0; index < this._relations.Length; ++index)
     {
         BattlegroundRelation relation = this._relations[index];
         if (relation != null)
         {
             this.CancelRelation(index, relation, false);
         }
     }
 }
Пример #13
0
        public int CancelRelation(int index, BattlegroundRelation relation, bool charActive)
        {
            this._chr.EnsureContext();
            BattlegroundTeamQueue queue = relation.Queue;

            if (queue != null)
            {
                queue.Remove(relation);
            }
            this.RemoveRelation(index, relation, charActive);
            return(index);
        }
Пример #14
0
 internal void Remove(BattlegroundRelation relation)
 {
     if (this._parentQueue.RequiresLocking)
     {
         lock (this.PendingRequests)
             this.RemoveUnlocked(relation);
     }
     else
     {
         this.RemoveUnlocked(relation);
     }
 }
Пример #15
0
        public virtual BattlegroundRelation Enqueue(ICharacterSet chrs)
        {
            var request = new BattlegroundRelation(this, chrs);

            chrs.ForeachCharacter(chr =>
                                  chr.ExecuteInContext(() => {
                chr.Battlegrounds.AddRelation(request);
            }));

            Enqueue(request);
            return(request);
        }
Пример #16
0
        internal void InviteTo(BattlegroundTeam team, int queueIndex, BattlegroundRelation relation)
        {
            this._chr.EnsureContext();
            relation.IsEnqueued = false;
            Battleground           bg = team.Battleground;
            BattlegroundInvitation battlegroundInvitation = new BattlegroundInvitation(team, queueIndex);

            this._chr.Battlegrounds.Invitation = battlegroundInvitation;
            battlegroundInvitation.CancelTimer = this._chr.CallDelayed(BattlegroundMgr.InvitationTimeoutMillis,
                                                                       (Action <WorldObject>)(obj => this.RemoveRelation(bg.Template.Id)));
            BattlegroundHandler.SendStatusInvited(this._chr);
        }
Пример #17
0
        /// <summary>
        /// Gets the <see cref="T:WCell.RealmServer.Battlegrounds.BattlegroundRelation" /> for the given Battleground for
        /// the Character.
        /// </summary>
        /// <param name="bgId"></param>
        /// <returns></returns>
        public BattlegroundRelation GetRelation(BattlegroundId bgId)
        {
            for (int index = 0; index < this._relations.Length; ++index)
            {
                BattlegroundRelation relation = this._relations[index];
                if (relation != null && relation.Queue.ParentQueue.Template.Id == bgId)
                {
                    return(relation);
                }
            }

            return((BattlegroundRelation)null);
        }
Пример #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <remarks>Requires Context</remarks>
        public int GetIndex(BattlegroundId id)
        {
            this._chr.ContextHandler.EnsureContext();
            for (int index = 0; index < this._relations.Length; ++index)
            {
                BattlegroundRelation relation = this._relations[index];
                if (relation != null && relation.Queue.ParentQueue.Template.Id == id)
                {
                    return(index);
                }
            }

            return(-1);
        }
Пример #19
0
        internal void RemoveRelation(int index, BattlegroundRelation relation, bool isCharActive)
        {
            _chr.EnsureContext();
            _relations[index] = null;

            var invite = Invitation;

            if (invite != null)
            {
                // cancel reserved slot
                invite.Team.ReservedSlots--;
                Invitation = null;
            }

            var bgId = relation.BattlegroundId;
            var bg   = _chr.Map as Battleground;

            if (bg != null &&
                bg.Template.Id == bgId &&
                !relation.IsEnqueued &&
                !_chr.IsTeleporting &&
                isCharActive)
            {
                bg.TeleportOutside(_chr);
            }

            if (isCharActive)
            {
                BattlegroundHandler.ClearStatus(_chr, index);
            }

            if (relation.IsEnqueued && relation.Characters.CharacterCount > 1)
            {
                var group = _chr.Group;
                if (group != null && group.IsLeader(_chr))
                {
                    // also dequeue everyone else
                    relation.Characters.ForeachCharacter(chr =>
                    {
                        if (chr != _chr)
                        {
                            chr.ExecuteInContext(() =>
                            {
                                chr.Battlegrounds.RemoveRelation(bgId);
                            });
                        }
                    });
                }
            }
        }
Пример #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="relation"></param>
        /// <returns>The index of the newly created relation</returns>
        public int AddRelation(BattlegroundRelation relation)
        {
            this._chr.EnsureContext();
            int index = (int)ArrayUtil.AddOnlyOne <BattlegroundRelation>(ref this._relations, relation);

            ++this._relationCount;
            BattlegroundQueue parentQueue = relation.Queue.ParentQueue;

            if (parentQueue != null)
            {
                BattlegroundHandler.SendStatusEnqueued(this._chr, index, relation, parentQueue);
            }
            return(index);
        }
Пример #21
0
        /// <summary>
        /// Removes the corresponding relation and removes it from the queue
        /// if it is enqueued.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int CancelRelation(BattlegroundId id)
        {
            this._chr.EnsureContext();
            for (int index = 0; index < this._relations.Length; ++index)
            {
                BattlegroundRelation relation = this._relations[index];
                if (relation != null && relation.Queue.ParentQueue.Template.Id == id)
                {
                    this.CancelRelation(index, relation, true);
                    return(index);
                }
            }

            return(-1);
        }
Пример #22
0
        /// <summary>
        /// Invites this Character to the given Battleground or enqueues him/her.
        /// </summary>
        internal void InviteTo(BattlegroundTeam team)
        {
            var index = GetIndex(team.Battleground.Template.Id);
            BattlegroundRelation relation;

            if (index == -1)
            {
                index = AddRelation(relation = new BattlegroundRelation(team.Queue, _chr, false));
            }
            else
            {
                relation = _relations[index];
            }
            InviteTo(team, index, relation);
        }
Пример #23
0
        /// <summary>
        /// Invites this Character to the given Battleground or enqueues him/her.
        /// </summary>
        internal void InviteTo(BattlegroundTeam team)
        {
            int queueIndex = this.GetIndex(team.Battleground.Template.Id);
            BattlegroundRelation relation;

            if (queueIndex == -1)
            {
                queueIndex =
                    this.AddRelation(relation = new BattlegroundRelation(team.Queue, (ICharacterSet)this._chr, false));
            }
            else
            {
                relation = this._relations[queueIndex];
            }
            this.InviteTo(team, queueIndex, relation);
        }
Пример #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="relation"></param>
        /// <returns>The index of the newly created relation</returns>
        public int AddRelation(BattlegroundRelation relation)
        {
            _chr.EnsureContext();

            var index = (int)ArrayUtil.AddOnlyOne(ref _relations, relation);

            _relationCount++;
            var queue = relation.Queue.ParentQueue;

            if (queue != null)
            {
                BattlegroundHandler.SendStatusEnqueued(_chr, index, relation, queue);
            }

            return(index);
        }
Пример #25
0
 internal void Enqueue(BattlegroundRelation request)
 {
     if (this._parentQueue.RequiresLocking)
     {
         lock (this.PendingRequests)
         {
             this.PendingRequests.AddLast(request);
             this.m_chrCount += request.Characters.CharacterCount;
         }
     }
     else
     {
         this.PendingRequests.AddLast(request);
         this.m_chrCount += request.Characters.CharacterCount;
     }
 }
Пример #26
0
        internal void InviteTo(BattlegroundTeam team, int queueIndex, BattlegroundRelation relation)
        {
            _chr.EnsureContext();

            relation.IsEnqueued = false;
            var bg     = team.Battleground;
            var invite = new BattlegroundInvitation(team, queueIndex);

            _chr.Battlegrounds.Invitation = invite;

            invite.CancelTimer = _chr.CallDelayed(BattlegroundMgr.InvitationTimeoutMillis, obj =>
            {
                RemoveRelation(bg.Template.Id);
            });

            BattlegroundHandler.SendStatusInvited(_chr);
        }
Пример #27
0
        internal void RemoveRelation(int index, BattlegroundRelation relation, bool isCharActive)
        {
            this._chr.EnsureContext();
            this._relations[index] = (BattlegroundRelation)null;
            BattlegroundInvitation invitation = this.Invitation;

            if (invitation != null)
            {
                --invitation.Team.ReservedSlots;
                this.Invitation = (BattlegroundInvitation)null;
            }

            BattlegroundId bgId = relation.BattlegroundId;
            Battleground   map  = this._chr.Map as Battleground;

            if (map != null && map.Template.Id == bgId && (!relation.IsEnqueued && !this._chr.IsTeleporting) &&
                isCharActive)
            {
                map.TeleportOutside(this._chr);
            }
            if (isCharActive)
            {
                BattlegroundHandler.ClearStatus((IPacketReceiver)this._chr, index);
            }
            if (!relation.IsEnqueued || relation.Characters.CharacterCount <= 1)
            {
                return;
            }
            Group group = this._chr.Group;

            if (group == null || !group.IsLeader(this._chr))
            {
                return;
            }
            relation.Characters.ForeachCharacter((Action <Character>)(chr =>
            {
                if (chr == this._chr)
                {
                    return;
                }
                chr.ExecuteInContext((Action)(() => chr.Battlegrounds.RemoveRelation(bgId)));
            }));
        }
Пример #28
0
        public bool CancelIfEnqueued(BattlegroundId bgId)
        {
            this._chr.ContextHandler.EnsureContext();
            for (int index = 0; index < this._relations.Length; ++index)
            {
                BattlegroundRelation relation = this._relations[index];
                if (relation != null && relation.Queue.ParentQueue.Template.Id == bgId)
                {
                    if (!relation.IsEnqueued)
                    {
                        return(false);
                    }
                    relation.Cancel();
                    return(true);
                }
            }

            return(false);
        }
Пример #29
0
        private void RemoveUnlocked(BattlegroundRelation relation)
        {
            LinkedListNode <BattlegroundRelation> node = this.PendingRequests.First;

            while (node != null)
            {
                if (node.Value == relation)
                {
                    this.m_chrCount -= relation.Characters.CharacterCount;
                    LinkedListNode <BattlegroundRelation> next = node.Next;
                    relation.IsEnqueued = false;
                    this.PendingRequests.Remove(node);
                    node = next;
                    if (node == null)
                    {
                        break;
                    }
                }
                else
                {
                    node = node.Next;
                }
            }
        }
Пример #30
0
		internal void RemoveRelation(int index, BattlegroundRelation relation, bool isCharActive)
		{
			_chr.EnsureContext();
			_relations[index] = null;

			var invite = Invitation;
			if (invite != null)
			{
				// cancel reserved slot
				invite.Team.ReservedSlots--;
				Invitation = null;
			}

			var bgId = relation.BattlegroundId;
			var bg = _chr.Map as Battleground;
			if (bg != null &&
				bg.Template.Id == bgId &&
				!relation.IsEnqueued &&
				!_chr.IsTeleporting &&
				isCharActive)
			{
				bg.TeleportOutside(_chr);
			}

			if (isCharActive)
			{
				BattlegroundHandler.ClearStatus(_chr, index);
			}

			if (relation.IsEnqueued && relation.Characters.CharacterCount > 1)
			{
				var group = _chr.Group;
				if (group != null && group.IsLeader(_chr))
				{
					// also dequeue everyone else
					relation.Characters.ForeachCharacter(chr =>
					{
						if (chr != _chr)
						{
							chr.ExecuteInContext(() =>
							{
								chr.Battlegrounds.RemoveRelation(bgId);
							});
						}
					});
				}
			}
		}
Пример #31
0
 public int RemoveRelation(BattlegroundRelation relation)
 {
     return(RemoveRelation(relation.BattlegroundId));
 }
Пример #32
0
		internal void Enqueue(BattlegroundRelation request)
		{
			if (_parentQueue.RequiresLocking)
			{
				lock (PendingRequests)
				{
					PendingRequests.AddLast(request);
					m_chrCount += request.Characters.CharacterCount;
				}
			}
			else
			{
				PendingRequests.AddLast(request);
				m_chrCount += request.Characters.CharacterCount;
			}
		}
Пример #33
0
		public int GetIndex(BattlegroundRelation request)
		{
			var queue = request.Queue.ParentQueue;
			if (queue != null)
			{
				return GetIndex(queue.Template.Id);
			}

			return 0;
		}
Пример #34
0
		public virtual BattlegroundRelation Enqueue(ICharacterSet chrs)
		{
			var request = new BattlegroundRelation(this, chrs);

			chrs.ForeachCharacter(chr =>
				chr.ExecuteInContext(() => {
					chr.Battlegrounds.AddRelation(request);
				}));

			Enqueue(request);
			return request;
		}
Пример #35
0
		internal void InviteTo(BattlegroundTeam team, int queueIndex, BattlegroundRelation relation)
		{
			_chr.EnsureContext();

			relation.IsEnqueued = false;
			var bg = team.Battleground;
			var invite = new BattlegroundInvitation(team, queueIndex);
			_chr.Battlegrounds.Invitation = invite;

			invite.CancelTimer = _chr.CallDelayed(BattlegroundMgr.InvitationTimeoutMillis, obj =>
			{
				RemoveRelation(bg.Template.Id);
			});

			BattlegroundHandler.SendStatusInvited(_chr);
		}
Пример #36
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="relation"></param>
		/// <returns>The index of the newly created relation</returns>
		public int AddRelation(BattlegroundRelation relation)
		{
			_chr.EnsureContext();

			var index = (int)ArrayUtil.AddOnlyOne(ref _relations, relation);

			_relationCount++;
			var queue = relation.Queue.ParentQueue;
			if (queue != null)
			{
				BattlegroundHandler.SendStatusEnqueued(_chr, index, relation, queue);
			}

			return index;
		}
Пример #37
0
		/// <summary>
		/// Make sure that Battleground.HasQueue is true before calling this method.
		/// Adds the given set of Characters to this team's queue. 
		/// Will invite immediately if there are enough open slots and
		/// <see cref="WCell.RealmServer.Battlegrounds.Battleground.IsAddingPlayers"/> is true.
		/// </summary>
		/// <param name="chrs"></param>
		public BattlegroundRelation Enqueue(ICharacterSet chrs)
		{
			_battleground.EnsureContext();

			var relation = new BattlegroundRelation(Queue, chrs);
			var shouldInvite = _battleground.IsAddingPlayers && chrs.Count <= OpenPlayerSlotCount;

			if (!shouldInvite)
			{
				Queue.Enqueue(relation);
			}
			else
			{
				ReservedSlots += chrs.Count;
				relation.IsEnqueued = false;
			}

			chrs.ForeachCharacter(chr => chr.ExecuteInContext(() =>
			{
				var index = chr.Battlegrounds.AddRelation(relation);
				if (shouldInvite)
				{
					chr.Battlegrounds.InviteTo(this, index, relation);
				}
			}));

			return relation;
		}
Пример #38
0
		internal void Remove(BattlegroundRelation relation)
		{
			if (_parentQueue.RequiresLocking)
			{
				lock (PendingRequests)
				{
					RemoveUnlocked(relation);
				}
			}
			else
			{
				RemoveUnlocked(relation);
			}
		}
Пример #39
0
		public int CancelRelation(int index, BattlegroundRelation relation, bool charActive)
		{
			_chr.EnsureContext();

			var queue = relation.Queue;
			if (queue != null)
			{
				queue.Remove(relation);
			}

			RemoveRelation(index, relation, charActive);

			return index;
		}
Пример #40
0
		public int RemoveRelation(BattlegroundRelation relation)
		{
			return RemoveRelation(relation.BattlegroundId);
		}
Пример #41
0
		private void RemoveUnlocked(BattlegroundRelation relation)
		{
			var node = PendingRequests.First;
			while (node != null)
			{
				if (node.Value == relation)
				{
					m_chrCount -= relation.Characters.CharacterCount;

					var next = node.Next;
					relation.IsEnqueued = false;
					PendingRequests.Remove(node);
					node = next;

					if (node == null)
					{
						// was the last node
						break;
					}

					// next node already selected
					continue;
				}
				node = node.Next;
			}
		}
Пример #42
0
        public static void SendStatusEnqueued(Character chr,
			int index,
            BattlegroundRelation relation,
			BattlegroundQueue queue)
        {
            var status = BattlegroundStatus.Enqueued;

            using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_BATTLEFIELD_STATUS))
            {
				packet.Write(index);

                var bgId = queue.Template.Id;

                // 64-bit guid start
                packet.Write((byte)ArenaType.None);
                packet.Write((byte)1);              // affects level range calculation?
                packet.Write((uint)bgId);
                packet.Write((ushort)8080);
                // 64-bit guid stop

				packet.Write((byte)0);				// since 3.3
				packet.Write((byte)0);				// since 3.3
                packet.Write(queue.InstanceId);     // instance id
                packet.Write(false);                // bool isRatedMatch
                packet.Write((int)status);

                packet.Write(queue.AverageWaitTime);					// avg wait time for queue, in ms
                packet.Write((int)relation.QueueTime.TotalMilliseconds); // time in the queue, also in ms

                chr.Send(packet);
            }
        }
Пример #43
0
		/// <summary>
		/// Invites this Character to the given Battleground or enqueues him/her.
		/// </summary>
		internal void InviteTo(BattlegroundTeam team)
		{
			var index = GetIndex(team.Battleground.Template.Id);
			BattlegroundRelation relation;
			if (index == -1)
			{
				index = AddRelation(relation = new BattlegroundRelation(team.Queue, _chr, false));
			}
			else
			{
				relation = _relations[index];
			}
			InviteTo(team, index, relation);
		}