GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/localplayer.h Lines: 1 20 5.0 %
Date: 2018-07-14 Branches: 0 4 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
#ifndef BEING_LOCALPLAYER_H
24
#define BEING_LOCALPLAYER_H
25
26
#include "being/being.h"
27
28
#include "enums/being/pickup.h"
29
#include "enums/being/visiblename.h"
30
31
#include "enums/simpletypes/allowsort.h"
32
#include "enums/simpletypes/keep.h"
33
34
#include "listeners/actorspritelistener.h"
35
#include "listeners/attributelistener.h"
36
#include "listeners/playerdeathlistener.h"
37
38
#include "localconsts.h"
39
40
class AwayListener;
41
class ChatTab;
42
class FloorItem;
43
class Map;
44
class OkDialog;
45
46
/**
47
 * The local player character.
48
 */
49
class LocalPlayer final : public Being,
50
                          public ActorSpriteListener,
51
                          public AttributeListener,
52
                          public PlayerDeathListener
53
{
54
    public:
55
        /**
56
         * Constructor.
57
         */
58
        LocalPlayer(const BeingId id,
59
                    const BeingTypeId subType);
60
61
        A_DELETE_COPY(LocalPlayer)
62
63
        /**
64
         * Destructor.
65
         */
66
        ~LocalPlayer() override final;
67
68
        void logic() override final;
69
70
        void slowLogic();
71
72
        void setAction(const BeingActionT &action,
73
                       const int attackId) override final;
74
75
        /**
76
         * Compute the next pathnode location when walking using keyboard.
77
         * used by nextTile().
78
         */
79
        Position getNextWalkPosition(const unsigned char dir)
80
                                     const A_WARN_UNUSED;
81
82
        /**
83
         * Adds a new tile to the path when walking.
84
         * @note Eathena
85
         * Also, when specified, it picks up an item at the end of a path
86
         * or attack target.
87
         */
88
        void nextTile() override final;
89
90
        bool pickUp(FloorItem *const item);
91
92
        /**
93
         * Called when an ActorSprite has been destroyed.
94
         * @param actorSprite the ActorSprite being destroyed.
95
         */
96
        void actorSpriteDestroyed(const ActorSprite &actorSprite)
97
                                  override final;
98
99
        /**
100
         * Gets the attack range.
101
         */
102
        int getAttackRange() const A_WARN_UNUSED;
103
104
        int getAttackRange2() const A_WARN_UNUSED;
105
106
        void attack(Being *const target,
107
                    const bool keep,
108
                    const bool dontChangeEquipment);
109
110
        void attack2(Being *const target,
111
                     const bool keep,
112
                     const bool dontChangeEquipment);
113
114
        void setGroupId(const int id) override final;
115
116
        void stopAttack(const bool keepAttack);
117
118
        void untarget();
119
120
        /**
121
         * Returns the current target of the player. Returns 0 if no being is
122
         * currently targeted.
123
         */
124
        Being *getTarget() const A_WARN_UNUSED;
125
126
        /**
127
         * Sets the target being of the player.
128
         */
129
        void setTarget(Being *const target);
130
131
        Being *setNewTarget(const ActorTypeT type,
132
                            const AllowSort allowSort);
133
134
        /**
135
         * Sets a new destination for this being to walk to.
136
         */
137
        void setDestination(const int x, const int y);
138
139
        /**
140
         * Sets a new direction to keep walking in.
141
         */
142
        void setWalkingDir(const unsigned char dir);
143
144
        /**
145
         * Gets the walking direction
146
         */
147
        unsigned char getWalkingDir() const noexcept2 A_WARN_UNUSED
148
        { return mWalkingDir; }
149
150
        /**
151
         * Sets going to being to attack
152
         */
153
        void setGotoTarget(Being *const target);
154
155
        /**
156
         * Returns whether the target is in range to attack
157
         */
158
        bool withinAttackRange(const Being *const target,
159
                               const bool fixDistance,
160
                               const int addRange) const A_WARN_UNUSED;
161
162
        /**
163
         * Stops the player dead in his tracks
164
         */
165
        void stopWalking(const bool sendToServer);
166
167
        bool toggleSit() const;
168
169
        bool updateSit() const;
170
171
        static bool emote(const uint8_t emotion);
172
173
        /**
174
         * Shows item pickup notifications.
175
         */
176
        void pickedUp(const ItemInfo &itemInfo,
177
                      const int amount,
178
                      const ItemColor color,
179
                      const BeingId floorItemId,
180
                      const PickupT fail);
181
182
        int getLevel() const override final A_WARN_UNUSED;
183
184
        /** Tells that the path has been set by mouse. */
185
        void pathSetByMouse()
186
        { mPathSetByMouse = true; }
187
188
        /** Tells if the path has been set by mouse. */
189
        bool isPathSetByMouse() const noexcept2 A_WARN_UNUSED
190
        { return mPathSetByMouse; }
191
192
        unsigned int getMoveState() const noexcept2 A_WARN_UNUSED
193
        { return mMoveState; }
194
195
        void setMoveState(const unsigned int n) noexcept2
196
        { mMoveState = n; }
197
198
        std::string getPingTime() const A_WARN_UNUSED;
199
200
        void tryPingRequest();
201
202
#ifdef TMWA_SUPPORT
203
        void magicAttack() const;
204
#endif  // TMWA_SUPPORT
205
206
        void specialMove(const unsigned char direction);
207
208
        void moveByDirection(const unsigned char dir);
209
210
        bool pickUpItems(int pickUpType);
211
212
        void move(const int dX, const int dY);
213
214
        void moveToTarget(int dist);
215
216
        void moveToHome();
217
218
        bool isReachable(Being *const being,
219
                         const int maxCost) A_WARN_UNUSED;
220
221
        bool isReachable(const int x,
222
                         const int y,
223
                         const bool allowCollision) const A_WARN_UNUSED;
224
225
        void setHome();
226
227
        void pingRequest();
228
229
        void pingResponse();
230
231
        void setAway(const std::string &message) const;
232
233
        static void setPseudoAway(const std::string &message);
234
235
        void setHalfAway(const bool n)
236
        { mInactive = n; }
237
238
        bool getHalfAway() const noexcept2 A_WARN_UNUSED
239
        { return mInactive; }
240
241
        void afkRespond(ChatTab *const tab, const std::string &nick);
242
243
        static void setAfkMessage(std::string message);
244
245
        bool navigateTo(const int x, const int y);
246
247
        void navigateClean();
248
249
        void imitateEmote(const Being *const being,
250
                          const unsigned char action) const;
251
252
        void imitateAction(const Being *const being,
253
                           const BeingActionT &action);
254
255
        void imitateDirection(const Being *const being,
256
                              const unsigned char dir);
257
258
        void imitateOutfit(const Being *const player,
259
                           const int sprite) const;
260
261
        void followMoveTo(const Being *const being,
262
                          const int x,
263
                          const int y);
264
265
        void followMoveTo(const Being *const being,
266
                          const int x1,
267
                          const int y1,
268
                          const int x2,
269
                          const int y2);
270
271
        bool allowAction() A_WARN_UNUSED;
272
273
        void setRealPos(const int x, const int y);
274
275
        bool isServerBuggy() const noexcept2 A_WARN_UNUSED
276
        { return mIsServerBuggy; }
277
278
        void fixPos();
279
280
        /**
281
         * Sets the map the being is on
282
         */
283
        void setMap(Map *const map) override final;
284
285
        void addMessageToQueue(const std::string &message,
286
                               const UserColorIdT color);
287
288
        /**
289
         * Called when a option (set with config.addListener()) is changed
290
         */
291
        void optionChanged(const std::string &value) override final;
292
293
        void playerDeath() override final;
294
295
        /**
296
         * set a following player.
297
         */
298
        void setFollow(const std::string &player);
299
300
        /**
301
         * set an imitation player.
302
         */
303
        void setImitate(const std::string &player);
304
305
        /**
306
         * setting the next destination of the following, in case of warp
307
         */
308
        void setNextDest(const int x, const int y);
309
310
        int getNextDestX() const noexcept2 A_WARN_UNUSED
311
        { return mNextDestX; }
312
313
        int getNextDestY() const noexcept2 A_WARN_UNUSED
314
        { return mNextDestY; }
315
316
        void respawn();
317
318
        const FloorItem *getPickUpTarget() const noexcept2 A_WARN_UNUSED
319
        { return mPickUpTarget; }
320
321
        void unSetPickUpTarget()
322
5
        { mPickUpTarget = nullptr; }
323
324
        /**
325
         * Stop following a player.
326
         */
327
        void cancelFollow();
328
329
        /**
330
         * Get the playername followed by the current player.
331
         */
332
        const std::string &getFollow() const noexcept2 A_WARN_UNUSED
333
        { return mPlayerFollowed; }
334
335
        /**
336
         * Get the playername imitated by the current player.
337
         */
338
        const std::string &getImitate() const noexcept2 A_WARN_UNUSED
339
        { return mPlayerImitated; }
340
341
        /**
342
         * Tells the engine whether to check
343
         * if the Player Name is to be displayed.
344
         */
345
        void setCheckNameSetting(const bool checked)
346
        { mUpdateName = checked; }
347
348
        /**
349
         * Gets if the engine has to check
350
         * if the Player Name is to be displayed.
351
         */
352
        bool getCheckNameSetting() const noexcept2 A_WARN_UNUSED
353
        { return mUpdateName; }
354
355
        void fixAttackTarget();
356
357
        void updateNavigateList();
358
359
        int getPathLength(const Being *const being) const A_WARN_UNUSED;
360
361
        void targetMoved() const;
362
363
        void setLastHitFrom(const std::string &n)
364
        { mLastHitFrom = n; }
365
366
        void waitFor(const std::string &nick);
367
368
        void checkNewName(Being *const being);
369
370
        unsigned char getBlockWalkMask() const override final
371
                                       A_CONST A_WARN_UNUSED;
372
373
        void saveHomes();
374
375
        void removeHome();
376
377
        void stopAdvert();
378
379
        void addXpMessage(const int64_t change);
380
381
        void addHomunXpMessage(const int change);
382
383
        void addJobMessage(const int64_t change);
384
385
        void addHpMessage(const int change);
386
387
        void addSpMessage(const int change);
388
389
        static bool checAttackPermissions(const Being *const target)
390
                                          A_WARN_UNUSED;
391
392
        void updateStatus() const;
393
394
        void setTestParticle(const std::string &fileName,
395
                             const bool updateHash);
396
397
        int getLastAttackX() const override final
398
        { return mTarget != nullptr ? mTarget->mX : mLastAttackX; }
399
400
        int getLastAttackY() const override final
401
        { return mTarget != nullptr ? mTarget->mY : mLastAttackY; }
402
403
        void attributeChanged(const AttributesT id,
404
                              const int64_t oldVal,
405
                              const int64_t newVal) override final;
406
407
        void updateMusic() const;
408
409
        void setAfkTime(const int v) noexcept2
410
        { mAfkTime = v; }
411
412
        void setAwayDialog(OkDialog *const dialog)
413
        { mAwayDialog = dialog; }
414
415
        AwayListener *getAwayListener() const noexcept2 A_WARN_UNUSED
416
        { return mAwayListener; }
417
418
        void setRename(const bool r) noexcept2
419
        { mAllowRename = r; }
420
421
        bool getRename() const noexcept2
422
        { return mAllowRename; }
423
424
        bool canMove() const;
425
426
        void freezeMoving(const int timeWaitTicks);
427
428
        void failMove(const int x,
429
                      const int y);
430
431
    protected:
432
        void updateCoords() override final;
433
434
        void handleStatusEffect(const StatusEffect *const effect,
435
                                const int32_t effectId,
436
                                const Enable newStatus,
437
                                const IsStart start) override final;
438
439
        void startWalking(const unsigned char dir);
440
441
        void changeEquipmentBeforeAttack(const Being *const target) const;
442
443
#ifdef TMWA_SUPPORT
444
        static void tryMagic(const std::string &spell,
445
                             const int baseMagic,
446
                             const int schoolMagic,
447
                             const int mana);
448
#endif  // TMWA_SUPPORT
449
450
        void loadHomes();
451
452
        // move state. used if mMoveType == 2
453
        unsigned int mMoveState;
454
455
        int mLastTargetX;
456
        int mLastTargetY;
457
458
        std::map<std::string, Vector> mHomes;
459
460
        Being *mTarget;
461
462
        /** Follow system **/
463
        std::string mPlayerFollowed;
464
        std::string mPlayerImitated;
465
        int mNextDestX;
466
        int mNextDestY;
467
468
        FloorItem *mPickUpTarget;
469
470
        int mLastAction;      // Time stamp of the last action, -1 if none.
471
472
        STD_VECTOR<int32_t> mStatusEffectIcons;
473
474
        typedef std::pair<std::string, UserColorIdT> MessagePair;
475
        /** Queued messages*/
476
        std::list<MessagePair> mMessages;
477
        int mMessageTime;
478
        AwayListener *mAwayListener;
479
        OkDialog *mAwayDialog;
480
481
        int mPingSendTick;
482
        time_t mPingTime;
483
        time_t mAfkTime;
484
        time_t mActivityTime;
485
        int mNavigateX;
486
        int mNavigateY;
487
        BeingId mNavigateId;
488
        int mCrossX;
489
        int mCrossY;
490
        int mOldX;
491
        int mOldY;
492
        int mOldTileX;
493
        int mOldTileY;
494
        Path mNavigatePath;
495
496
        std::string mLastHitFrom;
497
        std::string mWaitFor;
498
        time_t mAdvertTime;
499
        Particle *mTestParticle;
500
        std::string mTestParticleName;
501
        time_t mTestParticleTime;
502
        unsigned long mTestParticleHash;
503
        int mSyncPlayerMoveDistance;
504
        int mUnfreezeTime;
505
        unsigned char mWalkingDir;  // The direction the player is walking in.
506
        /** Whether or not the name settings have changed */
507
        bool mUpdateName;
508
        bool mBlockAdvert;
509
        bool mTargetDeadPlayers;
510
        Keep mServerAttack;
511
        VisibleName::Type mVisibleNames;
512
        bool mEnableAdvert;
513
        bool mTradebot;
514
        bool mTargetOnlyReachable;
515
        bool mIsServerBuggy;
516
        bool mSyncPlayerMove;
517
        bool mDrawPath;
518
        bool mAttackMoving;
519
        bool mAttackNext;
520
        bool mShowJobExp;
521
        bool mShowServerPos;
522
        bool mNextStep;
523
        // temporary disable crazy moves in moves
524
        bool mGoingToTarget;
525
        // Whether or not to continue to attack
526
        bool mKeepAttacking;
527
        // Tells if the path was set using mouse
528
        bool mPathSetByMouse;
529
        bool mWaitPing;
530
        bool mShowNavigePath;
531
        bool mAllowRename;
532
        bool mFreezed;
533
};
534
535
extern LocalPlayer *localPlayer;
536
537
#endif  // BEING_LOCALPLAYER_H