From 08ffaa978c70cfef954e19da1302feced321857d Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Mon, 8 Mar 2021 21:37:17 -0300 Subject: [PATCH] :recycle: Extract 'ItemStruct.isEquipment' method --- Source/inv.cpp | 4 +--- Source/items.h | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index 27381f944..98fb243b0 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -654,9 +654,7 @@ bool CanBePlacedOnBelt(int playerNumber, const ItemStruct &item) bool CanEquip(const ItemStruct &item) { return - item._iLoc != ILOC_INVALID && - item._iLoc != ILOC_NONE && - item._iLoc != ILOC_UNEQUIPABLE && + item.isEquipment() && item._iStatFlag; } diff --git a/Source/items.h b/Source/items.h index 058f61f08..31b298320 100644 --- a/Source/items.h +++ b/Source/items.h @@ -132,6 +132,30 @@ typedef struct ItemStruct { return this->_itype == ITYPE_NONE; } + /** + * @brief Checks whether this item is an equipment. + * @return 'True' in case the item is an equipment and 'False' otherwise. + */ + bool isEquipment() const + { + if (this->isEmpty()) { + return false; + } + + switch (this->_iLoc) { + case ILOC_AMULET: + case ILOC_ARMOR: + case ILOC_HELM: + case ILOC_ONEHAND: + case ILOC_RING: + case ILOC_TWOHAND: + return true; + + default: + return false; + } + } + } ItemStruct; typedef struct ItemGetRecordStruct {