summaryrefslogtreecommitdiff
path: root/src/net/tmwa
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tmwa')
-rw-r--r--src/net/tmwa/inventoryhandler.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h
index bbb58b15..88ab953d 100644
--- a/src/net/tmwa/inventoryhandler.h
+++ b/src/net/tmwa/inventoryhandler.h
@@ -23,8 +23,9 @@
#define NET_TA_INVENTORYHANDLER_H
#include "equipment.h"
-#include "inventory.h"
#include "eventlistener.h"
+#include "inventory.h"
+#include "log.h"
#include "playerinfo.h"
#include "gui/inventorywindow.h"
@@ -104,16 +105,24 @@ class EquipBackend : public Equipment::Backend
void setEquipment(int index, int inventoryIndex)
{
Inventory *inventory = PlayerInfo::getInventory();
+ Item *newItem = inventory->getItem(inventoryIndex);
- // Unequip existing item
- if (Item *item = inventory->getItem(mEquipment[index]))
- item->setEquipped(false);
+ if (!newItem && inventoryIndex >= 0)
+ {
+ logger->log("EquipBackend: Warning, trying to equip "
+ "non-existing item from inventory index %i at "
+ "equipment slot %i.", inventoryIndex, index);
+ return;
+ }
- mEquipment[index] = inventoryIndex;
+ // Unequip existing item
+ if (Item *oldItem = inventory->getItem(mEquipment[index]))
+ oldItem->setEquipped(false);
- if (Item *item = inventory->getItem(inventoryIndex))
- item->setEquipped(true);
+ if (newItem)
+ newItem->setEquipped(true);
+ mEquipment[index] = inventoryIndex;
inventoryWindow->updateButtons();
}