/// <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); }
/// <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); }
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; } }
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); }
public override BattlegroundRelation Enqueue(ICharacterSet chrs) { BattlegroundRelation battlegroundRelation = base.Enqueue(chrs); ((GlobalBattlegroundQueue)this.ParentQueue).CheckBGCreation(); return(battlegroundRelation); }
/// <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); }
/// <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); }
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); }
public bool IsEnqueuedFor(BattlegroundId bgId) { BattlegroundRelation relation = this.GetRelation(bgId); if (relation != null) { return(relation.IsEnqueued); } return(false); }
public int GetIndex(BattlegroundRelation request) { BattlegroundQueue parentQueue = request.Queue.ParentQueue; if (parentQueue != null) { return(this.GetIndex(parentQueue.Template.Id)); } return(0); }
public int GetIndex(BattlegroundRelation request) { var queue = request.Queue.ParentQueue; if (queue != null) { return(GetIndex(queue.Template.Id)); } return(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); } } }
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); }
internal void Remove(BattlegroundRelation relation) { if (this._parentQueue.RequiresLocking) { lock (this.PendingRequests) this.RemoveUnlocked(relation); } else { this.RemoveUnlocked(relation); } }
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); }
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); }
/// <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); }
/// <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); }
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); }); } }); } } }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
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; } }
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); }
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))); })); }
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); }
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; } } }
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); }); } }); } } }
public int RemoveRelation(BattlegroundRelation relation) { return(RemoveRelation(relation.BattlegroundId)); }
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; } }
public int GetIndex(BattlegroundRelation request) { var queue = request.Queue.ParentQueue; if (queue != null) { return GetIndex(queue.Template.Id); } return 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; }
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); }
/// <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; }
/// <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; }
internal void Remove(BattlegroundRelation relation) { if (_parentQueue.RequiresLocking) { lock (PendingRequests) { RemoveUnlocked(relation); } } else { RemoveUnlocked(relation); } }
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; }
public int RemoveRelation(BattlegroundRelation relation) { return RemoveRelation(relation.BattlegroundId); }
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; } }
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); } }
/// <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); }