Smarter NPC loading (#2199)

This commit is contained in:
Nazrin 2023-06-09 10:27:34 -07:00 committed by GitHub
parent b4b0b8d2a8
commit b412a24657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<SceneNpcBornEntry> 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<QuestGroupSuite> sceneGroupSuite) {