From 184eec82b319b6e91fc22bea828f7e539a5968ce Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Mon, 30 May 2022 19:49:42 -0700 Subject: [PATCH] Limit spawn amount if too many entities are in the world Can be controlled in the config with `sceneEntityLimit` --- .../grasscutter/command/commands/SpawnCommand.java | 12 +++++++++++- .../java/emu/grasscutter/utils/ConfigContainer.java | 2 +- src/main/resources/languages/en-US.json | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java index 60d4c3c17..d8588b9fb 100644 --- a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java @@ -20,6 +20,7 @@ import javax.swing.text.html.parser.Entity; import java.util.List; import java.util.Random; +import static emu.grasscutter.Configuration.*; import static emu.grasscutter.utils.Language.translate; @Command(label = "spawn", usage = "spawn [amount] [level(monster only)]", permission = "server.spawn", permissionTargeted = "server.spawn.others", description = "commands.spawn.description") @@ -54,7 +55,7 @@ public final class SpawnCommand implements CommandHandler { CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.usage")); return; } - + MonsterData monsterData = GameData.getMonsterDataMap().get(id); GadgetData gadgetData = GameData.getGadgetDataMap().get(id); ItemData itemData = GameData.getItemDataMap().get(id); @@ -62,7 +63,16 @@ public final class SpawnCommand implements CommandHandler { CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.entityId")); return; } + Scene scene = targetPlayer.getScene(); + + if (scene.getEntities().size() + amount > GAME_OPTIONS.sceneEntityLimit) { + amount = Math.max(Math.min(GAME_OPTIONS.sceneEntityLimit - scene.getEntities().size(), amount), 0); + CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.limit_reached", amount)); + if (amount <= 0) { + return; + } + } double maxRadius = Math.sqrt(amount * 0.2 / Math.PI); for (int i = 0; i < amount; i++) { diff --git a/src/main/java/emu/grasscutter/utils/ConfigContainer.java b/src/main/java/emu/grasscutter/utils/ConfigContainer.java index aea9411c0..57fe13194 100644 --- a/src/main/java/emu/grasscutter/utils/ConfigContainer.java +++ b/src/main/java/emu/grasscutter/utils/ConfigContainer.java @@ -171,7 +171,7 @@ public class ConfigContainer { public static class GameOptions { public InventoryLimits inventoryLimits = new InventoryLimits(); public AvatarLimits avatarLimits = new AvatarLimits(); - public int worldEntityLimit = 1000; // Unenforced. TODO: Implement. + public int sceneEntityLimit = 1000; // Unenforced. TODO: Implement. public boolean watchGachaConfig = false; public boolean enableShopItems = true; diff --git a/src/main/resources/languages/en-US.json b/src/main/resources/languages/en-US.json index aa44dbecf..269b10c7b 100644 --- a/src/main/resources/languages/en-US.json +++ b/src/main/resources/languages/en-US.json @@ -306,6 +306,7 @@ "spawn": { "usage": "Usage: spawn [amount] [level(monster only)]", "success": "Spawned %s of %s.", + "limit_reached": "Scene spawn limit reached. Spawning %s entities instead.", "description": "Spawns an entity near you" }, "stop": {