From 0e2ab0c294e1bc6703f2bbadd7ffe424b071fdcb Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sat, 23 Sep 2023 10:43:38 +0200 Subject: [PATCH 1/2] refactor(npc): renamed methods for spawning NPCs to make it more obvious what amount of NPCs are being spawned --- .../holocore/resources/support/npc/spawn/NPCCreator.java | 6 +++--- .../services/gameplay/missions/DestroyMissionTerminal.kt | 2 +- .../holocore/services/support/npc/spawn/SpawnerService.kt | 4 ++-- .../services/gameplay/combat/NpcDefaultAttackTest.kt | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/projectswg/holocore/resources/support/npc/spawn/NPCCreator.java b/src/main/java/com/projectswg/holocore/resources/support/npc/spawn/NPCCreator.java index ec9e9877a..502c3d54f 100644 --- a/src/main/java/com/projectswg/holocore/resources/support/npc/spawn/NPCCreator.java +++ b/src/main/java/com/projectswg/holocore/resources/support/npc/spawn/NPCCreator.java @@ -61,19 +61,19 @@ public class NPCCreator { - public static Collection createNPCs(Spawner spawner) { + public static Collection createAllNPCs(Spawner spawner) { Arguments.validate(spawner.getMinLevel() <= spawner.getMaxLevel(), "min level must be less than max level"); int amount = spawner.getAmount(); Collection npcs = new ArrayList<>(); for (int i = 0; i < amount; i++) { - npcs.add(createNPC(spawner)); + npcs.add(createSingleNpc(spawner)); } return npcs; } - private static AIObject createNPC(Spawner spawner) { + public static AIObject createSingleNpc(Spawner spawner) { int combatLevel = ThreadLocalRandom.current().nextInt(spawner.getMinLevel(), spawner.getMaxLevel()+1); AIObject object = ObjectCreator.createObjectFromTemplate(spawner.getRandomIffTemplate(), AIObject.class); diff --git a/src/main/java/com/projectswg/holocore/services/gameplay/missions/DestroyMissionTerminal.kt b/src/main/java/com/projectswg/holocore/services/gameplay/missions/DestroyMissionTerminal.kt index 79a80566f..27739b919 100644 --- a/src/main/java/com/projectswg/holocore/services/gameplay/missions/DestroyMissionTerminal.kt +++ b/src/main/java/com/projectswg/holocore/services/gameplay/missions/DestroyMissionTerminal.kt @@ -120,7 +120,7 @@ class DestroyMissionTerminal(private val missionsToGenerate: Int, private val de .withBehavior(AIBehavior.LOITER) .build() - NPCCreator.createNPCs(Spawner(spawnInfo, egg)) + NPCCreator.createAllNPCs(Spawner(spawnInfo, egg)) } private fun createLair(missionObject: MissionObject): TangibleObject { diff --git a/src/main/java/com/projectswg/holocore/services/support/npc/spawn/SpawnerService.kt b/src/main/java/com/projectswg/holocore/services/support/npc/spawn/SpawnerService.kt index 883e6b084..51e8cede3 100644 --- a/src/main/java/com/projectswg/holocore/services/support/npc/spawn/SpawnerService.kt +++ b/src/main/java/com/projectswg/holocore/services/support/npc/spawn/SpawnerService.kt @@ -154,7 +154,7 @@ class SpawnerService : Service() { if (respawnDelay > 0) { executor.execute((respawnDelay * 1000).toLong()) { - NPCCreator.createNPCs(spawner) + NPCCreator.createAllNPCs(spawner) } } else { DestroyObjectIntent.broadcast(spawner.egg) @@ -202,7 +202,7 @@ class SpawnerService : Service() { val spawner = Spawner(spawn, egg) egg.setServerAttribute(ServerAttribute.EGG_SPAWNER, spawner) - NPCCreator.createNPCs(spawner) + NPCCreator.createAllNPCs(spawner) val patrolRoute = spawner.patrolRoute if (patrolRoute != null) { diff --git a/src/test/java/com/projectswg/holocore/services/gameplay/combat/NpcDefaultAttackTest.kt b/src/test/java/com/projectswg/holocore/services/gameplay/combat/NpcDefaultAttackTest.kt index 9a696a816..b45c6a119 100644 --- a/src/test/java/com/projectswg/holocore/services/gameplay/combat/NpcDefaultAttackTest.kt +++ b/src/test/java/com/projectswg/holocore/services/gameplay/combat/NpcDefaultAttackTest.kt @@ -80,7 +80,7 @@ class NpcDefaultAttackTest : TestRunnerSynchronousIntents() { .withLocation(inFrontOfMosEisleyStarport) .build() - return NPCCreator.createNPCs(Spawner(spawnInfo, egg)).first() + return NPCCreator.createAllNPCs(Spawner(spawnInfo, egg)).first() } } \ No newline at end of file From 663d4818d81df7920da67aa1b5abfb75cce2fb49 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sat, 23 Sep 2023 10:45:24 +0200 Subject: [PATCH 2/2] fix(npc): when a single NPC is killed, we should not be respawning the max amount of NPCs supported by the spawner --- .../holocore/services/support/npc/spawn/SpawnerService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/projectswg/holocore/services/support/npc/spawn/SpawnerService.kt b/src/main/java/com/projectswg/holocore/services/support/npc/spawn/SpawnerService.kt index 51e8cede3..42dde3be6 100644 --- a/src/main/java/com/projectswg/holocore/services/support/npc/spawn/SpawnerService.kt +++ b/src/main/java/com/projectswg/holocore/services/support/npc/spawn/SpawnerService.kt @@ -154,7 +154,7 @@ class SpawnerService : Service() { if (respawnDelay > 0) { executor.execute((respawnDelay * 1000).toLong()) { - NPCCreator.createAllNPCs(spawner) + NPCCreator.createSingleNpc(spawner) } } else { DestroyObjectIntent.broadcast(spawner.egg)