| 1 |  |  | /* | 
    
    | 2 |  |  |  *  The ManaPlus Client | 
    
    | 3 |  |  |  *  Copyright (C) 2004-2009  The Mana World Development Team | 
    
    | 4 |  |  |  *  Copyright (C) 2009-2010  The Mana Developers | 
    
    | 5 |  |  |  *  Copyright (C) 2011-2019  The ManaPlus Developers | 
    
    | 6 |  |  |  *  Copyright (C) 2019-2021  Andrei Karas | 
    
    | 7 |  |  |  * | 
    
    | 8 |  |  |  *  This file is part of The ManaPlus Client. | 
    
    | 9 |  |  |  * | 
    
    | 10 |  |  |  *  This program is free software; you can redistribute it and/or modify | 
    
    | 11 |  |  |  *  it under the terms of the GNU General Public License as published by | 
    
    | 12 |  |  |  *  the Free Software Foundation; either version 2 of the License, or | 
    
    | 13 |  |  |  *  any later version. | 
    
    | 14 |  |  |  * | 
    
    | 15 |  |  |  *  This program is distributed in the hope that it will be useful, | 
    
    | 16 |  |  |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
    
    | 17 |  |  |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
    
    | 18 |  |  |  *  GNU General Public License for more details. | 
    
    | 19 |  |  |  * | 
    
    | 20 |  |  |  *  You should have received a copy of the GNU General Public License | 
    
    | 21 |  |  |  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
    
    | 22 |  |  |  */ | 
    
    | 23 |  |  |  | 
    
    | 24 |  |  | #include "net/tmwa/inventoryhandler.h" | 
    
    | 25 |  |  |  | 
    
    | 26 |  |  | #include "const/net/inventory.h" | 
    
    | 27 |  |  |  | 
    
    | 28 |  |  | #include "enums/equipslot.h" | 
    
    | 29 |  |  |  | 
    
    | 30 |  |  | #include "net/tmwa/messageout.h" | 
    
    | 31 |  |  | #include "net/tmwa/protocolout.h" | 
    
    | 32 |  |  |  | 
    
    | 33 |  |  | #include "resources/item/item.h" | 
    
    | 34 |  |  |  | 
    
    | 35 |  |  | #include "debug.h" | 
    
    | 36 |  |  |  | 
    
    | 37 |  |  | // missing EQUIP_RING1_SLOT | 
    
    | 38 |  |  | const EquipSlot::Type EQUIP_CONVERT[] = | 
    
    | 39 |  |  | { | 
    
    | 40 |  |  |     EquipSlot::PROJECTILE_SLOT,    // 0    0 | 
    
    | 41 |  |  |     EquipSlot::FEET_SLOT,          // 1    SPRITE_HAIR | 
    
    | 42 |  |  |     EquipSlot::LEGS_SLOT,          // 2    SPRITE_WEAPON | 
    
    | 43 |  |  |     EquipSlot::TORSO_SLOT,         // 3    SPRITE_HEAD_BOTTOM | 
    
    | 44 |  |  |     EquipSlot::PROJECTILE_SLOT,    // 4    0 | 
    
    | 45 |  |  |     EquipSlot::NECK_SLOT,          // 5    SPRITE_RING | 
    
    | 46 |  |  |     EquipSlot::PROJECTILE_SLOT,    // 6    0 | 
    
    | 47 |  |  |     EquipSlot::HEAD_SLOT,          // 7    SPRITE_CLOTHES_COLOR | 
    
    | 48 |  |  |     EquipSlot::RING2_SLOT,         // 8    0 | 
    
    | 49 |  |  |     EquipSlot::GLOVES_SLOT,        // 9    SPRITE_SHOES | 
    
    | 50 |  |  |     EquipSlot::FIGHT1_SLOT,        // 10   SPRITE_BODY | 
    
    | 51 |  |  |     EquipSlot::FIGHT2_SLOT,        // 11   SPRITE_FLOOR | 
    
    | 52 |  |  |     EquipSlot::EVOL_RING1_SLOT,    // 12   SPRITE_ROBE | 
    
    | 53 |  |  |     EquipSlot::EVOL_RING2_SLOT,    // 13   SPRITE_EVOL2 | 
    
    | 54 |  |  | }; | 
    
    | 55 |  |  |  | 
    
    | 56 |  |  | namespace TmwAthena | 
    
    | 57 |  |  | { | 
    
    | 58 |  |  |  | 
    
    | 59 |  |  | InventoryHandler::InventoryHandler() : | 
    
    | 60 |  |  |     Ea::InventoryHandler() | 
    
    | 61 |  |  | { | 
    
    | 62 |  |  |     inventoryHandler = this; | 
    
    | 63 |  |  | } | 
    
    | 64 |  |  |  | 
    
    | 65 |  |  | InventoryHandler::~InventoryHandler() | 
    
    | 66 |  |  | { | 
    
    | 67 |  |  |     inventoryHandler = nullptr; | 
    
    | 68 |  |  | } | 
    
    | 69 |  |  |  | 
    
    | 70 |  |  | void InventoryHandler::equipItem(const Item *const item) const | 
    
    | 71 |  |  | { | 
    
    | 72 |  |  |     if (item == nullptr) | 
    
    | 73 |  |  |         return; | 
    
    | 74 |  |  |  | 
    
    | 75 |  |  |     createOutPacket(CMSG_PLAYER_EQUIP); | 
    
    | 76 |  |  |     outMsg.writeInt16(CAST_S16( | 
    
    | 77 |  |  |         item->getInvIndex() + INVENTORY_OFFSET), "index"); | 
    
    | 78 |  |  |     outMsg.writeInt16(0, "unused"); | 
    
    | 79 |  |  | } | 
    
    | 80 |  |  |  | 
    
    | 81 |  |  | void InventoryHandler::unequipItem(const Item *const item) const | 
    
    | 82 |  |  | { | 
    
    | 83 |  |  |     if (item == nullptr) | 
    
    | 84 |  |  |         return; | 
    
    | 85 |  |  |  | 
    
    | 86 |  |  |     createOutPacket(CMSG_PLAYER_UNEQUIP); | 
    
    | 87 |  |  |     outMsg.writeInt16(CAST_S16( | 
    
    | 88 |  |  |         item->getInvIndex() + INVENTORY_OFFSET), "index"); | 
    
    | 89 |  |  | } | 
    
    | 90 |  |  |  | 
    
    | 91 |  |  | void InventoryHandler::useItem(const Item *const item) const | 
    
    | 92 |  |  | { | 
    
    | 93 |  |  |     if (item == nullptr) | 
    
    | 94 |  |  |         return; | 
    
    | 95 |  |  |  | 
    
    | 96 |  |  |     createOutPacket(CMSG_PLAYER_INVENTORY_USE); | 
    
    | 97 |  |  |     outMsg.writeInt16(CAST_S16( | 
    
    | 98 |  |  |         item->getInvIndex() + INVENTORY_OFFSET), "index"); | 
    
    | 99 |  |  |     outMsg.writeInt32(item->getId(), "item id"); | 
    
    | 100 |  |  | } | 
    
    | 101 |  |  |  | 
    
    | 102 |  |  | void InventoryHandler::useItem(const Item *const item, | 
    
    | 103 |  |  |                                const int16_t useType A_UNUSED) const | 
    
    | 104 |  |  | { | 
    
    | 105 |  |  |     if (item == nullptr) | 
    
    | 106 |  |  |         return; | 
    
    | 107 |  |  |  | 
    
    | 108 |  |  |     createOutPacket(CMSG_PLAYER_INVENTORY_USE); | 
    
    | 109 |  |  |     outMsg.writeInt16(CAST_S16( | 
    
    | 110 |  |  |         item->getInvIndex() + INVENTORY_OFFSET), "index"); | 
    
    | 111 |  |  |     outMsg.writeInt32(item->getId(), "item id"); | 
    
    | 112 |  |  | } | 
    
    | 113 |  |  |  | 
    
    | 114 |  |  | void InventoryHandler::dropItem(const Item *const item, const int amount) const | 
    
    | 115 |  |  | { | 
    
    | 116 |  |  |     if (item == nullptr) | 
    
    | 117 |  |  |         return; | 
    
    | 118 |  |  |  | 
    
    | 119 |  |  |     createOutPacket(CMSG_PLAYER_INVENTORY_DROP); | 
    
    | 120 |  |  |     outMsg.writeInt16(CAST_S16( | 
    
    | 121 |  |  |         item->getInvIndex() + INVENTORY_OFFSET), "index"); | 
    
    | 122 |  |  |     outMsg.writeInt16(CAST_S16(amount), "amount"); | 
    
    | 123 |  |  | } | 
    
    | 124 |  |  |  | 
    
    | 125 |  |  | void InventoryHandler::closeStorage() const | 
    
    | 126 |  |  | { | 
    
    | 127 |  |  |     createOutPacket(CMSG_CLOSE_STORAGE); | 
    
    | 128 |  |  | } | 
    
    | 129 |  |  |  | 
    
    | 130 |  |  | void InventoryHandler::moveItem2(const InventoryTypeT source, | 
    
    | 131 |  |  |                                  const int slot, | 
    
    | 132 |  |  |                                  const int amount, | 
    
    | 133 |  |  |                                  const InventoryTypeT destination) const | 
    
    | 134 |  |  | { | 
    
    | 135 |  |  |     if (source == InventoryType::Inventory && | 
    
    | 136 |  |  |         destination == InventoryType::Storage) | 
    
    | 137 |  |  |     { | 
    
    | 138 |  |  |         createOutPacket(CMSG_MOVE_TO_STORAGE); | 
    
    | 139 |  |  |         outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), | 
    
    | 140 |  |  |             "index"); | 
    
    | 141 |  |  |         outMsg.writeInt32(amount, "amount"); | 
    
    | 142 |  |  |     } | 
    
    | 143 |  |  |     else if (source == InventoryType::Storage && | 
    
    | 144 |  |  |              destination == InventoryType::Inventory) | 
    
    | 145 |  |  |     { | 
    
    | 146 |  |  |         createOutPacket(CMSG_MOVE_FROM_STORAGE); | 
    
    | 147 |  |  |         outMsg.writeInt16(CAST_S16(slot + STORAGE_OFFSET), | 
    
    | 148 |  |  |             "index"); | 
    
    | 149 |  |  |         outMsg.writeInt32(amount, "amount"); | 
    
    | 150 |  |  |     } | 
    
    | 151 |  |  | } | 
    
    | 152 |  |  |  | 
    
    | 153 |  |  | void InventoryHandler::useCard(const Item *const item A_UNUSED) | 
    
    | 154 |  |  | { | 
    
    | 155 |  |  | } | 
    
    | 156 |  |  |  | 
    
    | 157 |  |  | void InventoryHandler::insertCard(const int cardIndex A_UNUSED, | 
    
    | 158 |  |  |                                   const int itemIndex A_UNUSED) const | 
    
    | 159 |  |  | { | 
    
    | 160 |  |  | } | 
    
    | 161 |  |  |  | 
    
    | 162 |  |  | void InventoryHandler::favoriteItem(const Item *const item A_UNUSED, | 
    
    | 163 |  |  |                                     const bool favorite A_UNUSED) const | 
    
    | 164 |  |  | { | 
    
    | 165 |  |  | } | 
    
    | 166 |  |  |  | 
    
    | 167 |  |  | void InventoryHandler::selectEgg(const Item *const item A_UNUSED) const | 
    
    | 168 |  |  | { | 
    
    | 169 |  |  | } | 
    
    | 170 |  |  |  | 
    
    | 171 |  |  | int InventoryHandler::convertFromServerSlot(const int serverSlot) const | 
    
    | 172 |  |  | { | 
    
    | 173 |  |  |     if (serverSlot < 0 || serverSlot > 13) | 
    
    | 174 |  |  |         return 0; | 
    
    | 175 |  |  |  | 
    
    | 176 |  |  |     return CAST_S32(EQUIP_CONVERT[serverSlot]); | 
    
    | 177 |  |  | } | 
    
    | 178 |  |  |  | 
    
    | 179 |  |  | void InventoryHandler::selectCart(const BeingId accountId A_UNUSED, | 
    
    | 180 |  |  |                                   const int type A_UNUSED) const | 
    
    | 181 |  |  | { | 
    
    | 182 |  |  | } | 
    
    | 183 |  |  |  | 
    
    | 184 |  |  | void InventoryHandler::identifyItem(const Item *const item A_UNUSED) const | 
    
    | 185 |  |  | { | 
    
    | 186 |  |  | } | 
    
    | 187 |  |  |  | 
    
    | 188 |  |  | void InventoryHandler::mergeItemsAck(const STD_VECTOR<Item*> &items A_UNUSED) | 
    
    | 189 |  |  |                                      const | 
    
    | 190 |  |  | { | 
    
    | 191 |  |  | } | 
    
    | 192 |  |  |  | 
    
    | 193 |  |  | void InventoryHandler::mergetItemsCancel() const | 
    
    | 194 |  |  | { | 
    
    | 195 |  |  | } | 
    
    | 196 |  |  |  | 
    
    | 197 |  |  | void InventoryHandler::expandInventory() const | 
    
    | 198 |  |  | { | 
    
    | 199 |  |  | } | 
    
    | 200 |  |  |  | 
    
    | 201 |  |  | void InventoryHandler::expandInventoryConfirm() const | 
    
    | 202 |  |  | { | 
    
    | 203 |  |  | } | 
    
    | 204 |  |  |  | 
    
    | 205 |  |  | void InventoryHandler::expandInventoryReject() const | 
    
    | 206 |  |  | { | 
    
    | 207 |  |  | } | 
    
    | 208 |  |  |  | 
    
    | 209 |  |  | }  // namespace TmwAthena |