This commit is contained in:
simon 2018-01-05 21:35:35 -05:00
parent 8b0460f5f1
commit 0bd25df977

View File

@ -20,35 +20,35 @@ public class UserCreationListener implements GameEventListener {
@Override @Override
public void handle(GameEvent event) { public void handle(GameEvent event) {
User user = (User) event.getSource();
LogManager.LOGGER.fine("(Plugin) Handled User creation event (Cubot Plugin)");
Cubot cubot = new Cubot();
Random random = new Random(); Random random = new Random();
User user = (User) event.getSource();
Cubot cubot = new Cubot();
cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
Point point = null;
while (point == null || cubot.getWorld() == null) {
int spawnX = GameServer.INSTANCE.getConfig().getInt("new_user_worldX") + random.nextInt(5); int spawnX = GameServer.INSTANCE.getConfig().getInt("new_user_worldX") + random.nextInt(5);
int spawnY = GameServer.INSTANCE.getConfig().getInt("new_user_worldY") + random.nextInt(5); int spawnY = GameServer.INSTANCE.getConfig().getInt("new_user_worldY") + random.nextInt(5);
cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(spawnX, spawnY, true)); cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(spawnX, spawnY, true));
point = cubot.getWorld().getRandomPassableTile();
}
cubot.setX(point.x);
cubot.setY(point.y);
cubot.getWorld().getGameObjects().add(cubot); cubot.getWorld().getGameObjects().add(cubot);
cubot.getWorld().incUpdatable(); cubot.getWorld().incUpdatable();
cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
cubot.setHeldItem(GameServer.INSTANCE.getConfig().getInt("new_user_item")); cubot.setHeldItem(GameServer.INSTANCE.getConfig().getInt("new_user_item"));
cubot.setEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy")); cubot.setEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy"));
cubot.setMaxEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy")); cubot.setMaxEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy"));
cubot.setParent(user); cubot.setParent(user);
Point point = cubot.getWorld().getRandomPassableTile();
cubot.setX(point.x);
cubot.setY(point.y);
user.setControlledUnit(cubot); user.setControlledUnit(cubot);
LogManager.LOGGER.fine("(Plugin) Handled User creation event (Cubot Plugin)");
} }
} }