3
* Copyright (C) 2004-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
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
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.
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/>.
26
#include "actorspritelistener.h"
28
#include "depricatedlistener.h"
29
#include "localconsts.h"
31
#include "gui/userpalette.h"
33
#include <guichan/actionlistener.hpp>
45
class AwayListener final : public gcn::ActionListener
48
void action(const gcn::ActionEvent &event) override;
52
* Reasons an item can fail to be picked up.
66
* The local player character.
68
class LocalPlayer final : public Being,
69
public ActorSpriteListener,
70
public DepricatedListener
76
explicit LocalPlayer(const int id = 65535, const int subtype = 0);
78
A_DELETE_COPY(LocalPlayer)
85
virtual void logic() override;
89
virtual void setAction(const Action &action,
90
const int attackType = 0) override;
93
* Compute the next pathnode location when walking using keyboard.
96
Position getNextWalkPosition(const unsigned char dir)
100
* Adds a new tile to the path when walking.
102
* Also, when specified, it picks up an item at the end of a path
105
virtual void nextTile() override
108
virtual void nextTile(unsigned char dir);
110
bool pickUp(FloorItem *const item);
113
* Called when an ActorSprite has been destroyed.
114
* @param actorSprite the ActorSprite being destroyed.
116
void actorSpriteDestroyed(const ActorSprite &actorSprite) override;
119
* Gets the attack range.
121
int getAttackRange() const A_WARN_UNUSED;
123
int getAttackRange2() const A_WARN_UNUSED;
125
void attack(Being *const target = nullptr, const bool keep = false,
126
const bool dontChangeEquipment = false);
128
void attack2(Being *const target = nullptr, const bool keep = false,
129
const bool dontChangeEquipment = false);
131
void setGMLevel(const int level);
133
int getGMLevel() const A_WARN_UNUSED
136
void stopAttack(const bool keepAttack = false);
141
* Returns the current target of the player. Returns 0 if no being is
142
* currently targeted.
144
Being *getTarget() const A_WARN_UNUSED;
147
* Sets the target being of the player.
149
void setTarget(Being *const target);
152
* Sets a new destination for this being to walk to.
154
virtual void setDestination(const int x, const int y);
157
* Sets a new direction to keep walking in.
159
void setWalkingDir(const unsigned char dir);
162
* Gets the walking direction
164
unsigned char getWalkingDir() const A_WARN_UNUSED
165
{ return mWalkingDir; }
168
* Sets going to being to attack
170
void setGotoTarget(Being *const target);
173
* Returns whether the target is in range to attack
175
bool withinAttackRange(const Being *const target,
176
const bool fixDistance = false,
177
const int addRange = 0) const A_WARN_UNUSED;
180
* Stops the player dead in his tracks
182
void stopWalking(const bool sendToServer = true);
184
bool toggleSit() const;
186
bool updateSit() const;
188
static bool emote(const uint8_t emotion);
191
* Shows item pickup notifications.
193
void pickedUp(const ItemInfo &itemInfo, const int amount,
194
const unsigned char color, const int floorItemId,
195
const unsigned char fail);
197
int getLevel() const override A_WARN_UNUSED;
199
/** Tells that the path has been set by mouse. */
200
void pathSetByMouse()
201
{ mPathSetByMouse = true; }
203
/** Tells if the path has been set by mouse. */
204
bool isPathSetByMouse() const A_WARN_UNUSED
205
{ return mPathSetByMouse; }
207
int getInvertDirection() const A_WARN_UNUSED
208
{ return mInvertDirection; }
210
void setInvertDirection(const int n)
211
{ mInvertDirection = n; }
213
void invertDirection();
215
int getAttackWeaponType() const A_WARN_UNUSED
216
{ return mAttackWeaponType; }
218
int getAttackType() const A_WARN_UNUSED
219
{ return mAttackType; }
221
int getFollowMode() const A_WARN_UNUSED
222
{ return mFollowMode; }
224
int getImitationMode() const A_WARN_UNUSED
225
{ return mImitationMode; }
227
void changeAttackWeaponType();
229
void changeAttackType();
231
void changeFollowMode();
233
void changeImitationMode();
235
void changePickUpType();
237
int getCrazyMoveType() const A_WARN_UNUSED
238
{ return mCrazyMoveType; }
240
int getPickUpType() const A_WARN_UNUSED
241
{ return mPickUpType; }
243
int getQuickDropCounter() const A_WARN_UNUSED
244
{ return mQuickDropCounter; }
246
void setQuickDropCounter(const int n);
248
void changeQuickDropCounter();
250
int getMoveState() const A_WARN_UNUSED
251
{ return mMoveState; }
253
void setMoveState(const int n)
256
void switchMagicAttack();
258
void switchPvpAttack();
260
int getMagicAttackType() const A_WARN_UNUSED
261
{ return mMagicAttackType; }
263
int getPvpAttackType() const A_WARN_UNUSED
264
{ return mPvpAttackType; }
266
int getMoveToTargetType() const A_WARN_UNUSED
267
{ return mMoveToTargetType; }
269
int getDisableGameModifiers() const A_WARN_UNUSED
270
{ return mDisableGameModifiers; }
272
std::string getPingTime() const A_WARN_UNUSED;
274
void tryPingRequest();
276
void changeMoveToTargetType();
278
void switchGameModifiers();
280
void magicAttack() const;
282
void specialMove(const unsigned char direction);
284
void moveByDirection(const unsigned char dir);
286
bool pickUpItems(int pickUpType = 0);
288
void changeCrazyMoveType();
292
void moveTo(const int x, const int y);
294
void move(const int dX, const int dY);
296
void moveToTarget(int dist = -1);
300
void debugMsg(const std::string &str) const;
302
bool isReachable(Being *const being,
303
const int maxCost = 0) A_WARN_UNUSED;
305
bool isReachable(const int x, const int y,
306
const bool allowCollision) const A_WARN_UNUSED;
314
void changeAwayMode();
316
void setAway(const std::string &message);
318
void setPseudoAway(const std::string &message);
320
bool getAway() const A_WARN_UNUSED
321
{ return mAwayMode; }
323
bool getPseudoAway() const A_WARN_UNUSED
324
{ return mPseudoAwayMode; }
326
void setHalfAway(const bool n)
329
bool getHalfAway() const A_WARN_UNUSED
330
{ return mInactive; }
332
void afkRespond(ChatTab *const tab, const std::string &nick);
334
bool navigateTo(const int x, const int y);
336
void navigateTo(const Being *const being);
338
void navigateClean();
340
void imitateEmote(const Being *const being,
341
const unsigned char emote) const;
343
void imitateAction(const Being *const being,
344
const Being::Action &action);
346
void imitateDirection(const Being *const being,
347
const unsigned char dir);
349
void imitateOutfit(Being *const player, const int sprite = -1) const;
351
void followMoveTo(const Being *const being, const int x, const int y);
353
void followMoveTo(const Being *const being, const int x1, const int y1,
354
const int x2, const int y2);
356
bool allowAction() A_WARN_UNUSED;
358
void setRealPos(const int x, const int y);
360
bool isServerBuggy() const A_WARN_UNUSED
361
{ return mIsServerBuggy; }
363
void fixPos(const int maxDist = 1);
366
* Sets the map the being is on
368
void setMap(Map *const map);
370
void addMessageToQueue(const std::string &message,
371
const int color = UserPalette::EXP_INFO);
374
* Called when a option (set with config.addListener()) is changed
376
void optionChanged(const std::string &value) override;
378
void processEvent(Channels channel,
379
const DepricatedEvent &event) override;
382
* set a following player.
384
void setFollow(const std::string &player);
387
* set an imitation player.
389
void setImitate(const std::string &player);
392
* setting the next destination of the following, in case of warp
394
void setNextDest(const int x, const int y);
396
int getNextDestX() const A_WARN_UNUSED
397
{ return mNextDestX; }
399
int getNextDestY() const A_WARN_UNUSED
400
{ return mNextDestY; }
404
const FloorItem *getPickUpTarget() const A_WARN_UNUSED
405
{ return mPickUpTarget; }
407
void unSetPickUpTarget()
408
{ mPickUpTarget = nullptr; }
411
* Stop following a player.
416
* Get the playername followed by the current player.
418
const std::string &getFollow() const A_WARN_UNUSED
419
{ return mPlayerFollowed; }
422
* Get the playername imitated by the current player.
424
const std::string &getImitate() const A_WARN_UNUSED
425
{ return mPlayerImitated; }
428
* Tells the engine whether to check
429
* if the Player Name is to be displayed.
431
void setCheckNameSetting(const bool checked)
432
{ mUpdateName = checked; }
435
* Gets if the engine has to check
436
* if the Player Name is to be displayed.
438
bool getCheckNameSetting() const A_WARN_UNUSED
439
{ return mUpdateName; }
441
void fixAttackTarget();
443
void updateNavigateList();
445
int getPathLength(const Being *const being) const A_WARN_UNUSED;
447
void targetMoved() const;
449
void setLastHitFrom(const std::string &n)
450
{ mLastHitFrom = n; }
452
void waitFor(const std::string &nick);
454
void checkNewName(Being *const being);
456
void resetYellowBar();
458
unsigned char getWalkMask() const override A_WARN_UNUSED;
466
bool checAttackPermissions(const Being *const target)
469
void updateStatus() const;
471
void setTestParticle(const std::string &fileName,
472
bool updateHash = true);
474
std::string getInvertDirectionString();
476
std::string getCrazyMoveTypeString();
478
std::string getMoveToTargetTypeString();
480
std::string getFollowModeString();
482
std::string getAttackWeaponTypeString();
484
std::string getAttackTypeString();
486
std::string getQuickDropCounterString();
488
std::string getPickUpTypeString();
490
std::string getDebugPathString() const;
492
std::string getMagicAttackString();
494
std::string getPvpAttackString();
496
std::string getImitationModeString();
498
std::string getAwayModeString();
500
std::string getCameraModeString() const;
502
std::string getGameModifiersString();
505
void updateCoords() override;
508
virtual void handleStatusEffect(StatusEffect *const effect,
511
void startWalking(const unsigned char dir);
513
void changeEquipmentBeforeAttack(const Being *const target) const;
515
static void tryMagic(const std::string &spell, const int baseMagic,
516
const int schoolMagic, const int mana);
518
const char *getVarItem(const char *const *const arr,
519
const unsigned index,
520
const unsigned sz) const A_WARN_UNUSED;
522
void changeMode(unsigned *const var, const unsigned limit,
523
const char *const conf,
524
std::string (LocalPlayer::*const func)(),
525
const unsigned def = 0,
526
const bool save = true);
544
unsigned int mInvertDirection;
546
unsigned int mCrazyMoveType;
548
unsigned int mCrazyMoveState;
549
// attack weapon type
550
unsigned int mAttackWeaponType;
551
// quick drop counter
552
unsigned int mQuickDropCounter;
553
// move state. used if mInvertDirection == 2
554
unsigned int mMoveState;
555
// pick up type 1x1, normal aka 2x1, forward aka 2x3, 3x3, 3x3 + 1
556
unsigned int mPickUpType;
558
unsigned int mMagicAttackType;
560
unsigned int mPvpAttackType;
561
// type how move to target
562
unsigned int mMoveToTargetType;
563
unsigned int mAttackType;
564
unsigned int mFollowMode;
565
unsigned int mImitationMode;
570
std::map<std::string, Vector> mHomes;
574
/** Follow system **/
575
std::string mPlayerFollowed;
576
std::string mPlayerImitated;
580
FloorItem *mPickUpTarget;
582
int mLastAction; // Time stamp of the last action, -1 if none.
584
std::vector<int> mStatusEffectIcons;
586
int mLocalWalkTime; // Timestamp used to control keyboard walk
589
typedef std::pair<std::string, int> MessagePair;
590
/** Queued messages*/
591
std::list<MessagePair> mMessages;
593
AwayListener *mAwayListener;
594
OkDialog *mAwayDialog;
611
std::string mLastHitFrom;
612
std::string mWaitFor;
614
Particle *mTestParticle;
615
std::string mTestParticleName;
616
int mTestParticleTime;
617
unsigned long mTestParticleHash;
618
unsigned char mWalkingDir; // The direction the player is walking in.
619
/** Whether or not the name settings have changed */
622
bool mTargetDeadPlayers;
626
bool mTargetOnlyReachable;
627
bool mDisableGameModifiers;
629
bool mSyncPlayerMove;
635
// temporary disable crazy moves in moves
636
bool mDisableCrazyMove;
638
// Whether or not to continue to attack
640
// Tells if the path was set using mouse
641
bool mPathSetByMouse;
644
bool mPseudoAwayMode;
645
bool mShowNavigePath;
648
extern LocalPlayer *player_node;
650
#endif // LOCALPLAYER_H