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
public static class ServerOptions {
public boolean autoCreateAccount = true;
public int entitySceneLimit = 2000;
public int sceneMaxEntites = 500;
public boolean spendStamina = true;
public boolean unlockAllChallenges = true;
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_RESERVE = 2400;
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 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
// 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_FLOOR_ID = 20001001;
public static final int START_ENTRY_ID = 2000101;
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
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");
}
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
List<GameItem> items = GameData.getItemExcelMap().values()
.stream()
@ -74,6 +81,13 @@ public class GiveAllCommand implements CommandHandler {
this.sendMessage(sender, "Added all icons to " + target.getName());
}
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
List<GameItem> items = GameData.getItemExcelMap().values()
.stream()
@ -84,7 +98,7 @@ public class GiveAllCommand implements CommandHandler {
return item;
})
.toList();
// Add to target's inventory
target.getInventory().addItems(items, true);

View File

@ -44,11 +44,16 @@ public class GiveCommand implements CommandHandler {
// Add item
if (itemData.getItemMainType() == ItemMainType.AvatarCard) {
// Add avatar
// Add avatar to target
GameAvatar avatar = new GameAvatar(itemData.getId());
args.setProperties(avatar);
args.getTarget().addAvatar(avatar);
} 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++) {
GameItem item = new GameItem(itemData);
args.setProperties(item);

View File

@ -1,5 +1,6 @@
package emu.lunarcore.command.commands;
import emu.lunarcore.LunarCore;
import emu.lunarcore.command.Command;
import emu.lunarcore.command.CommandArgs;
import emu.lunarcore.command.CommandHandler;
@ -34,6 +35,12 @@ public class SpawnCommand implements CommandHandler {
int amount = Math.max(args.getAmount(), 1);
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
NpcMonsterExcel monsterExcel = GameData.getNpcMonsterExcelMap().get(id);
if (monsterExcel != null) {

View File

@ -73,7 +73,8 @@ public class GachaService extends BaseGameService {
// Sanity checks
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());
return;
}

View File

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

View File

@ -10,4 +10,8 @@ public abstract class InventoryTab implements Iterable<GameItem> {
public abstract int getSize();
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);
}
// Add trigger
// Add trigger to scene
if (propInfo.getTrigger() != null) {
scene.getTriggers().add(propInfo.getTrigger());
}