summaryrefslogtreecommitdiff
path: root/src/net/tmwa/playerhandler.cpp
blob: 3f8bdab7b9be4ea1aa6b738ef8038759ec8b2ebe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/*
 *  The ManaPlus Client
 *  Copyright (C) 2004-2009  The Mana World Development Team
 *  Copyright (C) 2009-2010  The Mana Developers
 *  Copyright (C) 2011  The ManaPlus Developers
 *
 *  This file is part of The ManaPlus Client.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "net/tmwa/playerhandler.h"

#include "event.h"
#include "game.h"
#include "localplayer.h"
#include "log.h"
#include "party.h"
#include "playerinfo.h"
#include "units.h"

#include "gui/gui.h"
#include "gui/okdialog.h"
#include "gui/skilldialog.h"
#include "gui/statuswindow.h"
#include "gui/viewport.h"

#include "net/messagein.h"
#include "net/messageout.h"

#include "net/tmwa/protocol.h"
#include "net/tmwa/npchandler.h"

#include "utils/stringutils.h"
#include "utils/gettext.h"

extern OkDialog *weightNotice;
extern OkDialog *deathNotice;
extern int weightNoticeTime;

// Max. distance we are willing to scroll after a teleport;
// everything beyond will reset the port hard.
static const int MAP_TELEPORT_SCROLL_DISTANCE = 8;

// TODO Move somewhere else
namespace
{
    /**
     * Listener used for handling the overweigth message.
     */
    struct WeightListener : public gcn::ActionListener
    {
        void action(const gcn::ActionEvent &event _UNUSED_)
        {
            weightNotice = NULL;
        }
    } weightListener;

    /**
     * Listener used for handling death message.
     */
    struct DeathListener : public gcn::ActionListener
    {
        void action(const gcn::ActionEvent &event _UNUSED_)
        {
            Net::getPlayerHandler()->respawn();
            deathNotice = NULL;

            Client::closeDialogs();

            if (viewport)
                viewport->closePopupMenu();

            TmwAthena::NpcHandler *handler =
                    static_cast<TmwAthena::NpcHandler*>(Net::getNpcHandler());
            if (handler)
                handler->clearDialogs();
            if (player_node)
                player_node->respawn();
        }
    } deathListener;

} // anonymous namespace

static const char *randomDeathMessage()
{
    static char const *const deadMsg[] =
    {
        N_("You are dead."),
        N_("We regret to inform you that your character was killed in "
           "battle."),
        N_("You are not that alive anymore."),
        N_("The cold hands of the grim reaper are grabbing for your soul."),
        N_("Game Over!"),
        N_("Insert coin to continue."),
        N_("No, kids. Your character did not really die. It... "
           "err... went to a better place."),
        N_("Your plan of breaking your enemies weapon by "
           "bashing it with your throat failed."),
        N_("I guess this did not run too well."),
        // NetHack reference:
        N_("Do you want your possessions identified?"),
        // Secret of Mana reference:
        N_("Sadly, no trace of you was ever found..."),
        // Final Fantasy VI reference:
        N_("Annihilated."),
        // Earthbound reference:
        N_("Looks like you got your head handed to you."),
        // Leisure Suit Larry 1 reference:
        N_("You screwed up again, dump your body down the tubes "
           "and get you another one."),
        // Monty Python references (Dead Parrot sketch mostly):
        N_("You're not dead yet. You're just resting."),
        N_("You are no more."),
        N_("You have ceased to be."),
        N_("You've expired and gone to meet your maker."),
        N_("You're a stiff."),
        N_("Bereft of life, you rest in peace."),
        N_("If you weren't so animated, you'd be pushing up the daisies."),
        N_("Your metabolic processes are now history."),
        N_("You're off the twig."),
        N_("You've kicked the bucket."),
        N_("You've shuffled off your mortal coil, run down the "
           "curtain and joined the bleedin' choir invisibile."),
        N_("You are an ex-player."),
        N_("You're pining for the fjords.")
    };

    const int random = static_cast<int>(rand() % (sizeof(deadMsg)
        / sizeof(deadMsg[0])));
    return gettext(deadMsg[random]);
}

extern Net::PlayerHandler *playerHandler;

namespace TmwAthena
{

PlayerHandler::PlayerHandler()
{
    static const Uint16 _messages[] =
    {
        SMSG_WALK_RESPONSE,
        SMSG_PLAYER_WARP,
        SMSG_PLAYER_STAT_UPDATE_1,
        SMSG_PLAYER_STAT_UPDATE_2,
        SMSG_PLAYER_STAT_UPDATE_3,
        SMSG_PLAYER_STAT_UPDATE_4,
        SMSG_PLAYER_STAT_UPDATE_5,
        SMSG_PLAYER_STAT_UPDATE_6,
        SMSG_PLAYER_ARROW_MESSAGE,
        0
    };
    handledMessages = _messages;
    playerHandler = this;
}

void PlayerHandler::handleMessage(Net::MessageIn &msg)
{
    switch (msg.getId())
    {
        case SMSG_WALK_RESPONSE:
            /*
             * This client assumes that all walk messages succeed,
             * and that the server will send a correction notice
             * otherwise.
             */
            Uint16 srcX, srcY, dstX, dstY;
            msg.readInt32();    //tick
            msg.readCoordinatePair(srcX, srcY, dstX, dstY);
            if (player_node)
                player_node->setRealPos(dstX, dstY);
//            if (debugChatTab)
//                debugChatTab->chatLog("move resp: " + toString((int)srcX) + "," + toString((int)srcY) + " "
//             + toString((int)dstX) + "," + toString((int)dstY));

            break;

        case SMSG_PLAYER_WARP:
            {
                std::string mapPath = msg.readString(16);
                int x = msg.readInt16();
                int y = msg.readInt16();

                logger->log("Warping to %s (%d, %d)", mapPath.c_str(), x, y);

                if (!player_node)
                    logger->log1("SMSG_PLAYER_WARP player_node null");

                /*
                 * We must clear the local player's target *before* the call
                 * to changeMap, as it deletes all beings.
                 */
                if (player_node)
                    player_node->stopAttack();

                Game *game = Game::instance();

                const std::string &currentMapName = game->getCurrentMapName();
                bool sameMap = (currentMapName == mapPath);

                // Switch the actual map, deleting the previous one if necessary
                mapPath = mapPath.substr(0, mapPath.rfind("."));
                game->changeMap(mapPath);

                float scrollOffsetX = 0.0f;
                float scrollOffsetY = 0.0f;

                if (player_node)
                {
                    /* Scroll if neccessary */
                    if (!sameMap
                        || (abs(x - player_node->getTileX())
                        > MAP_TELEPORT_SCROLL_DISTANCE)
                        || (abs(y - player_node->getTileY())
                        > MAP_TELEPORT_SCROLL_DISTANCE))
                    {
                        Map *map = game->getCurrentMap();
                        if (map)
                        {
                            scrollOffsetX = static_cast<float>((x
                                - player_node->getTileX())
                                * map->getTileWidth());
                            scrollOffsetY = static_cast<float>((y
                                - player_node->getTileY())
                                * map->getTileHeight());
                        }
                    }

                    player_node->setAction(Being::STAND);
                    player_node->setTileCoords(x, y);
                    player_node->naviageClean();
//                    player_node->updateNavigateList();
                }

                logger->log("Adjust scrolling by %d:%d",
                    static_cast<int>(scrollOffsetX),
                    static_cast<int>(scrollOffsetY));

                if (viewport)
                    viewport->scrollBy(scrollOffsetX, scrollOffsetY);
            }
            break;

        case SMSG_PLAYER_STAT_UPDATE_1:
            {
                int type = msg.readInt16();
                int value = msg.readInt32();
                if (!player_node)
                    return;

                switch (type)
                {
                    case 0x0000:
                        player_node->setWalkSpeed(Vector(static_cast<float>(
                            value), static_cast<float>(value), 0));
                        PlayerInfo::setStatBase(WALK_SPEED, value);
                        PlayerInfo::setStatMod(WALK_SPEED, 0);
                    break;
                    case 0x0004: break; // manner
                    case 0x0005:
                        PlayerInfo::setAttribute(HP, value);
                        if (player_node->isInParty() && Party::getParty(1))
                        {
                            PartyMember *m = Party::getParty(1)
                                ->getMember(player_node->getId());
                            if (m)
                            {
                                m->setHp(value);
                                m->setMaxHp(PlayerInfo::getAttribute(MAX_HP));
                            }
                        }
                        break;
                    case 0x0006:
                        PlayerInfo::setAttribute(MAX_HP, value);

                        if (player_node->isInParty() && Party::getParty(1))
                        {
                            PartyMember *m = Party::getParty(1)->getMember(
                                player_node->getId());
                            if (m)
                            {
                                m->setHp(PlayerInfo::getAttribute(HP));
                                m->setMaxHp(value);
                            }
                        }
                        break;
                    case 0x0007:
                        PlayerInfo::setAttribute(MP, value);
                        break;
                    case 0x0008:
                        PlayerInfo::setAttribute(MAX_MP, value);
                        break;
                    case 0x0009:
                        PlayerInfo::setAttribute(CHAR_POINTS, value);
                        break;
                    case 0x000b:
                        PlayerInfo::setAttribute(LEVEL, value);
                        if (player_node)
                        {
                            player_node->setLevel(value);
                            player_node->updateName();
                        }
                        break;
                    case 0x000c:
                        PlayerInfo::setAttribute(SKILL_POINTS, value);
                        if (skillDialog)
                            skillDialog->update();
                        break;
                    case 0x0018:
                        if (!weightNotice)
                        {
                            const int max
                                = PlayerInfo::getAttribute(MAX_WEIGHT) / 2;
                            const int total
                                = PlayerInfo::getAttribute(TOTAL_WEIGHT);
                            if (value >= max && total < max)
                            {
                                weightNoticeTime = cur_time + 10;
                                weightNotice = new OkDialog(_("Message"),
                                    _("You are carrying more than "
                                    "half your weight. You are "
                                    "unable to regain health."), false);
                                weightNotice->addActionListener(
                                    &weightListener);
                            }
                            else if (value < max && total >= max)
                            {
                                weightNoticeTime = cur_time + 10;
                                weightNotice = new OkDialog(_("Message"),
                                    _("You are carrying less than "
                                    "half your weight. You are "
                                    "can regain health."), false);
                                weightNotice->addActionListener(
                                    &weightListener);
                            }
                        }
                        PlayerInfo::setAttribute(TOTAL_WEIGHT, value);
                        break;
                    case 0x0019:
                        PlayerInfo::setAttribute(MAX_WEIGHT, value);
                        break;

                    case 0x0029:
                        PlayerInfo::setStatBase(ATK, value);
                        break;
                    case 0x002a:
                        PlayerInfo::setStatMod(ATK, value);
                        break;

                    case 0x002b:
                        PlayerInfo::setStatBase(MATK, value);
                        break;
                    case 0x002c:
                        PlayerInfo::setStatMod(MATK, value);
                        break;

                    case 0x002d:
                        PlayerInfo::setStatBase(DEF, value);
                        break;
                    case 0x002e:
                        PlayerInfo::setStatMod(DEF, value);
                        break;

                    case 0x002f:
                        PlayerInfo::setStatBase(MDEF, value);
                        break;
                    case 0x0030:
                        PlayerInfo::setStatMod(MDEF, value);
                        break;

                    case 0x0031:
                        PlayerInfo::setStatBase(HIT, value);
                        break;

                    case 0x0032:
                        PlayerInfo::setStatBase(FLEE, value);
                        break;
                    case 0x0033:
                        PlayerInfo::setStatMod(FLEE, value);
                        break;

                    case 0x0034:
                        PlayerInfo::setStatBase(CRIT, value);
                        break;

                    case 0x0035:
                        player_node->setAttackSpeed(value);
                        PlayerInfo::setStatBase(ATTACK_SPEED, value);
                        PlayerInfo::setStatMod(ATTACK_SPEED, 0);
                        break;

                    case 0x0037:
                        PlayerInfo::setStatBase(JOB, value);
                        break;

                    case 500:
                        player_node->setGMLevel(value);
                        break;

                    default:
                        logger->log("QQQQ PLAYER_STAT_UPDATE_1 "
                                    + toString(type) + "," + toString(value));
                        break;
                }

                if (PlayerInfo::getAttribute(HP) == 0 && !deathNotice)
                {
                    deathNotice = new OkDialog(_("Message"),
                                               randomDeathMessage(),
                                               false);
                    deathNotice->addActionListener(&deathListener);
                    player_node->setAction(Being::DEAD);
                }
            }
            break;

        case SMSG_PLAYER_STAT_UPDATE_2:
        {
            int type = msg.readInt16();
            switch (type)
            {
                case 0x0001:
                    PlayerInfo::setAttribute(EXP, msg.readInt32());
                    break;
                case 0x0002:
                    PlayerInfo::setStatExperience(JOB, msg.readInt32(),
                    PlayerInfo::getStatExperience(JOB).second);
                    break;
                case 0x0014:
                {
                        int oldMoney = PlayerInfo::getAttribute(MONEY);
                        int newMoney = msg.readInt32();
                        if (newMoney > oldMoney)
                        {
                            SERVER_NOTICE(strprintf(_("You picked up %s."),
                                          Units::formatCurrency(newMoney -
                                          oldMoney).c_str()))
                        }
                        else if (newMoney < oldMoney)
                        {
                            SERVER_NOTICE(strprintf(_("You spent %s."),
                                          Units::formatCurrency(oldMoney -
                                          newMoney).c_str()))
                        }

                        PlayerInfo::setAttribute(MONEY, newMoney);
                    break;
                }
                case 0x0016:
                    PlayerInfo::setAttribute(EXP_NEEDED, msg.readInt32());
                    break;
                case 0x0017:
                    PlayerInfo::setStatExperience(JOB,
                        PlayerInfo::getStatExperience(JOB).first,
                        msg.readInt32());
                    break;
                default:
                    logger->log("QQQQ PLAYER_STAT_UPDATE_2 " + toString(type));
                    break;
            }
            break;
        }
        case SMSG_PLAYER_STAT_UPDATE_3: // Update a base attribute
            {
                int type = msg.readInt32();
                int base = msg.readInt32();
                int bonus = msg.readInt32();

                PlayerInfo::setStatBase(type, base, false);
                PlayerInfo::setStatMod(type, bonus);
            }
            break;

        case SMSG_PLAYER_STAT_UPDATE_4: // Attribute increase ack
            {
                int type = msg.readInt16();
                int ok = msg.readInt8();
                int value = msg.readInt8();

                if (ok != 1)
                {
                    int oldValue = PlayerInfo::getStatBase(type);
                    int points = PlayerInfo::getAttribute(CHAR_POINTS);
                    points += oldValue - value;
                    PlayerInfo::setAttribute(CHAR_POINTS, points);
                    SERVER_NOTICE(_("Cannot raise skill!"))
                }

                PlayerInfo::setStatBase(type, value);
            }
            break;

        // Updates stats and status points
        case SMSG_PLAYER_STAT_UPDATE_5:
            PlayerInfo::setAttribute(CHAR_POINTS, msg.readInt16());
            {
                int val = msg.readInt8();
                PlayerInfo::setStatBase(STR, val);
                if (statusWindow)
                    statusWindow->setPointsNeeded(STR, msg.readInt8());
                else
                    msg.readInt8();

                val = msg.readInt8();
                PlayerInfo::setStatBase(AGI, val);
                if (statusWindow)
                    statusWindow->setPointsNeeded(AGI, msg.readInt8());
                else
                    msg.readInt8();

                val = msg.readInt8();
                PlayerInfo::setStatBase(VIT, val);
                if (statusWindow)
                    statusWindow->setPointsNeeded(VIT, msg.readInt8());
                else
                    msg.readInt8();

                val = msg.readInt8();
                PlayerInfo::setStatBase(INT, val);
                if (statusWindow)
                    statusWindow->setPointsNeeded(INT, msg.readInt8());
                else
                    msg.readInt8();

                val = msg.readInt8();
                PlayerInfo::setStatBase(DEX, val);
                if (statusWindow)
                    statusWindow->setPointsNeeded(DEX, msg.readInt8());
                else
                    msg.readInt8();

                val = msg.readInt8();
                PlayerInfo::setStatBase(LUK, val);
                if (statusWindow)
                    statusWindow->setPointsNeeded(LUK, msg.readInt8());
                else
                    msg.readInt8();

                PlayerInfo::setStatBase(ATK, msg.readInt16(), false);
                PlayerInfo::setStatMod(ATK, msg.readInt16());

                val = msg.readInt16();
                PlayerInfo::setStatBase(MATK, val, false);

                val = msg.readInt16();
                PlayerInfo::setStatMod(MATK, val);

                PlayerInfo::setStatBase(DEF, msg.readInt16(), false);
                PlayerInfo::setStatMod(DEF, msg.readInt16());

                PlayerInfo::setStatBase(MDEF, msg.readInt16(), false);
                PlayerInfo::setStatMod(MDEF, msg.readInt16());

                PlayerInfo::setStatBase(HIT, msg.readInt16());

                PlayerInfo::setStatBase(FLEE, msg.readInt16(), false);
                PlayerInfo::setStatMod(FLEE, msg.readInt16());

                PlayerInfo::setStatBase(CRIT, msg.readInt16());
            }

            msg.readInt16();  // manner
            break;

        case SMSG_PLAYER_STAT_UPDATE_6:
        {
            int type = msg.readInt16();
            if (statusWindow)
            {
                switch (type)
                {
                    case 0x0020:
                        statusWindow->setPointsNeeded(STR, msg.readInt8());
                        break;
                    case 0x0021:
                        statusWindow->setPointsNeeded(AGI, msg.readInt8());
                        break;
                    case 0x0022:
                        statusWindow->setPointsNeeded(VIT, msg.readInt8());
                        break;
                    case 0x0023:
                        statusWindow->setPointsNeeded(INT, msg.readInt8());
                        break;
                    case 0x0024:
                        statusWindow->setPointsNeeded(DEX, msg.readInt8());
                        break;
                    case 0x0025:
                        statusWindow->setPointsNeeded(LUK, msg.readInt8());
                        break;
                    default:
                        logger->log("QQQQ PLAYER_STAT_UPDATE_6 "
                                    + toString(type));
                        break;
                }
            }
            break;
        }
        case SMSG_PLAYER_ARROW_MESSAGE:
            {
                int type = msg.readInt16();

                switch (type)
                {
                    case 0:
                        {
                            SERVER_NOTICE(_("Equip arrows first."))
                        }
                        break;
                    case 3:
                        // arrows equiped
                        break;
                    default:
                        logger->log("QQQQ 0x013b: Unhandled message %i", type);
                        break;
                }
            }
            break;

        default:
            break;
    }
}

void PlayerHandler::attack(int id, bool keep)
{
    MessageOut outMsg(CMSG_PLAYER_ATTACK);
    outMsg.writeInt32(id);
    if (keep)
        outMsg.writeInt8(7);
    else
        outMsg.writeInt8(0);
}

void PlayerHandler::stopAttack()
{
    MessageOut outMsg(CMSG_PLAYER_STOP_ATTACK);
}

void PlayerHandler::emote(Uint8 emoteId)
{
    MessageOut outMsg(CMSG_PLAYER_EMOTE);
    outMsg.writeInt8(emoteId);
}

void PlayerHandler::increaseAttribute(int attr)
{
    if (attr >= STR && attr <= LUK)
    {
        MessageOut outMsg(CMSG_STAT_UPDATE_REQUEST);
        outMsg.writeInt16(static_cast<Sint16>(attr));
        outMsg.writeInt8(1);
    }
}

void PlayerHandler::decreaseAttribute(int attr _UNUSED_)
{
    // Supported by eA?
}

void PlayerHandler::increaseSkill(unsigned short skillId)
{
    if (PlayerInfo::getAttribute(SKILL_POINTS) <= 0)
        return;

    MessageOut outMsg(CMSG_SKILL_LEVELUP_REQUEST);
    outMsg.writeInt16(skillId);
}

void PlayerHandler::pickUp(FloorItem *floorItem)
{
    if (!floorItem)
        return;

    MessageOut outMsg(CMSG_ITEM_PICKUP);
    outMsg.writeInt32(floorItem->getId());
}

void PlayerHandler::setDirection(char direction)
{
    MessageOut outMsg(CMSG_PLAYER_CHANGE_DIR);
    outMsg.writeInt16(0);
    outMsg.writeInt8(direction);
}

void PlayerHandler::setDestination(int x, int y, int direction)
{
    MessageOut outMsg(CMSG_PLAYER_CHANGE_DEST);
    outMsg.writeCoordinates(static_cast<short unsigned int>(x),
        static_cast<short unsigned int>(y),
        static_cast<unsigned char>(direction));
}

void PlayerHandler::changeAction(Being::Action action)
{
    char type;
    switch (action)
    {
        case Being::SIT:
            type = 2;
            break;
        case Being::STAND:
            type = 3;
            break;
        default:
        case Being::MOVE:
        case Being::ATTACK:
        case Being::DEAD:
        case Being::HURT:
            return;
    }

    MessageOut outMsg(CMSG_PLAYER_CHANGE_ACT);
    outMsg.writeInt32(0);
    outMsg.writeInt8(type);
}

void PlayerHandler::respawn()
{
    MessageOut outMsg(CMSG_PLAYER_RESTART);
    outMsg.writeInt8(0);
}

void PlayerHandler::ignorePlayer(const std::string &player _UNUSED_,
                                 bool ignore _UNUSED_)
{
    // TODO
}

void PlayerHandler::ignoreAll(bool ignore _UNUSED_)
{
    // TODO
}

bool PlayerHandler::canUseMagic()
{
    return PlayerInfo::getStatEffective(MATK) > 0;
}

bool PlayerHandler::canCorrectAttributes()
{
    return false;
}

int PlayerHandler::getJobLocation()
{
    return JOB;
}

Vector PlayerHandler::getDefaultWalkSpeed()
{
    // Return an normalized speed for any side
    // as the offset is calculated elsewhere.
    return Vector(150, 150, 0);
}

} // namespace TmwAthena