From 2ac3ce5bc8362bb8a7492424b5c9c99341ee8d81 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 1 Jan 2025 19:18:31 -0600 Subject: [PATCH] Arena System --- src/engine/gameManager/ArenaManager.java | 27 ++++++++++++----- src/engine/gameManager/SimulationManager.java | 5 ++-- src/engine/objects/Arena.java | 8 +++++ src/engine/objects/Contract.java | 30 ++++++++++++------- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/engine/gameManager/ArenaManager.java b/src/engine/gameManager/ArenaManager.java index 2175c24b..4c95e2ae 100644 --- a/src/engine/gameManager/ArenaManager.java +++ b/src/engine/gameManager/ArenaManager.java @@ -1,22 +1,25 @@ package engine.gameManager; +import engine.InterestManagement.WorldGrid; import engine.math.Vector3fImmutable; -import engine.objects.Arena; -import engine.objects.PlayerCharacter; -import engine.objects.Regions; -import engine.objects.Zone; +import engine.objects.*; +import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class ArenaManager { private static final List activeArenas = new ArrayList<>(); public static final List playerQueue = new ArrayList<>(); + public static Long pulseDelay = 180000L; + public static Long lastExecution = 0L; public static void pulseArenas() { + if(lastExecution == 0L){ + lastExecution = System.currentTimeMillis(); + } + Iterator iterator = activeArenas.iterator(); while (iterator.hasNext()) { @@ -26,6 +29,11 @@ public class ArenaManager { } } + if(lastExecution + pulseDelay < System.currentTimeMillis()) + return; + + lastExecution = System.currentTimeMillis(); + while (playerQueue.size() > 1) { createArena(); } @@ -43,6 +51,7 @@ public class ArenaManager { private static void createArena() { if (playerQueue.size() > 1) { + Collections.shuffle(playerQueue); Arena newArena = new Arena(); //decide an arena location @@ -87,7 +96,9 @@ public class ArenaManager { loc = new Vector3fImmutable(x, y, z); Zone zone = ZoneManager.findSmallestZone(loc); if (zone.isContinent() && !ZoneManager.getSeaFloor().equals(zone)) { - locSet = true; + HashSet inRange = WorldGrid.getObjectsInRangePartial(loc,250f, MBServerStatics.MASK_PLAYER); + if(inRange.isEmpty()) + locSet = true; } }catch(Exception e){ diff --git a/src/engine/gameManager/SimulationManager.java b/src/engine/gameManager/SimulationManager.java index 1651e5c9..6e9d4423 100644 --- a/src/engine/gameManager/SimulationManager.java +++ b/src/engine/gameManager/SimulationManager.java @@ -113,9 +113,10 @@ public enum SimulationManager { } try { - if ((_cityPulseTime != 0) - && (System.currentTimeMillis() > _cityPulseTime)) + if ((_cityPulseTime != 0) && (System.currentTimeMillis() > _cityPulseTime)) { pulseCities(); + ArenaManager.pulseArenas(); + } } catch (Exception e) { Logger.error( "Fatal error in City Pulse: DISABLED. Error Message : " diff --git a/src/engine/objects/Arena.java b/src/engine/objects/Arena.java index 0f5af258..dc26eb02 100644 --- a/src/engine/objects/Arena.java +++ b/src/engine/objects/Arena.java @@ -2,6 +2,7 @@ package engine.objects; import engine.InterestManagement.WorldGrid; import engine.gameManager.ArenaManager; +import engine.gameManager.ChatManager; import engine.gameManager.MovementManager; import engine.math.Vector3fImmutable; import engine.server.MBServerStatics; @@ -19,7 +20,14 @@ public class Arena { } public Boolean disqualify() { HashSet inRange = WorldGrid.getObjectsInRangePartial(this.loc, 250f, MBServerStatics.MASK_PLAYER); + HashSet warningRange = WorldGrid.getObjectsInRangePartial(this.loc, 500f, MBServerStatics.MASK_PLAYER); + for(AbstractWorldObject obj : warningRange){ + PlayerCharacter pc = (PlayerCharacter)obj; + if(pc.equals(this.player1) || pc.equals(this.player2)) + continue; + ChatManager.chatSystemInfo(pc, "WARNING!! You are entering an arena zone!"); + } //boot out all non competitors for(AbstractWorldObject obj : inRange){ if(obj.equals(this.player1)) diff --git a/src/engine/objects/Contract.java b/src/engine/objects/Contract.java index 7e1e51ec..e2bf2df4 100644 --- a/src/engine/objects/Contract.java +++ b/src/engine/objects/Contract.java @@ -202,23 +202,31 @@ public class Contract extends AbstractGameObject { vd.getOptions().clear(); switch(optionId){ - default: - MenuOption option1 = new MenuOption(15020431, "Join Arena Que", 15020431); - vd.getOptions().add(option1); - MenuOption option2 = new MenuOption(15020432, "Leave Arena Que", 15020432); - vd.getOptions().add(option2); - break; case 15020431: - ArenaManager.joinQueue(pc); - ChatManager.chatSystemInfo(pc, "You Have Joined The Arena Que"); + if(pc.isBoxed){ + ChatManager.chatSystemInfo(pc, "You Cannot Join The Que, You Are Boxed"); + }else { + if (ArenaManager.playerQueue.contains(pc)) { + ChatManager.chatSystemInfo(pc, "You Are Already In The Arena Que"); + } else { + ArenaManager.joinQueue(pc); + ChatManager.chatSystemInfo(pc, "You Have Joined The Arena Que"); + } + } break; case 15020432: - if(ArenaManager.playerQueue.contains(pc)) + if(ArenaManager.playerQueue.contains(pc)) { ArenaManager.leaveQueue(pc); - ChatManager.chatSystemInfo(pc, "You Have Left The Arena Que"); + ChatManager.chatSystemInfo(pc, "You Have Left The Arena Que"); + }else{ + ChatManager.chatSystemInfo(pc, "You Are Not In The Arena Que"); + } break; } - + MenuOption option1 = new MenuOption(15020431, "Join Arena Que", 15020431); + vd.getOptions().add(option1); + MenuOption option2 = new MenuOption(15020432, "Leave Arena Que", 15020432); + vd.getOptions().add(option2); return vd; } public static VendorDialog HandleEnrollmentOfficer(int optionId, NPC npc, PlayerCharacter pc){