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/>.
23
#ifndef BEING_LOCALPLAYER_H
24
#define BEING_LOCALPLAYER_H
26
#include "depricatedlistener.h"
28
#include "being/actorspritelistener.h"
29
#include "being/being.h"
31
#include "gui/userpalette.h"
33
#include <guichan/actionlistener.hpp>
37
#include "localconsts.h"
44
class AwayListener final : public gcn::ActionListener
47
void action(const gcn::ActionEvent &event) override;
51
* Reasons an item can fail to be picked up.
65
* The local player character.
67
class LocalPlayer final : public Being,
68
public ActorSpriteListener,
69
public DepricatedListener
75
explicit LocalPlayer(const int id = 65535, const int subtype = 0);
77
A_DELETE_COPY(LocalPlayer)
84
virtual void logic() override;
88
virtual void setAction(const Action &action,
89
const int attackType = 0) override;
92
* Compute the next pathnode location when walking using keyboard.
95
Position getNextWalkPosition(const unsigned char dir)
99
* Adds a new tile to the path when walking.
101
* Also, when specified, it picks up an item at the end of a path
104
virtual void nextTile() override
107
virtual void nextTile(unsigned char dir);
109
bool pickUp(FloorItem *const item);
112
* Called when an ActorSprite has been destroyed.
113
* @param actorSprite the ActorSprite being destroyed.
115
void actorSpriteDestroyed(const ActorSprite &actorSprite) override;
118
* Gets the attack range.
120
int getAttackRange() const A_WARN_UNUSED;
122
int getAttackRange2() const A_WARN_UNUSED;
124
void attack(Being *const target = nullptr, const bool keep = false,
125
const bool dontChangeEquipment = false);
127
void attack2(Being *const target = nullptr, const bool keep = false,
128
const bool dontChangeEquipment = false);
130
void setGMLevel(const int level);
132
int getGMLevel() const A_WARN_UNUSED
135
void stopAttack(const bool keepAttack = false);
140
* Returns the current target of the player. Returns 0 if no being is
141
* currently targeted.
143
Being *getTarget() const A_WARN_UNUSED;
146
* Sets the target being of the player.
148
void setTarget(Being *const target);
151
* Sets a new destination for this being to walk to.
153
virtual void setDestination(const int x, const int y);
156
* Sets a new direction to keep walking in.
158
void setWalkingDir(const unsigned char dir);
161
* Gets the walking direction
163
unsigned char getWalkingDir() const A_WARN_UNUSED
164
{ return mWalkingDir; }
167
* Sets going to being to attack
169
void setGotoTarget(Being *const target);
172
* Returns whether the target is in range to attack
174
bool withinAttackRange(const Being *const target,
175
const bool fixDistance = false,
176
const int addRange = 0) const A_WARN_UNUSED;
179
* Stops the player dead in his tracks
181
void stopWalking(const bool sendToServer = true);
183
bool toggleSit() const;
185
bool updateSit() const;
187
static bool emote(const uint8_t emotion);
190
* Shows item pickup notifications.
192
void pickedUp(const ItemInfo &itemInfo, const int amount,
193
const unsigned char color, const int floorItemId,
194
const unsigned char fail);
196
int getLevel() const override A_WARN_UNUSED;
198
/** Tells that the path has been set by mouse. */
199
void pathSetByMouse()
200
{ mPathSetByMouse = true; }
202
/** Tells if the path has been set by mouse. */
203
bool isPathSetByMouse() const A_WARN_UNUSED
204
{ return mPathSetByMouse; }
206
int getInvertDirection() const A_WARN_UNUSED
207
{ return mInvertDirection; }
209
void setInvertDirection(const int n)
210
{ mInvertDirection = n; }
212
void invertDirection();
214
int getAttackWeaponType() const A_WARN_UNUSED
215
{ return mAttackWeaponType; }
217
int getAttackType() const A_WARN_UNUSED
218
{ return mAttackType; }
220
int getFollowMode() const A_WARN_UNUSED
221
{ return mFollowMode; }
223
int getImitationMode() const A_WARN_UNUSED
224
{ return mImitationMode; }
226
void changeAttackWeaponType();
228
void changeAttackType();
230
void changeFollowMode();
232
void changeImitationMode();
234
void changePickUpType();
236
int getCrazyMoveType() const A_WARN_UNUSED
237
{ return mCrazyMoveType; }
239
int getPickUpType() const A_WARN_UNUSED
240
{ return mPickUpType; }
242
int getQuickDropCounter() const A_WARN_UNUSED
243
{ return mQuickDropCounter; }
245
void setQuickDropCounter(const int n);
247
void changeQuickDropCounter();
249
int getMoveState() const A_WARN_UNUSED
250
{ return mMoveState; }
252
void setMoveState(const int n)
255
void switchMagicAttack();
257
void switchPvpAttack();
259
int getMagicAttackType() const A_WARN_UNUSED
260
{ return mMagicAttackType; }
262
int getPvpAttackType() const A_WARN_UNUSED
263
{ return mPvpAttackType; }
265
int getMoveToTargetType() const A_WARN_UNUSED
266
{ return mMoveToTargetType; }
268
int getDisableGameModifiers() const A_WARN_UNUSED
269
{ return mDisableGameModifiers; }
271
std::string getPingTime() const A_WARN_UNUSED;
273
void tryPingRequest();
275
void changeMoveToTargetType();
277
void switchGameModifiers();
279
void magicAttack() const;
281
void specialMove(const unsigned char direction);
283
void moveByDirection(const unsigned char dir);
285
bool pickUpItems(int pickUpType = 0);
287
void changeCrazyMoveType();
291
void moveTo(const int x, const int y);
293
void move(const int dX, const int dY);
295
void moveToTarget(int dist = -1);
299
void debugMsg(const std::string &str) const;
301
bool isReachable(Being *const being,
302
const int maxCost = 0) A_WARN_UNUSED;
304
bool isReachable(const int x, const int y,
305
const bool allowCollision) const A_WARN_UNUSED;
313
void changeAwayMode();
315
void setAway(const std::string &message);
317
void setPseudoAway(const std::string &message);
319
bool getAway() const A_WARN_UNUSED
320
{ return mAwayMode; }
322
bool getPseudoAway() const A_WARN_UNUSED
323
{ return mPseudoAwayMode; }
325
void setHalfAway(const bool n)
328
bool getHalfAway() const A_WARN_UNUSED
329
{ return mInactive; }
331
void afkRespond(ChatTab *const tab, const std::string &nick);
333
bool navigateTo(const int x, const int y);
335
void navigateTo(const Being *const being);
337
void navigateClean();
339
void imitateEmote(const Being *const being,
340
const unsigned char emote) const;
342
void imitateAction(const Being *const being,
343
const Being::Action &action);
345
void imitateDirection(const Being *const being,
346
const unsigned char dir);
348
void imitateOutfit(Being *const player, const int sprite = -1) const;
350
void followMoveTo(const Being *const being, const int x, const int y);
352
void followMoveTo(const Being *const being, const int x1, const int y1,
353
const int x2, const int y2);
355
bool allowAction() A_WARN_UNUSED;
357
void setRealPos(const int x, const int y);
359
bool isServerBuggy() const A_WARN_UNUSED
360
{ return mIsServerBuggy; }
362
void fixPos(const int maxDist = 1);
365
* Sets the map the being is on
367
void setMap(Map *const map);
369
void addMessageToQueue(const std::string &message,
370
const int color = UserPalette::EXP_INFO);
373
* Called when a option (set with config.addListener()) is changed
375
void optionChanged(const std::string &value) override;
377
void processEvent(Channels channel,
378
const DepricatedEvent &event) override;
381
* set a following player.
383
void setFollow(const std::string &player);
386
* set an imitation player.
388
void setImitate(const std::string &player);
391
* setting the next destination of the following, in case of warp
393
void setNextDest(const int x, const int y);
395
int getNextDestX() const A_WARN_UNUSED
396
{ return mNextDestX; }
398
int getNextDestY() const A_WARN_UNUSED
399
{ return mNextDestY; }
403
const FloorItem *getPickUpTarget() const A_WARN_UNUSED
404
{ return mPickUpTarget; }
406
void unSetPickUpTarget()
407
{ mPickUpTarget = nullptr; }
410
* Stop following a player.
415
* Get the playername followed by the current player.
417
const std::string &getFollow() const A_WARN_UNUSED
418
{ return mPlayerFollowed; }
421
* Get the playername imitated by the current player.
423
const std::string &getImitate() const A_WARN_UNUSED
424
{ return mPlayerImitated; }
427
* Tells the engine whether to check
428
* if the Player Name is to be displayed.
430
void setCheckNameSetting(const bool checked)
431
{ mUpdateName = checked; }
434
* Gets if the engine has to check
435
* if the Player Name is to be displayed.
437
bool getCheckNameSetting() const A_WARN_UNUSED
438
{ return mUpdateName; }
440
void fixAttackTarget();
442
void updateNavigateList();
444
int getPathLength(const Being *const being) const A_WARN_UNUSED;
446
void targetMoved() const;
448
void setLastHitFrom(const std::string &n)
449
{ mLastHitFrom = n; }
451
void waitFor(const std::string &nick);
453
void checkNewName(Being *const being);
455
void resetYellowBar();
457
unsigned char getWalkMask() const override A_WARN_UNUSED;
465
bool checAttackPermissions(const Being *const target)
468
void updateStatus() const;
470
void setTestParticle(const std::string &fileName,
471
bool updateHash = true);
473
std::string getInvertDirectionString();
475
std::string getCrazyMoveTypeString();
477
std::string getMoveToTargetTypeString();
479
std::string getFollowModeString();
481
std::string getAttackWeaponTypeString();
483
std::string getAttackTypeString();
485
std::string getQuickDropCounterString();
487
std::string getPickUpTypeString();
489
std::string getDebugPathString() const;
491
std::string getMagicAttackString();
493
std::string getPvpAttackString();
495
std::string getImitationModeString();
497
std::string getAwayModeString();
499
std::string getCameraModeString() const;
501
std::string getGameModifiersString();
504
void updateCoords() override;
507
virtual void handleStatusEffect(StatusEffect *const effect,
510
void startWalking(const unsigned char dir);
512
void changeEquipmentBeforeAttack(const Being *const target) const;
514
static void tryMagic(const std::string &spell, const int baseMagic,
515
const int schoolMagic, const int mana);
517
const char *getVarItem(const char *const *const arr,
518
const unsigned index,
519
const unsigned sz) const A_WARN_UNUSED;
521
void changeMode(unsigned *const var, const unsigned limit,
522
const char *const conf,
523
std::string (LocalPlayer::*const func)(),
524
const unsigned def = 0,
525
const bool save = true);
543
unsigned int mInvertDirection;
545
unsigned int mCrazyMoveType;
547
unsigned int mCrazyMoveState;
548
// attack weapon type
549
unsigned int mAttackWeaponType;
550
// quick drop counter
551
unsigned int mQuickDropCounter;
552
// move state. used if mInvertDirection == 2
553
unsigned int mMoveState;
554
// pick up type 1x1, normal aka 2x1, forward aka 2x3, 3x3, 3x3 + 1
555
unsigned int mPickUpType;
557
unsigned int mMagicAttackType;
559
unsigned int mPvpAttackType;
560
// type how move to target
561
unsigned int mMoveToTargetType;
562
unsigned int mAttackType;
563
unsigned int mFollowMode;
564
unsigned int mImitationMode;
569
std::map<std::string, Vector> mHomes;
573
/** Follow system **/
574
std::string mPlayerFollowed;
575
std::string mPlayerImitated;
579
FloorItem *mPickUpTarget;
581
int mLastAction; // Time stamp of the last action, -1 if none.
583
std::vector<int> mStatusEffectIcons;
585
int mLocalWalkTime; // Timestamp used to control keyboard walk
588
typedef std::pair<std::string, int> MessagePair;
589
/** Queued messages*/
590
std::list<MessagePair> mMessages;
592
AwayListener *mAwayListener;
593
OkDialog *mAwayDialog;
610
std::string mLastHitFrom;
611
std::string mWaitFor;
613
Particle *mTestParticle;
614
std::string mTestParticleName;
615
int mTestParticleTime;
616
unsigned long mTestParticleHash;
617
unsigned char mWalkingDir; // The direction the player is walking in.
618
/** Whether or not the name settings have changed */
621
bool mTargetDeadPlayers;
625
bool mTargetOnlyReachable;
626
bool mDisableGameModifiers;
628
bool mSyncPlayerMove;
634
// temporary disable crazy moves in moves
635
bool mDisableCrazyMove;
637
// Whether or not to continue to attack
639
// Tells if the path was set using mouse
640
bool mPathSetByMouse;
643
bool mPseudoAwayMode;
644
bool mShowNavigePath;
647
extern LocalPlayer *player_node;
649
#endif // BEING_LOCALPLAYER_H