Browse Source

Arena Infrastructure

lakebane2
FatBoy-DOTC 2 weeks ago
parent
commit
9d5c4424a1
  1. 99
      src/engine/gameManager/ArenaManager.java
  2. 68
      src/engine/objects/Arena.java
  3. 2
      src/engine/objects/Bane.java

99
src/engine/gameManager/ArenaManager.java

@ -0,0 +1,99 @@ @@ -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<Arena> activeArenas = new ArrayList<>();
private static final List<PlayerCharacter> playerQueue = new ArrayList<>();
public static void pulseArenas() {
Iterator<Arena> 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;
}
}

68
src/engine/objects/Arena.java

@ -0,0 +1,68 @@ @@ -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<AbstractWorldObject> 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;
}
}

2
src/engine/objects/Bane.java

@ -742,7 +742,7 @@ public final class Bane { @@ -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;

Loading…
Cancel
Save