Im currently working on the "Inventory" mechanic especially the drop / pickup part of the items.
When the player drops an item, i delete the row out of the inventoryTable and create a new row in the items table which contains all items laying around in the world. At the same time i create a mmoItem with the ItemID, Amount and two other little variables.
I noticed that it seems to take a bit longer using MMOItems instead of just sending an packet, is this true ?
Theres also a little delay of about 500 ms - 1 sec when dropping an item im not sure if this happens due to the mysql querys or the mmoitem.
Heres a little code snippet just for showcase
Code: Select all
public static void dropItemsOutOfInventory(IDBManager dbManager, User user, String itemTypeID, String chunkName, int amount){
try {
if(removeItemsFromInventory(dbManager, user, itemTypeID, amount, false)){
String positionX = user.getVariable(UserVariables.PositionLatLngX.toString()).getStringValue();
String positionY = user.getVariable(UserVariables.PositionLatLngY.toString()).getStringValue();
String position = positionX+";"+positionY;
Object insertedRowID = dbManager.executeInsert("INSERT INTO "+ItemColumns.tableName+"("+ItemColumns.itemtype_ID+","+ItemColumns.chunk_ID+","+ItemColumns.position+","+ItemColumns.amount+") values("+itemTypeID+","+SQLSnippets.determineChunkID(chunkName)+",'"+position+"',"+String.valueOf(amount)+")", new Object[]{});
InventoryManager.sendUpdatedInventoryItemToPlayer(dbManager, user, itemTypeID);
Utils.sfsExtension.trace("<InventoryManager : Droped item and sended back the updated inventory>");
MMOItem item = new MMOItem();
item.setVariable(new MMOItemVariable("ID", insertedRowID.toString()));
item.setVariable(new MMOItemVariable("itemtypes_ID", itemTypeID));
item.setVariable(new MMOItemVariable("amount", amount));
item.setVariable(new MMOItemVariable("chunkName", chunkName));
Utils.spawnExistingMMOItemInCurrentRoom(user, item, Float.parseFloat(positionX), Float.parseFloat(positionY));
Utils.sfsExtension.trace("<InventoryManager : Spawned MMOItem with the certain attributes>");
}
} catch (SQLException e) {
Utils.sfsExtension.trace("<InventoryManager : MySql Error "+e.getMessage());
return;
}
}
Any tipps to make this faster ?