GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/inventoryhandler.cpp Lines: 15 385 3.9 %
Date: 2019-10-15 Branches: 0 618 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-2019  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/eathena/inventoryhandler.h"
24
25
#include "const/net/inventory.h"
26
27
#include "enums/equipslot.h"
28
29
#include "net/ea/inventoryrecv.h"
30
31
#include "net/eathena/inventoryrecv.h"
32
#include "net/eathena/menu.h"
33
#include "net/eathena/messageout.h"
34
#include "net/eathena/protocolout.h"
35
36
#include "utils/foreach.h"
37
38
#include "resources/item/item.h"
39
40
#include "debug.h"
41
42
extern int packetVersion;
43
extern int packetVersionMain;
44
extern int packetVersionRe;
45
extern int packetVersionZero;
46
extern int serverVersion;
47
48
// this conversion from bit corrupted LOOK_* to EquipSlot
49
// for how it corrupted, see BeingRecv::processBeingChangeLookContinue
50
const EquipSlot::Type EQUIP_CONVERT[] =
51
{
52
    EquipSlot::PROJECTILE_SLOT,    // 0    SPRITE_BASE
53
    EquipSlot::FEET_SLOT,          // 1    SPRITE_HAIR
54
    EquipSlot::LEGS_SLOT,          // 2    SPRITE_WEAPON
55
    EquipSlot::TORSO_SLOT,         // 3    SPRITE_HEAD_BOTTOM
56
    EquipSlot::GLOVES_SLOT,        // 4    SPRITE_HEAD_TOP
57
    EquipSlot::EVOL_RING1_SLOT,    // 5    SPRITE_HEAD_MID
58
    EquipSlot::PROJECTILE_SLOT,    // 6    SPRITE_HAIR_COLOR
59
    EquipSlot::HEAD_SLOT,          // 7    SPRITE_CLOTHES_COLOR
60
    EquipSlot::RING2_SLOT,         // 8    SPRITE_SHIELD
61
    EquipSlot::PROJECTILE_SLOT,    // 9    SPRITE_SHOES
62
    EquipSlot::FIGHT1_SLOT,        // 10   SPRITE_BODY
63
    EquipSlot::FIGHT2_SLOT,        // 11   SPRITE_FLOOR
64
    EquipSlot::EVOL_RING2_SLOT,    // 12   SPRITE_ROBE
65
    EquipSlot::PROJECTILE_SLOT,    // 13   SPRITE_EVOL2
66
    EquipSlot::COSTUME_ROBE_SLOT,  // 14   SPRITE_EVOL3
67
    EquipSlot::RING1_SLOT,         // 15   SPRITE_EVOL4
68
    EquipSlot::NECK_SLOT,          // 16   SPRITE_EVOL5
69
    EquipSlot::RING2_SLOT,         // 17   SPRITE_EVOL6
70
};
71
72
namespace EAthena
73
{
74
75
77
InventoryHandler::InventoryHandler() :
76
    Ea::InventoryHandler(),
77
77
    mItemIndex(0)
78
{
79
77
    inventoryHandler = this;
80
81
77
    InventoryRecv::mInventoryItems.clear();
82
77
    InventoryRecv::mCartItems.clear();
83
77
}
84
85
154
InventoryHandler::~InventoryHandler()
86
{
87
77
    inventoryHandler = nullptr;
88
77
}
89
90
77
void InventoryHandler::clear() const
91
{
92
77
    Ea::InventoryHandler::clear();
93
77
    Ea::InventoryRecv::mStorageItems.clear();
94
77
    InventoryRecv::mInventoryItems.clear();
95
77
    InventoryRecv::mCartItems.clear();
96
77
}
97
98
void InventoryHandler::equipItem(const Item *const item) const
99
{
100
    if (item == nullptr)
101
        return;
102
103
    createOutPacket(CMSG_PLAYER_EQUIP);
104
    outMsg.writeInt16(CAST_S16(
105
        item->getInvIndex() + INVENTORY_OFFSET), "index");
106
    // here we set flag for any slots,
107
    // probably better set to slot from item properties
108
    if (packetVersion >= 20130320)
109
        outMsg.writeInt32(0xFFFFFFFFU, "wear location");
110
    else
111
        outMsg.writeInt16(0x7FFFU, "wear location");
112
}
113
114
void InventoryHandler::unequipItem(const Item *const item) const
115
{
116
    if (item == nullptr)
117
        return;
118
119
    createOutPacket(CMSG_PLAYER_UNEQUIP);
120
    outMsg.writeInt16(CAST_S16(
121
        item->getInvIndex() + INVENTORY_OFFSET), "index");
122
}
123
124
void InventoryHandler::useItem(const Item *const item) const
125
{
126
    if (item == nullptr)
127
        return;
128
129
    createOutPacket(CMSG_PLAYER_INVENTORY_USE);
130
    outMsg.writeInt16(CAST_S16(
131
        item->getInvIndex() + INVENTORY_OFFSET), "index");
132
    outMsg.writeInt32(item->getId(), "unused");
133
}
134
135
void InventoryHandler::useItem(const Item *const item,
136
                               const int16_t useType) const
137
{
138
    if (item == nullptr)
139
        return;
140
141
    if (serverVersion > 0)
142
    {
143
        createOutPacket(CMSG_PLAYER_INVENTORY_USE2);
144
        outMsg.writeInt16(CAST_S16(
145
            item->getInvIndex() + INVENTORY_OFFSET), "index");
146
        outMsg.writeInt16(useType, "use type");
147
    }
148
    else
149
    {
150
        createOutPacket(CMSG_PLAYER_INVENTORY_USE);
151
        outMsg.writeInt16(CAST_S16(
152
            item->getInvIndex() + INVENTORY_OFFSET), "index");
153
        outMsg.writeInt32(item->getId(), "unused");
154
    }
155
}
156
157
void InventoryHandler::dropItem(const Item *const item, const int amount) const
158
{
159
    if (item == nullptr)
160
        return;
161
162
    createOutPacket(CMSG_PLAYER_INVENTORY_DROP);
163
    const int16_t index = CAST_S16(item->getInvIndex() + INVENTORY_OFFSET);
164
    if (packetVersion >= 20101124)
165
    {
166
        outMsg.writeInt16(index, "index");
167
        outMsg.writeInt16(CAST_S16(amount), "amount");
168
    }
169
    else if (packetVersion >= 20080827)
170
    {
171
        outMsg.writeInt16(0, "unknown");
172
        outMsg.writeInt16(index, "index");
173
        outMsg.writeInt32(0, "unknown");
174
        outMsg.writeInt16(0, "unknown");
175
        outMsg.writeInt8(0, "unknown");
176
        outMsg.writeInt16(CAST_S16(amount), "amount");
177
    }
178
    else if (packetVersion >= 20070212)
179
    {
180
        outMsg.writeInt16(0, "unknown");
181
        outMsg.writeInt8(0, "unknown");
182
        outMsg.writeInt16(index, "index");
183
        outMsg.writeInt8(0, "unknown");
184
        outMsg.writeInt16(CAST_S16(amount), "amount");
185
    }
186
    else if (packetVersion >= 20070108)
187
    {
188
        outMsg.writeInt32(0, "unknown");
189
        outMsg.writeInt32(0, "unknown");
190
        outMsg.writeInt16(0, "unknown");
191
        outMsg.writeInt16(index, "index");
192
        outMsg.writeInt32(0, "unknown");
193
        outMsg.writeInt16(CAST_S16(amount), "amount");
194
    }
195
    else if (packetVersion >= 20060327)
196
    {
197
        outMsg.writeInt32(0, "unknown");
198
        outMsg.writeInt16(0, "unknown");
199
        outMsg.writeInt16(index, "index");
200
        outMsg.writeInt32(0, "unknown");
201
        outMsg.writeInt8(0, "unknown");
202
        outMsg.writeInt16(CAST_S16(amount), "amount");
203
    }
204
    else if (packetVersion >= 20050719)
205
    {
206
        outMsg.writeInt8(0, "unknown");
207
        outMsg.writeInt16(index, "index");
208
        outMsg.writeInt8(0, "unknown");
209
        outMsg.writeInt32(0, "unknown");
210
        outMsg.writeInt16(CAST_S16(amount), "amount");
211
    }
212
    else if (packetVersion >= 20050718)
213
    {
214
        outMsg.writeInt32(0, "unknown");
215
        outMsg.writeInt16(index, "index");
216
        outMsg.writeInt16(0, "unknown");
217
        outMsg.writeInt16(CAST_S16(amount), "amount");
218
    }
219
    else if (packetVersion >= 20050628)
220
    {
221
        outMsg.writeInt8(0, "unknown");
222
        outMsg.writeInt16(index, "index");
223
        outMsg.writeInt32(0, "unknown");
224
        outMsg.writeInt8(0, "unknown");
225
        outMsg.writeInt16(CAST_S16(amount), "amount");
226
    }
227
    else if (packetVersion >= 20050509)
228
    {
229
        outMsg.writeInt16(0, "unknown");
230
        outMsg.writeInt8(0, "unknown");
231
        outMsg.writeInt16(index, "index");
232
        outMsg.writeInt8(0, "unknown");
233
        outMsg.writeInt16(CAST_S16(amount), "amount");
234
    }
235
    else if (packetVersion >= 20050110)
236
    {
237
        outMsg.writeInt32(0, "unknown");
238
        outMsg.writeInt32(0, "unknown");
239
        outMsg.writeInt32(0, "unknown");
240
        outMsg.writeInt8(0, "unknown");
241
        outMsg.writeInt16(index, "index");
242
        outMsg.writeInt8(0, "unknown");
243
        outMsg.writeInt16(CAST_S16(amount), "amount");
244
    }
245
    else if (packetVersion >= 20041129)
246
    {
247
        outMsg.writeInt16(0, "unknown");
248
        outMsg.writeInt16(index, "index");
249
        outMsg.writeInt32(0, "unknown");
250
        outMsg.writeInt16(CAST_S16(amount), "amount");
251
    }
252
    else if (packetVersion >= 20041025)
253
    {
254
        outMsg.writeInt32(0, "unknown");
255
        outMsg.writeInt16(index, "index");
256
        outMsg.writeInt16(0, "unknown");
257
        outMsg.writeInt16(CAST_S16(amount), "amount");
258
    }
259
    else if (packetVersion >= 20041005)
260
    {
261
        outMsg.writeInt16(0, "unknown");
262
        outMsg.writeInt8(0, "unknown");
263
        outMsg.writeInt16(index, "index");
264
        outMsg.writeInt32(0, "unknown");
265
        outMsg.writeInt8(0, "unknown");
266
        outMsg.writeInt16(CAST_S16(amount), "amount");
267
    }
268
    else if (packetVersion >= 20040920)
269
    {
270
        outMsg.writeInt32(0, "unknown");
271
        outMsg.writeInt32(0, "unknown");
272
        outMsg.writeInt16(0, "unknown");
273
        outMsg.writeInt16(index, "index");
274
        outMsg.writeInt16(0, "unknown");
275
        outMsg.writeInt8(0, "unknown");
276
        outMsg.writeInt16(CAST_S16(amount), "amount");
277
    }
278
    else if (packetVersion >= 20040906)
279
    {
280
        outMsg.writeInt32(0, "unknown");
281
        outMsg.writeInt16(index, "index");
282
        outMsg.writeInt32(0, "unknown");
283
        outMsg.writeInt16(0, "unknown");
284
        outMsg.writeInt8(0, "unknown");
285
        outMsg.writeInt16(CAST_S16(amount), "amount");
286
    }
287
    else if (packetVersion >= 20040809)
288
    {
289
        outMsg.writeInt32(0, "unknown");
290
        outMsg.writeInt16(0, "unknown");
291
        outMsg.writeInt16(index, "index");
292
        outMsg.writeInt32(0, "unknown");
293
        outMsg.writeInt8(0, "unknown");
294
        outMsg.writeInt16(CAST_S16(amount), "amount");
295
    }
296
    else if (packetVersion >= 20040726)
297
    {
298
        outMsg.writeInt16(0, "unknown");
299
        outMsg.writeInt8(0, "unknown");
300
        outMsg.writeInt16(index, "index");
301
        outMsg.writeInt32(0, "unknown");
302
        outMsg.writeInt8(0, "unknown");
303
        outMsg.writeInt16(CAST_S16(amount), "amount");
304
    }
305
    else
306
    {
307
        outMsg.writeInt16(index, "index");
308
        outMsg.writeInt16(CAST_S16(amount), "amount");
309
    }
310
}
311
312
void InventoryHandler::closeStorage() const
313
{
314
    createOutPacket(CMSG_CLOSE_STORAGE);
315
}
316
317
void InventoryHandler::moveItemInventoryToStorage(const int slot,
318
                                                  const int amount) const
319
{
320
    createOutPacket(CMSG_MOVE_TO_STORAGE);
321
    if (packetVersion >= 20101124)
322
    {
323
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
324
        outMsg.writeInt32(amount, "amount");
325
    }
326
    else if (packetVersion >= 20080827)
327
    {
328
        outMsg.writeInt8(0, "unknown");
329
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
330
        outMsg.writeInt32(0, "unknown");
331
        outMsg.writeInt32(0, "unknown");
332
        outMsg.writeInt32(0, "unknown");
333
        outMsg.writeInt16(0, "unknown");
334
        outMsg.writeInt8(0, "unknown");
335
        outMsg.writeInt32(amount, "amount");
336
    }
337
    else if (packetVersion >= 20070212)
338
    {
339
        outMsg.writeInt32(0, "unknown");
340
        outMsg.writeInt8(0, "unknown");
341
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
342
        outMsg.writeInt8(0, "unknown");
343
        outMsg.writeInt32(amount, "amount");
344
    }
345
    else if (packetVersion >= 20070108)
346
    {
347
        outMsg.writeInt16(0, "unknown");
348
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
349
        outMsg.writeInt32(0, "unknown");
350
        outMsg.writeInt16(0, "unknown");
351
        outMsg.writeInt8(0, "unknown");
352
        outMsg.writeInt32(amount, "amount");
353
    }
354
    else if (packetVersion >= 20060327)
355
    {
356
        outMsg.writeInt16(0, "unknown");
357
        outMsg.writeInt8(0, "unknown");
358
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
359
        outMsg.writeInt32(0, "unknown");
360
        outMsg.writeInt32(0, "unknown");
361
        outMsg.writeInt32(0, "unknown");
362
        outMsg.writeInt32(amount, "amount");
363
    }
364
    else if (packetVersion >= 20050719)
365
    {
366
        outMsg.writeInt32(0, "unknown");
367
        outMsg.writeInt32(0, "unknown");
368
        outMsg.writeInt32(0, "unknown");
369
        outMsg.writeInt16(0, "unknown");
370
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
371
        outMsg.writeInt32(0, "unknown");
372
        outMsg.writeInt32(0, "unknown");
373
        outMsg.writeInt8(0, "unknown");
374
        outMsg.writeInt32(amount, "amount");
375
    }
376
    else if (packetVersion >= 20050718)
377
    {
378
        outMsg.writeInt32(0, "unknown");
379
        outMsg.writeInt32(0, "unknown");
380
        outMsg.writeInt16(0, "unknown");
381
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
382
        outMsg.writeInt16(0, "unknown");
383
        outMsg.writeInt8(0, "unknown");
384
        outMsg.writeInt32(amount, "amount");
385
    }
386
    else if (packetVersion >= 20050628)
387
    {
388
        outMsg.writeInt32(0, "unknown");
389
        outMsg.writeInt32(0, "unknown");
390
        outMsg.writeInt32(0, "unknown");
391
        outMsg.writeInt16(0, "unknown");
392
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
393
        outMsg.writeInt32(0, "unknown");
394
        outMsg.writeInt32(0, "unknown");
395
        outMsg.writeInt16(0, "unknown");
396
        outMsg.writeInt32(amount, "amount");
397
    }
398
    else if (packetVersion >= 20050509)
399
    {
400
        outMsg.writeInt32(0, "unknown");
401
        outMsg.writeInt8(0, "unknown");
402
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
403
        outMsg.writeInt8(0, "unknown");
404
        outMsg.writeInt32(amount, "amount");
405
    }
406
    else if (packetVersion >= 20050110)
407
    {
408
        outMsg.writeInt32(0, "unknown");
409
        outMsg.writeInt32(0, "unknown");
410
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
411
        outMsg.writeInt32(0, "unknown");
412
        outMsg.writeInt16(0, "unknown");
413
        outMsg.writeInt32(amount, "amount");
414
    }
415
    else if (packetVersion >= 20041129)
416
    {
417
        outMsg.writeInt16(0, "unknown");
418
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
419
        outMsg.writeInt32(0, "unknown");
420
        outMsg.writeInt32(amount, "amount");
421
    }
422
    else if (packetVersion >= 20041025)
423
    {
424
        outMsg.writeInt32(0, "unknown");
425
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
426
        outMsg.writeInt8(0, "unknown");
427
        outMsg.writeInt32(amount, "amount");
428
    }
429
    else if (packetVersion >= 20041005)
430
    {
431
        outMsg.writeInt16(0, "unknown");
432
        outMsg.writeInt8(0, "unknown");
433
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
434
        outMsg.writeInt32(0, "unknown");
435
        outMsg.writeInt8(0, "unknown");
436
        outMsg.writeInt32(amount, "amount");
437
    }
438
    else if (packetVersion >= 20040920)
439
    {
440
        outMsg.writeInt32(0, "unknown");
441
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
442
        outMsg.writeInt32(0, "unknown");
443
        outMsg.writeInt32(0, "unknown");
444
        outMsg.writeInt32(0, "unknown");
445
        outMsg.writeInt8(0, "unknown");
446
        outMsg.writeInt32(amount, "amount");
447
    }
448
    else if (packetVersion >= 20040906)
449
    {
450
        outMsg.writeInt8(0, "unknown");
451
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
452
        outMsg.writeInt32(0, "unknown");
453
        outMsg.writeInt32(0, "unknown");
454
        outMsg.writeInt16(0, "unknown");
455
        outMsg.writeInt32(amount, "amount");
456
    }
457
    else if (packetVersion >= 20040809)
458
    {
459
        outMsg.writeInt16(0, "unknown");
460
        outMsg.writeInt8(0, "unknown");
461
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
462
        outMsg.writeInt32(0, "unknown");
463
        outMsg.writeInt32(0, "unknown");
464
        outMsg.writeInt32(0, "unknown");
465
        outMsg.writeInt32(amount, "amount");
466
    }
467
    else if (packetVersion >= 20040726)
468
    {
469
        outMsg.writeInt16(0, "unknown");
470
        outMsg.writeInt8(0, "unknown");
471
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
472
        outMsg.writeInt32(0, "unknown");
473
        outMsg.writeInt8(0, "unknown");
474
        outMsg.writeInt32(amount, "amount");
475
    }
476
    else
477
    {
478
        outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET), "index");
479
        outMsg.writeInt32(amount, "amount");
480
    }
481
}
482
483
void InventoryHandler::moveItem2(const InventoryTypeT source,
484
                                 const int slot,
485
                                 const int amount,
486
                                 const InventoryTypeT destination) const
487
{
488
    int packet = 0;
489
    int offset = INVENTORY_OFFSET;
490
    if (source == InventoryType::Inventory)
491
    {
492
        if (destination == InventoryType::Storage)
493
        {
494
            moveItemInventoryToStorage(slot, amount);
495
            return;
496
        }
497
        else if (destination == InventoryType::Cart)
498
        {
499
            packet = CMSG_MOVE_TO_CART;
500
        }
501
    }
502
    else if (source == InventoryType::Storage)
503
    {
504
        offset = STORAGE_OFFSET;
505
        if (destination == InventoryType::Inventory)
506
            packet = CMSG_MOVE_FROM_STORAGE;
507
        else if (destination == InventoryType::Cart)
508
            packet = CMSG_MOVE_FROM_STORAGE_TO_CART;
509
    }
510
    else if (source == InventoryType::Cart)
511
    {
512
        if (destination == InventoryType::Inventory)
513
            packet = CMSG_MOVE_FROM_CART;
514
        else if (destination == InventoryType::Storage)
515
            packet = CMSG_MOVE_FROM_CART_TO_STORAGE;
516
    }
517
518
    // for packetVersion < 20101124 need use other packet offset
519
    if (packet != 0)
520
    {
521
        createOutPacket(packet);
522
        outMsg.writeInt16(CAST_S16(slot + offset), "index");
523
        outMsg.writeInt32(amount, "amount");
524
    }
525
}
526
527
void InventoryHandler::useCard(const Item *const item)
528
{
529
    if (item == nullptr)
530
        return;
531
532
    mItemIndex = item->getInvIndex();
533
    createOutPacket(CMSG_PLAYER_USE_CARD);
534
    outMsg.writeInt16(CAST_S16(
535
        mItemIndex + INVENTORY_OFFSET), "index");
536
}
537
538
void InventoryHandler::insertCard(const int cardIndex,
539
                                  const int itemIndex) const
540
{
541
    createOutPacket(CMSG_PLAYER_INSERT_CARD);
542
    outMsg.writeInt16(CAST_S16(cardIndex + INVENTORY_OFFSET),
543
        "card index");
544
    outMsg.writeInt16(CAST_S16(itemIndex + INVENTORY_OFFSET),
545
        "item index");
546
}
547
548
void InventoryHandler::favoriteItem(const Item *const item,
549
                                    const bool favorite) const
550
{
551
    if (item == nullptr)
552
        return;
553
    if (packetVersion < 20120410)
554
        return;
555
    createOutPacket(CMSG_PLAYER_FAVORITE_ITEM);
556
    outMsg.writeInt16(CAST_S16(item->getInvIndex()
557
        + INVENTORY_OFFSET),
558
        "item index");
559
    outMsg.writeInt8(static_cast<int8_t>(favorite), "favorite flag");
560
}
561
562
void InventoryHandler::selectEgg(const Item *const item) const
563
{
564
    if (item == nullptr)
565
        return;
566
    createOutPacket(CMSG_PET_SELECT_EGG);
567
    outMsg.writeInt16(CAST_S16(
568
        item->getInvIndex() + INVENTORY_OFFSET), "index");
569
    menu = MenuType::Unknown;
570
}
571
572
int InventoryHandler::convertFromServerSlot(const int serverSlot) const
573
{
574
    if (serverSlot < 0 || serverSlot >= 17)
575
        return 0;
576
577
    return CAST_S32(EQUIP_CONVERT[serverSlot]);
578
}
579
580
void InventoryHandler::selectCart(const BeingId accountId,
581
                                  const int type) const
582
{
583
    if (packetVersion < 20150805)
584
        return;
585
    createOutPacket(CMSG_SELECT_CART);
586
    outMsg.writeBeingId(accountId, "account id");
587
    outMsg.writeInt8(CAST_S8(type), "type");
588
}
589
590
void InventoryHandler::identifyItem(const Item *const item) const
591
{
592
    if (packetVersion < 20150513)
593
        return;
594
    createOutPacket(CMSG_QUICK_IDENTIFY_ITEM);
595
    outMsg.writeInt16(CAST_S16(item->getInvIndex()),
596
        "item index");
597
}
598
599
void InventoryHandler::mergeItemsAck(const STD_VECTOR<Item*> &items) const
600
{
601
    createOutPacket(CMSG_MERGE_ITEM_ACK);
602
    const size_t sz = items.size();
603
    outMsg.writeInt16(CAST_S16(sz * 2 + 4),
604
        "len");
605
    FOR_EACH (STD_VECTOR<Item*>::const_iterator, it, items)
606
    {
607
        outMsg.writeInt16(CAST_S16((*it)->getInvIndex() + 2),
608
            "item index");
609
    }
610
}
611
612
void InventoryHandler::mergetItemsCancel() const
613
{
614
    createOutPacket(CMSG_MERGE_ITEM_CANCEL);
615
}
616
617
void InventoryHandler::expandInventory() const
618
{
619
    if (packetVersionMain < 20181031 &&
620
        packetVersionRe < 20181031 &&
621
        packetVersionZero < 20181114)
622
    {
623
        return;
624
    }
625
    createOutPacket(CMSG_INVENTORY_EXPAND);
626
}
627
628
void InventoryHandler::expandInventoryConfirm() const
629
{
630
    if (packetVersionMain < 20181031 &&
631
        packetVersionRe < 20181031 &&
632
        packetVersionZero < 20181114)
633
    {
634
        return;
635
    }
636
    createOutPacket(CMSG_INVENTORY_EXPAND_CONFIRM);
637
}
638
639
void InventoryHandler::expandInventoryReject() const
640
{
641
    if (packetVersionMain < 20181031 &&
642
        packetVersionRe < 20181031 &&
643
        packetVersionZero < 20181114)
644
    {
645
        return;
646
    }
647
    createOutPacket(CMSG_INVENTORY_EXPAND_REJECT);
648
}
649
650
}  // namespace EAthena