From 46b4c110e51f91fe00e0e258346019de5ebf1348 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 23 Apr 2024 12:38:49 -0400 Subject: [PATCH] Rebuild of ./createitem --- src/engine/devcmd/cmds/CreateItemCmd.java | 39 +++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/engine/devcmd/cmds/CreateItemCmd.java b/src/engine/devcmd/cmds/CreateItemCmd.java index c5acefab..4e2d0b87 100644 --- a/src/engine/devcmd/cmds/CreateItemCmd.java +++ b/src/engine/devcmd/cmds/CreateItemCmd.java @@ -10,8 +10,14 @@ package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; +import engine.gameManager.ChatManager; +import engine.gameManager.DbManager; +import engine.mbEnums; import engine.objects.AbstractGameObject; +import engine.objects.Item; +import engine.objects.ItemTemplate; import engine.objects.PlayerCharacter; +import org.pmw.tinylog.Logger; /** * @author Eighty @@ -23,22 +29,51 @@ public class CreateItemCmd extends AbstractDevCmd { } @Override - protected void _doCmd(PlayerCharacter pc, String[] words, + protected void _doCmd(PlayerCharacter playerCharacter, String[] words, AbstractGameObject target) { + boolean worked = false; if (words.length < 2) { - this.sendUsage(pc); + this.sendUsage(playerCharacter); return; } int templateID = Integer.parseInt(words[0]); + ItemTemplate template = ItemTemplate.templates.get(templateID); + + if (template == null) + return; + ; int size = 1; if (words.length == 2) size = Integer.parseInt(words[1]); + for (int i = 0; i < size; i++) { + worked = false; + + if (!playerCharacter.charItemManager.hasRoomInventory(template.item_wt)) { + ChatManager.chatSystemInfo(playerCharacter, "You can not carry any more of that item."); + break; + } + Item item = new Item(templateID); + item.ownerID = playerCharacter.getObjectUUID(); + item.ownerType = mbEnums.OwnerType.PlayerCharacter; + item.containerType = mbEnums.ItemContainerType.INVENTORY; + + try { + item = DbManager.ItemQueries.PERSIST(item); + worked = true; + } catch (Exception e) { + Logger.error(e); + } + if (worked) { + playerCharacter.charItemManager.addItemToInventory(item); + } + } + playerCharacter.charItemManager.updateInventory(); } @Override