Browse Source

Method moved to handler. Less in Item the better.

combat-2
MagicBot 8 months ago
parent
commit
4fc7c90c15
  1. 18
      src/engine/net/client/handlers/BuyFromNPCMsgHandler.java
  2. 15
      src/engine/objects/Item.java

18
src/engine/net/client/handlers/BuyFromNPCMsgHandler.java

@ -10,6 +10,7 @@ package engine.net.client.handlers;
import engine.Enum; import engine.Enum;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.DbManager;
import engine.gameManager.SessionManager; import engine.gameManager.SessionManager;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.BuyFromNPCMsg; import engine.net.client.msg.BuyFromNPCMsg;
@ -26,6 +27,21 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler {
super(BuyFromNPCMsg.class); super(BuyFromNPCMsg.class);
} }
public static Item createItemForPlayer(PlayerCharacter pc, int templateID) {
Item item = new Item(templateID);
item.ownerID = pc.getObjectUUID();
item.ownerType = Enum.OwnerType.PlayerCharacter;
item.containerType = Enum.ItemContainerType.INVENTORY;
try {
item = DbManager.ItemQueries.PERSIST(item);
} catch (Exception e) {
Logger.error(e);
}
return item;
}
@Override @Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
@ -108,7 +124,7 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler {
return true; return true;
} }
vendorItem = Item.createItemForPlayer(sourcePlayer, me.templateID); vendorItem = createItemForPlayer(sourcePlayer, me.templateID);
if (vendorItem != null) { if (vendorItem != null) {
// me.transferEnchants(buy); // me.transferEnchants(buy);

15
src/engine/objects/Item.java

@ -532,21 +532,6 @@ public class Item extends AbstractWorldObject {
writer.putIntAt(serialized, indexPosition); writer.putIntAt(serialized, indexPosition);
} }
public static Item createItemForPlayer(PlayerCharacter pc, int templateID) {
Item item = new Item(templateID);
item.ownerID = pc.getObjectUUID();
item.ownerType = OwnerType.PlayerCharacter;
item.containerType = ItemContainerType.INVENTORY;
try {
item = DbManager.ItemQueries.PERSIST(item);
} catch (Exception e) {
Logger.error(e);
}
return item;
}
public static Item getFromCache(int id) { public static Item getFromCache(int id) {
return (Item) DbManager.getFromCache(GameObjectType.Item, id); return (Item) DbManager.getFromCache(GameObjectType.Item, id);
} }

Loading…
Cancel
Save