GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/inventoryhandler.cpp Lines: 0 63 0.0 %
Date: 2017-11-29 Branches: 0 58 0.0 %

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