GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/playerhandler.cpp Lines: 1 203 0.5 %
Date: 2019-06-27 Branches: 0 150 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/tmwa/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/tmwa/messageout.h"
41
#include "net/tmwa/protocolout.h"
42
#include "net/tmwa/sp.h"
43
44
#include "resources/db/unitsdb.h"
45
46
#include "debug.h"
47
48
namespace TmwAthena
49
{
50
51
PlayerHandler::PlayerHandler() :
52
    Ea::PlayerHandler()
53
{
54
    playerHandler = this;
55
}
56
57
PlayerHandler::~PlayerHandler()
58
{
59
    playerHandler = nullptr;
60
}
61
62
void PlayerHandler::attack(const BeingId id,
63
                           const Keep keep) const
64
{
65
    createOutPacket(CMSG_PLAYER_CHANGE_ACT);
66
    outMsg.writeBeingId(id, "target id");
67
    if (keep == Keep_true)
68
        outMsg.writeInt8(7, "action");
69
    else
70
        outMsg.writeInt8(0, "action");
71
}
72
73
void PlayerHandler::stopAttack() const
74
{
75
    createOutPacket(CMSG_PLAYER_STOP_ATTACK);
76
}
77
78
void PlayerHandler::emote(const uint8_t emoteId) const
79
{
80
    createOutPacket(CMSG_PLAYER_EMOTE);
81
    outMsg.writeInt8(emoteId, "emote id");
82
}
83
84
void PlayerHandler::increaseAttribute(const AttributesT attr,
85
                                      const int amount A_UNUSED) const
86
{
87
    if (attr >= Attributes::PLAYER_STR && attr <= Attributes::PLAYER_LUK)
88
    {
89
        createOutPacket(CMSG_STAT_UPDATE_REQUEST);
90
        outMsg.writeInt16(CAST_S16(attr), "attribute id");
91
        outMsg.writeInt8(1, "increment");
92
    }
93
}
94
95
void PlayerHandler::increaseSkill(const uint16_t skillId) const
96
{
97
    if (PlayerInfo::getAttribute(Attributes::PLAYER_SKILL_POINTS) <= 0)
98
        return;
99
100
    createOutPacket(CMSG_SKILL_LEVELUP_REQUEST);
101
    outMsg.writeInt16(skillId, "skill id");
102
}
103
104
void PlayerHandler::pickUp(const FloorItem *const floorItem) const
105
{
106
    if (floorItem == nullptr)
107
        return;
108
109
    createOutPacket(CMSG_ITEM_PICKUP);
110
    outMsg.writeBeingId(floorItem->getId(), "object id");
111
    Ea::InventoryHandler::pushPickup(floorItem->getId());
112
}
113
114
void PlayerHandler::setDirection(const unsigned char direction) const
115
{
116
    createOutPacket(CMSG_PLAYER_CHANGE_DIR);
117
    outMsg.writeInt16(0, "unused");
118
    outMsg.writeInt8(direction, "direction");
119
}
120
121
void PlayerHandler::setDestination(const int x, const int y,
122
                                   const int direction) const
123
{
124
    createOutPacket(CMSG_PLAYER_CHANGE_DEST);
125
    outMsg.writeCoordinates(CAST_U16(x),
126
        CAST_U16(y),
127
        CAST_U8(direction), "destination");
128
}
129
130
void PlayerHandler::changeAction(const BeingActionT &action) const
131
{
132
    char type;
133
    switch (action)
134
    {
135
        case BeingAction::SIT:
136
            type = 2;
137
            break;
138
        case BeingAction::STAND:
139
        case BeingAction::PRESTAND:
140
            type = 3;
141
            break;
142
        default:
143
        case BeingAction::MOVE:
144
        case BeingAction::ATTACK:
145
        case BeingAction::DEAD:
146
        case BeingAction::HURT:
147
        case BeingAction::SPAWN:
148
        case BeingAction::CAST:
149
            return;
150
    }
151
152
    createOutPacket(CMSG_PLAYER_CHANGE_ACT);
153
    outMsg.writeInt32(0, "unused");
154
    outMsg.writeInt8(type, "action");
155
}
156
157
void PlayerHandler::respawn() const
158
{
159
    createOutPacket(CMSG_PLAYER_RESTART);
160
    outMsg.writeInt8(0, "action");
161
}
162
163
void PlayerHandler::requestOnlineList() const
164
{
165
    createOutPacket(CMSG_ONLINE_LIST);
166
}
167
168
void PlayerHandler::removeOption() const
169
{
170
}
171
172
void PlayerHandler::changeCart(const int type A_UNUSED) const
173
{
174
}
175
176
void PlayerHandler::setMemo() const
177
{
178
}
179
180
void PlayerHandler::updateStatus(const uint8_t status A_UNUSED) const
181
{
182
}
183
184
void PlayerHandler::setShortcut(const int idx A_UNUSED,
185
                                const int tab A_UNUSED,
186
                                const uint8_t type A_UNUSED,
187
                                const int id A_UNUSED,
188
                                const int level A_UNUSED) const
189
{
190
}
191
192
void PlayerHandler::doriDori() const
193
{
194
}
195
196
void PlayerHandler::explosionSpirits() const
197
{
198
}
199
200
void PlayerHandler::requestPvpInfo() const
201
{
202
}
203
204
void PlayerHandler::revive() const
205
{
206
}
207
208
void PlayerHandler::shortcutShiftRow(const int row A_UNUSED,
209
                                     const int tab A_UNUSED) const
210
{
211
}
212
213
void PlayerHandler::setConfigOption(const int id A_UNUSED,
214
                                    const int data A_UNUSED) const
215
{
216
}
217
218
#define setStatComplex(stat) \
219
    PlayerInfo::setStatBase(stat, CAST_S32(base), notify); \
220
    if (mod != NoStat) \
221
        PlayerInfo::setStatMod(stat, mod, Notify_true)
222
223
void PlayerHandler::setStat(Net::MessageIn &msg,
224
                            const int type,
225
                            const int64_t base,
226
                            const int mod,
227
                            const Notify notify) const
228
{
229
    switch (type)
230
    {
231
        case Sp::SPEED:
232
            localPlayer->setWalkSpeed(CAST_S32(base));
233
            PlayerInfo::setStatBase(Attributes::PLAYER_WALK_SPEED,
234
                CAST_S32(base),
235
                Notify_true);
236
            PlayerInfo::setStatMod(Attributes::PLAYER_WALK_SPEED,
237
                0,
238
                Notify_true);
239
            break;
240
        case Sp::BASEEXP:
241
            PlayerInfo::setAttribute(Attributes::PLAYER_EXP,
242
                base,
243
                Notify_true);
244
            break;
245
        case Sp::JOBEXP:
246
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP,
247
                base,
248
                Notify_true);
249
            break;
250
        case Sp::KARMA:
251
            PlayerInfo::setStatBase(Attributes::PLAYER_KARMA,
252
                CAST_S32(base),
253
                Notify_true);
254
            PlayerInfo::setStatMod(Attributes::PLAYER_KARMA,
255
                0,
256
                Notify_true);
257
            break;
258
        case Sp::MANNER:
259
            PlayerInfo::setStatBase(Attributes::PLAYER_MANNER,
260
                CAST_S32(base),
261
                Notify_true);
262
            PlayerInfo::setStatMod(Attributes::PLAYER_MANNER,
263
                0,
264
                Notify_true);
265
            break;
266
        case Sp::HP:
267
            PlayerInfo::setAttribute(Attributes::PLAYER_HP,
268
                base,
269
                Notify_true);
270
            if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
271
            {
272
                PartyMember *const m = Party::getParty(1)
273
                    ->getMember(localPlayer->getId());
274
                if (m != nullptr)
275
                {
276
                    m->setHp(CAST_S32(base));
277
                    m->setMaxHp(PlayerInfo::getAttribute(
278
                        Attributes::PLAYER_MAX_HP));
279
                }
280
            }
281
            break;
282
        case Sp::MAXHP:
283
            PlayerInfo::setAttribute(Attributes::PLAYER_MAX_HP,
284
                base,
285
                Notify_true);
286
287
            if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
288
            {
289
                PartyMember *const m = Party::getParty(1)->getMember(
290
                    localPlayer->getId());
291
                if (m != nullptr)
292
                {
293
                    m->setHp(PlayerInfo::getAttribute(Attributes::PLAYER_HP));
294
                    m->setMaxHp(CAST_S32(base));
295
                }
296
            }
297
            break;
298
        case Sp::SP:
299
            PlayerInfo::setAttribute(Attributes::PLAYER_MP,
300
                base,
301
                Notify_true);
302
            break;
303
        case Sp::MAXSP:
304
            PlayerInfo::setAttribute(Attributes::PLAYER_MAX_MP,
305
                base,
306
                Notify_true);
307
            break;
308
        case Sp::STATUSPOINT:
309
            PlayerInfo::setAttribute(Attributes::PLAYER_CHAR_POINTS,
310
                base,
311
                Notify_true);
312
            break;
313
        case Sp::BASELEVEL:
314
            PlayerInfo::setAttribute(Attributes::PLAYER_BASE_LEVEL,
315
                base,
316
                Notify_true);
317
            if (localPlayer != nullptr)
318
            {
319
                localPlayer->setLevel(CAST_S32(base));
320
                localPlayer->updateName();
321
            }
322
            break;
323
        case Sp::SKILLPOINT:
324
            PlayerInfo::setAttribute(Attributes::PLAYER_SKILL_POINTS,
325
                base,
326
                Notify_true);
327
            if (skillDialog != nullptr)
328
                skillDialog->update();
329
            break;
330
        case Sp::STR:
331
            setStatComplex(Attributes::PLAYER_STR);
332
            break;
333
        case Sp::AGI:
334
            setStatComplex(Attributes::PLAYER_AGI);
335
            break;
336
        case Sp::VIT:
337
            setStatComplex(Attributes::PLAYER_VIT);
338
            break;
339
        case Sp::INT:
340
            setStatComplex(Attributes::PLAYER_INT);
341
            break;
342
        case Sp::DEX:
343
            setStatComplex(Attributes::PLAYER_DEX);
344
            break;
345
        case Sp::LUK:
346
            setStatComplex(Attributes::PLAYER_LUK);
347
            break;
348
        case Sp::ZENY:
349
        {
350
            const int oldMoney = PlayerInfo::getAttribute(Attributes::MONEY);
351
            const int newMoney = CAST_S32(base);
352
            if (newMoney > oldMoney)
353
            {
354
                NotifyManager::notify(NotifyTypes::MONEY_GET,
355
                    UnitsDb::formatCurrency(newMoney - oldMoney));
356
            }
357
            else if (newMoney < oldMoney)
358
            {
359
                NotifyManager::notify(NotifyTypes::MONEY_SPENT,
360
                    UnitsDb::formatCurrency(oldMoney - newMoney).c_str());
361
            }
362
363
            PlayerInfo::setAttribute(Attributes::MONEY,
364
                newMoney,
365
                Notify_true);
366
            break;
367
        }
368
        case Sp::NEXTBASEEXP:
369
            PlayerInfo::setAttribute(Attributes::PLAYER_EXP_NEEDED,
370
                base,
371
                Notify_true);
372
            break;
373
        case Sp::JOB_MOD:
374
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED,
375
                base,
376
                Notify_true);
377
            break;
378
        case Sp::WEIGHT:
379
            PlayerInfo::setAttribute(Attributes::TOTAL_WEIGHT,
380
                base,
381
                Notify_true);
382
            break;
383
        case Sp::MAXWEIGHT:
384
            PlayerInfo::setAttribute(Attributes::MAX_WEIGHT,
385
                base,
386
                Notify_true);
387
            break;
388
        case Sp::USTR:
389
            statusWindow->setPointsNeeded(Attributes::PLAYER_STR,
390
                CAST_S32(base));
391
            break;
392
        case Sp::UAGI:
393
            statusWindow->setPointsNeeded(Attributes::PLAYER_AGI,
394
                CAST_S32(base));
395
            break;
396
        case Sp::UVIT:
397
            statusWindow->setPointsNeeded(Attributes::PLAYER_VIT,
398
                CAST_S32(base));
399
            break;
400
        case Sp::UINT:
401
            statusWindow->setPointsNeeded(Attributes::PLAYER_INT,
402
                CAST_S32(base));
403
            break;
404
        case Sp::UDEX:
405
            statusWindow->setPointsNeeded(Attributes::PLAYER_DEX,
406
                CAST_S32(base));
407
            break;
408
        case Sp::ULUK:
409
            statusWindow->setPointsNeeded(Attributes::PLAYER_LUK,
410
                CAST_S32(base));
411
            break;
412
        case Sp::ATK1:
413
            PlayerInfo::setStatBase(Attributes::PLAYER_ATK,
414
                CAST_S32(base),
415
                Notify_true);
416
            PlayerInfo::updateAttrs();
417
            break;
418
        case Sp::ATK2:
419
            PlayerInfo::setStatMod(Attributes::PLAYER_ATK,
420
                CAST_S32(base),
421
                Notify_true);
422
            PlayerInfo::updateAttrs();
423
            break;
424
        case Sp::MATK1:
425
            PlayerInfo::setStatBase(Attributes::PLAYER_MATK,
426
                CAST_S32(base),
427
                Notify_true);
428
            break;
429
        case Sp::MATK2:
430
            PlayerInfo::setStatMod(Attributes::PLAYER_MATK,
431
                CAST_S32(base),
432
                Notify_true);
433
            break;
434
        case Sp::DEF1:
435
            PlayerInfo::setStatBase(Attributes::PLAYER_DEF,
436
                CAST_S32(base),
437
                Notify_true);
438
            break;
439
        case Sp::DEF2:
440
            PlayerInfo::setStatMod(Attributes::PLAYER_DEF,
441
                CAST_S32(base),
442
                Notify_true);
443
            break;
444
        case Sp::MDEF1:
445
            PlayerInfo::setStatBase(Attributes::PLAYER_MDEF,
446
                CAST_S32(base),
447
                Notify_true);
448
            break;
449
        case Sp::MDEF2:
450
            PlayerInfo::setStatMod(Attributes::PLAYER_MDEF,
451
                CAST_S32(base),
452
                Notify_true);
453
            break;
454
        case Sp::HIT:
455
            PlayerInfo::setStatBase(Attributes::PLAYER_HIT,
456
                CAST_S32(base),
457
                Notify_true);
458
            break;
459
        case Sp::FLEE1:
460
            PlayerInfo::setStatBase(Attributes::PLAYER_FLEE,
461
                CAST_S32(base),
462
                Notify_true);
463
            break;
464
        case Sp::FLEE2:
465
            PlayerInfo::setStatMod(Attributes::PLAYER_FLEE,
466
                CAST_S32(base),
467
                Notify_true);
468
            break;
469
        case Sp::CRITICAL:
470
            PlayerInfo::setStatBase(Attributes::PLAYER_CRIT,
471
                CAST_S32(base),
472
                Notify_true);
473
            break;
474
        case Sp::ASPD:
475
            localPlayer->setAttackSpeed(CAST_S32(base));
476
            PlayerInfo::setStatBase(Attributes::PLAYER_ATTACK_DELAY,
477
                CAST_S32(base),
478
                Notify_true);
479
            PlayerInfo::setStatMod(Attributes::PLAYER_ATTACK_DELAY,
480
                0,
481
                Notify_true);
482
            PlayerInfo::updateAttrs();
483
            break;
484
        case Sp::JOBLEVEL:
485
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_LEVEL,
486
                base,
487
                Notify_true);
488
            break;
489
        case Sp::GM_LEVEL:
490
            localPlayer->setGroupId(CAST_S32(base));
491
            break;
492
493
        default:
494
            UNIMPLEMENTEDPACKETFIELD(type);
495
            break;
496
    }
497
}
498
499
#undef setStatComplex
500
501
void PlayerHandler::selectStyle(const int headColor A_UNUSED,
502
                                const int headStyle A_UNUSED,
503
                                const int bodyColor A_UNUSED,
504
                                const int topStyle A_UNUSED,
505
                                const int middleStyle A_UNUSED,
506
                                const int bottomStyle A_UNUSED,
507
                                const int bodyStyle A_UNUSED) const
508
{
509
}
510
511
void PlayerHandler::setTitle(const int titleId A_UNUSED) const
512
{
513
}
514
515
void PlayerHandler::closeStyleWindow() const
516
{
517
}
518
519
2
}  // namespace TmwAthena