GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/playerhandler.cpp Lines: 8 457 1.8 %
Date: 2019-06-27 Branches: 0 649 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
    {
461
        outMsg.writeInt16(CAST_S16(tab), "tab");
462
    }
463
    outMsg.writeInt16(CAST_S16(idx), "index");
464
    outMsg.writeInt8(CAST_S8(type), "type");
465
    outMsg.writeInt32(id, "id");
466
    outMsg.writeInt16(CAST_S16(level), "level");
467
}
468
469
void PlayerHandler::shortcutShiftRow(const int row,
470
                                     const int tab) const
471
{
472
    if (packetVersion < 20140129)
473
        return;
474
    createOutPacket(CMSG_SHORTCUTS_ROW_SHIFT);
475
    if (packetVersionMain >= 20190522 ||
476
        packetVersionRe >= 20190508)
477
    {
478
        outMsg.writeInt16(CAST_S16(tab), "tab");
479
    }
480
    outMsg.writeInt8(CAST_S8(row), "row");
481
}
482
483
void PlayerHandler::removeOption() const
484
{
485
    createOutPacket(CMSG_REMOVE_OPTION);
486
}
487
488
void PlayerHandler::changeCart(const int type) const
489
{
490
    createOutPacket(CMSG_CHANGE_CART);
491
    outMsg.writeInt16(CAST_S16(type), "type");
492
}
493
494
void PlayerHandler::setMemo() const
495
{
496
    createOutPacket(CMSG_PLAYER_SET_MEMO);
497
}
498
499
void PlayerHandler::doriDori() const
500
{
501
    createOutPacket(CMSG_DORI_DORI);
502
}
503
504
void PlayerHandler::explosionSpirits() const
505
{
506
    createOutPacket(CMSG_EXPLOSION_SPIRITS);
507
}
508
509
void PlayerHandler::requestPvpInfo() const
510
{
511
    createOutPacket(CMSG_PVP_INFO);
512
    outMsg.writeInt32(0, "char id");
513
    outMsg.writeInt32(0, "account id");
514
}
515
516
void PlayerHandler::revive() const
517
{
518
    createOutPacket(CMSG_PLAYER_AUTO_REVIVE);
519
}
520
521
void PlayerHandler::setConfigOption(const int id,
522
                                    const int data) const
523
{
524
    createOutPacket(CMSG_SET_CONFIG_OPTION);
525
    outMsg.writeInt32(id, "config option");
526
    outMsg.writeInt32(data, "config data");
527
}
528
529
#define setStatComplex(stat) \
530
    PlayerInfo::setStatBase(stat, CAST_S32(base), notify); \
531
    if (mod != NoStat) \
532
        PlayerInfo::setStatMod(stat, mod, Notify_true)
533
534
void PlayerHandler::setStat(Net::MessageIn &msg,
535
                            const int type,
536
                            const int64_t base,
537
                            const int mod,
538
                            const Notify notify) const
539
{
540
    switch (type)
541
    {
542
        case Sp::SPEED:
543
            localPlayer->setWalkSpeed(CAST_S32(base));
544
            PlayerInfo::setStatBase(Attributes::PLAYER_WALK_SPEED,
545
                CAST_S32(base),
546
                Notify_true);
547
            PlayerInfo::setStatMod(Attributes::PLAYER_WALK_SPEED,
548
                0,
549
                Notify_true);
550
            break;
551
        case Sp::BASEEXP:
552
            PlayerInfo::setAttribute(Attributes::PLAYER_EXP,
553
                base,
554
                Notify_true);
555
            break;
556
        case Sp::JOBEXP:
557
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP,
558
                base,
559
                Notify_true);
560
            break;
561
        case Sp::KARMA:
562
            PlayerInfo::setStatBase(Attributes::PLAYER_KARMA,
563
                CAST_S32(base),
564
                Notify_true);
565
            PlayerInfo::setStatMod(Attributes::PLAYER_KARMA,
566
                0,
567
                Notify_true);
568
            break;
569
        case Sp::MANNER:
570
            PlayerInfo::setStatBase(Attributes::PLAYER_MANNER,
571
                CAST_S32(base),
572
                Notify_true);
573
            PlayerInfo::setStatMod(Attributes::PLAYER_MANNER,
574
                0,
575
                Notify_true);
576
            break;
577
        case Sp::HP:
578
            PlayerInfo::setAttribute(Attributes::PLAYER_HP,
579
                base,
580
                Notify_true);
581
            if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
582
            {
583
                PartyMember *const m = Party::getParty(1)
584
                    ->getMember(localPlayer->getId());
585
                if (m != nullptr)
586
                {
587
                    m->setHp(CAST_S32(base));
588
                    m->setMaxHp(PlayerInfo::getAttribute(
589
                        Attributes::PLAYER_MAX_HP));
590
                }
591
            }
592
            break;
593
        case Sp::MAXHP:
594
            PlayerInfo::setAttribute(Attributes::PLAYER_MAX_HP,
595
                base,
596
                Notify_true);
597
598
            if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
599
            {
600
                PartyMember *const m = Party::getParty(1)->getMember(
601
                    localPlayer->getId());
602
                if (m != nullptr)
603
                {
604
                    m->setHp(PlayerInfo::getAttribute(Attributes::PLAYER_HP));
605
                    m->setMaxHp(CAST_S32(base));
606
                }
607
            }
608
            break;
609
        case Sp::SP:
610
            PlayerInfo::setAttribute(Attributes::PLAYER_MP,
611
                base,
612
                Notify_true);
613
            break;
614
        case Sp::MAXSP:
615
            PlayerInfo::setAttribute(Attributes::PLAYER_MAX_MP,
616
                base,
617
                Notify_true);
618
            break;
619
        case Sp::STATUSPOINT:
620
            PlayerInfo::setAttribute(Attributes::PLAYER_CHAR_POINTS,
621
                base,
622
                Notify_true);
623
            break;
624
        case Sp::BASELEVEL:
625
            PlayerInfo::setAttribute(Attributes::PLAYER_BASE_LEVEL,
626
                base,
627
                Notify_true);
628
            if (localPlayer != nullptr)
629
            {
630
                localPlayer->setLevel(CAST_S32(base));
631
                localPlayer->updateName();
632
            }
633
            break;
634
        case Sp::SKILLPOINT:
635
            PlayerInfo::setAttribute(Attributes::PLAYER_SKILL_POINTS,
636
                base,
637
                Notify_true);
638
            if (skillDialog != nullptr)
639
                skillDialog->update();
640
            break;
641
        case Sp::STR:
642
            setStatComplex(Attributes::PLAYER_STR);
643
            break;
644
        case Sp::AGI:
645
            setStatComplex(Attributes::PLAYER_AGI);
646
            break;
647
        case Sp::VIT:
648
            setStatComplex(Attributes::PLAYER_VIT);
649
            break;
650
        case Sp::INT:
651
            setStatComplex(Attributes::PLAYER_INT);
652
            break;
653
        case Sp::DEX:
654
            setStatComplex(Attributes::PLAYER_DEX);
655
            break;
656
        case Sp::LUK:
657
            setStatComplex(Attributes::PLAYER_LUK);
658
            break;
659
        case Sp::ZENY:
660
        {
661
            const int oldMoney = PlayerInfo::getAttribute(Attributes::MONEY);
662
            const int newMoney = CAST_S32(base);
663
            if (newMoney > oldMoney)
664
            {
665
                NotifyManager::notify(NotifyTypes::MONEY_GET,
666
                    UnitsDb::formatCurrency(newMoney - oldMoney));
667
            }
668
            else if (newMoney < oldMoney)
669
            {
670
                NotifyManager::notify(NotifyTypes::MONEY_SPENT,
671
                    UnitsDb::formatCurrency(oldMoney - newMoney).c_str());
672
            }
673
674
            PlayerInfo::setAttribute(Attributes::MONEY,
675
                newMoney,
676
                Notify_true);
677
            break;
678
        }
679
        case Sp::NEXTBASEEXP:
680
            PlayerInfo::setAttribute(Attributes::PLAYER_EXP_NEEDED,
681
                base,
682
                Notify_true);
683
            break;
684
        case Sp::NEXTJOBEXP:
685
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED,
686
                base,
687
                Notify_true);
688
            break;
689
        case Sp::WEIGHT:
690
            PlayerInfo::setAttribute(Attributes::TOTAL_WEIGHT,
691
                base,
692
                Notify_true);
693
            break;
694
        case Sp::MAXWEIGHT:
695
            PlayerInfo::setAttribute(Attributes::MAX_WEIGHT,
696
                base,
697
                Notify_true);
698
            break;
699
        case Sp::USTR:
700
            statusWindow->setPointsNeeded(Attributes::PLAYER_STR,
701
                CAST_S32(base));
702
            break;
703
        case Sp::UAGI:
704
            statusWindow->setPointsNeeded(Attributes::PLAYER_AGI,
705
                CAST_S32(base));
706
            break;
707
        case Sp::UVIT:
708
            statusWindow->setPointsNeeded(Attributes::PLAYER_VIT,
709
                CAST_S32(base));
710
            break;
711
        case Sp::UINT:
712
            statusWindow->setPointsNeeded(Attributes::PLAYER_INT,
713
                CAST_S32(base));
714
            break;
715
        case Sp::UDEX:
716
            statusWindow->setPointsNeeded(Attributes::PLAYER_DEX,
717
                CAST_S32(base));
718
            break;
719
        case Sp::ULUK:
720
            statusWindow->setPointsNeeded(Attributes::PLAYER_LUK,
721
                CAST_S32(base));
722
            break;
723
724
        case Sp::ATK1:
725
            PlayerInfo::setStatBase(Attributes::PLAYER_ATK,
726
                CAST_S32(base),
727
                Notify_true);
728
            PlayerInfo::updateAttrs();
729
            break;
730
        case Sp::ATK2:
731
            PlayerInfo::setStatMod(Attributes::PLAYER_ATK,
732
                CAST_S32(base),
733
                Notify_true);
734
            PlayerInfo::updateAttrs();
735
            break;
736
        case Sp::MATK1:
737
            PlayerInfo::setStatBase(Attributes::PLAYER_MATK,
738
                CAST_S32(base),
739
                Notify_true);
740
            break;
741
        case Sp::MATK2:
742
            PlayerInfo::setStatMod(Attributes::PLAYER_MATK,
743
                CAST_S32(base),
744
                Notify_true);
745
            break;
746
        case Sp::DEF1:
747
            PlayerInfo::setStatBase(Attributes::PLAYER_DEF,
748
                CAST_S32(base),
749
                Notify_true);
750
            break;
751
        case Sp::DEF2:
752
            PlayerInfo::setStatMod(Attributes::PLAYER_DEF,
753
                CAST_S32(base),
754
                Notify_true);
755
            break;
756
        case Sp::MDEF1:
757
            PlayerInfo::setStatBase(Attributes::PLAYER_MDEF,
758
                CAST_S32(base),
759
                Notify_true);
760
            break;
761
        case Sp::MDEF2:
762
            PlayerInfo::setStatMod(Attributes::PLAYER_MDEF,
763
                CAST_S32(base),
764
                Notify_true);
765
            break;
766
        case Sp::HIT:
767
            PlayerInfo::setStatBase(Attributes::PLAYER_HIT,
768
                CAST_S32(base),
769
                Notify_true);
770
            break;
771
        case Sp::FLEE1:
772
            PlayerInfo::setStatBase(Attributes::PLAYER_FLEE,
773
                CAST_S32(base),
774
                Notify_true);
775
            break;
776
        case Sp::FLEE2:
777
            PlayerInfo::setStatMod(Attributes::PLAYER_FLEE,
778
                CAST_S32(base),
779
                Notify_true);
780
            break;
781
        case Sp::CRITICAL:
782
            PlayerInfo::setStatBase(Attributes::PLAYER_CRIT,
783
                CAST_S32(base),
784
                Notify_true);
785
            break;
786
        case Sp::ASPD:
787
            localPlayer->setAttackSpeed(CAST_S32(base));
788
            PlayerInfo::setStatBase(Attributes::PLAYER_ATTACK_DELAY,
789
                CAST_S32(base),
790
                Notify_true);
791
            PlayerInfo::setStatMod(Attributes::PLAYER_ATTACK_DELAY,
792
                0,
793
                Notify_true);
794
            PlayerInfo::updateAttrs();
795
            break;
796
        case Sp::JOBLEVEL:
797
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_LEVEL,
798
                base,
799
                Notify_true);
800
            break;
801
802
        default:
803
            UNIMPLEMENTEDPACKETFIELD(type);
804
            break;
805
    }
806
}
807
808
void PlayerHandler::selectStyle(const int headColor,
809
                                const int headStyle,
810
                                const int bodyColor,
811
                                const int topStyle,
812
                                const int middleStyle,
813
                                const int bottomStyle,
814
                                const int bodyStyle) const
815
{
816
    if (packetVersion < 20151104)
817
        return;
818
    if (packetVersionMain >= 20180516 ||
819
        packetVersionRe >= 20180516 ||
820
        packetVersionZero >= 20180523)
821
    {
822
        createOutPacket(CMSG_PLAYER_SELECT_STYLE2);
823
        outMsg.writeInt16(CAST_S16(headColor), "head color");
824
        outMsg.writeInt16(CAST_S16(headStyle), "head style");
825
        outMsg.writeInt16(CAST_S16(bodyColor), "body color");
826
        outMsg.writeInt16(CAST_S16(topStyle), "top style");
827
        outMsg.writeInt16(CAST_S16(middleStyle), "middle style");
828
        outMsg.writeInt16(CAST_S16(bottomStyle), "bottom style");
829
        outMsg.writeInt16(CAST_S16(bodyStyle), "body style");
830
    }
831
    else
832
    {
833
        createOutPacket(CMSG_PLAYER_SELECT_STYLE);
834
        outMsg.writeInt16(CAST_S16(headColor), "head color");
835
        outMsg.writeInt16(CAST_S16(headStyle), "head style");
836
        outMsg.writeInt16(CAST_S16(bodyColor), "body color");
837
        outMsg.writeInt16(CAST_S16(topStyle), "top style");
838
        outMsg.writeInt16(CAST_S16(middleStyle), "middle style");
839
        outMsg.writeInt16(CAST_S16(bottomStyle), "bottom style");
840
    }
841
}
842
843
void PlayerHandler::setTitle(const int titleId) const
844
{
845
    if (packetVersion < 20140903)
846
        return;
847
    createOutPacket(CMSG_PLAYER_SET_TITLE);
848
    outMsg.writeInt32(titleId, "title");
849
}
850
851
void PlayerHandler::closeStyleWindow() const
852
{
853
    if (packetVersion < 20151104)
854
        return;
855
    createOutPacket(CMSG_PLAYER_STYLE_CLOSE);
856
}
857
858
#undef setStatComplex
859
860
2
}  // namespace EAthena