Files
BattleBane/src/engine/gameManager/ArenaManager.java
T

169 lines
5.8 KiB
Java
Raw Normal View History

2025-01-01 17:44:34 -06:00
package engine.gameManager;
2025-01-01 20:35:21 -06:00
import engine.Enum;
2025-01-01 19:18:31 -06:00
import engine.InterestManagement.WorldGrid;
2025-01-01 20:35:21 -06:00
import engine.exception.MsgSendException;
2025-01-01 21:38:48 -06:00
import engine.math.Vector3f;
2025-01-01 17:44:34 -06:00
import engine.math.Vector3fImmutable;
2025-01-01 19:18:31 -06:00
import engine.objects.*;
import engine.server.MBServerStatics;
2025-01-01 17:44:34 -06:00
import org.pmw.tinylog.Logger;
2025-01-01 19:18:31 -06:00
import java.util.*;
2025-01-01 17:44:34 -06:00
import java.util.concurrent.ThreadLocalRandom;
public class ArenaManager {
private static final List<Arena> activeArenas = new ArrayList<>();
2025-01-01 18:43:32 -06:00
public static final List<PlayerCharacter> playerQueue = new ArrayList<>();
2025-01-01 19:18:31 -06:00
public static Long pulseDelay = 180000L;
public static Long lastExecution = 0L;
2025-01-01 17:44:34 -06:00
public static void pulseArenas() {
2025-01-01 19:18:31 -06:00
if(lastExecution == 0L){
lastExecution = System.currentTimeMillis();
}
2025-01-01 19:26:02 -06:00
if(activeArenas.isEmpty() && playerQueue.isEmpty())
return;
2025-01-01 17:44:34 -06:00
Iterator<Arena> iterator = activeArenas.iterator();
while (iterator.hasNext()) {
Arena arena = iterator.next();
if (arena.checkToComplete()) {
iterator.remove();
}
}
2025-01-01 21:26:51 -06:00
if(lastExecution + pulseDelay > System.currentTimeMillis())
return;
2025-01-01 19:18:31 -06:00
lastExecution = System.currentTimeMillis();
2025-01-01 17:44:34 -06:00
while (playerQueue.size() > 1) {
createArena();
}
}
public static void joinQueue(PlayerCharacter player) {
if (!playerQueue.contains(player)) {
playerQueue.add(player);
}
2025-01-05 18:42:06 -06:00
for(PlayerCharacter pc : playerQueue){
if(pc.equals(player))
continue;
ChatManager.chatSystemInfo(pc, player.getName() + " has joined the arena que. There are now " + playerQueue.size() + " players queued.");
}
2025-01-01 17:44:34 -06:00
}
public static void leaveQueue(PlayerCharacter player) {
playerQueue.remove(player);
2025-01-05 18:42:06 -06:00
for(PlayerCharacter pc : playerQueue){
if(pc.equals(player))
continue;
ChatManager.chatSystemInfo(pc, player.getName() + " has left the arena que. There are now " + playerQueue.size() + " players queued.");
}
2025-01-01 17:44:34 -06:00
}
private static void createArena() {
if (playerQueue.size() > 1) {
2025-01-01 21:38:48 -06:00
2025-01-01 19:18:31 -06:00
Collections.shuffle(playerQueue);
2025-01-01 17:44:34 -06:00
Arena newArena = new Arena();
2025-01-01 20:35:21 -06:00
//set starting time
newArena.startTime = System.currentTimeMillis();
2025-01-01 21:38:48 -06:00
2025-01-01 17:44:34 -06:00
//decide an arena location
newArena.loc = selectRandomArenaLocation();
// Assign players to the arena
newArena.player1 = playerQueue.remove(0);
newArena.player2 = playerQueue.remove(0);
// Teleport players to the arena location
2025-01-01 20:35:21 -06:00
Zone sdr = ZoneManager.getZoneByUUID(656);
MovementManager.translocate(newArena.player1, Vector3fImmutable.getRandomPointOnCircle(newArena.loc,75f), null);
MovementManager.translocate(newArena.player2, Vector3fImmutable.getRandomPointOnCircle(newArena.loc,75f), null);
2025-01-01 17:44:34 -06:00
// Add the new arena to the active arenas list
activeArenas.add(newArena);
}
}
2025-01-01 20:37:13 -06:00
public static void endArena(Arena arena, PlayerCharacter winner, PlayerCharacter loser, String condition){
2025-01-01 17:44:34 -06:00
if (winner != null && loser != null) {
Logger.info("[ARENA] The fight between {} and {} is concluded. Victor: {}",
arena.player1.getName(), arena.player2.getName(), winner.getName());
} else {
Logger.info("[ARENA] The fight between {} and {} is concluded. No Winner Declared.",
arena.player1.getName(), arena.player2.getName());
}
2025-01-01 20:35:21 -06:00
// Teleport players to the arena location
Zone sdr = ZoneManager.getZoneByUUID(656);
MovementManager.translocate(arena.player1, Vector3fImmutable.getRandomPointOnCircle(sdr.getLoc(),50f), null);
MovementManager.translocate(arena.player2, Vector3fImmutable.getRandomPointOnCircle(sdr.getLoc(),50f), null);
2025-01-01 21:38:48 -06:00
2025-01-01 21:50:03 -06:00
2025-01-01 21:38:48 -06:00
2025-01-01 17:44:34 -06:00
activeArenas.remove(arena);
2025-01-01 21:11:26 -06:00
if(winner != null){
2025-01-01 21:50:03 -06:00
ChatManager.chatPVP("[ARENA] " + winner.getName() + " has slain " + loser.getName() + " in the arena!");
2025-01-01 21:11:26 -06:00
//handle prize distribution
2025-01-01 21:26:51 -06:00
//ItemBase specialLoot = ItemBase.getItemBase(866);
//Item promoted = new MobLoot(winner, specialLoot, 1, false).promoteToItem(winner);
//promoted.setNumOfItems(21235);
//promoted.setName("Special Banker(21235)");
//DbManager.ItemQueries.UPDATE_NUM_ITEMS(promoted,21235);
//winner.getCharItemManager().addItemToInventory(promoted);
//winner.getCharItemManager().updateInventory();
2025-01-01 21:11:26 -06:00
}
2025-01-01 17:44:34 -06:00
}
public static Vector3fImmutable selectRandomArenaLocation() {
boolean locSet = false;
Vector3fImmutable loc = Vector3fImmutable.ZERO;
while (!locSet) {
try {
2025-01-01 20:04:16 -06:00
float x = ThreadLocalRandom.current().nextInt(114300, 123600);
float z = ThreadLocalRandom.current().nextInt(82675, 91700);
2025-01-01 17:44:34 -06:00
float y = 0; // Y coordinate is always 0
2025-01-01 20:35:21 -06:00
loc = new Vector3fImmutable(x, y, z * -1);
HashSet<AbstractWorldObject> inRange = WorldGrid.getObjectsInRangePartial(loc,500f, MBServerStatics.MASK_PLAYER);
2025-01-01 21:41:48 -06:00
if(inRange.isEmpty() && !isUnderWater(loc))
2025-01-01 20:35:21 -06:00
locSet = true;
//}
2025-01-01 17:44:34 -06:00
}catch(Exception e){
}
}
return loc;
}
2025-01-01 21:41:48 -06:00
public static boolean isUnderWater(Vector3fImmutable loc) {
try {
Zone zone = ZoneManager.findSmallestZone(loc);
if (zone.getSeaLevel() != 0) {
float localAltitude = loc.y;
if (localAltitude < zone.getSeaLevel())
return true;
} else {
if (loc.y < 0)
return true;
}
} catch (Exception e) {
}
return false;
}
2025-01-01 17:44:34 -06:00
}