public override void RunImplement() { try { Account player = client.SessionPlayer; Room room = player != null ? player.room : null; DateTime now = DateTime.Now; if (teamIdx >= 0 && teamIdx < 2 && room != null && (now - player.lastSlotChange).TotalSeconds >= 0.7 && !room.changingSlots) { Slot slot = room.GetSlot(player.slotId); if (slot != null && teamIdx != slot.teamId && slot.state == SlotStateEnum.NORMAL) { lock (room.slots) { room.changingSlots = true; List <SlotChange> changeList = new List <SlotChange>(); room.SwitchNewSlot(changeList, player, slot, teamIdx); if (changeList.Count > 0) { using (PROTOCOL_ROOM_CHANGE_SLOTS_ACK packet = new PROTOCOL_ROOM_CHANGE_SLOTS_ACK(changeList, room.leaderSlot, 0)) { room.SendPacketToPlayers(packet); } } room.changingSlots = false; } player.lastSlotChange = now; } } } catch (Exception ex) { PacketLog(ex); } }
public override void RunImplement() { try { Account player = client.SessionPlayer; Room room = player != null ? player.room : null; if (room != null && room.leaderSlot == player.slotId && room.state == RoomStateEnum.Ready && (DateTime.Now - room.lastChangeTeam).TotalSeconds >= 1.5 && !room.changingSlots) { List <SlotChange> changeList = new List <SlotChange>(); lock (room.slots) { room.changingSlots = true; foreach (int slotIdx in room.RED_TEAM) { int NewId = slotIdx + 1; if (slotIdx == room.leaderSlot) { room.leaderSlot = NewId; } else if (NewId == room.leaderSlot) { room.leaderSlot = slotIdx; } room.SwitchSlots(changeList, NewId, slotIdx, true); } if (changeList.Count > 0) { using (PROTOCOL_ROOM_CHANGE_SLOTS_ACK packet = new PROTOCOL_ROOM_CHANGE_SLOTS_ACK(changeList, room.leaderSlot, 2)) { byte[] data = packet.GetCompleteBytes("ROOM_CHANGE_TEAM_REQ"); List <Account> list = room.GetAllPlayers(); for (int i = 0; i < list.Count; i++) { Account account = list[i]; account.slotId = room.GetNewSlotId(account.slotId); account.SendCompletePacket(data); } } } room.changingSlots = false; } room.lastChangeTeam = DateTime.Now; } } catch (Exception ex) { PacketLog(ex); } }
private void TryBalanceTeams(Room room) //Balanceia os players com READY entre os times. (QTY/RANK) { lock (room.slots) { if (room.balancing == BalancingTeamEnum.QTY) { List <SlotChange> changeList = new List <SlotChange>(); foreach (int slotId in room.RED_TEAM) { Slot CurrentSlot = room.GetSlot(slotId); if (CurrentSlot.playerId > 0 && CurrentSlot.state == SlotStateEnum.READY) { if (room.GetPlayerBySlot(CurrentSlot, out Account player)) { foreach (int newSlotId in room.RED_TEAM) { if (newSlotId < slotId) { Slot newSlot = room.slots[newSlotId]; if (newSlot.state == SlotStateEnum.EMPTY && newSlot.playerId == 0) { newSlot.state = SlotStateEnum.READY; newSlot.playerId = player.playerId; newSlot.equipment = player.equipments; if (player.slotId == room.leaderSlot) { room.leaderSlot = newSlotId; } player.slotId = newSlotId; CurrentSlot.ResetSlot(); CurrentSlot.state = SlotStateEnum.EMPTY; CurrentSlot.playerId = 0; CurrentSlot.equipment = null; changeList.Add(new SlotChange(CurrentSlot, newSlot)); Logger.Red($" TEAM RED BALANCE [!] Nick: {player.nickname} OldSlot: {CurrentSlot.Id} NewSlot: {newSlot.Id}"); break; } //else if (newSlot.state > SlotStateEnum.CLOSE && newSlot.state < SlotStateEnum.READY) //{ // if (room.GetPlayerBySlot(CurrentSlot, out Account playerSlot)) // { // CurrentSlot.ResetSlot(); // CurrentSlot.state = newSlot.state; // CurrentSlot.playerId = playerSlot.playerId; // CurrentSlot.equipment = player.equipments; // playerSlot.slotId = CurrentSlot.Id; // newSlot.ResetSlot(); // newSlot.state = SlotStateEnum.READY; // newSlot.playerId = player.playerId; // newSlot.equipment = player.equipments; // if (player.slotId == room.leaderSlot) // { // room.leaderSlot = newSlotId; // } // player.slotId = newSlotId; // changeList.Add(new SlotChange(CurrentSlot, newSlot)); // } //} } else { break; } } } } } foreach (int slotId in room.BLUE_TEAM) { Slot CurrentSlot = room.GetSlot(slotId); if (CurrentSlot.playerId > 0 && CurrentSlot.state == SlotStateEnum.READY) { if (room.GetPlayerBySlot(CurrentSlot, out Account player)) { foreach (int newSlotId in room.BLUE_TEAM) { if (newSlotId < slotId) { Slot newSlot = room.slots[newSlotId]; if (newSlot.state == SlotStateEnum.EMPTY && newSlot.playerId == 0) { newSlot.state = SlotStateEnum.READY; newSlot.playerId = player.playerId; newSlot.equipment = player.equipments; if (player.slotId == room.leaderSlot) { room.leaderSlot = newSlotId; } player.slotId = newSlotId; CurrentSlot.ResetSlot(); CurrentSlot.state = SlotStateEnum.EMPTY; CurrentSlot.playerId = 0; CurrentSlot.equipment = null; changeList.Add(new SlotChange(CurrentSlot, newSlot)); Logger.Blue($" TEAM BLUE BALANCE [!] Nick: {player.nickname} OldSlot: {CurrentSlot.Id} NewSlot: {newSlot.Id}"); break; } //else if (newSlot.state > SlotStateEnum.CLOSE && newSlot.state < SlotStateEnum.READY) //{ // if (room.GetPlayerBySlot(CurrentSlot, out Account playerSlot)) // { // CurrentSlot.ResetSlot(); // CurrentSlot.state = newSlot.state; // CurrentSlot.playerId = playerSlot.playerId; // CurrentSlot.equipment = player.equipments; // playerSlot.slotId = CurrentSlot.Id; // newSlot.ResetSlot(); // newSlot.state = SlotStateEnum.READY; // newSlot.playerId = player.playerId; // newSlot.equipment = player.equipments; // if (player.slotId == room.leaderSlot) // { // room.leaderSlot = newSlotId; // } // player.slotId = newSlotId; // changeList.Add(new SlotChange(CurrentSlot, newSlot)); // } //} } else { break; } } } } } if (changeList.Count > 0) { using (PROTOCOL_ROOM_CHANGE_SLOTS_ACK packet = new PROTOCOL_ROOM_CHANGE_SLOTS_ACK(changeList, room.leaderSlot, 1)) { room.SendPacketToPlayers(packet); } room.UpdateSlotsInfo(); } } } for (int i = 0; i < 16; i++) { Slot slot = room.GetSlot(i); if (i != room.leaderSlot && slot.playerId > 0 && slot.state == SlotStateEnum.READY && room.GetPlayerBySlot(slot, out Account player)) { room.TryBalancePlayer(player, false, ref slot); } } }