@Test public void testNpcGenerator() { init(); Player player = new Player(); world.addEntity(player); world.gameLoop(1); assertEquals(0, world.getNpcEntities().size()); world.setNpcSpawnChance(1); assertEquals(1, world.getNpcSpawnChance()); int size = world.getNpcEntities().size(); world.setNpcGenEnabled(false); world.gameLoop(1); assertTrue(size == world.getNpcEntities().size()); world.setNpcGenEnabled(true); world.npcGenerator(player, 0, true, 0, BiomeType.FOREST); world.setNpcGenEnabled(false); world.gameLoop(1); assertTrue(world.getNpcEntities().stream().anyMatch(e -> e instanceof RatNPC)); world.setNpcGenEnabled(true); world.npcGenerator(player, 61, true, 0, BiomeType.ROCK); world.setNpcGenEnabled(false); world.gameLoop(1); assertTrue(world.getNpcEntities().stream().anyMatch(e -> e instanceof SkeletonNPC)); world.setNpcGenEnabled(true); world.npcGenerator(player, 1, true, 0, BiomeType.SNOW); world.setNpcGenEnabled(false); world.gameLoop(1); assertTrue(world.getNpcEntities().stream().anyMatch(e -> e instanceof IceSpiritNPC)); world.setNpcGenEnabled(true); world.npcGenerator(player, 1, true, 0, BiomeType.FOREST); world.setNpcGenEnabled(false); world.gameLoop(1); assertTrue(world.getNpcEntities().stream().anyMatch(e -> e instanceof FlyingNPC)); world.setNpcGenEnabled(true); world.npcGenerator(player, 1, true, 0, BiomeType.PLAIN); world.setNpcGenEnabled(false); world.gameLoop(1); assertTrue(world.getNpcEntities().stream().anyMatch(e -> e instanceof RhinoNPC)); world.setNpcGenEnabled(true); world.npcGenerator(player, 1, true, 0, BiomeType.DESERT); world.setNpcGenEnabled(false); world.gameLoop(1); assertTrue(world.getNpcEntities().stream().anyMatch(e -> e instanceof GhostShipNPC)); }
void npcGenerator(Player player, int spawnRate, boolean randomSpawn, int mobX, BiomeType biomeType) { if (isNpcGenEnabled() && randomGen.nextInt(npcSpawnChance) == 0) { if (randomSpawn) { mobX = (int) player.getX() + randomGen.nextInt(Chunk.CHUNK_WIDTH) + (Chunk.CHUNK_WIDTH / 2) * (randomGen.nextBoolean() ? 1 : -3); } if (biomeType == null) { biomeType = Chunk.getBiomeTypeOfX(mobX); } if (getNumMobsInChunk(mobX) >= NUM_MOBS_PER_CHUNK) { return; } BaseNPC mob; if (spawnRate == 0) { mob = new RatNPC(); } else { switch (biomeType) { case SNOW: mob = new IceSpiritNPC(); break; case PLAIN: if (spawnRate < 99) { mob = new RhinoNPC(); } else { mob = new SpaceSlimeNPC(); } break; case DESERT: if (spawnRate < 5) { mob = new GhostShipNPC(); } else if (spawnRate < 25) { mob = new MeleeEnemyNPC(); } else { mob = new EyeballNPC(); } break; case ROCK: if (spawnRate < 20) { mob = new RangedEnemyNPC(); } else if (spawnRate < 60){ mob= new GrenadierNPC(); }else { mob = new SkeletonNPC(); } break; case FOREST: mob = new BatNPC(); break; default: mob = new MeleeEnemyNPC(); break; } } if (!(mob instanceof GhostShipNPC) && (new Random()).nextFloat() < 0.03) { mob.setBoss(); } this.addEntity(mob); mob.setPosition(mobX, -10); if (mob instanceof SpaceSlimeNPC) { ((SpaceSlimeNPC) mob).spawnMob(); } } }
World { void npcGenerator(Player player, int spawnRate, boolean randomSpawn, int mobX, BiomeType biomeType) { if (isNpcGenEnabled() && randomGen.nextInt(npcSpawnChance) == 0) { if (randomSpawn) { mobX = (int) player.getX() + randomGen.nextInt(Chunk.CHUNK_WIDTH) + (Chunk.CHUNK_WIDTH / 2) * (randomGen.nextBoolean() ? 1 : -3); } if (biomeType == null) { biomeType = Chunk.getBiomeTypeOfX(mobX); } if (getNumMobsInChunk(mobX) >= NUM_MOBS_PER_CHUNK) { return; } BaseNPC mob; if (spawnRate == 0) { mob = new RatNPC(); } else { switch (biomeType) { case SNOW: mob = new IceSpiritNPC(); break; case PLAIN: if (spawnRate < 99) { mob = new RhinoNPC(); } else { mob = new SpaceSlimeNPC(); } break; case DESERT: if (spawnRate < 5) { mob = new GhostShipNPC(); } else if (spawnRate < 25) { mob = new MeleeEnemyNPC(); } else { mob = new EyeballNPC(); } break; case ROCK: if (spawnRate < 20) { mob = new RangedEnemyNPC(); } else if (spawnRate < 60){ mob= new GrenadierNPC(); }else { mob = new SkeletonNPC(); } break; case FOREST: mob = new BatNPC(); break; default: mob = new MeleeEnemyNPC(); break; } } if (!(mob instanceof GhostShipNPC) && (new Random()).nextFloat() < 0.03) { mob.setBoss(); } this.addEntity(mob); mob.setPosition(mobX, -10); if (mob instanceof SpaceSlimeNPC) { ((SpaceSlimeNPC) mob).spawnMob(); } } } }
World { void npcGenerator(Player player, int spawnRate, boolean randomSpawn, int mobX, BiomeType biomeType) { if (isNpcGenEnabled() && randomGen.nextInt(npcSpawnChance) == 0) { if (randomSpawn) { mobX = (int) player.getX() + randomGen.nextInt(Chunk.CHUNK_WIDTH) + (Chunk.CHUNK_WIDTH / 2) * (randomGen.nextBoolean() ? 1 : -3); } if (biomeType == null) { biomeType = Chunk.getBiomeTypeOfX(mobX); } if (getNumMobsInChunk(mobX) >= NUM_MOBS_PER_CHUNK) { return; } BaseNPC mob; if (spawnRate == 0) { mob = new RatNPC(); } else { switch (biomeType) { case SNOW: mob = new IceSpiritNPC(); break; case PLAIN: if (spawnRate < 99) { mob = new RhinoNPC(); } else { mob = new SpaceSlimeNPC(); } break; case DESERT: if (spawnRate < 5) { mob = new GhostShipNPC(); } else if (spawnRate < 25) { mob = new MeleeEnemyNPC(); } else { mob = new EyeballNPC(); } break; case ROCK: if (spawnRate < 20) { mob = new RangedEnemyNPC(); } else if (spawnRate < 60){ mob= new GrenadierNPC(); }else { mob = new SkeletonNPC(); } break; case FOREST: mob = new BatNPC(); break; default: mob = new MeleeEnemyNPC(); break; } } if (!(mob instanceof GhostShipNPC) && (new Random()).nextFloat() < 0.03) { mob.setBoss(); } this.addEntity(mob); mob.setPosition(mobX, -10); if (mob instanceof SpaceSlimeNPC) { ((SpaceSlimeNPC) mob).spawnMob(); } } } World(); }
World { void npcGenerator(Player player, int spawnRate, boolean randomSpawn, int mobX, BiomeType biomeType) { if (isNpcGenEnabled() && randomGen.nextInt(npcSpawnChance) == 0) { if (randomSpawn) { mobX = (int) player.getX() + randomGen.nextInt(Chunk.CHUNK_WIDTH) + (Chunk.CHUNK_WIDTH / 2) * (randomGen.nextBoolean() ? 1 : -3); } if (biomeType == null) { biomeType = Chunk.getBiomeTypeOfX(mobX); } if (getNumMobsInChunk(mobX) >= NUM_MOBS_PER_CHUNK) { return; } BaseNPC mob; if (spawnRate == 0) { mob = new RatNPC(); } else { switch (biomeType) { case SNOW: mob = new IceSpiritNPC(); break; case PLAIN: if (spawnRate < 99) { mob = new RhinoNPC(); } else { mob = new SpaceSlimeNPC(); } break; case DESERT: if (spawnRate < 5) { mob = new GhostShipNPC(); } else if (spawnRate < 25) { mob = new MeleeEnemyNPC(); } else { mob = new EyeballNPC(); } break; case ROCK: if (spawnRate < 20) { mob = new RangedEnemyNPC(); } else if (spawnRate < 60){ mob= new GrenadierNPC(); }else { mob = new SkeletonNPC(); } break; case FOREST: mob = new BatNPC(); break; default: mob = new MeleeEnemyNPC(); break; } } if (!(mob instanceof GhostShipNPC) && (new Random()).nextFloat() < 0.03) { mob.setBoss(); } this.addEntity(mob); mob.setPosition(mobX, -10); if (mob instanceof SpaceSlimeNPC) { ((SpaceSlimeNPC) mob).spawnMob(); } } } World(); static World getInstance(); void setEntityRenderDistance(int entityRenderDistance); int getEntityRenderDistance(); void setGlobalLightLevel(int lightLevel); int getGlobalLightLevel(); void addTerrainWaveform(Waveform waveform); void addCaveWaveform(Waveform waveform); boolean isChunkGenerationEnabled(); boolean isRandomSeedEnabled(); void setRandomSeedEnabled(boolean randomSeedEnabled); static int getMapSeed(); void setTiles(WorldTiles tileTemplate); void resetTiles(); void resetWorld(); void debugReset(); void setLighting(boolean lightingState); boolean getLightingState(); void initMulti(); void setDifficulty(Difficulty option); void toggleHitboxes(); boolean renderHitboxes(); void addEntity(Entity entity); void deleteEntity(Entity entity); void addIngameText(IngameText ingameText); List<IngameText> getIngameTexts(); void setPlayerText(IngameText ingameText); IngameText getPlayerText(); Debug getDebug(); List<Entity> getAllEntities(); List<Entity> getNpcEntities(); List<Entity> getMountEntities(); List<Decoration> getDecorationEntities(); List<ItemEntity> getItemEntities(); List<Player> getPlayerEntities(); List<TerrainEntity> getTerrainEntities(); long getFps(); WorldTiles getTiles(); boolean isGameOver(); void loadAroundPlayer(Player player); void gameLoop(long ms); void gameLoopMulti(long ms); void setLightning(boolean input); void loadPlayer(ExportablePlayer ep); void loadEntities(List<ExportableEntity> ee); boolean getSkillTreeScreen(); double getDifficulty(); boolean isNpcGenEnabled(); void toggleNpcGen(); void setNpcGenEnabled(boolean npcGenEnabled); void setLightGenEnabled(boolean enabled); boolean isDecoGenEnabled(); void setDecoGenEnabled(boolean enabled); boolean isBuildingGenEnabled(); void setBuildingGenEnabled(boolean enabled); boolean isTotemGenEnabled(); void setTotemGenEnabled(boolean enabled); CoasterClient getClient(); void setClient(CoasterClient client); User getUser(); void setUser(User user); Player getFirstPlayer(); void setTutorialMode(boolean tutorialMode); boolean getTutorialMode(); void setTerrainDestruction(boolean input); boolean getTerrainDestructionMode(); static WorldTiles getTutorialWorld(); WorldTiles getMultiWorld(); void checkDecorations(); boolean getDestructionShadowUpdate(); void setDestructionShadowUpdate(boolean update); static void handleEnterRoom(); }
World { void npcGenerator(Player player, int spawnRate, boolean randomSpawn, int mobX, BiomeType biomeType) { if (isNpcGenEnabled() && randomGen.nextInt(npcSpawnChance) == 0) { if (randomSpawn) { mobX = (int) player.getX() + randomGen.nextInt(Chunk.CHUNK_WIDTH) + (Chunk.CHUNK_WIDTH / 2) * (randomGen.nextBoolean() ? 1 : -3); } if (biomeType == null) { biomeType = Chunk.getBiomeTypeOfX(mobX); } if (getNumMobsInChunk(mobX) >= NUM_MOBS_PER_CHUNK) { return; } BaseNPC mob; if (spawnRate == 0) { mob = new RatNPC(); } else { switch (biomeType) { case SNOW: mob = new IceSpiritNPC(); break; case PLAIN: if (spawnRate < 99) { mob = new RhinoNPC(); } else { mob = new SpaceSlimeNPC(); } break; case DESERT: if (spawnRate < 5) { mob = new GhostShipNPC(); } else if (spawnRate < 25) { mob = new MeleeEnemyNPC(); } else { mob = new EyeballNPC(); } break; case ROCK: if (spawnRate < 20) { mob = new RangedEnemyNPC(); } else if (spawnRate < 60){ mob= new GrenadierNPC(); }else { mob = new SkeletonNPC(); } break; case FOREST: mob = new BatNPC(); break; default: mob = new MeleeEnemyNPC(); break; } } if (!(mob instanceof GhostShipNPC) && (new Random()).nextFloat() < 0.03) { mob.setBoss(); } this.addEntity(mob); mob.setPosition(mobX, -10); if (mob instanceof SpaceSlimeNPC) { ((SpaceSlimeNPC) mob).spawnMob(); } } } World(); static World getInstance(); void setEntityRenderDistance(int entityRenderDistance); int getEntityRenderDistance(); void setGlobalLightLevel(int lightLevel); int getGlobalLightLevel(); void addTerrainWaveform(Waveform waveform); void addCaveWaveform(Waveform waveform); boolean isChunkGenerationEnabled(); boolean isRandomSeedEnabled(); void setRandomSeedEnabled(boolean randomSeedEnabled); static int getMapSeed(); void setTiles(WorldTiles tileTemplate); void resetTiles(); void resetWorld(); void debugReset(); void setLighting(boolean lightingState); boolean getLightingState(); void initMulti(); void setDifficulty(Difficulty option); void toggleHitboxes(); boolean renderHitboxes(); void addEntity(Entity entity); void deleteEntity(Entity entity); void addIngameText(IngameText ingameText); List<IngameText> getIngameTexts(); void setPlayerText(IngameText ingameText); IngameText getPlayerText(); Debug getDebug(); List<Entity> getAllEntities(); List<Entity> getNpcEntities(); List<Entity> getMountEntities(); List<Decoration> getDecorationEntities(); List<ItemEntity> getItemEntities(); List<Player> getPlayerEntities(); List<TerrainEntity> getTerrainEntities(); long getFps(); WorldTiles getTiles(); boolean isGameOver(); void loadAroundPlayer(Player player); void gameLoop(long ms); void gameLoopMulti(long ms); void setLightning(boolean input); void loadPlayer(ExportablePlayer ep); void loadEntities(List<ExportableEntity> ee); boolean getSkillTreeScreen(); double getDifficulty(); boolean isNpcGenEnabled(); void toggleNpcGen(); void setNpcGenEnabled(boolean npcGenEnabled); void setLightGenEnabled(boolean enabled); boolean isDecoGenEnabled(); void setDecoGenEnabled(boolean enabled); boolean isBuildingGenEnabled(); void setBuildingGenEnabled(boolean enabled); boolean isTotemGenEnabled(); void setTotemGenEnabled(boolean enabled); CoasterClient getClient(); void setClient(CoasterClient client); User getUser(); void setUser(User user); Player getFirstPlayer(); void setTutorialMode(boolean tutorialMode); boolean getTutorialMode(); void setTerrainDestruction(boolean input); boolean getTerrainDestructionMode(); static WorldTiles getTutorialWorld(); WorldTiles getMultiWorld(); void checkDecorations(); boolean getDestructionShadowUpdate(); void setDestructionShadowUpdate(boolean update); static void handleEnterRoom();  }