diff options
50 files changed, 268 insertions, 109 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a93e156fd..130031873 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -665,6 +665,7 @@ SET(SRCS enums/resources/imageposition.h enums/resources/itemdbtype.h enums/resources/itemsoundevent.h + enums/resources/itemtype.h resources/itemtypemap.h resources/itemtypemapdata.h resources/db/mapdb.cpp diff --git a/src/Makefile.am b/src/Makefile.am index d1f09f575..519238be8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1198,6 +1198,7 @@ manaplus_SOURCES += main.cpp \ enums/resources/imageposition.h \ enums/resources/itemdbtype.h \ enums/resources/itemsoundevent.h \ + enums/resources/itemtype.h \ resources/itemtypemap.h \ resources/itemtypemapdata.h \ resources/mapinfo.h \ diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index 335a5439c..639894d9a 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -1480,7 +1480,11 @@ impHandler0(createItems) if (id <= 500) continue; - dialog->addItem(id, 0, ItemColor_one, 100, 0); + dialog->addItem(id, + ItemType::Unknown, + ItemColor_one, + 100, + 0); } dialog->sort(); return true; diff --git a/src/actormanager.cpp b/src/actormanager.cpp index fe4e55687..f02ddd30a 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -321,7 +321,7 @@ Being *ActorManager::createBeing(const BeingId id, FloorItem *ActorManager::createItem(const BeingId id, const int itemId, const int x, const int y, - const int itemType, + const ItemTypeT itemType, const int amount, const int refine, const ItemColor color, diff --git a/src/actormanager.h b/src/actormanager.h index eac773fe8..9c6672bbf 100644 --- a/src/actormanager.h +++ b/src/actormanager.h @@ -25,6 +25,8 @@ #include "enums/being/actortype.h" +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/allowsort.h" #include "enums/simpletypes/allplayers.h" #include "enums/simpletypes/beingid.h" @@ -98,7 +100,7 @@ class ActorManager final: public ConfigListener FloorItem *createItem(const BeingId id, const int itemId, const int x, const int y, - const int itemType, + const ItemTypeT itemType, const int amount, const int refine, const ItemColor color, diff --git a/src/being/flooritem.cpp b/src/being/flooritem.cpp index 72f30998e..00b4ae45a 100644 --- a/src/being/flooritem.cpp +++ b/src/being/flooritem.cpp @@ -46,7 +46,7 @@ extern volatile int cur_time; FloorItem::FloorItem(const BeingId id, const int itemId, const int x, const int y, - const int itemType, + const ItemTypeT itemType, const int amount, const int refine, const ItemColor color, diff --git a/src/being/flooritem.h b/src/being/flooritem.h index bb57039e1..1b5b87d3e 100644 --- a/src/being/flooritem.h +++ b/src/being/flooritem.h @@ -25,6 +25,8 @@ #include "const/resources/item/cards.h" +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/damaged.h" #include "enums/simpletypes/identified.h" #include "enums/simpletypes/itemcolor.h" @@ -54,7 +56,7 @@ class FloorItem final : public ActorSprite FloorItem(const BeingId id, const int itemId, const int x, const int y, - const int itemType, + const ItemTypeT itemType, const int amount, const int refine, const ItemColor color, @@ -121,7 +123,7 @@ class FloorItem final : public ActorSprite int getRefine() const A_WARN_UNUSED { return mRefine; } - int getItemType() const A_WARN_UNUSED + ItemTypeT getItemType() const A_WARN_UNUSED { return mItemType; } Identified getIdentified() const A_WARN_UNUSED @@ -138,7 +140,7 @@ class FloorItem final : public ActorSprite int mAmount; int mRefine; int mHeightPosDiff; - int mItemType; + ItemTypeT mItemType; unsigned int mPickupCount; Cursor::Cursor mCursor; ItemColor mColor; diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 04bb267aa..2d8f21056 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -276,8 +276,7 @@ void useEquipItem(const Item *const item, const Sfx sfx) if (item) { #ifdef EATHENA_SUPPORT - // IT_CARD - if (item->getType() == 6) + if (item->getType() == ItemType::Card) { if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) { diff --git a/src/beingequipbackend.cpp b/src/beingequipbackend.cpp index c078f9b7e..9a3d35bea 100644 --- a/src/beingequipbackend.cpp +++ b/src/beingequipbackend.cpp @@ -45,7 +45,7 @@ BeingEquipBackend::BeingEquipBackend(Being *const being) if (id > 0 && idx >= 0 && idx < EQUIPMENT_SIZE) { mEquipment[idx] = new Item(id, - 0, + ItemType::Unknown, 1, 0, being->mSpriteColorsIds[f], diff --git a/src/enums/resources/itemtype.h b/src/enums/resources/itemtype.h new file mode 100644 index 000000000..83a25f522 --- /dev/null +++ b/src/enums/resources/itemtype.h @@ -0,0 +1,44 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_ITEMTYPE_H +#define RESOURCES_ITEMTYPE_H + +#include "enums/simpletypes/enumdefines.h" + +enumStart(ItemType) +{ + Healing = 0, + Unknown = 1, + Usable = 2, + Etc = 3, + Weapon = 4, + Armor = 5, + Card = 6, + PetEgg = 7, + PetArmor = 8, + Unknown2 = 9, + Ammon = 10, + DelayConsume = 11, + Cash = 18 +} +enumEnd(ItemType); + +#endif // RESOURCES_ITEMTYPE_H diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp index 2a2b75ae8..c25664cdd 100644 --- a/src/gui/models/shopitems.cpp +++ b/src/gui/models/shopitems.cpp @@ -52,7 +52,7 @@ std::string ShopItems::getElementAt(int i) } ShopItem *ShopItems::addItem(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price) @@ -64,7 +64,7 @@ ShopItem *ShopItems::addItem(const int id, } ShopItem *ShopItems::addItemNoDup(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price) @@ -81,7 +81,7 @@ ShopItem *ShopItems::addItemNoDup(const int id, ShopItem *ShopItems::addItem2(const int inventoryIndex, const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int quantity, const int price) diff --git a/src/gui/models/shopitems.h b/src/gui/models/shopitems.h index d346c38b7..0aedce83f 100644 --- a/src/gui/models/shopitems.h +++ b/src/gui/models/shopitems.h @@ -23,6 +23,8 @@ #ifndef GUI_MODELS_SHOPITEMS_H #define GUI_MODELS_SHOPITEMS_H +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/itemcolor.h" #include "gui/models/listmodel.h" @@ -61,7 +63,7 @@ class ShopItems final : public ListModel * Adds an item to the list. */ ShopItem *addItem(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price); @@ -77,13 +79,13 @@ class ShopItems final : public ListModel */ ShopItem *addItem2(const int inventoryIndex, const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price); ShopItem *addItemNoDup(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price); diff --git a/src/gui/widgets/selldialog.cpp b/src/gui/widgets/selldialog.cpp index 17664ed78..c0b7fdd24 100644 --- a/src/gui/widgets/selldialog.cpp +++ b/src/gui/widgets/selldialog.cpp @@ -221,7 +221,7 @@ void SellDialog::addItem(const Item *const item, const int price) } ShopItem *SellDialog::addItem(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price) diff --git a/src/gui/widgets/selldialog.h b/src/gui/widgets/selldialog.h index 2918055c9..46512225f 100644 --- a/src/gui/widgets/selldialog.h +++ b/src/gui/widgets/selldialog.h @@ -23,6 +23,8 @@ #ifndef GUI_WIDGETS_SELLDIALOG_H #define GUI_WIDGETS_SELLDIALOG_H +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/advanced.h" #include "enums/simpletypes/issell.h" #include "enums/simpletypes/itemcolor.h" @@ -72,7 +74,8 @@ class SellDialog notfinal : public Window, /** * Adds an item to the inventory. */ - void addItem(const Item *const item, const int price); + void addItem(const Item *const item, + const int price); /** * Called when receiving actions from the widgets. @@ -97,7 +100,7 @@ class SellDialog notfinal : public Window, void setVisible(Visible visible) override final; ShopItem *addItem(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price); diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index b0cf5bc8c..fa7297bdd 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -390,12 +390,16 @@ void BuyDialog::reset() } ShopItem *BuyDialog::addItem(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price) { - ShopItem *const item = mShopItems->addItem(id, type, color, amount, price); + ShopItem *const item = mShopItems->addItem(id, + type, + color, + amount, + price); mShopItemList->adjustSize(); return item; } diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h index 3249eae2a..77d5c357f 100644 --- a/src/gui/windows/buydialog.h +++ b/src/gui/windows/buydialog.h @@ -23,6 +23,8 @@ #ifndef GUI_WINDOWS_BUYDIALOG_H #define GUI_WINDOWS_BUYDIALOG_H +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/beingid.h" #include "enums/simpletypes/itemcolor.h" @@ -105,7 +107,7 @@ class BuyDialog final : public Window, * Adds an item to the shop inventory. */ ShopItem *addItem(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int amount, const int price); diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index 5485bd98a..db256b4a1 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -1047,8 +1047,7 @@ void InventoryWindow::combineItems(const int index1, if (!item2) return; - // IT_CARD - if (item1->getType() != 6) + if (item1->getType() != ItemType::Card) { const Item *tmpItem = item1; item1 = item2; diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp index 8ad79ecab..02c94931e 100644 --- a/src/gui/windows/itemamountwindow.cpp +++ b/src/gui/windows/itemamountwindow.cpp @@ -388,7 +388,10 @@ void ItemAmountWindow::action(const ActionEvent &event) const int id = ItemDB::get(mItemsModal->getElementAt( mItemDropDown->getSelected())).getId(); - mItem = new Item(id, 0, 10000, 0, + mItem = new Item(id, + ItemType::Unknown, + 10000, + 0, ItemColor_one, Identified_true, Damaged_true, diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index 679bbc47f..eb07c90dc 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -562,12 +562,20 @@ void ShopWindow::loadList() if (tokens[1] && tokens[2]) { mBuyShopItems->addItem( - tokens[0], 0, ItemColor_one, tokens[1], tokens[2]); + tokens[0], + ItemType::Unknown, + ItemColor_one, + tokens[1], + tokens[2]); } if (tokens[3] && tokens[4]) { mSellShopItems->addItem( - tokens[0], 0, ItemColor_one, tokens[3], tokens[4]); + tokens[0], + ItemType::Unknown, + ItemColor_one, + tokens[3], + tokens[4]); } } } @@ -855,7 +863,13 @@ void ShopWindow::showList(const std::string &nick, std::string data) int amount = decodeStr(data.substr(f + 6, 3)); // +++ need impliment colors? if (buyDialog && amount > 0) - buyDialog->addItem(id, 0, ItemColor_one, amount, price); + { + buyDialog->addItem(id, + ItemType::Unknown, + ItemColor_one, + amount, + price); + } if (sellDialog) { // +++ need support for colors @@ -870,7 +884,7 @@ void ShopWindow::showList(const std::string &nick, std::string data) amount = 0; } ShopItem *const shopItem = sellDialog->addItem(id, - 0, + ItemType::Unknown, ItemColor_one, amount, price); @@ -940,7 +954,12 @@ void ShopWindow::processRequest(const std::string &nick, std::string data, delete mTradeItem; // +++ need impliment colors? - mTradeItem = new ShopItem(-1, id, 0, ItemColor_one, amount, price); + mTradeItem = new ShopItem(-1, + id, + ItemType::Unknown, + ItemColor_one, + amount, + price); if (mode == BUY) { diff --git a/src/gui/windows/tradewindow.cpp b/src/gui/windows/tradewindow.cpp index fe0ca85f1..e251b0bd9 100644 --- a/src/gui/windows/tradewindow.cpp +++ b/src/gui/windows/tradewindow.cpp @@ -195,7 +195,7 @@ void TradeWindow::setMoney(const int amount) } void TradeWindow::addItem(const int id, - const int type, + const ItemTypeT type, const bool own, const int quantity, const uint8_t refine, @@ -218,7 +218,7 @@ void TradeWindow::addItem(const int id, } void TradeWindow::addItem2(const int id, - const int type, + const ItemTypeT type, const int *const cards, const int sz, const bool own, diff --git a/src/gui/windows/tradewindow.h b/src/gui/windows/tradewindow.h index 98b18ba7e..f8a280a20 100644 --- a/src/gui/windows/tradewindow.h +++ b/src/gui/windows/tradewindow.h @@ -25,6 +25,8 @@ #include "gui/widgets/window.h" +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/damaged.h" #include "enums/simpletypes/equipm.h" #include "enums/simpletypes/favorite.h" @@ -72,7 +74,7 @@ class TradeWindow final : public Window, * Add an item to the trade window. */ void addItem(const int id, - const int type, + const ItemTypeT type, const bool own, const int quantity, const uint8_t refine, @@ -90,7 +92,7 @@ class TradeWindow final : public Window, * Add an item to the trade window. */ void addItem2(const int id, - const int type, + const ItemTypeT type, const int *const cards, const int sz, const bool own, @@ -122,7 +124,8 @@ class TradeWindow final : public Window, /** * Send trade packet. */ - void tradeItem(const Item *const item, const int quantity, + void tradeItem(const Item *const item, + const int quantity, const bool check = false) const; /** diff --git a/src/net/ea/inventoryitem.h b/src/net/ea/inventoryitem.h index 7971c9584..212ee98dc 100644 --- a/src/net/ea/inventoryitem.h +++ b/src/net/ea/inventoryitem.h @@ -25,6 +25,8 @@ #include "const/resources/item/cards.h" +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/damaged.h" #include "enums/simpletypes/equipm.h" #include "enums/simpletypes/favorite.h" @@ -52,7 +54,7 @@ class InventoryItem final public: int slot; int id; - int type; + ItemTypeT type; int cards[maxCards]; int quantity; uint8_t refine; @@ -64,7 +66,7 @@ class InventoryItem final InventoryItem(const int slot0, const int id0, - const int type0, + const ItemTypeT type0, const int *const cards0, const int quantity0, const uint8_t refine0, diff --git a/src/net/eathena/buyingstorerecv.cpp b/src/net/eathena/buyingstorerecv.cpp index 3596638b6..89a756ad3 100644 --- a/src/net/eathena/buyingstorerecv.cpp +++ b/src/net/eathena/buyingstorerecv.cpp @@ -134,7 +134,9 @@ void BuyingStoreRecv::processBuyingStoreItemsList(Net::MessageIn &msg) { const int price = msg.readInt32("price"); const int amount = msg.readInt16("amount"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const int itemId = msg.readInt16("item id"); if (!inv) diff --git a/src/net/eathena/buysellrecv.cpp b/src/net/eathena/buysellrecv.cpp index e59eb47a7..8fa02d185 100644 --- a/src/net/eathena/buysellrecv.cpp +++ b/src/net/eathena/buysellrecv.cpp @@ -55,7 +55,7 @@ void BuySellRecv::processNpcBuy(Net::MessageIn &msg) { const int value = msg.readInt32("price"); msg.readInt32("dc value?"); - const int type = msg.readUInt8("type"); + const ItemTypeT type = fromInt(msg.readUInt8("type"), ItemTypeT); const int itemId = msg.readInt16("item id"); const ItemColor color = ItemColor_one; Ea::BuySellRecv::mBuyDialog->addItem(itemId, type, color, 0, value); diff --git a/src/net/eathena/cashshoprecv.cpp b/src/net/eathena/cashshoprecv.cpp index 45f48eadc..4da1edcf3 100644 --- a/src/net/eathena/cashshoprecv.cpp +++ b/src/net/eathena/cashshoprecv.cpp @@ -51,7 +51,7 @@ void CashShopRecv::processCashShopOpen(Net::MessageIn &msg) { msg.readInt32("price"); const int value = msg.readInt32("discount price"); - const int type = msg.readUInt8("item type"); + const ItemTypeT type = fromInt(msg.readUInt8("item type"), ItemTypeT); const int itemId = msg.readInt16("item id"); const ItemColor color = ItemColor_one; mBuyDialog->addItem(itemId, type, color, 0, value); diff --git a/src/net/eathena/inventoryrecv.cpp b/src/net/eathena/inventoryrecv.cpp index 4d5565d1b..967c74978 100644 --- a/src/net/eathena/inventoryrecv.cpp +++ b/src/net/eathena/inventoryrecv.cpp @@ -127,7 +127,9 @@ void InventoryRecv::processPlayerEquipment(Net::MessageIn &msg) { const int index = msg.readInt16("index") - INVENTORY_OFFSET; const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); msg.readInt32("location"); const int equipType = msg.readInt32("wear state"); const uint8_t refine = CAST_U8(msg.readInt8("refine")); @@ -198,7 +200,7 @@ void InventoryRecv::processPlayerInventoryAdd(Net::MessageIn &msg) for (int f = 0; f < maxCards; f++) cards[f] = msg.readInt16("card"); const int equipType = msg.readInt32("location"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt(msg.readUInt8("item type"), ItemTypeT); const unsigned char err = msg.readUInt8("result"); msg.readInt32("hire expire date"); msg.readInt16("bind on equip"); @@ -322,7 +324,9 @@ void InventoryRecv::processPlayerInventory(Net::MessageIn &msg) { const int index = msg.readInt16("item index") - INVENTORY_OFFSET; const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemType); const int amount = msg.readInt16("count"); msg.readInt32("wear state / equip"); int cards[maxCards]; @@ -365,7 +369,9 @@ void InventoryRecv::processPlayerStorage(Net::MessageIn &msg) { const int index = msg.readInt16("item index") - STORAGE_OFFSET; const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const int amount = msg.readInt16("count"); msg.readInt32("wear state / equip"); int cards[maxCards]; @@ -526,7 +532,9 @@ void InventoryRecv::processPlayerStorageEquip(Net::MessageIn &msg) { const int index = msg.readInt16("index") - STORAGE_OFFSET; const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const int amount = 1; msg.readInt32("location"); msg.readInt32("wear state"); @@ -575,7 +583,7 @@ void InventoryRecv::processPlayerStorageAdd(Net::MessageIn &msg) const int index = msg.readInt16("index") - STORAGE_OFFSET; const int amount = msg.readInt32("amount"); const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("type"); + const ItemTypeT itemType = fromInt(msg.readUInt8("type"), ItemTypeT); const unsigned char identified = msg.readUInt8("identify"); const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged); const uint8_t refine = msg.readUInt8("refine"); @@ -777,7 +785,7 @@ void InventoryRecv::processPlayerCartAdd(Net::MessageIn &msg) const int index = msg.readInt16("index") - INVENTORY_OFFSET; int amount = msg.readInt32("count"); const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt(msg.readUInt8("item type"), ItemTypeT); const uint8_t identified = msg.readUInt8("identified"); const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged); const uint8_t refine = msg.readUInt8("refine"); @@ -853,7 +861,9 @@ void InventoryRecv::processPlayerCartEquip(Net::MessageIn &msg) { const int index = msg.readInt16("index") - INVENTORY_OFFSET; const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const int amount = 1; msg.readInt32("location"); msg.readInt32("wear state"); @@ -905,7 +915,9 @@ void InventoryRecv::processPlayerCartItems(Net::MessageIn &msg) { const int index = msg.readInt16("item index") - INVENTORY_OFFSET; const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const int amount = msg.readInt16("count"); msg.readInt32("wear state / equip"); int cards[maxCards]; diff --git a/src/net/eathena/itemrecv.cpp b/src/net/eathena/itemrecv.cpp index 822b4684d..80b0bd7a2 100644 --- a/src/net/eathena/itemrecv.cpp +++ b/src/net/eathena/itemrecv.cpp @@ -28,6 +28,8 @@ #include "const/resources/item/cards.h" +#include "enums/resources/itemtype.h" + #include "net/messagein.h" #include "debug.h" @@ -39,7 +41,7 @@ void ItemRecv::processItemDropped(Net::MessageIn &msg) { const BeingId id = msg.readBeingId("id"); const int itemId = msg.readInt16("item id"); - const int itemType = msg.readInt16("type"); + const ItemTypeT itemType = fromInt(msg.readInt16("type"), ItemTypeT); const Identified identified = fromInt( msg.readUInt8("identify"), Identified); const int x = msg.readInt16("x"); @@ -68,7 +70,7 @@ void ItemRecv::processItemDropped2(Net::MessageIn &msg) { const BeingId id = msg.readBeingId("id"); const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("type"); + const ItemTypeT itemType = fromInt(msg.readUInt8("type"), ItemTypeT); const Identified identified = fromInt( msg.readUInt8("identify"), Identified); const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged); @@ -127,7 +129,7 @@ void ItemRecv::processItemVisible(Net::MessageIn &msg) actorManager->createItem(id, itemId, x, y, - 0, + ItemType::Unknown, amount, 0, ItemColor_one, @@ -142,7 +144,7 @@ void ItemRecv::processItemVisible2(Net::MessageIn &msg) { const BeingId id = msg.readBeingId("item object id"); const int itemId = msg.readInt16("item id"); - const int itemType = msg.readUInt8("type"); + const ItemTypeT itemType = fromInt(msg.readUInt8("type"), ItemTypeT); const Identified identified = fromInt( msg.readUInt8("identify"), Identified); const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged); diff --git a/src/net/eathena/markethandler.cpp b/src/net/eathena/markethandler.cpp index 6c69664ea..15370d91c 100644 --- a/src/net/eathena/markethandler.cpp +++ b/src/net/eathena/markethandler.cpp @@ -45,11 +45,14 @@ void MarketHandler::close() const } void MarketHandler::buyItem(const int itemId, - const int type, + const ItemTypeT type, const ItemColor color A_UNUSED, const int amount) const { - const bool nonStack = type == 4 || type == 5 || type == 7 || type == 8; + const bool nonStack = type == ItemType::Weapon || + type == ItemType::Armor || + type == ItemType::PetEgg || + type == ItemType::PetArmor; int cnt = nonStack ? amount : 1; const int amount2 = nonStack ? 1 : amount; if (cnt > 100) @@ -73,13 +76,20 @@ void MarketHandler::buyItems(const std::vector<ShopItem*> &items) const { const ShopItem *const item = *it; const int usedQuantity = item->getUsedQuantity(); - const int type = item->getType(); + const ItemTypeT type = item->getType(); if (!usedQuantity) continue; - if (type == 4 || type == 5 || type == 7 || type == 8) + if (type == ItemType::Weapon || + type == ItemType::Armor || + type == ItemType::PetEgg || + type == ItemType::PetArmor) + { cnt += item->getUsedQuantity(); + } else + { cnt ++; + } } if (cnt > 100) @@ -96,8 +106,11 @@ void MarketHandler::buyItems(const std::vector<ShopItem*> &items) const item->increaseQuantity(usedQuantity); item->increaseUsedQuantity(-usedQuantity); item->update(); - const int type = item->getType(); - if (type == 4 || type == 5 || type == 7 || type == 8) + const ItemTypeT type = fromInt(item->getType(), ItemTypeT); + if (type == ItemType::Weapon || + type == ItemType::Armor || + type == ItemType::PetEgg || + type == ItemType::PetArmor) { for (int f = 0; f < usedQuantity; f ++) { diff --git a/src/net/eathena/markethandler.h b/src/net/eathena/markethandler.h index 8ba0be922..fd0d4aea5 100644 --- a/src/net/eathena/markethandler.h +++ b/src/net/eathena/markethandler.h @@ -36,7 +36,7 @@ class MarketHandler final : public Net::MarketHandler void close() const override final; void buyItem(const int itemId, - const int type, + const ItemTypeT type, const ItemColor color, const int amount) const override final; diff --git a/src/net/eathena/marketrecv.cpp b/src/net/eathena/marketrecv.cpp index 2f8d5aaae..66cab540a 100644 --- a/src/net/eathena/marketrecv.cpp +++ b/src/net/eathena/marketrecv.cpp @@ -53,7 +53,7 @@ void MarketRecv::processMarketOpen(Net::MessageIn &msg) for (int f = 0; f < len; f ++) { const int itemId = msg.readInt16("item id"); - const int type = msg.readUInt8("type"); + const ItemTypeT type = fromInt(msg.readUInt8("type"), ItemTypeT); const int value = msg.readInt32("price"); const int amount = msg.readInt32("amount"); msg.readInt16("view"); diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp index 7d0a65abc..2e5175253 100644 --- a/src/net/eathena/npchandler.cpp +++ b/src/net/eathena/npchandler.cpp @@ -142,13 +142,20 @@ void NpcHandler::buyItems(std::vector<ShopItem*> &items) const { ShopItem *const item = *it; const int usedQuantity = item->getUsedQuantity(); - const int type = item->getType(); + const ItemTypeT type = item->getType(); if (!usedQuantity) continue; - if (type == 4 || type == 5 || type == 7 || type == 8) + if (type == ItemType::Weapon || + type == ItemType::Armor || + type == ItemType::PetEgg || + type == ItemType::PetArmor) + { cnt += item->getUsedQuantity(); + } else + { cnt ++; + } } if (cnt > 100) @@ -164,8 +171,11 @@ void NpcHandler::buyItems(std::vector<ShopItem*> &items) const continue; item->increaseUsedQuantity(-usedQuantity); item->update(); - const int type = item->getType(); - if (type == 4 || type == 5 || type == 7 || type == 8) + const ItemTypeT type = item->getType(); + if (type == ItemType::Weapon || + type == ItemType::Armor || + type == ItemType::PetEgg || + type == ItemType::PetArmor) { for (int f = 0; f < usedQuantity; f ++) { diff --git a/src/net/eathena/traderecv.cpp b/src/net/eathena/traderecv.cpp index b77c8af87..edac5d21e 100644 --- a/src/net/eathena/traderecv.cpp +++ b/src/net/eathena/traderecv.cpp @@ -72,7 +72,7 @@ void TradeRecv::processTradeResponse(Net::MessageIn &msg) void TradeRecv::processTradeItemAdd(Net::MessageIn &msg) { const int type = msg.readInt16("type"); - const int itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt(msg.readUInt8("item type"), ItemTypeT); const int amount = msg.readInt32("amount"); const uint8_t identify = msg.readUInt8("identify"); const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged); diff --git a/src/net/eathena/vendingrecv.cpp b/src/net/eathena/vendingrecv.cpp index 7e088a2b0..06cdfa44c 100644 --- a/src/net/eathena/vendingrecv.cpp +++ b/src/net/eathena/vendingrecv.cpp @@ -93,7 +93,7 @@ void VendingRecv::processItemsList(Net::MessageIn &msg) const int value = msg.readInt32("price"); const int amount = msg.readInt16("amount"); const int index = msg.readInt16("inv index"); - const int type = msg.readUInt8("item type"); + const ItemTypeT type = fromInt(msg.readUInt8("item type"), ItemTypeT); const int itemId = msg.readInt16("item id"); msg.readUInt8("identify"); msg.readUInt8("attribute"); diff --git a/src/net/markethandler.h b/src/net/markethandler.h index 856014686..f571237a8 100644 --- a/src/net/markethandler.h +++ b/src/net/markethandler.h @@ -23,6 +23,8 @@ #ifdef EATHENA_SUPPORT +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/itemcolor.h" #include <string> @@ -44,7 +46,7 @@ class MarketHandler notfinal virtual void close() const = 0; virtual void buyItem(const int itemId, - const int type, + const ItemTypeT type, const ItemColor color, const int amount) const = 0; diff --git a/src/net/tmwa/buysellrecv.cpp b/src/net/tmwa/buysellrecv.cpp index 13027d1f2..625cb2a14 100644 --- a/src/net/tmwa/buysellrecv.cpp +++ b/src/net/tmwa/buysellrecv.cpp @@ -54,7 +54,7 @@ void BuySellRecv::processNpcBuy(Net::MessageIn &msg) { const int value = msg.readInt32("price"); msg.readInt32("dc value?"); - const int type = msg.readUInt8("type"); + const ItemTypeT type = fromInt(msg.readUInt8("type"), ItemTypeT); const int itemId = msg.readInt16("item id"); const ItemColor color = ItemColor_one; Ea::BuySellRecv::mBuyDialog->addItem(itemId, type, color, 0, value); diff --git a/src/net/tmwa/inventoryrecv.cpp b/src/net/tmwa/inventoryrecv.cpp index 6e1fe0cfe..605f08bbe 100644 --- a/src/net/tmwa/inventoryrecv.cpp +++ b/src/net/tmwa/inventoryrecv.cpp @@ -93,9 +93,10 @@ void InventoryRecv::processPlayerEquipment(Net::MessageIn &msg) { const int index = msg.readInt16("index") - INVENTORY_OFFSET; const int itemId = msg.readInt16("item id"); - const uint8_t itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const uint8_t identified = msg.readUInt8("identify"); - msg.readInt16("equip type?"); const int equipType = msg.readInt16("equip type"); msg.readUInt8("attribute"); @@ -107,7 +108,7 @@ void InventoryRecv::processPlayerEquipment(Net::MessageIn &msg) if (Ea::InventoryRecv::mDebugInventory) { logger->log("Index: %d, ID: %d, Type: %d, Identified: %d", - index, itemId, itemType, identified); + index, itemId, CAST_S32(itemType), identified); } if (inventory) @@ -158,8 +159,7 @@ void InventoryRecv::processPlayerInventoryAdd(Net::MessageIn &msg) for (int f = 0; f < maxCards; f++) cards[f] = msg.readInt16("card"); const int equipType = msg.readInt16("equip type"); - const int type = msg.readUInt8("item type"); - + const ItemTypeT type = fromInt(msg.readUInt8("item type"), ItemTypeT); const ItemInfo &itemInfo = ItemDB::get(itemId); const unsigned char err = msg.readUInt8("status"); BeingId floorId; @@ -270,7 +270,9 @@ void InventoryRecv::processPlayerInventory(Net::MessageIn &msg) int cards[maxCards]; const int index = msg.readInt16("index") - INVENTORY_OFFSET; const int itemId = msg.readInt16("item id"); - const uint8_t itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const uint8_t identified = msg.readUInt8("identified"); const int amount = msg.readInt16("amount"); const int arrow = msg.readInt16("arrow"); @@ -281,7 +283,7 @@ void InventoryRecv::processPlayerInventory(Net::MessageIn &msg) { logger->log("Index: %d, ID: %d, Type: %d, Identified: %d, " "Qty: %d, Cards: %d, %d, %d, %d", - index, itemId, itemType, identified, amount, + index, itemId, CAST_S32(itemType), identified, amount, cards[0], cards[1], cards[2], cards[3]); } @@ -320,7 +322,9 @@ void InventoryRecv::processPlayerStorage(Net::MessageIn &msg) int cards[maxCards]; const int index = msg.readInt16("index") - STORAGE_OFFSET; const int itemId = msg.readInt16("item id"); - const uint8_t itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const uint8_t identified = msg.readUInt8("identified"); const int amount = msg.readInt16("amount"); msg.readInt16("arrow"); @@ -331,7 +335,7 @@ void InventoryRecv::processPlayerStorage(Net::MessageIn &msg) { logger->log("Index: %d, ID: %d, Type: %d, Identified: %d, " "Qty: %d, Cards: %d, %d, %d, %d", - index, itemId, itemType, identified, amount, + index, itemId, CAST_S32(itemType), identified, amount, cards[0], cards[1], cards[2], cards[3]); } @@ -400,7 +404,9 @@ void InventoryRecv::processPlayerStorageEquip(Net::MessageIn &msg) int cards[maxCards]; const int index = msg.readInt16("index") - STORAGE_OFFSET; const int itemId = msg.readInt16("item id"); - const uint8_t itemType = msg.readUInt8("item type"); + const ItemTypeT itemType = fromInt( + msg.readUInt8("item type"), + ItemTypeT); const uint8_t identified = msg.readUInt8("identified"); const int amount = 1; msg.readInt16("equip point?"); @@ -414,7 +420,7 @@ void InventoryRecv::processPlayerStorageEquip(Net::MessageIn &msg) { logger->log("Index: %d, ID: %d, Type: %d, Identified: %u, " "Qty: %d, Cards: %d, %d, %d, %d, Refine: %u", - index, itemId, itemType, + index, itemId, CAST_S32(itemType), CAST_U32(identified), amount, cards[0], cards[1], cards[2], cards[3], CAST_U32(refine)); @@ -461,7 +467,7 @@ void InventoryRecv::processPlayerStorageAdd(Net::MessageIn &msg) { Ea::InventoryRecv::mStorage->setItem(index, itemId, - 0, + ItemType::Unknown, amount, refine, ItemColor_one, diff --git a/src/net/tmwa/itemrecv.cpp b/src/net/tmwa/itemrecv.cpp index d7038942d..041bf5af7 100644 --- a/src/net/tmwa/itemrecv.cpp +++ b/src/net/tmwa/itemrecv.cpp @@ -47,7 +47,7 @@ void ItemRecv::processItemDropped(Net::MessageIn &msg) actorManager->createItem(id, itemId, x, y, - 0, + ItemType::Unknown, amount, 0, ItemColor_one, @@ -75,7 +75,7 @@ void ItemRecv::processItemVisible(Net::MessageIn &msg) actorManager->createItem(id, itemId, x, y, - 0, + ItemType::Unknown, amount, 0, ItemColor_one, diff --git a/src/net/tmwa/markethandler.cpp b/src/net/tmwa/markethandler.cpp index ecab3790e..7c29d042d 100644 --- a/src/net/tmwa/markethandler.cpp +++ b/src/net/tmwa/markethandler.cpp @@ -37,7 +37,7 @@ void MarketHandler::close() const } void MarketHandler::buyItem(const int itemId A_UNUSED, - const int type A_UNUSED, + const ItemTypeT type A_UNUSED, const ItemColor color A_UNUSED, const int amount A_UNUSED) const { diff --git a/src/net/tmwa/markethandler.h b/src/net/tmwa/markethandler.h index 7c99bd164..a9dac7519 100644 --- a/src/net/tmwa/markethandler.h +++ b/src/net/tmwa/markethandler.h @@ -37,7 +37,7 @@ class MarketHandler final : public Net::MarketHandler void close() const override final A_CONST; void buyItem(const int itemId, - const int type, + const ItemTypeT type, const ItemColor color, const int amount) const override final A_CONST; diff --git a/src/net/tmwa/traderecv.cpp b/src/net/tmwa/traderecv.cpp index 393502273..f68bee9f5 100644 --- a/src/net/tmwa/traderecv.cpp +++ b/src/net/tmwa/traderecv.cpp @@ -77,7 +77,7 @@ void TradeRecv::processTradeItemAdd(Net::MessageIn &msg) else { tradeWindow->addItem2(type, - 0, + ItemType::Unknown, cards, 4, false, diff --git a/src/resources/inventory/complexinventory.cpp b/src/resources/inventory/complexinventory.cpp index 60f6092e6..724b89762 100644 --- a/src/resources/inventory/complexinventory.cpp +++ b/src/resources/inventory/complexinventory.cpp @@ -116,7 +116,7 @@ bool ComplexInventory::addVirtualItem(const Item *const item, void ComplexInventory::setItem(const int index, const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, diff --git a/src/resources/inventory/complexinventory.h b/src/resources/inventory/complexinventory.h index 95183cb7f..996212d18 100644 --- a/src/resources/inventory/complexinventory.h +++ b/src/resources/inventory/complexinventory.h @@ -51,7 +51,7 @@ class ComplexInventory final : public Inventory void setItem(const int index, const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, diff --git a/src/resources/inventory/inventory.cpp b/src/resources/inventory/inventory.cpp index 7d78605dc..d732874be 100644 --- a/src/resources/inventory/inventory.cpp +++ b/src/resources/inventory/inventory.cpp @@ -54,7 +54,8 @@ namespace }; } // namespace -Inventory::Inventory(const InventoryTypeT type, const int size1) : +Inventory::Inventory(const InventoryTypeT type, + const int size1) : mInventoryListeners(), mVirtualRemove(), mType(type), @@ -109,7 +110,7 @@ Item *Inventory::findItem(const int itemId, } int Inventory::addItem(const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, @@ -120,14 +121,23 @@ int Inventory::addItem(const int id, const Equipped equipped) { const int slot = getFreeSlot(); - setItem(slot, id, type, quantity, refine, color, - identified, damaged, favorite, equipment, equipped); + setItem(slot, + id, + type, + quantity, + refine, + color, + identified, + damaged, + favorite, + equipment, + equipped); return slot; } void Inventory::setItem(const int index, const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, @@ -146,8 +156,16 @@ void Inventory::setItem(const int index, Item *const item1 = mItems[index]; if (!item1 && id > 0) { - Item *const item = new Item(id, type, quantity, refine, color, - identified, damaged, favorite, equipment, equipped); + Item *const item = new Item(id, + type, + quantity, + refine, + color, + identified, + damaged, + favorite, + equipment, + equipped); item->setInvIndex(index); mItems[index] = item; mUsed++; diff --git a/src/resources/inventory/inventory.h b/src/resources/inventory/inventory.h index 9186fbd73..f687339cb 100644 --- a/src/resources/inventory/inventory.h +++ b/src/resources/inventory/inventory.h @@ -25,6 +25,8 @@ #include "enums/inventorytype.h" +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/beingtypeid.h" #include "enums/simpletypes/damaged.h" #include "enums/simpletypes/equipm.h" @@ -90,7 +92,7 @@ class Inventory notfinal * Adds a new item in a free slot. */ int addItem(const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, @@ -105,7 +107,7 @@ class Inventory notfinal */ virtual void setItem(const int index, const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, diff --git a/src/resources/item/complexitem.cpp b/src/resources/item/complexitem.cpp index 3d50d62e5..ecb4edb9e 100644 --- a/src/resources/item/complexitem.cpp +++ b/src/resources/item/complexitem.cpp @@ -25,7 +25,7 @@ #include "debug.h" ComplexItem::ComplexItem(const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, diff --git a/src/resources/item/complexitem.h b/src/resources/item/complexitem.h index b567c49e8..aae9130fc 100644 --- a/src/resources/item/complexitem.h +++ b/src/resources/item/complexitem.h @@ -35,7 +35,7 @@ class ComplexItem final : public Item * Constructor. */ ComplexItem(const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, diff --git a/src/resources/item/item.cpp b/src/resources/item/item.cpp index 044e11fdb..f6d0af1d9 100644 --- a/src/resources/item/item.cpp +++ b/src/resources/item/item.cpp @@ -38,7 +38,7 @@ DragDrop dragDrop(nullptr, DragDropSource::Empty); Item::Item(const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, diff --git a/src/resources/item/item.h b/src/resources/item/item.h index 9a910c31b..d0bb9b9f3 100644 --- a/src/resources/item/item.h +++ b/src/resources/item/item.h @@ -25,6 +25,8 @@ #include "const/resources/item/cards.h" +#include "enums/resources/itemtype.h" + #include "enums/simpletypes/damaged.h" #include "enums/simpletypes/equipm.h" #include "enums/simpletypes/equipped.h" @@ -48,7 +50,7 @@ class Item notfinal * Constructor. */ Item(const int id, - const int type, + const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, @@ -209,10 +211,10 @@ class Item notfinal const int *getCards() const { return mCards; } - void setType(const int type) + void setType(const ItemTypeT type) { mType = type; } - int getType() const A_WARN_UNUSED + ItemTypeT getType() const A_WARN_UNUSED { return mType; } void setTag(const int tag) @@ -225,7 +227,7 @@ class Item notfinal void updateColor(); - int mId; /**< Item type id. */ + int mId; /**< Item id. */ ItemColor mColor; int mQuantity; /**< Number of items. */ int mTag; @@ -237,7 +239,7 @@ class Item notfinal int mCards[maxCards]; uint8_t mRefine; /**< Item refine level. */ int mInvIndex; /**< Inventory index. */ - int mType; /**< Item type. */ + ItemTypeT mType; /**< Item type. */ Equipm mEquipment; /**< Item is equipment. */ Equipped mEquipped; /**< Item is equipped. */ bool mInEquipment; /**< Item is in equipment */ diff --git a/src/resources/item/shopitem.cpp b/src/resources/item/shopitem.cpp index f8e837c86..1f70076b9 100644 --- a/src/resources/item/shopitem.cpp +++ b/src/resources/item/shopitem.cpp @@ -34,7 +34,7 @@ ShopItem::ShopItem(const int inventoryIndex, const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int quantity, const int price) : @@ -58,7 +58,7 @@ ShopItem::ShopItem(const int inventoryIndex, } ShopItem::ShopItem(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int price) : Item(id, type, 0, 0, color, diff --git a/src/resources/item/shopitem.h b/src/resources/item/shopitem.h index 6c4d3f886..bf966aeb7 100644 --- a/src/resources/item/shopitem.h +++ b/src/resources/item/shopitem.h @@ -46,7 +46,7 @@ class ShopItem final : public Item */ ShopItem(const int inventoryIndex, const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int quantity, const int price); @@ -59,7 +59,7 @@ class ShopItem final : public Item * @param price price of the item */ ShopItem(const int id, - const int type, + const ItemTypeT type, const ItemColor color, const int price); |