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