UHC map gen
This commit is contained in:
parent
5ec60d234a
commit
123af16bd2
@ -98,8 +98,8 @@ public class UtilTime
|
||||
if (type == TimeUnit.DAYS) text = (num = UtilMath.trim(trim, time / 86400000d)) + " Day";
|
||||
else if (type == TimeUnit.HOURS) text = (num = UtilMath.trim(trim, time / 3600000d)) + " Hour";
|
||||
else if (type == TimeUnit.MINUTES) text = (num = UtilMath.trim(trim, time / 60000d)) + " Minute";
|
||||
else if (type == TimeUnit.SECONDS) text = (num = UtilMath.trim(trim, time / 1000d)) + " Second";
|
||||
else text = (num = UtilMath.trim(trim, time)) + " Millisecond";
|
||||
else if (type == TimeUnit.SECONDS) text = (int) (num = (int) UtilMath.trim(0, time / 1000d)) + " Second";
|
||||
else text = (int) (num = (int) UtilMath.trim(0, time)) + " Millisecond";
|
||||
}
|
||||
|
||||
if (num != 1)
|
||||
|
@ -75,10 +75,7 @@ public class TimingManager implements Listener
|
||||
{
|
||||
if (_totalList.containsKey(title))
|
||||
{
|
||||
TimeData data = _totalList.get(title);
|
||||
data.addTime();
|
||||
|
||||
_totalList.put(title, data);
|
||||
_totalList.get(title).addTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -57,10 +57,7 @@ import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
@ -86,6 +83,11 @@ public class UHC extends TeamGame
|
||||
|
||||
private int _borderSize = 1000;
|
||||
private int _yMax = 0;
|
||||
|
||||
private Chunk _chunk = null;
|
||||
private int _chunkX = 0;
|
||||
private int _chunkZ = 0;
|
||||
private int _chunksLoaded = 0;
|
||||
|
||||
private int _gameMinutes = 0;
|
||||
private int _safeTime = 11;
|
||||
@ -93,7 +95,6 @@ public class UHC extends TeamGame
|
||||
|
||||
private Objective _scoreObj;
|
||||
|
||||
private long _hour = 3600000;
|
||||
private long _createTime;
|
||||
private long _serverTime;
|
||||
private boolean _mapLoaded = false;
|
||||
@ -189,6 +190,161 @@ public class UHC extends TeamGame
|
||||
public void ParseData()
|
||||
{
|
||||
WorldData.World.setDifficulty(Difficulty.HARD);
|
||||
|
||||
_chunkX = -(_borderSize / 16);
|
||||
_chunkZ = -(_borderSize / 16);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void loadMap(UpdateEvent event)
|
||||
{
|
||||
if (_mapLoaded)
|
||||
return;
|
||||
|
||||
int chunksPerTick = 4;
|
||||
|
||||
//Print Debug
|
||||
if (event.getType() == UpdateType.SLOW)
|
||||
{
|
||||
int chunkTotal = (_borderSize*2/16)*(_borderSize*2/16);
|
||||
|
||||
int chunksToGo = chunkTotal - _chunksLoaded;
|
||||
|
||||
Announce(C.cGreen + C.Bold + "Generating Map: " + ChatColor.RESET +
|
||||
UtilTime.MakeStr((long)((double)chunksToGo / (double)(20 * chunksPerTick) * 1000d), 1));
|
||||
|
||||
TimingManager.endTotal("UHC Generation", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
//Timings
|
||||
TimingManager.startTotal("UHC Generation");
|
||||
|
||||
for (int i=0 ; i<chunksPerTick ; i++)
|
||||
{
|
||||
//Unload Previous
|
||||
if (_chunk != null)
|
||||
_chunk.unload(true);
|
||||
|
||||
//Load Chunks
|
||||
_chunk = WorldData.World.getChunkAt(_chunkX, _chunkZ);
|
||||
_chunk.load(true);
|
||||
|
||||
//Scan Map
|
||||
if (_chunkX < _borderSize / 16)
|
||||
{
|
||||
_chunkX++;
|
||||
}
|
||||
else if (_chunkZ < _borderSize / 16)
|
||||
{
|
||||
_chunkX = -(_borderSize / 16);
|
||||
_chunkZ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapLoaded = true;
|
||||
System.out.println("Map Loading Finished!");
|
||||
generateSpawns();
|
||||
}
|
||||
|
||||
_chunksLoaded++;
|
||||
}
|
||||
|
||||
//Timings
|
||||
TimingManager.stopTotal("UHC Generation");
|
||||
}
|
||||
|
||||
public void generateSpawns()
|
||||
{
|
||||
//Wipe Spawns
|
||||
for (GameTeam team : this.GetTeamList())
|
||||
{
|
||||
team.GetSpawns().clear();
|
||||
}
|
||||
|
||||
TimingManager.start("UHC Spawn Generation");
|
||||
|
||||
//Solo Game
|
||||
if (this.GetTeamList().size() == 1)
|
||||
{
|
||||
while (GetTeamList().get(0).GetSpawns().size() < this.GetPlayers(true).size())
|
||||
{
|
||||
Location loc = GetRandomSpawn(null);
|
||||
|
||||
//Dynamically scale distance requirement based on how many teams need to fit
|
||||
double dist = (2*_borderSize) / (Math.sqrt(this.GetPlayers(true).size()) + 3);
|
||||
|
||||
//Ensure distance between Teams
|
||||
while (true)
|
||||
{
|
||||
boolean clash = false;
|
||||
|
||||
for (Location otherSpawn : GetTeamList().get(0).GetSpawns())
|
||||
{
|
||||
if (UtilMath.offset(loc, otherSpawn) < dist)
|
||||
{
|
||||
clash = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clash)
|
||||
break;
|
||||
|
||||
loc = GetRandomSpawn(null);
|
||||
}
|
||||
|
||||
GetTeamList().get(0).GetSpawns().add(loc);
|
||||
}
|
||||
}
|
||||
//Team Game
|
||||
else
|
||||
{
|
||||
for (GameTeam team : GetTeamList())
|
||||
{
|
||||
Location loc = GetRandomSpawn(null);
|
||||
|
||||
//Dynamically scale distance requirement based on how many teams need to fit
|
||||
double dist = (2*_borderSize) / (Math.sqrt(GetTeamList().size()) + 3);
|
||||
|
||||
//Ensure distance between Teams
|
||||
while (true)
|
||||
{
|
||||
boolean clash = false;
|
||||
|
||||
for (GameTeam otherTeam : GetTeamList())
|
||||
{
|
||||
if (otherTeam.GetSpawns().isEmpty())
|
||||
continue;
|
||||
|
||||
if (UtilMath.offset(loc, otherTeam.GetSpawn()) < dist)
|
||||
{
|
||||
clash = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clash)
|
||||
break;
|
||||
|
||||
loc = GetRandomSpawn(null);
|
||||
}
|
||||
|
||||
team.GetSpawns().add(loc);
|
||||
|
||||
while (team.GetSpawns().size() < 20)
|
||||
{
|
||||
Location other = GetRandomSpawn(loc);
|
||||
|
||||
team.GetSpawns().add(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TimingManager.stop("UHC Spawn Generation");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -350,100 +506,6 @@ public class UHC extends TeamGame
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void GenerateSpawns(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() != GameState.Recruit)
|
||||
return;
|
||||
|
||||
//Wipe Spawns
|
||||
for (GameTeam team : this.GetTeamList())
|
||||
{
|
||||
team.GetSpawns().clear();
|
||||
}
|
||||
|
||||
TimingManager.start("UHC Spawn Generation");
|
||||
|
||||
//Solo Game
|
||||
if (this.GetTeamList().size() == 1)
|
||||
{
|
||||
while (GetTeamList().get(0).GetSpawns().size() < this.GetPlayers(true).size())
|
||||
{
|
||||
Location loc = GetRandomSpawn(null);
|
||||
|
||||
//Dynamically scale distance requirement based on how many teams need to fit
|
||||
double dist = (2*_borderSize) / (Math.sqrt(this.GetPlayers(true).size()) + 3);
|
||||
|
||||
//Ensure distance between Teams
|
||||
while (true)
|
||||
{
|
||||
boolean clash = false;
|
||||
|
||||
for (Location otherSpawn : GetTeamList().get(0).GetSpawns())
|
||||
{
|
||||
if (UtilMath.offset(loc, otherSpawn) < dist)
|
||||
{
|
||||
clash = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clash)
|
||||
break;
|
||||
|
||||
loc = GetRandomSpawn(null);
|
||||
}
|
||||
|
||||
GetTeamList().get(0).GetSpawns().add(loc);
|
||||
}
|
||||
}
|
||||
//Team Game
|
||||
else
|
||||
{
|
||||
for (GameTeam team : GetTeamList())
|
||||
{
|
||||
Location loc = GetRandomSpawn(null);
|
||||
|
||||
//Dynamically scale distance requirement based on how many teams need to fit
|
||||
double dist = (2*_borderSize) / (Math.sqrt(GetTeamList().size()) + 3);
|
||||
|
||||
//Ensure distance between Teams
|
||||
while (true)
|
||||
{
|
||||
boolean clash = false;
|
||||
|
||||
for (GameTeam otherTeam : GetTeamList())
|
||||
{
|
||||
if (otherTeam.GetSpawns().isEmpty())
|
||||
continue;
|
||||
|
||||
if (UtilMath.offset(loc, otherTeam.GetSpawn()) < dist)
|
||||
{
|
||||
clash = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clash)
|
||||
break;
|
||||
|
||||
loc = GetRandomSpawn(null);
|
||||
}
|
||||
|
||||
team.GetSpawns().add(loc);
|
||||
|
||||
while (team.GetSpawns().size() < 20)
|
||||
{
|
||||
Location other = GetRandomSpawn(loc);
|
||||
|
||||
team.GetSpawns().add(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TimingManager.stop("UHC Spawn Generation");
|
||||
}
|
||||
|
||||
public Location GetRandomSpawn(Location around)
|
||||
{
|
||||
HashSet<Material> ignore = new HashSet<Material>();
|
||||
|
@ -224,11 +224,8 @@ public class GameManager implements Listener
|
||||
|
||||
public void StateCountdown(Game game, int timer, boolean force)
|
||||
{
|
||||
if (game instanceof UHC)
|
||||
{
|
||||
if (((UHC)game).isMapLoaded())
|
||||
return;
|
||||
}
|
||||
if (game instanceof UHC && !((UHC)game).isMapLoaded())
|
||||
return;
|
||||
|
||||
//Disabling Cosmetics
|
||||
if (game.GetCountdown() <= 5 && game.GetCountdown() >= 0 && game.GadgetsDisabled)
|
||||
|
Loading…
Reference in New Issue
Block a user