diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-10-08 01:00:52 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-10-08 01:02:48 +0300 |
commit | 29187a2582c04e3ede63f9c58f09dbbe34834a30 (patch) | |
tree | 93b77c0ad573af9c6d52a6932e76f6c223e2c8f3 /src/net/ea/inventoryhandler.h | |
parent | af98cb5dea5644e0d95a5bf41c03655e4ab808ef (diff) | |
download | mv-29187a2582c04e3ede63f9c58f09dbbe34834a30.tar.gz mv-29187a2582c04e3ede63f9c58f09dbbe34834a30.tar.bz2 mv-29187a2582c04e3ede63f9c58f09dbbe34834a30.tar.xz mv-29187a2582c04e3ede63f9c58f09dbbe34834a30.zip |
Add checks and fix code style.
Diffstat (limited to 'src/net/ea/inventoryhandler.h')
-rw-r--r-- | src/net/ea/inventoryhandler.h | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index cb1e84673..3a99bc47f 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -60,16 +60,22 @@ class EquipBackend : public Equipment::Backend if (invyIndex == -1) return NULL; - return PlayerInfo::getInventory()->getItem(invyIndex); + if (PlayerInfo::getInventory()) + return PlayerInfo::getInventory()->getItem(invyIndex); + else + return 0; } void clear() { + Inventory *inv = PlayerInfo::getInventory(); + if (!inv) + return; for (int i = 0; i < EQUIPMENT_SIZE; i++) { if (mEquipment[i] != -1) { - Item* item = PlayerInfo::getInventory()->getItem(i); + Item* item = inv->getItem(i); if (item) item->setEquipped(false); } @@ -80,16 +86,19 @@ class EquipBackend : public Equipment::Backend void setEquipment(int index, int inventoryIndex) { + Inventory *inv = PlayerInfo::getInventory(); + if (!inv) + return; + // Unequip existing item - Item* item = PlayerInfo::getInventory() - ->getItem(mEquipment[index]); + Item* item = inv->getItem(mEquipment[index]); if (item) item->setEquipped(false); mEquipment[index] = inventoryIndex; - item = PlayerInfo::getInventory()->getItem(inventoryIndex); + item = inv->getItem(inventoryIndex); if (item) item->setEquipped(true); @@ -115,14 +124,14 @@ class InventoryItem bool equip; InventoryItem(int slot0, int id0, int quantity0, int refine0, - unsigned char color0, bool equip0) + unsigned char color0, bool equip0) : + slot(slot0), + id(id0), + quantity(quantity0), + color(color0), + refine(refine0), + equip(equip0) { - slot = slot0; - id = id0; - quantity = quantity0; - refine = refine0; - color = color0; - equip = equip0; } }; |