Mana
Loading...
Searching...
No Matches
being.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 "actorsprite.h"
25#include "eventlistener.h"
26#include "gui/gui.h"
27#include "map.h"
28#include "position.h"
29#include "vector.h"
30
31#include "utils/time.h"
32
33#include <guichan/color.hpp>
34#include <guichan/deathlistener.hpp>
35
36#include <cstdint>
37#include <map>
38#include <set>
39#include <string>
40#include <vector>
41
42#define STATUS_EFFECTS 32
43
44#define SPEECH_TIME 500
45#define SPEECH_MAX_TIME 10000
46
47class BeingInfo;
48class FlashText;
49class Guild;
50class ItemInfo;
51class Particle;
52class Party;
53struct Position;
54class SpeechBubble;
55class Text;
56
57enum class Gender
58{
59 Neutral,
60 Male,
61 Female
62};
63
64class Being : public ActorSprite, public EventListener, public gcn::DeathListener
65{
66 public:
81
89
91 {
92 HIT = 0x00,
93 CRITICAL = 0x0a,
94 MULTI = 0x08,
95 REFLECT = 0x04,
96 FLEE = 0x0b
97 };
98
103 {
104 DOWN = 1,
105 LEFT = 2,
106 UP = 4,
107 RIGHT = 8
108 };
109
118 Being(int id, Type type, int subtype, Map *map);
119
120 ~Being() override;
121
122 Type getType() const final
123 { return mType; }
124
125 void setType(Type type, int subtype);
126
130 void clearPath();
131
135 void setDestination(int ex, int ey);
136
140 const Vector &getDestination() const
141 { return mDest; }
142
146 int getTileX() const override
147 { return mPos.x / mMap->getTileWidth(); }
148
152 int getTileY() const override
153 { return mPos.y / mMap->getTileHeight(); }
154
162 void setSpeech(const std::string &text, int time = 5000);
163
172 void takeDamage(Being *attacker, int damage,
173 AttackType type, int attackId = 1);
174
182 void handleAttack(Being *victim, int damage, int attackId = 1);
183
185 { return mEquippedWeapon; }
186
190 const std::string &getName() const
191 { return mName; }
192
198 void setName(const std::string &name);
199
200 bool getShowName() const
201 { return mShowName; }
202
203 void setShowName(bool doShowName);
204
208 void setPartyName(const std::string &name) { mPartyName = name; }
209
210 const std::string &getPartyName() const { return mPartyName; }
211
216 void setGuildName(const std::string &name);
217
218 void setGuildPos(const std::string &pos);
219
223 void addGuild(Guild *guild);
224
228 void removeGuild(int id);
229
233 Guild *getGuild(const std::string &guildName) const;
234
238 Guild *getGuild(int id) const;
239
243 const std::map<int, Guild*> &getGuilds() const
244 { return mGuilds; }
245
249 void clearGuilds();
250
254 short getNumberOfGuilds() const
255 { return mGuilds.size(); }
256
257 bool isInParty() const
258 { return mParty != nullptr; }
259
260 void setParty(Party *party);
261
263 { return mParty; }
264
268 void setSprite(unsigned slot, int id,
269 const std::string &color = std::string(),
270 bool isWeapon = false);
271
272 void setSpriteID(unsigned slot, int id);
273
274 void setSpriteColor(unsigned slot,
275 const std::string &color = std::string());
276
277 unsigned getSpriteCount() const
278 { return mSpriteStates.size(); }
279
280 bool drawnWhenBehind() const override;
281
285 void logic() override;
286
290 void drawSpeech(int offsetX, int offsetY);
291
292 uint16_t getSubType() const { return mSubType; }
293
294 const BeingInfo &getInfo() const
295 { return *mInfo; }
296
297 bool isTargetSelection() const;
298
299 TargetCursorSize getTargetCursorSize() const override;
300
301 Cursor getHoverCursor() const;
302
306 unsigned char getWalkMask() const;
307
311 Map::BlockType getBlockType() const override;
312
318 void setMoveSpeed(const Vector &speed);
319
325 void setAttackSpeed(int speed) { mAttackSpeed = speed; }
326
331 int getAttackSpeed() const { return mAttackSpeed; }
332
336 virtual void setAction(Action action, int attackId = 1);
337
341 void setAction(const std::string &action);
342
346 Action getCurrentAction() const { return mAction; }
347
351 bool isAlive() const { return mAction != DEAD; }
352
356 uint8_t getDirection() const { return mDirection; }
357
361 void setDirection(uint8_t direction);
362
368
369 void setPosition(const Vector &pos) final;
370
376 void setPosition(float x, float y, float z = 0.0f)
377 {
378 setPosition(Vector(x, y, z));
379 }
380
384 int getCollisionRadius() const;
385
389 void fireMissile(Being *target, const std::string &particle);
390
391 void setStatusEffect(int id, bool active);
392
397 const Path &getPath() const { return mPath; }
398
399 void flashName(int time);
400
401 int getDamageTaken() const
402 { return mDamageTaken; }
403
404 void updateName();
405
409 void setGender(Gender gender);
410
412 { return mGender; }
413
417 bool isGM() const
418 { return mIsGM; }
419
423 void setGM(bool gm);
424
429 void setIp(int ip);
430
435 int getIp() const { return mIp; }
436
437 bool canTalk();
438
439 void talkTo();
440
441 // EventListener
442 void event(Event::Channel channel, const Event &event) override;
443
444 // gcn::DeathListener
445 void death(const gcn::Event &event) override;
446
447 void setMap(Map *map) final;
448
452 void lookAt(const Vector &destVec);
453 void lookAt(const Position &destPos)
454 { lookAt(Vector(destPos.x, destPos.y)); }
455
456 protected:
457 struct SpriteState {
458 int id = 0;
459 int visibleId = 0;
460 std::string color;
461 std::vector<ParticleHandle> particles;
462 };
463
467 void setPath(const Path &path);
468
472 void updateNamePosition();
473
474 void addSpriteParticles(SpriteState &spriteState, const SpriteDisplay &display);
476
477 void updateColors();
478 void updatePlayerSprites();
479
483 int getSpeechTextYPosition() const;
484
488 virtual void pathFinished() {}
489
494 virtual void updateStatusEffect(int index, bool newStatus);
495
497
502
503 int mAttackSpeed = 350;
506 int mSubType = 0xFFFF;
510 std::string mName;
511 std::string mPartyName;
512
517 const gcn::Color *mNameColor;
518 bool mShowName = false;
519
521 const ItemInfo *mEquippedWeapon = nullptr;
522
524 std::string mSpeech;
525 Text *mText = nullptr;
526
529 std::vector<SpriteState> mSpriteStates;
531
533
534 // Character guild information
535 std::map<int, Guild*> mGuilds;
536 Party *mParty = nullptr;
537
538 bool mIsGM = false;
539
540 private:
541 void updateMovement();
542
544
545 std::set<int> mStatusEffects;
546 std::map<int, ParticleHandle> mStatusParticleEffects;
547
550
557
562
564 int mIp = 0;
565};
Gender
Definition being.h:58
An action consists of several animations, one for each direction.
Definition action.h:32
Vector mPos
Position in pixels relative to map.
Definition actor.h:114
Map * mMap
Definition actor.h:113
Holds information about a certain type of monster.
Definition beinginfo.h:59
Definition being.h:65
void setPosition(const Vector &pos) final
Sets the pixel position of this actor.
Definition being.cpp:187
unsigned getSpriteCount() const
Definition being.h:277
void setStatusEffect(int id, bool active)
Definition being.cpp:596
Party * getParty() const
Definition being.h:262
bool mIsGM
Definition being.h:538
Text * mText
Definition being.h:525
void event(Event::Channel channel, const Event &event) override
Definition being.cpp:1365
AttackType
Definition being.h:91
@ REFLECT
Definition being.h:95
@ HIT
Definition being.h:92
@ FLEE
Definition being.h:96
@ MULTI
Definition being.h:94
@ CRITICAL
Definition being.h:93
int mSubType
Subtype (graphical view, basically)
Definition being.h:506
const ItemInfo * getEquippedWeapon() const
Definition being.h:184
void setSprite(unsigned slot, int id, const std::string &color=std::string(), bool isWeapon=false)
Sets visible equipments for this being.
Definition being.cpp:1254
void setDestination(int ex, int ey)
Creates a path for the being from current position to ex and ey.
Definition being.cpp:197
bool mRestoreParticlesOnLogic
Definition being.h:530
void setGuildName(const std::string &name)
Sets the name of the primary guild the being is in.
Definition being.cpp:482
TargetCursorSize getTargetCursorSize() const override
Returns the required size of a target cursor for this being.
Definition being.cpp:153
void setShowName(bool doShowName)
Definition being.cpp:473
int mDamageTaken
Definition being.h:563
std::string mPartyName
Definition being.h:511
void setMoveSpeed(const Vector &speed)
Sets the move speed.
Definition being.cpp:173
void setDirection(uint8_t direction)
Sets the current direction.
Definition being.cpp:782
void fireMissile(Being *target, const std::string &particle)
Shoots a missile particle from this being, to target being.
Definition being.cpp:574
const BeingInfo & getInfo() const
Definition being.h:294
void setMap(Map *map) final
Definition being.cpp:1398
Action mAction
Action the being is performing.
Definition being.h:505
void updateMovement()
Definition being.cpp:858
uint8_t getDirection() const
Returns the current direction.
Definition being.h:356
void updateName()
Definition being.cpp:1029
std::string mSpeech
Definition being.h:524
unsigned char getWalkMask() const
Gets the way the object is blocked by other objects.
Definition being.cpp:163
const std::map< int, Guild * > & getGuilds() const
Returns all guilds the being is in.
Definition being.h:243
int getIp() const
Returns the player's IP or an IP hash.
Definition being.h:435
Type getType() const final
Returns the type of the ActorSprite.
Definition being.h:122
uint8_t mSpriteDirection
Facing direction.
Definition being.h:509
virtual void updateStatusEffect(int index, bool newStatus)
Notify self that a status effect has flipped.
Definition being.cpp:612
std::vector< SpriteState > mSpriteStates
Definition being.h:529
std::map< int, Guild * > mGuilds
Definition being.h:535
std::string mName
Name of character.
Definition being.h:510
SpriteDirection getSpriteDirection() const
Returns the direction the being is facing.
Definition being.h:366
SpeechBubble * mSpeechBubble
Speech Bubble components.
Definition being.h:549
bool drawnWhenBehind() const override
Determines wether the actor should be drawn translucent when behind another object.
Definition being.cpp:1307
void setPath(const Path &path)
Sets the new path for this being.
Definition being.cpp:259
int getTileX() const override
Returns the tile x coord.
Definition being.h:146
void setSpriteColor(unsigned slot, const std::string &color=std::string())
Definition being.cpp:1301
void lookAt(const Vector &destVec)
Make the being look at a given pixel position.
Definition being.cpp:702
void updateColors()
Definition being.cpp:1107
int getCollisionRadius() const
Returns the being's pixel radius used to detect collisions.
Definition being.cpp:804
void drawSpeech(int offsetX, int offsetY)
Draws the speech text above the being.
Definition being.cpp:963
bool getShowName() const
Definition being.h:200
void updateNamePosition()
Updates name's location.
Definition being.cpp:1011
const ItemInfo * mEquippedWeapon
Engine-related infos about weapon.
Definition being.h:521
bool isGM() const
Whether or not this player is a GM.
Definition being.h:417
void setPosition(float x, float y, float z=0.0f)
Overloaded method provided for convenience.
Definition being.h:376
const std::string & getPartyName() const
Definition being.h:210
void setName(const std::string &name)
Sets the name for the being.
Definition being.cpp:463
void setIp(int ip)
Sets the IP or an IP hash.
Definition being.cpp:1344
virtual void pathFinished()
Called when the being has reached the end of its path.
Definition being.h:488
int getSpeechTextYPosition() const
Gets the advised Y chat text position.
Definition being.cpp:182
Vector mDest
destination coordinates.
Definition being.h:527
BeingDirection
Directions, to be used as bitmask values.
Definition being.h:103
@ RIGHT
Definition being.h:107
@ DOWN
Definition being.h:104
@ UP
Definition being.h:106
@ LEFT
Definition being.h:105
void setAttackSpeed(int speed)
Sets the attack speed.
Definition being.h:325
Speech
Definition being.h:83
@ NAME_IN_BUBBLE
Definition being.h:87
@ NO_NAME_IN_BUBBLE
Definition being.h:86
@ TEXT_OVERHEAD
Definition being.h:85
@ NO_SPEECH
Definition being.h:84
Gender mGender
Definition being.h:532
@ SIT
Definition being.h:77
@ MOVE
Definition being.h:75
@ ATTACK
Definition being.h:76
@ STAND
Definition being.h:74
@ HURT
Definition being.h:79
@ DEAD
Definition being.h:78
bool isAlive() const
Returns whether this being is still alive.
Definition being.h:351
void setGM(bool gm)
Triggers whether or not to show the name as a GM name.
Definition being.cpp:1337
void setGuildPos(const std::string &pos)
Definition being.cpp:489
void setPartyName(const std::string &name)
Sets the name of the party the being is in.
Definition being.h:208
virtual void setAction(Action action, int attackId=1)
Sets the current action.
Definition being.cpp:624
void talkTo()
Definition being.cpp:1360
Cursor getHoverCursor() const
Definition being.cpp:158
void setType(Type type, int subtype)
Can be used to change the type of the being.
Definition being.cpp:93
Type mType
Definition being.h:543
const gcn::Color * mNameColor
Definition being.h:517
void lookAt(const Position &destPos)
Definition being.h:453
int getAttackSpeed() const
Gets the attack speed.
Definition being.h:331
bool isInParty() const
Definition being.h:257
const std::string & getName() const
Returns the name of the being.
Definition being.h:190
void setParty(Party *party)
Definition being.cpp:549
Timer mSpeechTimer
Time until the last speech sentence disappears.
Definition being.h:501
void logic() override
Performs being logic.
Definition being.cpp:810
~Being() override
Definition being.cpp:81
FlashText * mDispName
Holds a text object when the being displays its name, 0 otherwise.
Definition being.h:516
void handleAttack(Being *victim, int damage, int attackId=1)
Handles an attack of another being by this being.
Definition being.cpp:421
void setGender(Gender gender)
Sets the gender of this being.
Definition being.cpp:1313
const BeingInfo * mInfo
Definition being.h:496
Map::BlockType getBlockType() const override
Gets the way the monster blocks pathfinding for other objects.
Definition being.cpp:168
Timer mActionTimer
Time spent in current action.
Definition being.h:498
void flashName(int time)
Definition being.cpp:1023
Party * mParty
Definition being.h:536
void addGuild(Guild *guild)
Adds a guild to the being.
Definition being.cpp:495
void updatePlayerSprites()
Updates the visible sprite IDs of the player, taking into account the item replacements.
Definition being.cpp:1149
short getNumberOfGuilds() const
Get number of guilds the being belongs to.
Definition being.h:254
void removeGuild(int id)
Removers a guild from the being.
Definition being.cpp:504
Action getCurrentAction() const
Get the being's action currently performed.
Definition being.h:346
Vector mMoveSpeed
Walk speed for x and y movement values.
Definition being.h:556
bool isTargetSelection() const
Definition being.cpp:148
int getTileY() const override
Returns the tile y coord.
Definition being.h:152
uint16_t getSubType() const
Definition being.h:292
std::map< int, ParticleHandle > mStatusParticleEffects
Definition being.h:546
Guild * getGuild(const std::string &guildName) const
Returns a pointer to the specified guild that the being is in.
Definition being.cpp:518
uint8_t mDirection
Facing direction.
Definition being.h:508
void death(const gcn::Event &event) override
Definition being.cpp:1392
void takeDamage(Being *attacker, int damage, AttackType type, int attackId=1)
Puts a damage bubble above this being.
Definition being.cpp:316
Vector mSpeedPixelsPerSecond
Being speed in pixel per second.
Definition being.h:561
void clearPath()
Removes all path nodes from this being.
Definition being.cpp:254
void setSpriteID(unsigned slot, int id)
Definition being.cpp:1295
const Vector & getDestination() const
Returns the destination for this being.
Definition being.h:140
void setSpeech(const std::string &text, int time=5000)
Puts a "speech balloon" above this being for the specified amount of time.
Definition being.cpp:264
const Path & getPath() const
Returns the path this being is following.
Definition being.h:397
bool canTalk()
Definition being.cpp:1355
void addSpriteParticles(SpriteState &spriteState, const SpriteDisplay &display)
Definition being.cpp:1078
void restoreAllSpriteParticles()
Definition being.cpp:1092
int mAttackSpeed
Attack speed.
Definition being.h:503
int mIp
Definition being.h:564
std::set< int > mStatusEffects
set of active status effects
Definition being.h:545
bool mShowName
Definition being.h:518
Path mPath
Definition being.h:523
void clearGuilds()
Removes all guilds the being is in.
Definition being.cpp:536
Gender getGender() const
Definition being.h:411
int getDamageTaken() const
Definition being.h:401
Definition event.h:42
Channel
Definition event.h:45
Definition guild.h:55
Defines a class for storing generic item infos.
Definition iteminfo.h:100
A tile map.
Definition map.h:147
int getTileHeight() const
Returns the tile height used by this map.
Definition map.h:271
BlockType
Definition map.h:150
int getTileWidth() const
Returns the tile width of this map.
Definition map.h:265
A particle spawned by a ParticleEmitter.
Definition particle.h:42
Definition party.h:59
Definition text.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
Cursor
Cursors are in graphic order from left to right.
Definition gui.h:55
std::list< Position > Path
Definition position.h:40
unsigned char uint8_t
Definition sha256.cpp:81
SpriteDirection
Definition spritedef.h:74
@ DIRECTION_DOWN
Definition spritedef.h:77
std::string color
Definition being.h:460
std::vector< ParticleHandle > particles
Definition being.h:461
A position along a being's path.
Definition position.h:31
int y
Definition position.h:37
int x
Definition position.h:36