summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Dombrowski <stefan@uni-bonn.de>2012-02-14 22:36:54 +0100
committerStefan Dombrowski <stefan@uni-bonn.de>2012-02-14 22:36:54 +0100
commitdf812e5ee220a9c62dfa67804bc62d9fe98a9dda (patch)
treeb1f344bbb5e50b3ce1123c597bf5139ff047d514
parent562b6ec9be6293a4bf81c72b44ff8a8d60d5fe66 (diff)
downloadmana-df812e5ee220a9c62dfa67804bc62d9fe98a9dda.tar.gz
mana-df812e5ee220a9c62dfa67804bc62d9fe98a9dda.tar.bz2
mana-df812e5ee220a9c62dfa67804bc62d9fe98a9dda.tar.xz
mana-df812e5ee220a9c62dfa67804bc62d9fe98a9dda.zip
Omit equipping of non-existing items
Reviewed-by: Ablu and Bjorn
-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();
}