GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/playerhandler.cpp Lines: 1 202 0.5 %
Date: 2018-11-12 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-2018  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 uint8_t type A_UNUSED,
186
                                const int id A_UNUSED,
187
                                const int level A_UNUSED) const
188
{
189
}
190
191
void PlayerHandler::doriDori() const
192
{
193
}
194
195
void PlayerHandler::explosionSpirits() const
196
{
197
}
198
199
void PlayerHandler::requestPvpInfo() const
200
{
201
}
202
203
void PlayerHandler::revive() const
204
{
205
}
206
207
void PlayerHandler::shortcutShiftRow(const int row A_UNUSED) const
208
{
209
}
210
211
void PlayerHandler::setConfigOption(const int id A_UNUSED,
212
                                    const int data A_UNUSED) const
213
{
214
}
215
216
#define setStatComplex(stat) \
217
    PlayerInfo::setStatBase(stat, CAST_S32(base), notify); \
218
    if (mod != NoStat) \
219
        PlayerInfo::setStatMod(stat, mod, Notify_true)
220
221
void PlayerHandler::setStat(Net::MessageIn &msg,
222
                            const int type,
223
                            const int64_t base,
224
                            const int mod,
225
                            const Notify notify) const
226
{
227
    switch (type)
228
    {
229
        case Sp::SPEED:
230
            localPlayer->setWalkSpeed(CAST_S32(base));
231
            PlayerInfo::setStatBase(Attributes::PLAYER_WALK_SPEED,
232
                CAST_S32(base),
233
                Notify_true);
234
            PlayerInfo::setStatMod(Attributes::PLAYER_WALK_SPEED,
235
                0,
236
                Notify_true);
237
            break;
238
        case Sp::BASEEXP:
239
            PlayerInfo::setAttribute(Attributes::PLAYER_EXP,
240
                base,
241
                Notify_true);
242
            break;
243
        case Sp::JOBEXP:
244
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP,
245
                base,
246
                Notify_true);
247
            break;
248
        case Sp::KARMA:
249
            PlayerInfo::setStatBase(Attributes::PLAYER_KARMA,
250
                CAST_S32(base),
251
                Notify_true);
252
            PlayerInfo::setStatMod(Attributes::PLAYER_KARMA,
253
                0,
254
                Notify_true);
255
            break;
256
        case Sp::MANNER:
257
            PlayerInfo::setStatBase(Attributes::PLAYER_MANNER,
258
                CAST_S32(base),
259
                Notify_true);
260
            PlayerInfo::setStatMod(Attributes::PLAYER_MANNER,
261
                0,
262
                Notify_true);
263
            break;
264
        case Sp::HP:
265
            PlayerInfo::setAttribute(Attributes::PLAYER_HP,
266
                base,
267
                Notify_true);
268
            if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
269
            {
270
                PartyMember *const m = Party::getParty(1)
271
                    ->getMember(localPlayer->getId());
272
                if (m != nullptr)
273
                {
274
                    m->setHp(CAST_S32(base));
275
                    m->setMaxHp(PlayerInfo::getAttribute(
276
                        Attributes::PLAYER_MAX_HP));
277
                }
278
            }
279
            break;
280
        case Sp::MAXHP:
281
            PlayerInfo::setAttribute(Attributes::PLAYER_MAX_HP,
282
                base,
283
                Notify_true);
284
285
            if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
286
            {
287
                PartyMember *const m = Party::getParty(1)->getMember(
288
                    localPlayer->getId());
289
                if (m != nullptr)
290
                {
291
                    m->setHp(PlayerInfo::getAttribute(Attributes::PLAYER_HP));
292
                    m->setMaxHp(CAST_S32(base));
293
                }
294
            }
295
            break;
296
        case Sp::SP:
297
            PlayerInfo::setAttribute(Attributes::PLAYER_MP,
298
                base,
299
                Notify_true);
300
            break;
301
        case Sp::MAXSP:
302
            PlayerInfo::setAttribute(Attributes::PLAYER_MAX_MP,
303
                base,
304
                Notify_true);
305
            break;
306
        case Sp::STATUSPOINT:
307
            PlayerInfo::setAttribute(Attributes::PLAYER_CHAR_POINTS,
308
                base,
309
                Notify_true);
310
            break;
311
        case Sp::BASELEVEL:
312
            PlayerInfo::setAttribute(Attributes::PLAYER_BASE_LEVEL,
313
                base,
314
                Notify_true);
315
            if (localPlayer != nullptr)
316
            {
317
                localPlayer->setLevel(CAST_S32(base));
318
                localPlayer->updateName();
319
            }
320
            break;
321
        case Sp::SKILLPOINT:
322
            PlayerInfo::setAttribute(Attributes::PLAYER_SKILL_POINTS,
323
                base,
324
                Notify_true);
325
            if (skillDialog != nullptr)
326
                skillDialog->update();
327
            break;
328
        case Sp::STR:
329
            setStatComplex(Attributes::PLAYER_STR);
330
            break;
331
        case Sp::AGI:
332
            setStatComplex(Attributes::PLAYER_AGI);
333
            break;
334
        case Sp::VIT:
335
            setStatComplex(Attributes::PLAYER_VIT);
336
            break;
337
        case Sp::INT:
338
            setStatComplex(Attributes::PLAYER_INT);
339
            break;
340
        case Sp::DEX:
341
            setStatComplex(Attributes::PLAYER_DEX);
342
            break;
343
        case Sp::LUK:
344
            setStatComplex(Attributes::PLAYER_LUK);
345
            break;
346
        case Sp::ZENY:
347
        {
348
            const int oldMoney = PlayerInfo::getAttribute(Attributes::MONEY);
349
            const int newMoney = CAST_S32(base);
350
            if (newMoney > oldMoney)
351
            {
352
                NotifyManager::notify(NotifyTypes::MONEY_GET,
353
                    UnitsDb::formatCurrency(newMoney - oldMoney));
354
            }
355
            else if (newMoney < oldMoney)
356
            {
357
                NotifyManager::notify(NotifyTypes::MONEY_SPENT,
358
                    UnitsDb::formatCurrency(oldMoney - newMoney).c_str());
359
            }
360
361
            PlayerInfo::setAttribute(Attributes::MONEY,
362
                newMoney,
363
                Notify_true);
364
            break;
365
        }
366
        case Sp::NEXTBASEEXP:
367
            PlayerInfo::setAttribute(Attributes::PLAYER_EXP_NEEDED,
368
                base,
369
                Notify_true);
370
            break;
371
        case Sp::JOB_MOD:
372
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED,
373
                base,
374
                Notify_true);
375
            break;
376
        case Sp::WEIGHT:
377
            PlayerInfo::setAttribute(Attributes::TOTAL_WEIGHT,
378
                base,
379
                Notify_true);
380
            break;
381
        case Sp::MAXWEIGHT:
382
            PlayerInfo::setAttribute(Attributes::MAX_WEIGHT,
383
                base,
384
                Notify_true);
385
            break;
386
        case Sp::USTR:
387
            statusWindow->setPointsNeeded(Attributes::PLAYER_STR,
388
                CAST_S32(base));
389
            break;
390
        case Sp::UAGI:
391
            statusWindow->setPointsNeeded(Attributes::PLAYER_AGI,
392
                CAST_S32(base));
393
            break;
394
        case Sp::UVIT:
395
            statusWindow->setPointsNeeded(Attributes::PLAYER_VIT,
396
                CAST_S32(base));
397
            break;
398
        case Sp::UINT:
399
            statusWindow->setPointsNeeded(Attributes::PLAYER_INT,
400
                CAST_S32(base));
401
            break;
402
        case Sp::UDEX:
403
            statusWindow->setPointsNeeded(Attributes::PLAYER_DEX,
404
                CAST_S32(base));
405
            break;
406
        case Sp::ULUK:
407
            statusWindow->setPointsNeeded(Attributes::PLAYER_LUK,
408
                CAST_S32(base));
409
            break;
410
        case Sp::ATK1:
411
            PlayerInfo::setStatBase(Attributes::PLAYER_ATK,
412
                CAST_S32(base),
413
                Notify_true);
414
            PlayerInfo::updateAttrs();
415
            break;
416
        case Sp::ATK2:
417
            PlayerInfo::setStatMod(Attributes::PLAYER_ATK,
418
                CAST_S32(base),
419
                Notify_true);
420
            PlayerInfo::updateAttrs();
421
            break;
422
        case Sp::MATK1:
423
            PlayerInfo::setStatBase(Attributes::PLAYER_MATK,
424
                CAST_S32(base),
425
                Notify_true);
426
            break;
427
        case Sp::MATK2:
428
            PlayerInfo::setStatMod(Attributes::PLAYER_MATK,
429
                CAST_S32(base),
430
                Notify_true);
431
            break;
432
        case Sp::DEF1:
433
            PlayerInfo::setStatBase(Attributes::PLAYER_DEF,
434
                CAST_S32(base),
435
                Notify_true);
436
            break;
437
        case Sp::DEF2:
438
            PlayerInfo::setStatMod(Attributes::PLAYER_DEF,
439
                CAST_S32(base),
440
                Notify_true);
441
            break;
442
        case Sp::MDEF1:
443
            PlayerInfo::setStatBase(Attributes::PLAYER_MDEF,
444
                CAST_S32(base),
445
                Notify_true);
446
            break;
447
        case Sp::MDEF2:
448
            PlayerInfo::setStatMod(Attributes::PLAYER_MDEF,
449
                CAST_S32(base),
450
                Notify_true);
451
            break;
452
        case Sp::HIT:
453
            PlayerInfo::setStatBase(Attributes::PLAYER_HIT,
454
                CAST_S32(base),
455
                Notify_true);
456
            break;
457
        case Sp::FLEE1:
458
            PlayerInfo::setStatBase(Attributes::PLAYER_FLEE,
459
                CAST_S32(base),
460
                Notify_true);
461
            break;
462
        case Sp::FLEE2:
463
            PlayerInfo::setStatMod(Attributes::PLAYER_FLEE,
464
                CAST_S32(base),
465
                Notify_true);
466
            break;
467
        case Sp::CRITICAL:
468
            PlayerInfo::setStatBase(Attributes::PLAYER_CRIT,
469
                CAST_S32(base),
470
                Notify_true);
471
            break;
472
        case Sp::ASPD:
473
            localPlayer->setAttackSpeed(CAST_S32(base));
474
            PlayerInfo::setStatBase(Attributes::PLAYER_ATTACK_DELAY,
475
                CAST_S32(base),
476
                Notify_true);
477
            PlayerInfo::setStatMod(Attributes::PLAYER_ATTACK_DELAY,
478
                0,
479
                Notify_true);
480
            PlayerInfo::updateAttrs();
481
            break;
482
        case Sp::JOBLEVEL:
483
            PlayerInfo::setAttribute(Attributes::PLAYER_JOB_LEVEL,
484
                base,
485
                Notify_true);
486
            break;
487
        case Sp::GM_LEVEL:
488
            localPlayer->setGroupId(CAST_S32(base));
489
            break;
490
491
        default:
492
            UNIMPLEMENTEDPACKETFIELD(type);
493
            break;
494
    }
495
}
496
497
#undef setStatComplex
498
499
void PlayerHandler::selectStyle(const int headColor A_UNUSED,
500
                                const int headStyle A_UNUSED,
501
                                const int bodyColor A_UNUSED,
502
                                const int topStyle A_UNUSED,
503
                                const int middleStyle A_UNUSED,
504
                                const int bottomStyle A_UNUSED,
505
                                const int bodyStyle A_UNUSED) const
506
{
507
}
508
509
void PlayerHandler::setTitle(const int titleId A_UNUSED) const
510
{
511
}
512
513
2
}  // namespace TmwAthena