ManaPlus
localplayer.h
Go to the documentation of this file.
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  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef BEING_LOCALPLAYER_H
25 #define BEING_LOCALPLAYER_H
26 
27 #include "being/being.h"
28 
29 #include "enums/being/pickup.h"
31 
33 #include "enums/simpletypes/keep.h"
34 
38 
39 #include "localconsts.h"
40 
41 class AwayListener;
42 class ChatTab;
43 class FloorItem;
44 class Map;
45 class OkDialog;
46 
50 class LocalPlayer final : public Being,
51  public ActorSpriteListener,
52  public AttributeListener,
53  public PlayerDeathListener
54 {
55  public:
59  LocalPlayer(const BeingId id,
60  const BeingTypeId subType);
61 
63 
64 
67  ~LocalPlayer() override final;
68 
69  void logic() override final;
70 
71  void slowLogic();
72 
73  void setAction(const BeingActionT &action,
74  const int attackId) override final;
75 
80  Position getNextWalkPosition(const unsigned char dir)
81  const A_WARN_UNUSED;
82 
89  void nextTile() override final;
90 
91  bool pickUp(FloorItem *const item);
92 
97  void actorSpriteDestroyed(const ActorSprite &actorSprite)
99 
103  int getAttackRange() const A_WARN_UNUSED;
104 
105  int getAttackRange2() const A_WARN_UNUSED;
106 
107  void attack(Being *const target,
108  const bool keep,
109  const bool dontChangeEquipment);
110 
111  void attack2(Being *const target,
112  const bool keep,
113  const bool dontChangeEquipment);
114 
115  void setGroupId(const int id) override final;
116 
117  void stopAttack(const bool keepAttack);
118 
119  void untarget();
120 
125  Being *getTarget() const A_WARN_UNUSED;
126 
130  void setTarget(Being *const target);
131 
132  Being *setNewTarget(const ActorTypeT type,
133  const AllowSort allowSort);
134 
138  void setDestination(const int x, const int y);
139 
143  void setWalkingDir(const unsigned char dir);
144 
148  unsigned char getWalkingDir() const noexcept2 A_WARN_UNUSED
149  { return mWalkingDir; }
150 
154  void setGotoTarget(Being *const target);
155 
159  bool withinAttackRange(const Being *const target,
160  const bool fixDistance,
161  const int addRange) const A_WARN_UNUSED;
162 
166  void stopWalking(const bool sendToServer);
167 
168  bool toggleSit() const;
169 
170  bool updateSit() const;
171 
172  static bool emote(const uint8_t emotion);
173 
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 
187  { mPathSetByMouse = true; }
188 
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);
212 
213  void move(const int dX, const int dY);
214 
215  void moveToTarget(int dist);
216 
217  void moveToHome();
218 
219  bool isReachable(Being *const being,
220  const int maxCost) A_WARN_UNUSED;
221 
222  bool isReachable(const int x,
223  const int y,
224  const bool allowCollision) const A_WARN_UNUSED;
225 
226  void setHome();
227 
228  void pingRequest();
229 
230  void pingResponse();
231 
232  void setAway(const std::string &message) const;
233 
234  static void setPseudoAway(const std::string &message);
235 
236  void setHalfAway(const bool n)
237  { mInactive = n; }
238 
240  { return mInactive; }
241 
242  void afkRespond(ChatTab *const tab, const std::string &nick);
243 
244  static void setAfkMessage(std::string message);
245 
246  bool navigateTo(const int x, const int y);
247 
248  void navigateClean();
249 
250  void imitateEmote(const Being *const being,
251  const unsigned char action) const;
252 
253  void imitateAction(const Being *const being,
254  const BeingActionT &action);
255 
256  void imitateDirection(const Being *const being,
257  const unsigned char dir);
258 
259  void imitateOutfit(const Being *const player,
260  const int sprite) const;
261 
262  void followMoveTo(const Being *const being,
263  const int x,
264  const int y);
265 
266  void followMoveTo(const Being *const being,
267  const int x1,
268  const int y1,
269  const int x2,
270  const int y2);
271 
272  bool allowAction() A_WARN_UNUSED;
273 
274  void setRealPos(const int x, const int y);
275 
277  { return mIsServerBuggy; }
278 
279  void fixPos();
280 
281  void setTileCoords(const int x,
282  const int y) restrict2 override final;
283 
287  void setMap(Map *const map) override final;
288 
289  void addMessageToQueue(const std::string &message,
290  const UserColorIdT color);
291 
295  void optionChanged(const std::string &value) override final;
296 
297  void playerDeath() override final;
298 
302  void setFollow(const std::string &player);
303 
307  void setImitate(const std::string &player);
308 
312  void setNextDest(const int x, const int y);
313 
315  { return mNextDestX; }
316 
318  { return mNextDestY; }
319 
320  void respawn();
321 
323  { return mPickUpTarget; }
324 
326  { mPickUpTarget = nullptr; }
327 
331  void cancelFollow();
332 
336  const std::string &getFollow() const noexcept2 A_WARN_UNUSED
337  { return mPlayerFollowed; }
338 
342  const std::string &getImitate() const noexcept2 A_WARN_UNUSED
343  { return mPlayerImitated; }
344 
349  void setCheckNameSetting(const bool checked)
350  { mUpdateName = checked; }
351 
357  { return mUpdateName; }
358 
359  void fixAttackTarget();
360 
361  void updateNavigateList();
362 
363  int getPathLength(const Being *const being) const A_WARN_UNUSED;
364 
365  void targetMoved() const;
366 
367  void setLastHitFrom(const std::string &n)
368  { mLastHitFrom = n; }
369 
370  void waitFor(const std::string &nick);
371 
372  void checkNewName(Being *const being);
373 
374  unsigned char getBlockWalkMask() const override final
375  A_CONST A_WARN_UNUSED;
376 
377  void saveHomes();
378 
379  void removeHome();
380 
381  void stopAdvert();
382 
383  void addXpMessage(const int64_t change);
384 
385  void addHomunXpMessage(const int change);
386 
387  void addJobMessage(const int64_t change);
388 
389  void addHpMessage(const int change);
390 
391  void addSpMessage(const int change);
392 
393  static bool checAttackPermissions(const Being *const target)
395 
396  void updateStatus() const;
397 
398  void setTestParticle(const std::string &fileName,
399  const bool updateHash);
400 
402  { return mTarget != nullptr ? mTarget->mX : mLastAttackX; }
403 
405  { return mTarget != nullptr ? mTarget->mY : mLastAttackY; }
406 
407  void attributeChanged(const AttributesT id,
408  const int64_t oldVal,
409  const int64_t newVal) override final;
410 
411  void updateMusic() const;
412 
413  void setAfkTime(const int v) noexcept2
414  { mAfkTime = v; }
415 
416  void setAwayDialog(OkDialog *const dialog)
417  { mAwayDialog = dialog; }
418 
420  { return mAwayListener; }
421 
422  void setRename(const bool r) noexcept2
423  { mAllowRename = r; }
424 
425  bool getRename() const noexcept2
426  { return mAllowRename; }
427 
428  bool canMove() const;
429 
430  void freezeMoving(const int timeWaitTicks);
431 
432  void failMove(const int x,
433  const int y);
434 
435  protected:
436  void updateCoords() override final;
437 
438  void handleStatusEffect(const StatusEffect *const effect,
439  const int32_t effectId,
440  const Enable newStatus,
441  const IsStart start) override final;
442 
443  void startWalking(const unsigned char dir);
444 
445  void changeEquipmentBeforeAttack(const Being *const target) const;
446 
447 #ifdef TMWA_SUPPORT
448  static void tryMagic(const std::string &spell,
449  const int baseMagic,
450  const int schoolMagic,
451  const int mana);
452 #endif // TMWA_SUPPORT
453 
454  void loadHomes();
455 
456  // move state. used if mMoveType == 2
457  unsigned int mMoveState;
458 
461 
462  std::map<std::string, Vector> mHomes;
463 
465 
467  std::string mPlayerFollowed;
468  std::string mPlayerImitated;
471 
473 
474  int mLastAction; // Time stamp of the last action, -1 if none.
475 
476  STD_VECTOR<int32_t> mStatusEffectIcons;
477 
478  typedef std::pair<std::string, UserColorIdT> MessagePair;
480  std::list<MessagePair> mMessages;
484 
486  time_t mPingTime;
487  time_t mAfkTime;
492  int mCrossX;
493  int mCrossY;
494  int mOldX;
495  int mOldY;
499 
500  std::string mLastHitFrom;
501  std::string mWaitFor;
502  time_t mAdvertTime;
504  std::string mTestParticleName;
506  unsigned long mTestParticleHash;
509  unsigned char mWalkingDir; // The direction the player is walking in.
517  bool mTradebot;
521  bool mDrawPath;
526  bool mNextStep;
527  // temporary disable crazy moves in moves
529  // Whether or not to continue to attack
531  // Tells if the path was set using mouse
533  bool mWaitPing;
536  bool mFreezed;
537 };
538 
539 extern LocalPlayer *localPlayer;
540 
541 #endif // BEING_LOCALPLAYER_H
ActorType ::T ActorTypeT
Definition: actortype.h:43
bool AllowSort
Definition: allowsort.h:30
Attributes ::T AttributesT
Definition: attributes.h:118
BeingAction ::T BeingActionT
Definition: beingaction.h:41
int BeingId
Definition: beingid.h:30
int BeingTypeId
Definition: beingtypeid.h:30
Definition: being.h:96
int mLastAttackX
Definition: being.h:1223
int mX
Definition: being.h:1314
int mY
Definition: being.h:1315
friend class LocalPlayer
Definition: being.h:100
int mLastAttackY
Definition: being.h:1224
bool mInactive
Definition: being.h:1383
void updateCoords()
void setNextDest(const int x, const int y)
void updateNavigateList()
AwayListener * mAwayListener
Definition: localplayer.h:482
static bool checAttackPermissions(const Being *const target)
bool mTargetDeadPlayers
Definition: localplayer.h:513
void attack2(Being *const target, const bool keep, const bool dontChangeEquipment)
int getLevel() const
void fixAttackTarget()
void moveToTarget(int dist)
bool mShowJobExp
Definition: localplayer.h:524
std::string mTestParticleName
Definition: localplayer.h:504
void freezeMoving(const int timeWaitTicks)
int getLastAttackX() const
Definition: localplayer.h:401
void setTileCoords(const int x, const int y)
void setWalkingDir(const unsigned char dir)
bool mUpdateName
Definition: localplayer.h:511
bool pickUpItems(int pickUpType)
void moveToHome()
bool toggleSit() const
void followMoveTo(const Being *const being, const int x, const int y)
bool getCheckNameSetting() const
Definition: localplayer.h:356
void removeHome()
int getNextDestX() const
Definition: localplayer.h:314
void stopAdvert()
void setLastHitFrom(const std::string &n)
Definition: localplayer.h:367
void addHpMessage(const int change)
void setMap(Map *const map)
void failMove(const int x, const int y)
void startWalking(const unsigned char dir)
std::string getPingTime() const
int mUnfreezeTime
Definition: localplayer.h:508
void attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal)
void setTarget(Being *const target)
std::vector< int32_t > mStatusEffectIcons
Definition: localplayer.h:476
bool mWaitPing
Definition: localplayer.h:533
Being * getTarget() const
bool mAllowRename
Definition: localplayer.h:535
int getAttackRange() const
bool mAttackMoving
Definition: localplayer.h:522
int mMessageTime
Definition: localplayer.h:481
void imitateDirection(const Being *const being, const unsigned char dir)
int getLastAttackY() const
Definition: localplayer.h:404
void untarget()
void addHomunXpMessage(const int change)
unsigned char getWalkingDir() const
Definition: localplayer.h:148
void setCheckNameSetting(const bool checked)
Definition: localplayer.h:349
void nextTile()
void waitFor(const std::string &nick)
void setFollow(const std::string &player)
Path mNavigatePath
Definition: localplayer.h:498
FloorItem * mPickUpTarget
Definition: localplayer.h:472
int mLastTargetY
Definition: localplayer.h:460
time_t mAdvertTime
Definition: localplayer.h:502
void attack(Being *const target, const bool keep, const bool dontChangeEquipment)
unsigned char mWalkingDir
Definition: localplayer.h:509
void pingRequest()
void setGroupId(const int id)
bool mKeepAttacking
Definition: localplayer.h:530
void targetMoved() const
void setAction(const BeingActionT &action, const int attackId)
bool mIsServerBuggy
Definition: localplayer.h:519
void imitateEmote(const Being *const being, const unsigned char action) const
static void tryMagic(const std::string &spell, const int baseMagic, const int schoolMagic, const int mana)
bool navigateTo(const int x, const int y)
void setRealPos(const int x, const int y)
int getAttackRange2() const
void stopAttack(const bool keepAttack)
void stopWalking(const bool sendToServer)
time_t mAfkTime
Definition: localplayer.h:487
std::list< MessagePair > mMessages
Definition: localplayer.h:480
OkDialog * mAwayDialog
Definition: localplayer.h:483
bool mGoingToTarget
Definition: localplayer.h:528
bool mEnableAdvert
Definition: localplayer.h:516
AwayListener * getAwayListener() const
Definition: localplayer.h:419
void setImitate(const std::string &player)
bool mShowNavigePath
Definition: localplayer.h:534
bool mTradebot
Definition: localplayer.h:517
bool mAttackNext
Definition: localplayer.h:523
void setHalfAway(const bool n)
Definition: localplayer.h:236
void slowLogic()
void setMoveState(const unsigned int n)
Definition: localplayer.h:196
void optionChanged(const std::string &value)
bool mBlockAdvert
Definition: localplayer.h:512
void setDestination(const int x, const int y)
void setTestParticle(const std::string &fileName, const bool updateHash)
void actorSpriteDestroyed(const ActorSprite &actorSprite)
bool isPathSetByMouse() const
Definition: localplayer.h:190
void move(const int dX, const int dY)
void handleStatusEffect(const StatusEffect *const effect, const int32_t effectId, const Enable newStatus, const IsStart start)
time_t mTestParticleTime
Definition: localplayer.h:505
void moveByDirection(const unsigned char dir)
bool withinAttackRange(const Being *const target, const bool fixDistance, const int addRange) const
void setAfkTime(const int v)
Definition: localplayer.h:413
unsigned int mMoveState
Definition: localplayer.h:457
bool getHalfAway() const
Definition: localplayer.h:239
void setAway(const std::string &message) const
unsigned long mTestParticleHash
Definition: localplayer.h:506
void addJobMessage(const int64_t change)
const std::string & getImitate() const
Definition: localplayer.h:342
std::string mPlayerImitated
Definition: localplayer.h:468
bool mTargetOnlyReachable
Definition: localplayer.h:518
Being * mTarget
Definition: localplayer.h:464
unsigned int getMoveState() const
Definition: localplayer.h:193
void unSetPickUpTarget()
Definition: localplayer.h:325
bool getRename() const
Definition: localplayer.h:425
int mPingSendTick
Definition: localplayer.h:485
VisibleName::Type mVisibleNames
Definition: localplayer.h:515
void navigateClean()
void imitateOutfit(const Being *const player, const int sprite) const
bool allowAction()
void afkRespond(ChatTab *const tab, const std::string &nick)
void magicAttack() const
std::pair< std::string, UserColorIdT > MessagePair
Definition: localplayer.h:478
Particle * mTestParticle
Definition: localplayer.h:503
void checkNewName(Being *const being)
void setRename(const bool r)
Definition: localplayer.h:422
std::string mPlayerFollowed
Definition: localplayer.h:467
int getNextDestY() const
Definition: localplayer.h:317
BeingId mNavigateId
Definition: localplayer.h:491
bool mPathSetByMouse
Definition: localplayer.h:532
void setGotoTarget(Being *const target)
static bool emote(const uint8_t emotion)
std::string mLastHitFrom
Definition: localplayer.h:500
int getPathLength(const Being *const being) const
void addXpMessage(const int64_t change)
time_t mActivityTime
Definition: localplayer.h:488
std::string mWaitFor
Definition: localplayer.h:501
void pingResponse()
void addSpMessage(const int change)
bool mDrawPath
Definition: localplayer.h:521
void changeEquipmentBeforeAttack(const Being *const target) const
void loadHomes()
void specialMove(const unsigned char direction)
Being * setNewTarget(const ActorTypeT type, const AllowSort allowSort)
static void setPseudoAway(const std::string &message)
bool isReachable(Being *const being, const int maxCost)
bool isServerBuggy() const
Definition: localplayer.h:276
static void setAfkMessage(std::string message)
time_t mPingTime
Definition: localplayer.h:486
void addMessageToQueue(const std::string &message, const UserColorIdT color)
bool mShowServerPos
Definition: localplayer.h:525
unsigned char getBlockWalkMask() const A_CONST
bool mNextStep
Definition: localplayer.h:526
void saveHomes()
bool canMove() const
void setAwayDialog(OkDialog *const dialog)
Definition: localplayer.h:416
bool pickUp(FloorItem *const item)
void updateStatus() const
void pathSetByMouse()
Definition: localplayer.h:186
void pickedUp(const ItemInfo &itemInfo, const int amount, const ItemColor color, const BeingId floorItemId, const PickupT fail)
int mLastTargetX
Definition: localplayer.h:459
void playerDeath()
void imitateAction(const Being *const being, const BeingActionT &action)
void updateMusic() const
void tryPingRequest()
bool mSyncPlayerMove
Definition: localplayer.h:520
const std::string & getFollow() const
Definition: localplayer.h:336
int mSyncPlayerMoveDistance
Definition: localplayer.h:507
Keep mServerAttack
Definition: localplayer.h:514
bool updateSit() const
std::map< std::string, Vector > mHomes
Definition: localplayer.h:462
void cancelFollow()
Position getNextWalkPosition(const unsigned char dir) const
const FloorItem * getPickUpTarget() const
Definition: localplayer.h:322
Definition: map.h:75
bool Enable
Definition: enable.h:30
bool IsStart
Definition: isstart.h:30
uint16_t ItemColor
Definition: itemcolor.h:30
bool Keep
Definition: keep.h:30
#define restrict2
Definition: localconsts.h:166
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
LocalPlayer * localPlayer
bool itemInfo(InputEvent &event)
Definition: commands.cpp:105
Pickup ::T PickupT
Definition: pickup.h:44
std::list< Position > Path
Definition: position.h:49
std::string fileName
Definition: testmain.cpp:39
UserColorId ::T UserColorIdT
Definition: usercolorid.h:99