GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/localplayer.h Lines: 1 20 5.0 %
Date: 2019-10-15 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-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
#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
        void setTileCoords(const int x,
281
                           const int y) restrict2 override final;
282
283
        /**
284
         * Sets the map the being is on
285
         */
286
        void setMap(Map *const map) override final;
287
288
        void addMessageToQueue(const std::string &message,
289
                               const UserColorIdT color);
290
291
        /**
292
         * Called when a option (set with config.addListener()) is changed
293
         */
294
        void optionChanged(const std::string &value) override final;
295
296
        void playerDeath() override final;
297
298
        /**
299
         * set a following player.
300
         */
301
        void setFollow(const std::string &player);
302
303
        /**
304
         * set an imitation player.
305
         */
306
        void setImitate(const std::string &player);
307
308
        /**
309
         * setting the next destination of the following, in case of warp
310
         */
311
        void setNextDest(const int x, const int y);
312
313
        int getNextDestX() const noexcept2 A_WARN_UNUSED
314
        { return mNextDestX; }
315
316
        int getNextDestY() const noexcept2 A_WARN_UNUSED
317
        { return mNextDestY; }
318
319
        void respawn();
320
321
        const FloorItem *getPickUpTarget() const noexcept2 A_WARN_UNUSED
322
        { return mPickUpTarget; }
323
324
        void unSetPickUpTarget()
325
5
        { mPickUpTarget = nullptr; }
326
327
        /**
328
         * Stop following a player.
329
         */
330
        void cancelFollow();
331
332
        /**
333
         * Get the playername followed by the current player.
334
         */
335
        const std::string &getFollow() const noexcept2 A_WARN_UNUSED
336
        { return mPlayerFollowed; }
337
338
        /**
339
         * Get the playername imitated by the current player.
340
         */
341
        const std::string &getImitate() const noexcept2 A_WARN_UNUSED
342
        { return mPlayerImitated; }
343
344
        /**
345
         * Tells the engine whether to check
346
         * if the Player Name is to be displayed.
347
         */
348
        void setCheckNameSetting(const bool checked)
349
        { mUpdateName = checked; }
350
351
        /**
352
         * Gets if the engine has to check
353
         * if the Player Name is to be displayed.
354
         */
355
        bool getCheckNameSetting() const noexcept2 A_WARN_UNUSED
356
        { return mUpdateName; }
357
358
        void fixAttackTarget();
359
360
        void updateNavigateList();
361
362
        int getPathLength(const Being *const being) const A_WARN_UNUSED;
363
364
        void targetMoved() const;
365
366
        void setLastHitFrom(const std::string &n)
367
        { mLastHitFrom = n; }
368
369
        void waitFor(const std::string &nick);
370
371
        void checkNewName(Being *const being);
372
373
        unsigned char getBlockWalkMask() const override final
374
                                       A_CONST A_WARN_UNUSED;
375
376
        void saveHomes();
377
378
        void removeHome();
379
380
        void stopAdvert();
381
382
        void addXpMessage(const int64_t change);
383
384
        void addHomunXpMessage(const int change);
385
386
        void addJobMessage(const int64_t change);
387
388
        void addHpMessage(const int change);
389
390
        void addSpMessage(const int change);
391
392
        static bool checAttackPermissions(const Being *const target)
393
                                          A_WARN_UNUSED;
394
395
        void updateStatus() const;
396
397
        void setTestParticle(const std::string &fileName,
398
                             const bool updateHash);
399
400
        int getLastAttackX() const override final
401
        { return mTarget != nullptr ? mTarget->mX : mLastAttackX; }
402
403
        int getLastAttackY() const override final
404
        { return mTarget != nullptr ? mTarget->mY : mLastAttackY; }
405
406
        void attributeChanged(const AttributesT id,
407
                              const int64_t oldVal,
408
                              const int64_t newVal) override final;
409
410
        void updateMusic() const;
411
412
        void setAfkTime(const int v) noexcept2
413
        { mAfkTime = v; }
414
415
        void setAwayDialog(OkDialog *const dialog)
416
        { mAwayDialog = dialog; }
417
418
        AwayListener *getAwayListener() const noexcept2 A_WARN_UNUSED
419
        { return mAwayListener; }
420
421
        void setRename(const bool r) noexcept2
422
        { mAllowRename = r; }
423
424
        bool getRename() const noexcept2
425
        { return mAllowRename; }
426
427
        bool canMove() const;
428
429
        void freezeMoving(const int timeWaitTicks);
430
431
        void failMove(const int x,
432
                      const int y);
433
434
    protected:
435
        void updateCoords() override final;
436
437
        void handleStatusEffect(const StatusEffect *const effect,
438
                                const int32_t effectId,
439
                                const Enable newStatus,
440
                                const IsStart start) override final;
441
442
        void startWalking(const unsigned char dir);
443
444
        void changeEquipmentBeforeAttack(const Being *const target) const;
445
446
#ifdef TMWA_SUPPORT
447
        static void tryMagic(const std::string &spell,
448
                             const int baseMagic,
449
                             const int schoolMagic,
450
                             const int mana);
451
#endif  // TMWA_SUPPORT
452
453
        void loadHomes();
454
455
        // move state. used if mMoveType == 2
456
        unsigned int mMoveState;
457
458
        int mLastTargetX;
459
        int mLastTargetY;
460
461
        std::map<std::string, Vector> mHomes;
462
463
        Being *mTarget;
464
465
        /** Follow system **/
466
        std::string mPlayerFollowed;
467
        std::string mPlayerImitated;
468
        int mNextDestX;
469
        int mNextDestY;
470
471
        FloorItem *mPickUpTarget;
472
473
        int mLastAction;      // Time stamp of the last action, -1 if none.
474
475
        STD_VECTOR<int32_t> mStatusEffectIcons;
476
477
        typedef std::pair<std::string, UserColorIdT> MessagePair;
478
        /** Queued messages*/
479
        std::list<MessagePair> mMessages;
480
        int mMessageTime;
481
        AwayListener *mAwayListener;
482
        OkDialog *mAwayDialog;
483
484
        int mPingSendTick;
485
        time_t mPingTime;
486
        time_t mAfkTime;
487
        time_t mActivityTime;
488
        int mNavigateX;
489
        int mNavigateY;
490
        BeingId mNavigateId;
491
        int mCrossX;
492
        int mCrossY;
493
        int mOldX;
494
        int mOldY;
495
        int mOldTileX;
496
        int mOldTileY;
497
        Path mNavigatePath;
498
499
        std::string mLastHitFrom;
500
        std::string mWaitFor;
501
        time_t mAdvertTime;
502
        Particle *mTestParticle;
503
        std::string mTestParticleName;
504
        time_t mTestParticleTime;
505
        unsigned long mTestParticleHash;
506
        int mSyncPlayerMoveDistance;
507
        int mUnfreezeTime;
508
        unsigned char mWalkingDir;  // The direction the player is walking in.
509
        /** Whether or not the name settings have changed */
510
        bool mUpdateName;
511
        bool mBlockAdvert;
512
        bool mTargetDeadPlayers;
513
        Keep mServerAttack;
514
        VisibleName::Type mVisibleNames;
515
        bool mEnableAdvert;
516
        bool mTradebot;
517
        bool mTargetOnlyReachable;
518
        bool mIsServerBuggy;
519
        bool mSyncPlayerMove;
520
        bool mDrawPath;
521
        bool mAttackMoving;
522
        bool mAttackNext;
523
        bool mShowJobExp;
524
        bool mShowServerPos;
525
        bool mNextStep;
526
        // temporary disable crazy moves in moves
527
        bool mGoingToTarget;
528
        // Whether or not to continue to attack
529
        bool mKeepAttacking;
530
        // Tells if the path was set using mouse
531
        bool mPathSetByMouse;
532
        bool mWaitPing;
533
        bool mShowNavigePath;
534
        bool mAllowRename;
535
        bool mFreezed;
536
};
537
538
extern LocalPlayer *localPlayer;
539
540
#endif  // BEING_LOCALPLAYER_H