From b412a24657435f31402b49bed16b43423b8bfd55 Mon Sep 17 00:00:00 2001 From: Nazrin Date: Fri, 9 Jun 2023 10:27:34 -0700 Subject: [PATCH] Smarter NPC loading (#2199) --- .../emu/grasscutter/game/world/Scene.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 2c8d8c735..dafedb57e 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -696,18 +696,6 @@ public final class Scene { npcBornEntries.addAll(loadNpcForPlayer(player)); } - // clear the unreachable group for client - var toUnload = - this.npcBornEntrySet.stream() - .filter(i -> !npcBornEntries.contains(i)) - .map(SceneNpcBornEntry::getGroupId) - .toList(); - - if (toUnload.size() > 0) { - broadcastPacket(new PacketGroupUnloadNotify(toUnload)); - Grasscutter.getLogger().trace("Unload NPC Group {}", toUnload); - } - // exchange the new npcBornEntry Set this.npcBornEntrySet = npcBornEntries; } @@ -1160,14 +1148,24 @@ public final class Scene { pos.toDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange); - var sceneNpcBornEntries = + var sceneNpcBornCanidates = npcList.stream().filter(i -> !this.npcBornEntrySet.contains(i)).toList(); + List sceneNpcBornEntries = new ArrayList<>(); + sceneNpcBornCanidates.forEach( + i -> { + var groupInstance = scriptManager.getGroupInstanceById(i.getGroupId()); + if (groupInstance == null) return; + if (i.getSuiteIdList() != null && !i.getSuiteIdList().contains(groupInstance.getActiveSuiteId())) return; + sceneNpcBornEntries.add(i); + }); + if (sceneNpcBornEntries.size() > 0) { this.broadcastPacket(new PacketGroupSuiteNotify(sceneNpcBornEntries)); Grasscutter.getLogger().trace("Loaded Npc Group Suite {}", sceneNpcBornEntries); } - return npcList; + + return npcList.stream().filter(i -> this.npcBornEntrySet.contains(i) || sceneNpcBornEntries.contains(i)).toList(); } public void loadGroupForQuest(List sceneGroupSuite) {