Mana
Loading...
Searching...
No Matches
localplayer.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "being.h"
25
27
28#include "utils/time.h"
29
30#include <guichan/actionlistener.hpp>
31#include <guichan/deathlistener.hpp>
32
33#include <memory>
34
35class ChatTab;
36class FloorItem;
37class ImageSet;
38class Map;
39class OkDialog;
40
41class AwayListener : public gcn::ActionListener, public gcn::DeathListener
42{
43 public:
44 AwayListener() = default;
45 ~AwayListener() override;
46
47 void showDialog(const std::string &message);
48 void closeDialog();
49
50 void action(const gcn::ActionEvent &event) override;
51 void death(const gcn::Event &event) override;
52
53 private:
55};
56
60enum
61{
69};
70
74class LocalPlayer final : public Being
75{
76 public:
77 LocalPlayer(int id = 65535, int subtype = 0);
78 ~LocalPlayer() override;
79
80 void logic() override;
81
82 void setAction(Action action, int attackId = 1) override;
83
87 bool checkInviteRights(const std::string &guildName);
88
92 void inviteToGuild(Being *being);
93
94 void pickUp(FloorItem *item);
95
99 void setAttackRange(int range);
100
104 int getAttackRange() const
105 { return mAttackRange; }
106
107 void attack(Being *target = nullptr, bool keep = false);
108
109 void setGMLevel(int level);
110
111 void stopAttack();
112
117 Being *getTarget() const;
118
122 void setTarget(Being *target);
123
127 virtual void setDestination(int x, int y);
128 virtual void setDestination(const Vector &dest)
129 { setDestination((int)dest.x, (int)dest.y); }
130 virtual void setDestination(const Position &dest)
131 { setDestination(dest.x, dest.y); }
132
137 void setWalkingDir(int dir);
138
142 int getWalkingDir() const
143 { return mWalkingDir; }
144
148 void setGotoTarget(Being *target);
149
156
160 bool withinRange(Actor *target, int range) const;
161
162 void toggleSit();
163 void emote(int emoteId);
164
168 void pickedUp(const ItemInfo &itemInfo, int amount,
169 unsigned char fail);
170
171 void setShowIp(bool show)
172 { mShowIp = show; }
173
174 bool getShowIp() const
175 { return mShowIp; }
176
179 { mPathSetByMouse = true; }
180
182 bool isPathSetByMouse() const
183 { return mPathSetByMouse; }
184
185 void setAwayMode(bool away);
186 bool getAwayMode() const
187 { return mAwayMode; }
188
189 void afkRespond(ChatTab *tab, const std::string &nick);
190
191 void addMessageToQueue(const std::string &message,
192 int color = UserPalette::EXP_INFO);
193
194 void event(Event::Channel channel, const Event &event) override;
195
196 protected:
197 void updateStatusEffect(int id, bool newStatus) override;
198
200 void startWalking(unsigned char dir);
201
205 void stopWalking(bool sendToServer = true);
206
210 void nextTile(unsigned char dir);
211
216 Position getNextWalkPosition(unsigned char dir) const;
217
218 void pathFinished() override { nextTile(mWalkingDir); }
219
220 int mAttackRange = -1;
221
224 int mGMLevel = 0;
225
226 Being *mTarget = nullptr;
227
229
230 bool mGoingToTarget = false;
231 bool mKeepAttacking = false;
233 int mWalkingDir = 0;
234 bool mPathSetByMouse = false;
237 std::list<std::pair<std::string, int>> mMessages;
239
240 bool mShowIp = false;
241
242 std::unique_ptr<AwayListener> mAwayListener;
244 bool mAwayMode = false;
245};
246
An action consists of several animations, one for each direction.
Definition action.h:32
Definition actor.h:35
void action(const gcn::ActionEvent &event) override
OkDialog * mAwayDialog
Definition localplayer.h:54
~AwayListener() override
AwayListener()=default
void showDialog(const std::string &message)
void death(const gcn::Event &event) override
Definition being.h:65
A tab for the chat window.
Definition chattab.h:36
Definition event.h:42
Channel
Definition event.h:45
An item lying on the floor.
Definition flooritem.h:32
Stores a set of subimages originating from a single image.
Definition imageset.h:34
Defines a class for storing generic item infos.
Definition iteminfo.h:100
The local player character.
Definition localplayer.h:75
bool getAwayMode() const
int getWalkingDir() const
Gets the walking direction.
void setTarget(Being *target)
Sets the target being of the player.
std::list< std::pair< std::string, int > > mMessages
Queued messages.
void setAttackRange(int range)
Sets the attack range.
virtual void setDestination(const Position &dest)
void afkRespond(ChatTab *tab, const std::string &nick)
void pickedUp(const ItemInfo &itemInfo, int amount, unsigned char fail)
Shows item pickup notifications.
void setGMLevel(int level)
void inviteToGuild(Being *being)
Invite a player to join guild.
void addMessageToQueue(const std::string &message, int color=UserPalette::EXP_INFO)
Being * getTarget() const
Returns the current target of the player.
int getAttackRange() const
Gets the attack range.
void updateStatusEffect(int id, bool newStatus) override
Notify self that a status effect has flipped.
void setAction(Action action, int attackId=1) override
Sets the current action.
virtual void setDestination(int x, int y)
Sets a new destination for this being to walk to.
virtual void setDestination(const Vector &dest)
FloorItem * mPickUpTarget
std::unique_ptr< AwayListener > mAwayListener
Position getNextWalkPosition(unsigned char dir) const
Compute the next pathnode location when walking using keyboard.
bool mKeepAttacking
Whether or not to continue to attack.
void setShowIp(bool show)
bool mGoingToTarget
Timer mMessageTimer
void setWalkingDir(int dir)
Sets a new direction to keep walking in, when using the keyboard or the joystick.
bool isPathSetByMouse() const
Tells if the path has been set by mouse.
void event(Event::Channel channel, const Event &event) override
void emote(int emoteId)
void setGotoTarget(Being *target)
Sets going to being to attack.
Being * mTarget
bool withinRange(Actor *target, int range) const
Returns whether the target is in range (in pixels).
void setAwayMode(bool away)
void pickUp(FloorItem *item)
Timer mLastTargetTimer
Timer for last targeting action.
void cancelGoToTarget()
Cancel a possible target destination in progress, but not the targeting.
void attack(Being *target=nullptr, bool keep=false)
bool mPathSetByMouse
Tells if the path was set using mouse.
void stopWalking(bool sendToServer=true)
Stops the player dead in his tracks.
int mWalkingDir
The direction the player is walking in.
~LocalPlayer() override
bool getShowIp() const
Timer mLastActionTimer
Timeout for the last action.
Timer mAfkTimer
bool checkInviteRights(const std::string &guildName)
Check the player has permission to invite users to specific guild.
void logic() override
Performs being logic.
void pathFinished() override
Called when the being has reached the end of its path.
void pathSetByMouse()
Tells that the path has been set by mouse.
void stopAttack()
void nextTile(unsigned char dir)
set the next path tile when walking and using the keyboard.
void startWalking(unsigned char dir)
Make the character starts to walk.
A tile map.
Definition map.h:147
An 'Ok' button dialog.
Definition okdialog.h:34
Simple timer that can be used to check if a certain amount of time has passed.
Definition time.h:62
Vector class.
Definition vector.h:33
float y
Definition vector.h:172
float x
Definition vector.h:171
LocalPlayer * local_player
@ PICKUP_DROP_STEAL
Definition localplayer.h:68
@ PICKUP_TOO_FAR
Definition localplayer.h:65
@ PICKUP_BAD_ITEM
Definition localplayer.h:63
@ PICKUP_TOO_HEAVY
Definition localplayer.h:64
@ PICKUP_OKAY
Definition localplayer.h:62
@ PICKUP_STACK_FULL
Definition localplayer.h:67
@ PICKUP_INV_FULL
Definition localplayer.h:66
A position along a being's path.
Definition position.h:31
int y
Definition position.h:37
int x
Definition position.h:36