Rehti MMORPG  1.0.0
Rehti MMORPG is a free and open source MMORPG game.
Entity.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../action/AttackAction.hpp"
4 #include "../action/MoveAction.hpp"
5 #include "../action/RespawnAction.hpp"
6 #include "../item/Equipment.hpp"
7 #include "../item/Inventory.hpp"
8 #include "../skill/SkillSet.hpp"
9 #include "../world/Coordinates.hpp"
10 
11 class GameWorld;
12 
16 class Entity : public std::enable_shared_from_this<Entity>
17 {
18 public:
19  Entity(GameWorld* pGameWorld, std::string name, int baseAccuracy, int baseDamage, SpawnCoordinateBounds spawnCoordinateBounds, unsigned int id = 0, Coordinates location = Coordinates());
20 
21  ~Entity() = default;
22 
27  unsigned int getId();
28 
34  unsigned int getInstanceId();
35 
40  std::string getName();
41 
47 
52  void setLocation(Coordinates location);
53 
60 
65  std::shared_ptr<Action>& getCurrentAction();
66 
71  int getHp();
72 
77  int getMaxHp();
78 
84 
90 
95  int getRange();
96 
101  int getAttackSpeed();
102 
107  std::chrono::milliseconds getMoveSpeed();
108 
114 
119  void changeHp(int amount);
120 
125  void setAction(std::shared_ptr<Action> action);
126 
132  bool move(Coordinates location);
133 
138  virtual void attack(Entity& target);
139 
144  void pickUpItem(int itemId, Coordinates itemLocation);
145 
150  void dropItem(int itemId);
151 
157 
161  virtual void update() = 0;
162 
166  virtual void respawn() = 0;
167 
172  bool isDisconnected();
173 
177  void setDisconnected();
178 
179 protected:
180  unsigned int idM;
181  unsigned int instanceIdM;
182  inline static int nextInstanceIdM = 0;
183 
184  std::string nameM;
185 
187 
189 
190  std::shared_ptr<Action> currentActionM = nullptr;
191 
192  int maxHpM = 1000;
193 
194  int hpM = maxHpM;
195 
197 
199 
201 
203 
206 
207  bool isDisconnectedM = false; // for players only, but defined for entity for polymorphism reaons
208 
209  std::chrono::milliseconds respawnTimeM{2000};
210 
211  std::chrono::milliseconds moveSpeedM{1000};
212 };
Base pure virtual Entity class. Different types of enities inherit this.
Definition: Entity.hpp:17
unsigned int getInstanceId()
Get the unique id of this entity.
Definition: Entity.cpp:34
void setLocation(Coordinates location)
Set the location of this entity.
Definition: Entity.cpp:49
bool isDisconnectedM
Definition: Entity.hpp:207
virtual void respawn()=0
Pure virtual function that child classes need to implement. Performs entity's respawning.
SkillSet & getSkillSet()
Get the SkillSet of this entity.
Definition: Entity.cpp:175
int baseDamageM
Definition: Entity.hpp:204
Inventory & getInventory()
Get the Inventory object of this entity.
Definition: Entity.cpp:76
Entity(GameWorld *pGameWorld, std::string name, int baseAccuracy, int baseDamage, SpawnCoordinateBounds spawnCoordinateBounds, unsigned int id=0, Coordinates location=Coordinates())
Definition: Entity.cpp:7
GameWorld * getGameWorld()
Get pointer to the GameWorld that this entity resides in.
Definition: Entity.cpp:102
SkillSet skillSetM
Definition: Entity.hpp:202
int getHp()
Get the current hp of this entity.
Definition: Entity.cpp:66
std::chrono::milliseconds getMoveSpeed()
Get the movement speed of this entity.
Definition: Entity.cpp:97
Coordinates getRespawnLocation()
Returns a random location within the spawn bounds.
Definition: Entity.cpp:54
int getRange()
Get tha attack range of this entity.
Definition: Entity.cpp:86
int hpM
Definition: Entity.hpp:194
virtual void attack(Entity &target)
Perform an attack on target entity.
Definition: Entity.cpp:135
void changeHp(int amount)
Change the hp of this entity by amount.
Definition: Entity.cpp:107
Coordinates & getLocation()
Get the current location of this entity.
Definition: Entity.cpp:44
int getAttackSpeed()
Get the attack speed of this entity in milliseconds.
Definition: Entity.cpp:91
virtual void update()=0
Pure virtual function that child classes need to implement. Updates the entity on server tick.
Inventory inventoryM
Definition: Entity.hpp:198
bool isDisconnected()
Returns whether entity is disconnected, only relevant for players.
Definition: Entity.cpp:180
std::shared_ptr< Action > currentActionM
Definition: Entity.hpp:190
bool move(Coordinates location)
Move to a neighboring tile.
Definition: Entity.cpp:125
void pickUpItem(int itemId, Coordinates itemLocation)
Pick up an item.
Definition: Entity.cpp:154
int getMaxHp()
Get the maximum hp of this entity.
Definition: Entity.cpp:71
unsigned int instanceIdM
Definition: Entity.hpp:181
std::shared_ptr< Action > & getCurrentAction()
Get the current action of this entity.
Definition: Entity.cpp:61
void setDisconnected()
Sets entity as disconnected, only relevant for players.
Definition: Entity.cpp:185
unsigned int idM
Definition: Entity.hpp:180
~Entity()=default
std::chrono::milliseconds moveSpeedM
Definition: Entity.hpp:211
void dropItem(int itemId)
Drop an item.
Definition: Entity.cpp:166
SpawnCoordinateBounds spawnCoordinateBoundsM
Definition: Entity.hpp:188
int maxHpM
Definition: Entity.hpp:192
GameWorld * pGameWorldM
Definition: Entity.hpp:196
std::chrono::milliseconds respawnTimeM
Definition: Entity.hpp:209
std::string getName()
Get the name of this entity.
Definition: Entity.cpp:39
Equipment & getEquipment()
Get the Equipment object of this entity.
Definition: Entity.cpp:81
int baseAccuracyM
Definition: Entity.hpp:205
Coordinates locationM
Definition: Entity.hpp:186
unsigned int getId()
Get the type id of this entity.
Definition: Entity.cpp:29
static int nextInstanceIdM
Definition: Entity.hpp:182
void setAction(std::shared_ptr< Action > action)
Set the current action to parameter action.
Definition: Entity.cpp:120
std::string nameM
Definition: Entity.hpp:184
Equipment equipmentM
Definition: Entity.hpp:200
Class for representing the items an entity has equipped.
Definition: Equipment.hpp:14
GameWorld class. It contains all the player, npc, object and item instances.
Definition: GameWorld.hpp:16
Represents the items that an entity can carry.
Definition: Inventory.hpp:12
Contains all the skills that a character has.
Definition: SkillSet.hpp:20
Struct for coordinates.
Definition: Coordinates.hpp:7
Contains the spawn coordinate bounds for a character.
Definition: CharacterReader.hpp:10