Enforce scene entity and inventory limits

This commit is contained in:
Melledy 2023-12-03 03:02:44 -08:00
parent 2dc2cd8df3
commit 773d56bbeb
9 changed files with 51 additions and 13 deletions

View File

@ -86,7 +86,7 @@ public class Config {
@Getter @Getter
public static class ServerOptions { public static class ServerOptions {
public boolean autoCreateAccount = true; public boolean autoCreateAccount = true;
public int entitySceneLimit = 2000; public int sceneMaxEntites = 500;
public boolean spendStamina = true; public boolean spendStamina = true;
public boolean unlockAllChallenges = true; public boolean unlockAllChallenges = true;
public int staminaRecoveryRate = 5 * 60; public int staminaRecoveryRate = 5 * 60;

View File

@ -18,21 +18,28 @@ public class GameConstants {
public static final int MAX_STAMINA = 240; public static final int MAX_STAMINA = 240;
public static final int MAX_STAMINA_RESERVE = 2400; public static final int MAX_STAMINA_RESERVE = 2400;
public static final int MAX_AVATARS_IN_TEAM = 4; public static final int MAX_AVATARS_IN_TEAM = 4;
public static final int MAX_FRIENDSHIPS = 100;
public static final int DEFAULT_TEAMS = 6; public static final int DEFAULT_TEAMS = 6;
public static final int MAX_MP = 5; // Client doesnt like more than 5 public static final int MAX_MP = 5; // Client doesnt like more than 5
// Chat/Social
public static final int MAX_FRIENDSHIPS = 100;
public static final int MAX_CHAT_HISTORY = 100; // Max chat messages per conversation public static final int MAX_CHAT_HISTORY = 100; // Max chat messages per conversation
// Inventory
public static final int MATERIAL_HCOIN_ID = 1; // Material id for jades. DO NOT CHANGE
public static final int MATERIAL_COIN_ID = 2; // Material id for credits. DO NOT CHANGE
public static final int TRAILBLAZER_EXP_ID = 22;
public static final int INVENTORY_MAX_EQUIPMENT = 1500;
public static final int INVENTORY_MAX_RELIC = 1500;
public static final int INVENTORY_MAX_MATERIAL = 2000;
// Start position
public static final int START_PLANE_ID = 20001; public static final int START_PLANE_ID = 20001;
public static final int START_FLOOR_ID = 20001001; public static final int START_FLOOR_ID = 20001001;
public static final int START_ENTRY_ID = 2000101; public static final int START_ENTRY_ID = 2000101;
public static final Position START_POS = new Position(99, 62, -4800); public static final Position START_POS = new Position(99, 62, -4800);
public static final int MATERIAL_HCOIN_ID = 1; // Material id for jades. DO NOT CHANGE
public static final int MATERIAL_COIN_ID = 2; // Material id for credits. DO NOT CHANGE
public static final int TRAILBLAZER_EXP_ID = 22;
// Battle // Battle
public static final int BATTLE_AMBUSH_BUFF_ID = 1000102; public static final int BATTLE_AMBUSH_BUFF_ID = 1000102;

View File

@ -46,6 +46,13 @@ public class GiveAllCommand implements CommandHandler {
this.sendMessage(sender, "Giving " + target.getName() + " " + items.size() + " items"); this.sendMessage(sender, "Giving " + target.getName() + " " + items.size() + " items");
} }
case "lc", "lightcones" -> { case "lc", "lightcones" -> {
// Make sure we dont go over the inventory limit
var tab = args.getTarget().getInventory().getInventoryTab(ItemMainType.Equipment);
if (tab.getSize() >= tab.getMaxCapacity()) {
this.sendMessage(sender, target.getName() + " has too many of this item type");
return;
}
// Get lightcones // Get lightcones
List<GameItem> items = GameData.getItemExcelMap().values() List<GameItem> items = GameData.getItemExcelMap().values()
.stream() .stream()
@ -74,6 +81,13 @@ public class GiveAllCommand implements CommandHandler {
this.sendMessage(sender, "Added all icons to " + target.getName()); this.sendMessage(sender, "Added all icons to " + target.getName());
} }
case "r", "relics" -> { case "r", "relics" -> {
// Make sure we dont go over the inventory limit
var tab = args.getTarget().getInventory().getInventoryTab(ItemMainType.Relic);
if (tab.getSize() >= tab.getMaxCapacity()) {
this.sendMessage(sender, target.getName() + " has too many of this item type");
return;
}
// Get relics // Get relics
List<GameItem> items = GameData.getItemExcelMap().values() List<GameItem> items = GameData.getItemExcelMap().values()
.stream() .stream()
@ -84,7 +98,7 @@ public class GiveAllCommand implements CommandHandler {
return item; return item;
}) })
.toList(); .toList();
// Add to target's inventory // Add to target's inventory
target.getInventory().addItems(items, true); target.getInventory().addItems(items, true);

View File

@ -44,11 +44,16 @@ public class GiveCommand implements CommandHandler {
// Add item // Add item
if (itemData.getItemMainType() == ItemMainType.AvatarCard) { if (itemData.getItemMainType() == ItemMainType.AvatarCard) {
// Add avatar // Add avatar to target
GameAvatar avatar = new GameAvatar(itemData.getId()); GameAvatar avatar = new GameAvatar(itemData.getId());
args.setProperties(avatar); args.setProperties(avatar);
args.getTarget().addAvatar(avatar); args.getTarget().addAvatar(avatar);
} else if (itemData.isEquippable()) { } else if (itemData.isEquippable()) {
// Make sure we dont go over the inventory limit
var tab = args.getTarget().getInventory().getInventoryTab(itemData.getItemMainType());
amount = Math.min(amount, tab.getAvailableCapacity());
// Add items
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
GameItem item = new GameItem(itemData); GameItem item = new GameItem(itemData);
args.setProperties(item); args.setProperties(item);

View File

@ -1,5 +1,6 @@
package emu.lunarcore.command.commands; package emu.lunarcore.command.commands;
import emu.lunarcore.LunarCore;
import emu.lunarcore.command.Command; import emu.lunarcore.command.Command;
import emu.lunarcore.command.CommandArgs; import emu.lunarcore.command.CommandArgs;
import emu.lunarcore.command.CommandHandler; import emu.lunarcore.command.CommandHandler;
@ -34,6 +35,12 @@ public class SpawnCommand implements CommandHandler {
int amount = Math.max(args.getAmount(), 1); int amount = Math.max(args.getAmount(), 1);
int radius = Math.max(args.getRank(), 5) * 1000; int radius = Math.max(args.getRank(), 5) * 1000;
// Enforce scene max entity limit
if (target.getScene().getEntities().size() + amount >= LunarCore.getConfig().getServerOptions().getSceneMaxEntites()) {
this.sendMessage(sender, "Error: Max entities in scene reached");
return;
}
// Spawn monster // Spawn monster
NpcMonsterExcel monsterExcel = GameData.getNpcMonsterExcelMap().get(id); NpcMonsterExcel monsterExcel = GameData.getNpcMonsterExcelMap().get(id);
if (monsterExcel != null) { if (monsterExcel != null) {

View File

@ -73,7 +73,8 @@ public class GachaService extends BaseGameService {
// Sanity checks // Sanity checks
if (times != 10 && times != 1) return; if (times != 10 && times != 1) return;
if (player.getInventory().getInventoryTab(ItemMainType.Equipment).getSize() + times > player.getInventory().getInventoryTab(ItemMainType.Equipment).getMaxCapacity()) { // Prevent player from using gacha if they are at max light cones
if (player.getInventory().getInventoryTab(ItemMainType.Equipment).getSize() >= player.getInventory().getInventoryTab(ItemMainType.Equipment).getMaxCapacity()) {
player.sendPacket(new PacketDoGachaScRsp()); player.sendPacket(new PacketDoGachaScRsp());
return; return;
} }

View File

@ -36,9 +36,9 @@ public class Inventory extends BasePlayerManager {
this.store = new Long2ObjectOpenHashMap<>(); this.store = new Long2ObjectOpenHashMap<>();
this.inventoryTypes = new Int2ObjectOpenHashMap<>(); this.inventoryTypes = new Int2ObjectOpenHashMap<>();
this.createInventoryTab(ItemMainType.Equipment, new EquipInventoryTab(1500)); this.createInventoryTab(ItemMainType.Equipment, new EquipInventoryTab(GameConstants.INVENTORY_MAX_EQUIPMENT));
this.createInventoryTab(ItemMainType.Relic, new EquipInventoryTab(1500)); this.createInventoryTab(ItemMainType.Relic, new EquipInventoryTab(GameConstants.INVENTORY_MAX_RELIC));
this.createInventoryTab(ItemMainType.Material, new MaterialInventoryTab(2000)); this.createInventoryTab(ItemMainType.Material, new MaterialInventoryTab(GameConstants.INVENTORY_MAX_MATERIAL));
} }
public AvatarStorage getAvatarStorage() { public AvatarStorage getAvatarStorage() {

View File

@ -10,4 +10,8 @@ public abstract class InventoryTab implements Iterable<GameItem> {
public abstract int getSize(); public abstract int getSize();
public abstract int getMaxCapacity(); public abstract int getMaxCapacity();
public int getAvailableCapacity() {
return Math.max(getMaxCapacity() - getSize(), 0);
}
} }

View File

@ -72,7 +72,7 @@ public class SceneEntityLoader {
scene.getHealingSprings().add(prop); scene.getHealingSprings().add(prop);
} }
// Add trigger // Add trigger to scene
if (propInfo.getTrigger() != null) { if (propInfo.getTrigger() != null) {
scene.getTriggers().add(propInfo.getTrigger()); scene.getTriggers().add(propInfo.getTrigger());
} }