GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/playerhandler.cpp Lines: 8 459 1.7 %
Date: 2019-10-15 Branches: 0 653 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/playerhandler.h"
24
25
#include "notifymanager.h"
26
#include "party.h"
27
28
#include "being/localplayer.h"
29
#include "being/playerinfo.h"
30
31
#include "const/net/nostat.h"
32
33
#include "enums/resources/notifytypes.h"
34
35
#include "gui/windows/skilldialog.h"
36
#include "gui/windows/statuswindow.h"
37
38
#include "net/ea/inventoryhandler.h"
39
40
#include "net/eathena/messageout.h"
41
#include "net/eathena/protocolout.h"
42
#include "net/eathena/sp.h"
43
44
#include "resources/db/unitsdb.h"
45
46
#include "debug.h"
47
48
extern int packetVersion;
49
extern int packetVersionMain;
50
extern int packetVersionRe;
51
extern int packetVersionZero;
52
extern int serverVersion;
53
54
namespace EAthena
55
{
56
57
77
PlayerHandler::PlayerHandler() :
58
77
    Ea::PlayerHandler()
59
{
60
77
    playerHandler = this;
61
77
}
62
63
231
PlayerHandler::~PlayerHandler()
64
{
65
77
    playerHandler = nullptr;
66
77
}
67
68
void PlayerHandler::attack(const BeingId id,
69
                           const Keep keep) const
70
{
71
    createOutPacket(CMSG_PLAYER_CHANGE_ACT);
72
    outMsg.writeBeingId(id, "target id");
73
    if (keep == Keep_true)
74
        outMsg.writeInt8(7, "action");
75
    else
76
        outMsg.writeInt8(0, "action");
77
}
78
79
void PlayerHandler::stopAttack() const
80
{
81
    createOutPacket(CMSG_PLAYER_STOP_ATTACK);
82
}
83
84
void PlayerHandler::emote(const uint8_t emoteId) const
85
{
86
    createOutPacket(CMSG_PLAYER_EMOTE);
87
    outMsg.writeInt8(emoteId, "emote id");
88
}
89
90
void PlayerHandler::increaseAttribute(const AttributesT attr,
91
                                      const int amount) const
92
{
93
    if (attr >= Attributes::PLAYER_STR && attr <= Attributes::PLAYER_LUK)
94
    {
95
        createOutPacket(CMSG_STAT_UPDATE_REQUEST);
96
        outMsg.writeInt16(CAST_S16(attr), "attribute id");
97
        outMsg.writeInt8(CAST_S8(amount), "increase");
98
    }
99
}
100
101
void PlayerHandler::increaseSkill(const uint16_t skillId) const
102
{
103
    if (PlayerInfo::getAttribute(Attributes::PLAYER_SKILL_POINTS) <= 0)
104
        return;
105
106
    createOutPacket(CMSG_SKILL_LEVELUP_REQUEST);
107
    outMsg.writeInt16(skillId, "skill id");
108
}
109
110
void PlayerHandler::pickUp(const FloorItem *const floorItem) const
111
{
112
    if (floorItem == nullptr)
113
        return;
114
115
    createOutPacket(CMSG_ITEM_PICKUP);
116
    const BeingId id = floorItem->getId();
117
    if (packetVersion >= 20101124)
118
    {
119
        outMsg.writeBeingId(id, "object id");
120
    }
121
    else if (packetVersion >= 20080827)
122
    {
123
        outMsg.writeInt32(0, "unused");
124
        outMsg.writeInt8(0, "unused");
125
        outMsg.writeBeingId(id, "object id");
126
    }
127
    else if (packetVersion >= 20070212)
128
    {
129
        outMsg.writeInt32(0, "unused");
130
        outMsg.writeBeingId(id, "object id");
131
    }
132
    else if (packetVersion >= 20070108)
133
    {
134
        outMsg.writeInt32(0, "unused");
135
        outMsg.writeInt8(0, "unused");
136
        outMsg.writeBeingId(id, "object id");
137
    }
138
    else if (packetVersion >= 20050719)
139
    {
140
        outMsg.writeInt32(0, "unused");
141
        outMsg.writeInt16(0, "unused");
142
        outMsg.writeInt8(0, "unused");
143
        outMsg.writeBeingId(id, "object id");
144
    }
145
    else if (packetVersion >= 20050718)
146
    {
147
        outMsg.writeInt8(0, "unused");
148
        outMsg.writeBeingId(id, "object id");
149
    }
150
    else if (packetVersion >= 20050628)
151
    {
152
        outMsg.writeInt32(0, "unused");
153
        outMsg.writeInt8(0, "unused");
154
        outMsg.writeBeingId(id, "object id");
155
    }
156
    else if (packetVersion >= 20050509)
157
    {
158
        outMsg.writeInt16(0, "unused");
159
        outMsg.writeBeingId(id, "object id");
160
    }
161
    else if (packetVersion >= 20050110)
162
    {
163
        outMsg.writeInt16(0, "unused");
164
        outMsg.writeInt8(0, "unused");
165
        outMsg.writeBeingId(id, "object id");
166
    }
167
    else if (packetVersion >= 20041129)
168
    {
169
        outMsg.writeInt8(0, "unused");
170
        outMsg.writeBeingId(id, "object id");
171
    }
172
    else if (packetVersion >= 20041025)
173
    {
174
        outMsg.writeInt16(0, "unused");
175
        outMsg.writeInt8(0, "unused");
176
        outMsg.writeBeingId(id, "object id");
177
    }
178
    else if (packetVersion >= 20041005)
179
    {
180
        outMsg.writeInt32(0, "unused");
181
        outMsg.writeBeingId(id, "object id");
182
    }
183
    else if (packetVersion >= 20040920)
184
    {
185
        outMsg.writeInt32(0, "unused");
186
        outMsg.writeInt32(0, "unused");
187
        outMsg.writeBeingId(id, "object id");
188
    }
189
    else if (packetVersion >= 20040906)
190
    {
191
        outMsg.writeInt32(0, "unused");
192
        outMsg.writeInt8(0, "unused");
193
        outMsg.writeBeingId(id, "object id");
194
    }
195
    else if (packetVersion >= 20040809)
196
    {
197
        outMsg.writeInt32(0, "unused");
198
        outMsg.writeInt16(0, "unused");
199
        outMsg.writeInt8(0, "unused");
200
        outMsg.writeBeingId(id, "object id");
201
    }
202
    else if (packetVersion >= 20040713)
203
    {
204
        outMsg.writeInt32(0, "unused");
205
        outMsg.writeBeingId(id, "object id");
206
    }
207
    else
208
    {
209
        outMsg.writeBeingId(id, "object id");
210
    }
211
212
    Ea::InventoryHandler::pushPickup(floorItem->getId());
213
}
214
215
void PlayerHandler::setDirection(const unsigned char direction) const
216
{
217
    createOutPacket(CMSG_PLAYER_CHANGE_DIR);
218
    if (packetVersion >= 20101124)
219
    {
220
        outMsg.writeInt8(0, "head direction");
221
        outMsg.writeInt8(0, "unused");
222
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
223
            "player direction");
224
    }
225
    else if (packetVersion >= 20080827)
226
    {
227
        outMsg.writeInt16(0, "unused");
228
        outMsg.writeInt8(0, "head direction");
229
        outMsg.writeInt32(0, "unused");
230
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
231
            "player direction");
232
    }
233
    else if (packetVersion >= 20070212)
234
    {
235
        outMsg.writeInt32(0, "unused");
236
        outMsg.writeInt16(0, "unused");
237
        outMsg.writeInt8(0, "head direction");
238
        outMsg.writeInt16(0, "unused");
239
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
240
            "player direction");
241
    }
242
    else if (packetVersion >= 20070108)
243
    {
244
        outMsg.writeInt32(0, "unused");
245
        outMsg.writeInt32(0, "unused");
246
        outMsg.writeInt8(0, "head direction");
247
        outMsg.writeInt16(0, "unused");
248
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
249
            "player direction");
250
    }
251
    else if (packetVersion >= 20060327)
252
    {
253
        outMsg.writeInt32(0, "unused");
254
        outMsg.writeInt8(0, "unused");
255
        outMsg.writeInt8(0, "head direction");
256
        outMsg.writeInt8(0, "unused");
257
        outMsg.writeInt16(0, "unused");
258
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
259
            "player direction");
260
    }
261
    else if (packetVersion >= 20050719)
262
    {
263
        outMsg.writeInt32(0, "unused");
264
        outMsg.writeInt16(0, "unused");
265
        outMsg.writeInt8(0, "head direction");
266
        outMsg.writeInt8(0, "unused");
267
        outMsg.writeInt32(0, "unused");
268
        outMsg.writeInt16(0, "unused");
269
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
270
            "player direction");
271
    }
272
    else if (packetVersion >= 20050718)
273
    {
274
        outMsg.writeInt32(0, "unused");
275
        outMsg.writeInt8(0, "head direction");
276
        outMsg.writeInt8(0, "unused");
277
        outMsg.writeInt16(0, "unused");
278
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
279
            "player direction");
280
    }
281
    else if (packetVersion >= 20050628)
282
    {
283
        outMsg.writeInt32(0, "unused");
284
        outMsg.writeInt16(0, "unused");
285
        outMsg.writeInt8(0, "head direction");
286
        outMsg.writeInt8(0, "unused");
287
        outMsg.writeInt32(0, "unused");
288
        outMsg.writeInt16(0, "unused");
289
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
290
            "player direction");
291
    }
292
    else if (packetVersion >= 20050509)
293
    {
294
        outMsg.writeInt8(0, "unused");
295
        outMsg.writeInt32(0, "unused");
296
        outMsg.writeInt16(0, "unused");
297
        outMsg.writeInt8(0, "head direction");
298
        outMsg.writeInt8(0, "unused");
299
        outMsg.writeInt16(0, "unused");
300
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
301
            "player direction");
302
    }
303
    else if (packetVersion >= 20050110)
304
    {
305
        outMsg.writeInt32(0, "unused");
306
        outMsg.writeInt32(0, "unused");
307
        outMsg.writeInt16(0, "unused");
308
        outMsg.writeInt8(0, "head direction");
309
        outMsg.writeInt8(0, "unused");
310
        outMsg.writeInt32(0, "unused");
311
        outMsg.writeInt32(0, "unused");
312
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
313
            "player direction");
314
    }
315
    else if (packetVersion >= 20041129)
316
    {
317
        outMsg.writeInt8(0, "unused");
318
        outMsg.writeInt8(0, "head direction");
319
        outMsg.writeInt8(0, "unused");
320
        outMsg.writeInt16(0, "unused");
321
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
322
            "player direction");
323
    }
324
    else if (packetVersion >= 20041025)
325
    {
326
        outMsg.writeInt32(0, "unused");
327
        outMsg.writeInt8(0, "head direction");
328
        outMsg.writeInt8(0, "unused");
329
        outMsg.writeInt32(0, "unused");
330
        outMsg.writeInt16(0, "unused");
331
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
332
            "player direction");
333
    }
334
    else if (packetVersion >= 20041005)
335
    {
336
        outMsg.writeInt16(0, "unused");
337
        outMsg.writeInt8(0, "unused");
338
        outMsg.writeInt8(0, "head direction");
339
        outMsg.writeInt32(0, "unused");
340
        outMsg.writeInt16(0, "unused");
341
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
342
            "player direction");
343
    }
344
    else if (packetVersion >= 20040920)
345
    {
346
        outMsg.writeInt32(0, "unused");
347
        outMsg.writeInt16(0, "unused");
348
        outMsg.writeInt8(0, "head direction");
349
        outMsg.writeInt32(0, "unused");
350
        outMsg.writeInt32(0, "unused");
351
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
352
            "player direction");
353
    }
354
    else if (packetVersion >= 20040906)
355
    {
356
        outMsg.writeInt16(0, "unused");
357
        outMsg.writeInt8(0, "head direction");
358
        outMsg.writeInt16(0, "unused");
359
        outMsg.writeInt16(0, "unused");
360
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
361
            "player direction");
362
    }
363
    else if (packetVersion >= 20040809)
364
    {
365
        outMsg.writeInt16(0, "unused");
366
        outMsg.writeInt16(0, "unused");
367
        outMsg.writeInt8(0, "unused");
368
        outMsg.writeInt8(0, "head direction");
369
        outMsg.writeInt16(0, "unused");
370
        outMsg.writeInt8(0, "unused");
371
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
372
            "player direction");
373
    }
374
    else if (packetVersion >= 20040713)
375
    {
376
        outMsg.writeInt8(0, "unused");
377
        outMsg.writeInt8(0, "unused");
378
        outMsg.writeInt8(0, "unused");
379
        outMsg.writeInt8(0, "head direction");
380
        outMsg.writeInt16(0, "unused");
381
        outMsg.writeInt16(0, "unused");
382
        outMsg.writeInt16(0, "unused");
383
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
384
            "player direction");
385
    }
386
    else
387
    {
388
        outMsg.writeInt8(0, "head direction");
389
        outMsg.writeInt8(0, "unused");
390
        outMsg.writeInt8(MessageOut::toServerDirection(direction),
391
            "player direction");
392
    }
393
}
394
395
void PlayerHandler::setDestination(const int x, const int y,
396
                                   const int direction) const
397
{
398
    createOutPacket(CMSG_PLAYER_CHANGE_DEST);
399
    if (packetVersion >= 20080827 && packetVersion < 20101124)
400
        outMsg.writeInt32(0, "unused");
401
    outMsg.writeCoordinates(CAST_U16(x),
402
        CAST_U16(y),
403
        CAST_U8(direction), "destination");
404
}
405
406
void PlayerHandler::changeAction(const BeingActionT &action) const
407
{
408
    unsigned char type;
409
    switch (action)
410
    {
411
        case BeingAction::SIT:
412
            type = 2;
413
            break;
414
        case BeingAction::STAND:
415
        case BeingAction::PRESTAND:
416
            type = 3;
417
            break;
418
        default:
419
        case BeingAction::MOVE:
420
        case BeingAction::ATTACK:
421
        case BeingAction::DEAD:
422
        case BeingAction::HURT:
423
        case BeingAction::SPAWN:
424
        case BeingAction::CAST:
425
            return;
426
    }
427
428
    createOutPacket(CMSG_PLAYER_CHANGE_ACT);
429
    outMsg.writeInt32(0, "unused");
430
    outMsg.writeInt8(type, "action");
431
}
432
433
void PlayerHandler::respawn() const
434
{
435
    createOutPacket(CMSG_PLAYER_RESTART);
436
    outMsg.writeInt8(0, "action");
437
}
438
439
void PlayerHandler::requestOnlineList() const
440
{
441
    createOutPacket(CMSG_ONLINE_LIST);
442
}
443
444
void PlayerHandler::updateStatus(const uint8_t status) const
445
{
446
    createOutPacket(CMSG_SET_STATUS);
447
    outMsg.writeInt8(status, "status");
448
    outMsg.writeInt8(0, "unused");
449
}
450
451
void PlayerHandler::setShortcut(const int idx,
452
                                const int tab,
453
                                const uint8_t type,
454
                                const int id,
455
                                const int level) const
456
{
457
    createOutPacket(CMSG_SET_SHORTCUTS);
458
    if (packetVersionMain >= 20190522 ||
459
        packetVersionRe >= 20190508 ||
460
        packetVersionZero >= 20190605)
461
    {
462
        outMsg.writeInt16(CAST_S16(tab), "tab");
463
    }
464
    outMsg.writeInt16(CAST_S16(idx), "index");
465
    outMsg.writeInt8(CAST_S8(type), "type");
466
    outMsg.writeInt32(id, "id");
467
    outMsg.writeInt16(CAST_S16(level), "level");
468
}
469
470
void PlayerHandler::shortcutShiftRow(const int row,
471
                                     const int tab) const
472
{
473
    if (packetVersion < 20140129)
474
        return;
475
    createOutPacket(CMSG_SHORTCUTS_ROW_SHIFT);
476
    if (packetVersionMain >= 20190522 ||
477
        packetVersionRe >= 20190508 ||
478
        packetVersionZero >= 20190605)
479
    {
480
        outMsg.writeInt16(CAST_S16(tab), "tab");
481
    }
482
    outMsg.writeInt8(CAST_S8(row), "row");
483
}
484
485
void PlayerHandler::removeOption() const
486
{
487
    createOutPacket(CMSG_REMOVE_OPTION);
488
}
489
490
void PlayerHandler::changeCart(const int type) const
491
{
492
    createOutPacket(CMSG_CHANGE_CART);
493
    outMsg.writeInt16(CAST_S16(type), "type");
494
}
495
496
void PlayerHandler::setMemo() const
497
{
498
    createOutPacket(CMSG_PLAYER_SET_MEMO);
499
}
500
501
void PlayerHandler::doriDori() const
502
{
503
    createOutPacket(CMSG_DORI_DORI);
504
}
505
506
void PlayerHandler::explosionSpirits() const
507
{
508
    createOutPacket(CMSG_EXPLOSION_SPIRITS);
509
}
510
511
void PlayerHandler::requestPvpInfo() const
512
{
513
    createOutPacket(CMSG_PVP_INFO);
514
    outMsg.writeInt32(0, "char id");
515
    outMsg.writeInt32(0, "account id");
516
}
517
518
void PlayerHandler::revive() const
519
{
520
    createOutPacket(CMSG_PLAYER_AUTO_REVIVE);
521
}
522
523
void PlayerHandler::setConfigOption(const int id,
524
                                    const int data) const
525
{
526
    createOutPacket(CMSG_SET_CONFIG_OPTION);
527
    outMsg.writeInt32(id, "config option");
528
    outMsg.writeInt32(data, "config data");
529
}
530
531
#define setStatComplex(stat) \
532
    PlayerInfo::setStatBase(stat, CAST_S32(base), notify); \
533
    if (mod != NoStat) \
534
        PlayerInfo::setStatMod(stat, mod, Notify_true)
535
536
void PlayerHandler::setStat(Net::MessageIn &msg,
537
                            const int type,
538
                            const int64_t base,
539
                            const int mod,
540
                            const Notify notify) const
541
{
542
    switch (type)
543
    {
544
        case Sp::SPEED:
545
            localPlayer->setWalkSpeed(CAST_S32(base));
546
            PlayerInfo::setStatBase(Attributes::PLAYER_WALK_SPEED,
547
                CAST_S32(base),
548
                Notify_true);
549
            PlayerInfo::setStatMod(Attributes::PLAYER_WALK_SPEED,
550
                0,
551
                Notify_true);
552
            break;
553
        case Sp::BASEEXP:
554
            PlayerInfo::setAttribute(Attributes::PLAYER_EXP,
555
                base,
556
                Notify_true);
557
            break;
558
        case Sp::JOBEXP:
559
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP,
560
                base,
561
                Notify_true);
562
            break;
563
        case Sp::KARMA:
564
            PlayerInfo::setStatBase(Attributes::PLAYER_KARMA,
565
                CAST_S32(base),
566
                Notify_true);
567
            PlayerInfo::setStatMod(Attributes::PLAYER_KARMA,
568
                0,
569
                Notify_true);
570
            break;
571
        case Sp::MANNER:
572
            PlayerInfo::setStatBase(Attributes::PLAYER_MANNER,
573
                CAST_S32(base),
574
                Notify_true);
575
            PlayerInfo::setStatMod(Attributes::PLAYER_MANNER,
576
                0,
577
                Notify_true);
578
            break;
579
        case Sp::HP:
580
            PlayerInfo::setAttribute(Attributes::PLAYER_HP,
581
                base,
582
                Notify_true);
583
            if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
584
            {
585
                PartyMember *const m = Party::getParty(1)
586
                    ->getMember(localPlayer->getId());
587
                if (m != nullptr)
588
                {
589
                    m->setHp(CAST_S32(base));
590
                    m->setMaxHp(PlayerInfo::getAttribute(
591
                        Attributes::PLAYER_MAX_HP));
592
                }
593
            }
594
            break;
595
        case Sp::MAXHP:
596
            PlayerInfo::setAttribute(Attributes::PLAYER_MAX_HP,
597
                base,
598
                Notify_true);
599
600
            if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
601
            {
602
                PartyMember *const m = Party::getParty(1)->getMember(
603
                    localPlayer->getId());
604
                if (m != nullptr)
605
                {
606
                    m->setHp(PlayerInfo::getAttribute(Attributes::PLAYER_HP));
607
                    m->setMaxHp(CAST_S32(base));
608
                }
609
            }
610
            break;
611
        case Sp::SP:
612
            PlayerInfo::setAttribute(Attributes::PLAYER_MP,
613
                base,
614
                Notify_true);
615
            break;
616
        case Sp::MAXSP:
617
            PlayerInfo::setAttribute(Attributes::PLAYER_MAX_MP,
618
                base,
619
                Notify_true);
620
            break;
621
        case Sp::STATUSPOINT:
622
            PlayerInfo::setAttribute(Attributes::PLAYER_CHAR_POINTS,
623
                base,
624
                Notify_true);
625
            break;
626
        case Sp::BASELEVEL:
627
            PlayerInfo::setAttribute(Attributes::PLAYER_BASE_LEVEL,
628
                base,
629
                Notify_true);
630
            if (localPlayer != nullptr)
631
            {
632
                localPlayer->setLevel(CAST_S32(base));
633
                localPlayer->updateName();
634
            }
635
            break;
636
        case Sp::SKILLPOINT:
637
            PlayerInfo::setAttribute(Attributes::PLAYER_SKILL_POINTS,
638
                base,
639
                Notify_true);
640
            if (skillDialog != nullptr)
641
                skillDialog->update();
642
            break;
643
        case Sp::STR:
644
            setStatComplex(Attributes::PLAYER_STR);
645
            break;
646
        case Sp::AGI:
647
            setStatComplex(Attributes::PLAYER_AGI);
648
            break;
649
        case Sp::VIT:
650
            setStatComplex(Attributes::PLAYER_VIT);
651
            break;
652
        case Sp::INT:
653
            setStatComplex(Attributes::PLAYER_INT);
654
            break;
655
        case Sp::DEX:
656
            setStatComplex(Attributes::PLAYER_DEX);
657
            break;
658
        case Sp::LUK:
659
            setStatComplex(Attributes::PLAYER_LUK);
660
            break;
661
        case Sp::ZENY:
662
        {
663
            const int oldMoney = PlayerInfo::getAttribute(Attributes::MONEY);
664
            const int newMoney = CAST_S32(base);
665
            if (newMoney > oldMoney)
666
            {
667
                NotifyManager::notify(NotifyTypes::MONEY_GET,
668
                    UnitsDb::formatCurrency(newMoney - oldMoney));
669
            }
670
            else if (newMoney < oldMoney)
671
            {
672
                NotifyManager::notify(NotifyTypes::MONEY_SPENT,
673
                    UnitsDb::formatCurrency(oldMoney - newMoney).c_str());
674
            }
675
676
            PlayerInfo::setAttribute(Attributes::MONEY,
677
                newMoney,
678
                Notify_true);
679
            break;
680
        }
681
        case Sp::NEXTBASEEXP:
682
            PlayerInfo::setAttribute(Attributes::PLAYER_EXP_NEEDED,
683
                base,
684
                Notify_true);
685
            break;
686
        case Sp::NEXTJOBEXP:
687
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED,
688
                base,
689
                Notify_true);
690
            break;
691
        case Sp::WEIGHT:
692
            PlayerInfo::setAttribute(Attributes::TOTAL_WEIGHT,
693
                base,
694
                Notify_true);
695
            break;
696
        case Sp::MAXWEIGHT:
697
            PlayerInfo::setAttribute(Attributes::MAX_WEIGHT,
698
                base,
699
                Notify_true);
700
            break;
701
        case Sp::USTR:
702
            statusWindow->setPointsNeeded(Attributes::PLAYER_STR,
703
                CAST_S32(base));
704
            break;
705
        case Sp::UAGI:
706
            statusWindow->setPointsNeeded(Attributes::PLAYER_AGI,
707
                CAST_S32(base));
708
            break;
709
        case Sp::UVIT:
710
            statusWindow->setPointsNeeded(Attributes::PLAYER_VIT,
711
                CAST_S32(base));
712
            break;
713
        case Sp::UINT:
714
            statusWindow->setPointsNeeded(Attributes::PLAYER_INT,
715
                CAST_S32(base));
716
            break;
717
        case Sp::UDEX:
718
            statusWindow->setPointsNeeded(Attributes::PLAYER_DEX,
719
                CAST_S32(base));
720
            break;
721
        case Sp::ULUK:
722
            statusWindow->setPointsNeeded(Attributes::PLAYER_LUK,
723
                CAST_S32(base));
724
            break;
725
726
        case Sp::ATK1:
727
            PlayerInfo::setStatBase(Attributes::PLAYER_ATK,
728
                CAST_S32(base),
729
                Notify_true);
730
            PlayerInfo::updateAttrs();
731
            break;
732
        case Sp::ATK2:
733
            PlayerInfo::setStatMod(Attributes::PLAYER_ATK,
734
                CAST_S32(base),
735
                Notify_true);
736
            PlayerInfo::updateAttrs();
737
            break;
738
        case Sp::MATK1:
739
            PlayerInfo::setStatBase(Attributes::PLAYER_MATK,
740
                CAST_S32(base),
741
                Notify_true);
742
            break;
743
        case Sp::MATK2:
744
            PlayerInfo::setStatMod(Attributes::PLAYER_MATK,
745
                CAST_S32(base),
746
                Notify_true);
747
            break;
748
        case Sp::DEF1:
749
            PlayerInfo::setStatBase(Attributes::PLAYER_DEF,
750
                CAST_S32(base),
751
                Notify_true);
752
            break;
753
        case Sp::DEF2:
754
            PlayerInfo::setStatMod(Attributes::PLAYER_DEF,
755
                CAST_S32(base),
756
                Notify_true);
757
            break;
758
        case Sp::MDEF1:
759
            PlayerInfo::setStatBase(Attributes::PLAYER_MDEF,
760
                CAST_S32(base),
761
                Notify_true);
762
            break;
763
        case Sp::MDEF2:
764
            PlayerInfo::setStatMod(Attributes::PLAYER_MDEF,
765
                CAST_S32(base),
766
                Notify_true);
767
            break;
768
        case Sp::HIT:
769
            PlayerInfo::setStatBase(Attributes::PLAYER_HIT,
770
                CAST_S32(base),
771
                Notify_true);
772
            break;
773
        case Sp::FLEE1:
774
            PlayerInfo::setStatBase(Attributes::PLAYER_FLEE,
775
                CAST_S32(base),
776
                Notify_true);
777
            break;
778
        case Sp::FLEE2:
779
            PlayerInfo::setStatMod(Attributes::PLAYER_FLEE,
780
                CAST_S32(base),
781
                Notify_true);
782
            break;
783
        case Sp::CRITICAL:
784
            PlayerInfo::setStatBase(Attributes::PLAYER_CRIT,
785
                CAST_S32(base),
786
                Notify_true);
787
            break;
788
        case Sp::ASPD:
789
            localPlayer->setAttackSpeed(CAST_S32(base));
790
            PlayerInfo::setStatBase(Attributes::PLAYER_ATTACK_DELAY,
791
                CAST_S32(base),
792
                Notify_true);
793
            PlayerInfo::setStatMod(Attributes::PLAYER_ATTACK_DELAY,
794
                0,
795
                Notify_true);
796
            PlayerInfo::updateAttrs();
797
            break;
798
        case Sp::JOBLEVEL:
799
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_LEVEL,
800
                base,
801
                Notify_true);
802
            break;
803
804
        default:
805
            UNIMPLEMENTEDPACKETFIELD(type);
806
            break;
807
    }
808
}
809
810
void PlayerHandler::selectStyle(const int headColor,
811
                                const int headStyle,
812
                                const int bodyColor,
813
                                const int topStyle,
814
                                const int middleStyle,
815
                                const int bottomStyle,
816
                                const int bodyStyle) const
817
{
818
    if (packetVersion < 20151104)
819
        return;
820
    if (packetVersionMain >= 20180516 ||
821
        packetVersionRe >= 20180516 ||
822
        packetVersionZero >= 20180523)
823
    {
824
        createOutPacket(CMSG_PLAYER_SELECT_STYLE2);
825
        outMsg.writeInt16(CAST_S16(headColor), "head color");
826
        outMsg.writeInt16(CAST_S16(headStyle), "head style");
827
        outMsg.writeInt16(CAST_S16(bodyColor), "body color");
828
        outMsg.writeInt16(CAST_S16(topStyle), "top style");
829
        outMsg.writeInt16(CAST_S16(middleStyle), "middle style");
830
        outMsg.writeInt16(CAST_S16(bottomStyle), "bottom style");
831
        outMsg.writeInt16(CAST_S16(bodyStyle), "body style");
832
    }
833
    else
834
    {
835
        createOutPacket(CMSG_PLAYER_SELECT_STYLE);
836
        outMsg.writeInt16(CAST_S16(headColor), "head color");
837
        outMsg.writeInt16(CAST_S16(headStyle), "head style");
838
        outMsg.writeInt16(CAST_S16(bodyColor), "body color");
839
        outMsg.writeInt16(CAST_S16(topStyle), "top style");
840
        outMsg.writeInt16(CAST_S16(middleStyle), "middle style");
841
        outMsg.writeInt16(CAST_S16(bottomStyle), "bottom style");
842
    }
843
}
844
845
void PlayerHandler::setTitle(const int titleId) const
846
{
847
    if (packetVersion < 20140903)
848
        return;
849
    createOutPacket(CMSG_PLAYER_SET_TITLE);
850
    outMsg.writeInt32(titleId, "title");
851
}
852
853
void PlayerHandler::closeStyleWindow() const
854
{
855
    if (packetVersion < 20151104)
856
        return;
857
    createOutPacket(CMSG_PLAYER_STYLE_CLOSE);
858
}
859
860
#undef setStatComplex
861
862
2
}  // namespace EAthena