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