Rehti MMORPG  1.0.0
Rehti MMORPG is a free and open source MMORPG game.
GameWorld Class Reference

GameWorld class. It contains all the player, npc, object and item instances. More...

#include <GameWorld.hpp>

Collaboration diagram for GameWorld:
Collaboration graph

Public Member Functions

 GameWorld ()
 
 ~GameWorld ()=default
 
std::vector< std::shared_ptr< PlayerCharacter > > & getPlayers ()
 
std::shared_ptr< PlayerCharactergetPlayer (unsigned int playerId)
 
MapgetMap ()
 
void addPlayer (std::string playerName, unsigned int playerId, int baseDamage, int baseAccuracy, SpawnCoordinateBounds spawnCoordinateBounds, Coordinates location)
 Adds player to the game world. More...
 
bool removePlayer (unsigned int playerId)
 Removes player from the game world. More...
 
void addNpc (Npc npc)
 Adds npc to the game world. More...
 
std::vector< std::shared_ptr< Npc > > & getNpcs ()
 Get all npcs. More...
 
std::shared_ptr< NpcgetNpc (unsigned int npcId)
 Get npc by id. More...
 
std::shared_ptr< EntitygetEntity (unsigned int entityId)
 Get entity by id. More...
 
std::map< std::string, std::shared_ptr< Object > > & getObjects ()
 Get all objects. More...
 
std::map< Coordinates, std::vector< std::shared_ptr< Item > > > & getItems ()
 Get all items. More...
 
void addItem (Coordinates location, std::shared_ptr< Item >)
 Add item to the game world. More...
 
std::shared_ptr< ItemremoveItem (Coordinates location, int itemId)
 Remove item from the game world. More...
 
void updateGameWorld ()
 Updates the game world. Updates all the npcs and players. More...
 
void initWorld ()
 Initializes the game world. Loads assets and map. Adds npcs and objects to the world. More...
 
std::mutex & getPlayersMutex ()
 
std::mutex & getItemsMutex ()
 

Private Attributes

std::vector< std::shared_ptr< PlayerCharacter > > playersM
 
std::mutex playersMutexM
 
std::vector< std::shared_ptr< Npc > > npcsM
 
std::map< std::string, std::shared_ptr< Object > > objectsM
 
std::map< Coordinates, std::vector< std::shared_ptr< Item > > > itemsM
 
std::mutex itemsMutexM
 
Map mapM
 

Detailed Description

GameWorld class. It contains all the player, npc, object and item instances.

Constructor & Destructor Documentation

◆ GameWorld()

GameWorld::GameWorld ( )

◆ ~GameWorld()

GameWorld::~GameWorld ( )
default

Member Function Documentation

◆ addItem()

void GameWorld::addItem ( Coordinates  location,
std::shared_ptr< Item item 
)

Add item to the game world.

Parameters
locationCoordinates where the item is located
itemshared pointer to Item
Here is the caller graph for this function:

◆ addNpc()

void GameWorld::addNpc ( Npc  npc)

Adds npc to the game world.

Parameters
npc

◆ addPlayer()

void GameWorld::addPlayer ( std::string  playerName,
unsigned int  playerId,
int  baseDamage,
int  baseAccuracy,
SpawnCoordinateBounds  spawnCoordinateBounds,
Coordinates  location 
)

Adds player to the game world.

Parameters
playerName
playerId
baseDamage
baseAccuracy
spawnCoordinateBoundsBounds within which the player can spawn
locationCoordinates
Here is the caller graph for this function:

◆ getEntity()

std::shared_ptr< Entity > GameWorld::getEntity ( unsigned int  entityId)

Get entity by id.

Parameters
entityId
Returns
shared pointer to Entity
Here is the caller graph for this function:

◆ getItems()

std::map< Coordinates, std::vector< std::shared_ptr< Item > > > & GameWorld::getItems ( )

Get all items.

Returns
std::map<Coordinates, std::vector<std::shared_ptr<Item>>>&
Here is the caller graph for this function:

◆ getItemsMutex()

std::mutex & GameWorld::getItemsMutex ( )
Here is the caller graph for this function:

◆ getMap()

Map & GameWorld::getMap ( )
Here is the caller graph for this function:

◆ getNpc()

std::shared_ptr< Npc > GameWorld::getNpc ( unsigned int  npcId)

Get npc by id.

Parameters
npcId
Returns
std::shared_ptr<Npc>
Here is the caller graph for this function:

◆ getNpcs()

std::vector< std::shared_ptr< Npc > > & GameWorld::getNpcs ( )

Get all npcs.

Returns
std::vector<std::shared_ptr<Npc>>
Here is the caller graph for this function:

◆ getObjects()

std::map< std::string, std::shared_ptr< Object > > & GameWorld::getObjects ( )

Get all objects.

Returns
std::map<std::string, std::shared_ptr<Object>>&
Here is the caller graph for this function:

◆ getPlayer()

std::shared_ptr< PlayerCharacter > GameWorld::getPlayer ( unsigned int  playerId)
Here is the caller graph for this function:

◆ getPlayers()

std::vector< std::shared_ptr< PlayerCharacter > > & GameWorld::getPlayers ( )
Here is the caller graph for this function:

◆ getPlayersMutex()

std::mutex & GameWorld::getPlayersMutex ( )

◆ initWorld()

void GameWorld::initWorld ( )

Initializes the game world. Loads assets and map. Adds npcs and objects to the world.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeItem()

std::shared_ptr< Item > GameWorld::removeItem ( Coordinates  location,
int  itemId 
)

Remove item from the game world.

Parameters
itemIdInstance id of item to be removed
Returns
std::shared_ptr<Item>
Here is the caller graph for this function:

◆ removePlayer()

bool GameWorld::removePlayer ( unsigned int  playerId)

Removes player from the game world.

Parameters
playerId
Returns
true if successful
Here is the caller graph for this function:

◆ updateGameWorld()

void GameWorld::updateGameWorld ( )

Updates the game world. Updates all the npcs and players.

Here is the caller graph for this function:

Member Data Documentation

◆ itemsM

std::map<Coordinates, std::vector<std::shared_ptr<Item> > > GameWorld::itemsM
private

◆ itemsMutexM

std::mutex GameWorld::itemsMutexM
private

◆ mapM

Map GameWorld::mapM
private

◆ npcsM

std::vector<std::shared_ptr<Npc> > GameWorld::npcsM
private

◆ objectsM

std::map<std::string, std::shared_ptr<Object> > GameWorld::objectsM
private

◆ playersM

std::vector<std::shared_ptr<PlayerCharacter> > GameWorld::playersM
private

◆ playersMutexM

std::mutex GameWorld::playersMutexM
private

The documentation for this class was generated from the following files: