Spawn facing fixes

This commit is contained in:
libraryaddict 2015-10-30 16:06:47 +13:00
parent 50edf557ab
commit da0a99d662
2 changed files with 151 additions and 17 deletions

View File

@ -111,6 +111,18 @@ public class GameTeam
return _spawns;
}
private Location fixFacing(Location loc)
{
float yaw = UtilAlg.GetYaw(UtilAlg.getTrajectory2d(loc, Host.GetSpectatorLocation()));
yaw = (int) (yaw / 90) * 90;
loc = loc.clone();
loc.setYaw(yaw);
return loc;
}
public Location GetSpawn()
{
//Keep allies together
@ -119,7 +131,7 @@ public class GameTeam
//Find Location Nearest Ally
Location loc = UtilAlg.getLocationNearPlayers(_spawns, GetPlayers(true), Host.GetPlayers(true));
if (loc != null)
return loc;
return fixFacing(loc);
//No allies existed spawned yet
@ -128,14 +140,14 @@ public class GameTeam
{
loc = UtilAlg.getLocationNearPlayers(_spawns, Host.GetPlayers(true), Host.GetPlayers(true));
if (loc != null)
return loc;
return fixFacing(loc);
}
//Spawn away from enemies
else
{
loc = UtilAlg.getLocationAwayFromPlayers(_spawns, Host.GetPlayers(true));
if (loc != null)
return loc;
return fixFacing(loc);
}
}
else
@ -145,18 +157,18 @@ public class GameTeam
{
Location loc = UtilAlg.getLocationNearPlayers(_spawns, Host.GetPlayers(true), Host.GetPlayers(true));
if (loc != null)
return loc;
return fixFacing(loc);
}
//Spawn away from players
else
{
Location loc = UtilAlg.getLocationAwayFromPlayers(_spawns, Host.GetPlayers(true));
if (loc != null)
return loc;
return fixFacing(loc);
}
}
return _spawns.get(UtilMath.r(_spawns.size()));
return fixFacing(_spawns.get(UtilMath.r(_spawns.size())));
}
public void AddPlayer(Player player, boolean in)

View File

@ -13,14 +13,12 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlockText;
import mineplex.core.common.util.UtilBlockText.TextAlign;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
@ -28,7 +26,6 @@ import mineplex.core.common.util.UtilWorld;
import mineplex.core.cosmetic.event.ActivateGemBoosterEvent;
import mineplex.core.donation.Donor;
import mineplex.core.event.CustomTagEvent;
import mineplex.core.explosion.ExplosionEvent;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
@ -137,8 +134,19 @@ public class GameLobbyManager implements Listener
_advText = new Location(world, 0, 140, -60);
_kitDisplay = new Location(world, -17, 101, 0);
float yaw = UtilAlg.GetYaw(UtilAlg.getTrajectory(_kitDisplay,
getRealSpawn()));
yaw = Math.round(yaw / 90) * 90;
_kitDisplay.setYaw(yaw);
_teamDisplay = new Location(world, 18, 101, 0);
yaw = UtilAlg.GetYaw(UtilAlg
.getTrajectory(_teamDisplay, getRealSpawn()));
yaw = Math.round(yaw / 90) * 90;
_teamDisplay.setYaw(yaw);
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
_serverName = Manager.getPlugin().getConfig().getString("serverstatus.name");
@ -295,9 +303,19 @@ public class GameLobbyManager implements Listener
UtilBlockText.MakeText(text, loc, face, id, data, TextAlign.CENTER);
}
public Location GetSpawn()
{
return spawn.clone().add(4 - Math.random()*8, 0, 4 - Math.random()*8);
public Location GetSpawn()
{
Location loc = spawn.clone().add(4 - Math.random() * 8, 0,
4 - Math.random() * 8);
loc.setYaw(90);
return loc;
}
public Location getRealSpawn()
{
return spawn;
}
@EventHandler(priority = EventPriority.MONITOR)
@ -340,6 +358,57 @@ public class GameLobbyManager implements Listener
CreateScoreboards();
return;
}
//UHC
if (game.GetType() == GameType.UHC)
{
if (game.GetTeamList().size() > 1)
{
//Text
WriteTeamLine("", 0, 159, (byte)15);
WriteTeamLine("", 1, 159, (byte)4);
for (int i=0 ; i<game.GetTeamList().size() ; i++)
{
GameTeam team = game.GetTeamList().get(i);
//Circle Math
double lead = i * ((2d * Math.PI)/game.GetTeamList().size());
double sizeMod = 32;
double oX = -Math.sin(lead) * sizeMod;
double oZ = Math.cos(lead) * sizeMod;
//Location
Location entLoc = spawn.clone().add(oX, 0, oZ);
entLoc.setY(_teamDisplay.getY());
//Blocks
SetKitTeamBlocks(entLoc.clone(), 35, team.GetColorData(), _teamBlocks);
entLoc.add(0, 1.5, 0);
entLoc.getChunk().load();
//NPC
Sheep ent = (Sheep)Manager.GetCreature().SpawnEntity(entLoc, EntityType.SHEEP);
ent.setRemoveWhenFarAway(false);
ent.setCustomNameVisible(false);
ent.setColor(DyeColor.getByWoolData(team.GetColorData()));
UtilEnt.Vegetate(ent);
team.SetTeamEntity(ent);
_teams.put(ent, new LobbyEnt(ent, entLoc, team));
}
return;
}
return;
}
//Standard
if ((game.GetKits().length > 1 || game.GetTeamList().size() < 6) && game.GetType() != GameType.SurvivalGamesTeams)
@ -434,7 +503,7 @@ public class GameLobbyManager implements Listener
for (int i=0 ; i<teamsB.size() ; i++)
{
Location entLoc = _kitDisplay.clone().subtract(0, 0, i*space - offset);
Location entLoc = _kitDisplay.clone().subtract(0, 0, i * space - offset);
SetKitTeamBlocks(entLoc.clone(), 35, teamsB.get(i).GetColorData(), _teamBlocks);
@ -541,7 +610,7 @@ public class GameLobbyManager implements Listener
if (kit.GetAvailability() == KitAvailability.Null)
continue;
Location entLoc = _kitDisplay.clone().subtract(0, 0, i*space - offset);
Location entLoc = _kitDisplay.clone().subtract(0, 0, i * space - offset);
byte data = 4;
if (kit.GetAvailability() == KitAvailability.Gem) data = 5;
@ -594,10 +663,63 @@ public class GameLobbyManager implements Listener
return;
}
//Positions
double space = 4;
double offset = (kits.size()-1)*space/2d;
if (game.GetType() == GameType.SearchAndDestroy)
{
int length = game.GetKits().length;
if (length > 10)
{
for (int i = 0; i < length; i++)
{
Kit kit = game.GetKits()[i];
if (kit.GetAvailability() == KitAvailability.Null)
continue;
// Circle Math
double lead = ((1.1 * ((i + .5) - (length / 2D))) + (length / 2D)) * ((2d * Math.PI) / (length * 2));
double sizeMod = 18;
double oX = -Math.sin(lead) * sizeMod;
double oZ = Math.cos(lead) * sizeMod;
// Location
Location entLoc = spawn.clone().add(Math.floor(oX), 0,
Math.floor(oZ));
entLoc.setY(_kitDisplay.getY());
float yaw = UtilAlg.GetYaw(UtilAlg.getTrajectory2d(entLoc, Manager
.GetLobby().getRealSpawn()));
entLoc.setYaw(yaw);
// Blocks
byte data = 4;
if (kit.GetAvailability() == KitAvailability.Gem)
data = 5;
else if (kit.GetAvailability() == KitAvailability.Achievement)
data = 2;
SetKitTeamBlocks(entLoc.clone(), 35, data, _kitBlocks);
entLoc.add(0, 1.5, 0);
entLoc.getChunk().load();
// NPC
Entity ent = kit.SpawnEntity(entLoc);
if (ent == null)
continue;
_kits.put(ent, new LobbyEnt(ent, entLoc, kit));
}
return;
}
}
for (int i=0 ; i<kits.size() ; i++)
{
@ -606,7 +728,7 @@ public class GameLobbyManager implements Listener
if (kit.GetAvailability() == KitAvailability.Null)
continue;
Location entLoc = _kitDisplay.clone().subtract(0, 0, i*space - offset);
Location entLoc = _kitDisplay.clone().subtract(0, 0, i * space - offset);
byte data = 4;
if (kit.GetAvailability() == KitAvailability.Gem) data = 5;