Browse Source

Rebuild of ./createitem

combat-2
MagicBot 8 months ago
parent
commit
46b4c110e5
  1. 39
      src/engine/devcmd/cmds/CreateItemCmd.java

39
src/engine/devcmd/cmds/CreateItemCmd.java

@ -10,8 +10,14 @@
package engine.devcmd.cmds; package engine.devcmd.cmds;
import engine.devcmd.AbstractDevCmd; import engine.devcmd.AbstractDevCmd;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.mbEnums;
import engine.objects.AbstractGameObject; import engine.objects.AbstractGameObject;
import engine.objects.Item;
import engine.objects.ItemTemplate;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
/** /**
* @author Eighty * @author Eighty
@ -23,22 +29,51 @@ public class CreateItemCmd extends AbstractDevCmd {
} }
@Override @Override
protected void _doCmd(PlayerCharacter pc, String[] words, protected void _doCmd(PlayerCharacter playerCharacter, String[] words,
AbstractGameObject target) { AbstractGameObject target) {
boolean worked = false;
if (words.length < 2) { if (words.length < 2) {
this.sendUsage(pc); this.sendUsage(playerCharacter);
return; return;
} }
int templateID = Integer.parseInt(words[0]); int templateID = Integer.parseInt(words[0]);
ItemTemplate template = ItemTemplate.templates.get(templateID);
if (template == null)
return;
;
int size = 1; int size = 1;
if (words.length == 2) if (words.length == 2)
size = Integer.parseInt(words[1]); 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 @Override

Loading…
Cancel
Save