From 9d5c4424a1c72b90be203bdaa9bacbebf0c20b8b Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 1 Jan 2025 17:44:34 -0600 Subject: [PATCH] Arena Infrastructure --- src/engine/gameManager/ArenaManager.java | 99 ++++++++++++++++++++++++ src/engine/objects/Arena.java | 68 ++++++++++++++++ src/engine/objects/Bane.java | 2 +- 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/engine/gameManager/ArenaManager.java create mode 100644 src/engine/objects/Arena.java diff --git a/src/engine/gameManager/ArenaManager.java b/src/engine/gameManager/ArenaManager.java new file mode 100644 index 00000000..278acc3c --- /dev/null +++ b/src/engine/gameManager/ArenaManager.java @@ -0,0 +1,99 @@ +package engine.gameManager; + +import engine.math.Vector3fImmutable; +import engine.objects.Arena; +import engine.objects.PlayerCharacter; +import engine.objects.Regions; +import engine.objects.Zone; +import org.pmw.tinylog.Logger; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +public class ArenaManager { + private static final List activeArenas = new ArrayList<>(); + private static final List playerQueue = new ArrayList<>(); + + public static void pulseArenas() { + Iterator iterator = activeArenas.iterator(); + + while (iterator.hasNext()) { + Arena arena = iterator.next(); + if (arena.checkToComplete()) { + iterator.remove(); + } + } + + while (playerQueue.size() > 1) { + createArena(); + } + } + + public static void joinQueue(PlayerCharacter player) { + if (!playerQueue.contains(player)) { + playerQueue.add(player); + } + } + + public static void leaveQueue(PlayerCharacter player) { + playerQueue.remove(player); + } + + private static void createArena() { + if (playerQueue.size() > 1) { + Arena newArena = new Arena(); + + //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 + MovementManager.translocate(newArena.player1, newArena.loc, Regions.GetRegionForTeleport(newArena.loc)); + MovementManager.translocate(newArena.player2, newArena.loc, Regions.GetRegionForTeleport(newArena.loc)); + + // Add the new arena to the active arenas list + activeArenas.add(newArena); + } + } + + public static void endArena(Arena arena, PlayerCharacter winner, PlayerCharacter loser, String condition) { + 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()); + } + + activeArenas.remove(arena); + } + + public static Vector3fImmutable selectRandomArenaLocation() { + boolean locSet = false; + Vector3fImmutable loc = Vector3fImmutable.ZERO; + + while (!locSet) { + try { + // Generate random X and Z coordinates within the range [10,000, 90,000] + float x = ThreadLocalRandom.current().nextInt(10000, 90000); + float z = ThreadLocalRandom.current().nextInt(-10000, -90000); + float y = 0; // Y coordinate is always 0 + + loc = new Vector3fImmutable(x, y, z); + Zone zone = ZoneManager.findSmallestZone(loc); + if (zone.isContinent() && !ZoneManager.getSeaFloor().equals(zone)) { + locSet = true; + } + }catch(Exception e){ + + } + } + + return loc; + } +} diff --git a/src/engine/objects/Arena.java b/src/engine/objects/Arena.java new file mode 100644 index 00000000..0f5af258 --- /dev/null +++ b/src/engine/objects/Arena.java @@ -0,0 +1,68 @@ +package engine.objects; + +import engine.InterestManagement.WorldGrid; +import engine.gameManager.ArenaManager; +import engine.gameManager.MovementManager; +import engine.math.Vector3fImmutable; +import engine.server.MBServerStatics; + +import java.util.HashSet; + +public class Arena { + public PlayerCharacter player1; + public PlayerCharacter player2; + public Long startTime; + public Vector3fImmutable loc; + + public Arena(){ + + } + public Boolean disqualify() { + HashSet inRange = WorldGrid.getObjectsInRangePartial(this.loc, 250f, MBServerStatics.MASK_PLAYER); + + //boot out all non competitors + for(AbstractWorldObject obj : inRange){ + if(obj.equals(this.player1)) + continue; + + if(obj.equals(this.player2)) + continue; + + PlayerCharacter intruder = (PlayerCharacter)obj; + MovementManager.translocate(intruder,new Vector3fImmutable(88853,32,45079),Regions.GetRegionForTeleport(new Vector3fImmutable(88853,32,45079))); + } + + if (!inRange.contains(this.player1) && inRange.contains(this.player2)) { + ArenaManager.endArena(this,this.player2,this.player1,"Player Has Left Arena"); + return true; + } else if (!inRange.contains(this.player2) && inRange.contains(this.player1)) { + ArenaManager.endArena(this,this.player1,this.player2,"Player Has Left Arena"); + return true; + }else if (!inRange.contains(this.player2) && !inRange.contains(this.player1)) { + ArenaManager.endArena(this,null,null,"Both Parties Have Left The Arena"); + return true; + } + return false; + } + + public Boolean checkToComplete(){ + + if(this.disqualify()) + return true; + + if(!this.player1.isAlive() && this.player2.isAlive()){ + ArenaManager.endArena(this,this.player2,this.player1,"Player Has Died"); + return true; + } else if(this.player1.isAlive() && !this.player2.isAlive()){ + ArenaManager.endArena(this,this.player1,this.player2,"Player Has Died"); + return true; + } else if(!this.player1.isAlive() && !this.player2.isAlive()){ + ArenaManager.endArena(this,null,null,"Both Players Have Died"); + return true; + } else if(this.startTime + 300000 > System.currentTimeMillis()){ + ArenaManager.endArena(this,null,null,"Time Has Elapsed"); + return true; + } + return false; + } +} diff --git a/src/engine/objects/Bane.java b/src/engine/objects/Bane.java index 7aa5ab58..44a4d326 100644 --- a/src/engine/objects/Bane.java +++ b/src/engine/objects/Bane.java @@ -742,7 +742,7 @@ public final class Bane { attackers.add(uuid); else if(city._playerMemory.contains(uuid)) - MovementManager.translocate(player,new Vector3fImmutable(88853,32,45079),Regions.GetRegionForTeleport(player.bindLoc)); + MovementManager.translocate(player,new Vector3fImmutable(88853,32,45079),Regions.GetRegionForTeleport(new Vector3fImmutable(88853,32,45079))); } int attackerSize = 0; int defenderSize = 0;