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