2018-01-27 23:52:49 +01:00
|
|
|
#ifndef SAPPHIRE_TERRITORYMGR_H
|
|
|
|
#define SAPPHIRE_TERRITORYMGR_H
|
|
|
|
|
2018-09-09 23:56:22 +02:00
|
|
|
#include "ForwardsZone.h"
|
2018-02-01 23:32:59 +01:00
|
|
|
#include <set>
|
2018-02-28 10:26:03 +01:00
|
|
|
#include <unordered_map>
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-12-01 00:27:16 +11:00
|
|
|
namespace Sapphire::Data
|
2018-11-06 11:11:07 +01:00
|
|
|
{
|
|
|
|
// TODO: this should actually not be here but should be generated in exdData aswell
|
|
|
|
struct PlaceName;
|
|
|
|
struct TerritoryType;
|
|
|
|
struct InstanceContent;
|
|
|
|
|
|
|
|
using PlaceNamePtr = std::shared_ptr< PlaceName >;
|
|
|
|
using TerritoryTypePtr = std::shared_ptr< TerritoryType >;
|
|
|
|
using InstanceContentPtr = std::shared_ptr< InstanceContent >;
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 00:27:16 +11:00
|
|
|
namespace Sapphire::World::Manager
|
2018-11-06 11:11:07 +01:00
|
|
|
{
|
2018-11-30 23:57:06 +01:00
|
|
|
/*!
|
|
|
|
\class TerritoryMgr_c
|
|
|
|
\brief A class managing zones
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
This class manages persistent and temporary instances alike.
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
*/
|
2020-03-01 01:00:57 +11:00
|
|
|
class TerritoryMgr
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
public:
|
|
|
|
enum TerritoryIntendedUse : uint8_t //TODO: Add the rest of the territory types and have better names for them
|
|
|
|
{
|
|
|
|
Town = 0,
|
|
|
|
OpenWorld = 1,
|
|
|
|
Inn = 2,
|
|
|
|
Dungeon = 3,
|
|
|
|
JailArea = 5,
|
|
|
|
OpeningArea = 6,
|
|
|
|
BeforeTrialDung = 7,
|
|
|
|
AllianceRaid = 8,
|
|
|
|
OpenWorldInstanceBattle = 9,
|
|
|
|
Trial = 10,
|
|
|
|
HousingArea = 13,
|
|
|
|
HousingPrivateArea = 14,
|
|
|
|
MSQPrivateArea = 15,
|
|
|
|
Raids = 16,
|
|
|
|
RaidFights = 17,
|
|
|
|
ChocoboTutorial = 21,
|
|
|
|
Wedding = 22,
|
|
|
|
BeginnerTutorial = 27,
|
|
|
|
FreeCompanyGarrison = 30,
|
|
|
|
PalaceOfTheDead = 31,
|
|
|
|
TreasureMapInstance = 33,
|
|
|
|
EventTrial = 36,
|
|
|
|
TheFeastArea = 37,
|
|
|
|
PrivateEventArea = 40,
|
|
|
|
//Eureka = 41, // wat
|
|
|
|
};
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
TerritoryMgr();
|
2018-11-30 23:57:06 +01:00
|
|
|
|
|
|
|
/*! initializes the territoryMgr */
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
bool createDefaultTerritories();
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
bool createHousingTerritories();
|
|
|
|
|
|
|
|
/*! caches TerritoryType details into m_territoryTypeMap */
|
|
|
|
void loadTerritoryTypeDetailCache();
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! List of positions for zonelines */
|
|
|
|
void loadTerritoryPositionMap();
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns true if the given territoryTypeId is in fact a valid zone
|
|
|
|
based on informations in the dats ( checks if an entry in the dats exists trhough cache ) */
|
|
|
|
bool isValidTerritory( uint32_t territoryTypeId ) const;
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns the next available instanceId */
|
|
|
|
uint32_t getNextInstanceId();
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns true if the territoryType in question is not a persistant zone */
|
|
|
|
bool isInstanceContentTerritory( uint32_t territoryTypeId ) const;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns true if the territoryType in question is not a private zone */
|
|
|
|
bool isPrivateTerritory( uint32_t territoryTypeId ) const;
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-12-28 19:45:04 +11:00
|
|
|
/*!
|
|
|
|
* @brief Checks if a territory type is an internal housing area
|
|
|
|
* @param territoryTypeId The territory to test
|
|
|
|
* @return true if it is a housing area, false if not
|
|
|
|
*/
|
|
|
|
bool isInternalEstateTerritory( uint32_t territoryTypeId ) const;
|
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns true if the territoryType is a default non-instanced zone */
|
|
|
|
bool isDefaultTerritory( uint32_t territoryTypeId ) const;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns true if the territoryType is a housing zone */
|
|
|
|
bool isHousingTerritory( uint32_t territoryTypeId ) const;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! creates a new instance for a given territoryTypeId */
|
2019-07-21 22:33:33 +10:00
|
|
|
TerritoryPtr createTerritoryInstance( uint32_t territoryTypeId );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2019-07-21 22:33:33 +10:00
|
|
|
TerritoryPtr createInstanceContent( uint32_t contentFinderConditionId );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2019-07-21 22:33:33 +10:00
|
|
|
TerritoryPtr createQuestBattle( uint32_t contentFinderConditionId );
|
2019-03-31 23:45:03 +02:00
|
|
|
|
2019-04-11 00:16:04 +02:00
|
|
|
void createAndJoinQuestBattle( Entity::Player& player, uint16_t contentFinderConditionId );
|
|
|
|
|
2019-07-21 22:33:33 +10:00
|
|
|
TerritoryPtr findOrCreateHousingInterior( const Common::LandIdent landIdent );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! removes instance by instanceId, return true if successful */
|
2019-04-07 16:01:53 +02:00
|
|
|
bool removeTerritoryInstance( uint32_t guId );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2019-07-21 22:33:33 +10:00
|
|
|
/*! returns a TerritoryPtr to the instance or nullptr if not found */
|
|
|
|
TerritoryPtr getTerritoryByGuId( uint32_t guId ) const;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns the cached detail of a territory, nullptr if not found */
|
|
|
|
Data::TerritoryTypePtr getTerritoryDetail( uint32_t territoryTypeId ) const;
|
2018-12-01 00:27:16 +11:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! loop for processing territory logic, iterating all existing instances */
|
2019-04-04 23:29:52 +02:00
|
|
|
void updateTerritoryInstances( uint64_t tickCount );
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns a ZonePositionPtr if found, else nullptr */
|
|
|
|
ZonePositionPtr getTerritoryPosition( uint32_t territoryPositionId ) const;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns a default Zone by territoryTypeId
|
|
|
|
TODO: Mind multiple instances?! */
|
2019-07-21 22:33:33 +10:00
|
|
|
TerritoryPtr getZoneByTerritoryTypeId( uint32_t territoryTypeId ) const;
|
2018-01-29 18:10:43 +11:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns a Zone by landSetId */
|
2019-07-21 22:33:33 +10:00
|
|
|
TerritoryPtr getZoneByLandSetId( uint32_t landSetId ) const;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
bool movePlayer( uint32_t territoryTypeId, Entity::PlayerPtr pPlayer );
|
2018-01-28 13:49:51 +01:00
|
|
|
|
2019-07-21 22:33:33 +10:00
|
|
|
bool movePlayer( TerritoryPtr, Entity::PlayerPtr pPlayer );
|
2018-12-01 00:27:16 +11:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! returns an instancePtr if the player is still bound to an isntance */
|
2019-07-21 22:33:33 +10:00
|
|
|
TerritoryPtr getLinkedInstance( uint32_t playerId ) const;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*!
|
|
|
|
* @brief Sets the current festival for every zone
|
|
|
|
* @param festivalId A valid festival id from festival.exd
|
|
|
|
* @param additionalFestival A valid festival id from festival.exd, this is shown in addition to the first festival
|
|
|
|
*/
|
|
|
|
void setCurrentFestival( uint16_t festivalId, uint16_t additionalFestival = 0 );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*!
|
|
|
|
* @brief Disables the current festival(s) in every zone
|
|
|
|
*/
|
|
|
|
void disableCurrentFestival();
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*!
|
|
|
|
* @brief Gets the current festival set on the server
|
|
|
|
* @return a pair with the 2 festivals currently active
|
|
|
|
*/
|
|
|
|
const std::pair< uint16_t, uint16_t >& getCurrentFestival() const;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2019-01-28 20:48:33 +11:00
|
|
|
float getInRangeDistance() const;
|
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
private:
|
|
|
|
using TerritoryTypeDetailCache = std::unordered_map< uint16_t, Data::TerritoryTypePtr >;
|
2019-07-21 22:33:33 +10:00
|
|
|
using InstanceIdToTerritoryPtrMap = std::unordered_map< uint32_t, TerritoryPtr >;
|
|
|
|
using LandSetIdToTerritoryPtrMap = std::unordered_map< uint32_t, TerritoryPtr >;
|
|
|
|
using TerritoryTypeIdToInstanceMap = std::unordered_map< uint16_t, InstanceIdToTerritoryPtrMap >;
|
|
|
|
using InstanceContentIdToInstanceMap = std::unordered_map< uint16_t, InstanceIdToTerritoryPtrMap >;
|
|
|
|
using QuestBattleIdToInstanceMap = std::unordered_map< uint16_t, InstanceIdToTerritoryPtrMap >;
|
2019-04-11 00:16:04 +02:00
|
|
|
using QuestBattleIdToContentFinderCondMap = std::unordered_map< uint16_t, uint16_t >;
|
2018-11-30 23:57:06 +01:00
|
|
|
using PlayerIdToInstanceIdMap = std::unordered_map< uint32_t, uint32_t >;
|
|
|
|
using PositionMap = std::unordered_map< int32_t, ZonePositionPtr >;
|
|
|
|
using InstanceIdList = std::vector< uint32_t >;
|
2019-07-21 22:33:33 +10:00
|
|
|
using LandIdentToTerritoryPtrMap = std::unordered_map< uint64_t, TerritoryPtr >;
|
2018-09-01 20:55:28 +10:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! map holding details for territory templates */
|
|
|
|
TerritoryTypeDetailCache m_territoryTypeDetailCacheMap;
|
2018-02-04 17:46:46 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! map holding actual instances of default territories */
|
|
|
|
TerritoryTypeIdToInstanceMap m_territoryTypeIdToInstanceGuidMap;
|
2018-03-20 20:30:05 +11:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! map holding actual instances of default territories */
|
2019-07-21 22:33:33 +10:00
|
|
|
LandSetIdToTerritoryPtrMap m_landSetIdToTerritoryPtrMap;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! map holding actual instances of InstanceContent */
|
2018-12-30 18:48:45 +11:00
|
|
|
InstanceContentIdToInstanceMap m_instanceContentIdToInstanceMap;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2019-04-07 16:01:53 +02:00
|
|
|
/*! map holding actual instances of InstanceContent */
|
|
|
|
QuestBattleIdToInstanceMap m_questBattleIdToInstanceMap;
|
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! flat map for easier lookup of instances by guid */
|
2019-07-21 22:33:33 +10:00
|
|
|
InstanceIdToTerritoryPtrMap m_guIdToTerritoryPtrMap;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! map holding positions for zonelines */
|
|
|
|
PositionMap m_territoryPositionMap;
|
2018-11-06 11:11:07 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! map storing playerIds to instanceIds, used for instanceContent */
|
|
|
|
PlayerIdToInstanceIdMap m_playerIdToInstanceMap;
|
2018-01-28 13:49:51 +01:00
|
|
|
|
2018-12-01 18:18:29 +11:00
|
|
|
/*! map for storing landident to zones, used for internal housing zones */
|
2019-07-21 22:33:33 +10:00
|
|
|
LandIdentToTerritoryPtrMap m_landIdentToTerritoryPtrMap;
|
2018-12-01 18:18:29 +11:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! internal counter for instanceIds */
|
|
|
|
uint32_t m_lastInstanceId;
|
2018-01-28 13:49:51 +01:00
|
|
|
|
2019-07-21 22:33:33 +10:00
|
|
|
/*! set of TerritoryPtrs for quick iteration*/
|
2019-07-24 21:58:48 +10:00
|
|
|
std::set< TerritoryPtr > m_territorySet;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2019-07-21 22:33:33 +10:00
|
|
|
/*! set of TerritoryPtrs for quick iteration*/
|
|
|
|
std::set< TerritoryPtr > m_instanceZoneSet;
|
2018-02-04 17:46:46 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
/*! current festival(s) to set for public zones from festival.exd */
|
|
|
|
std::pair< uint16_t, uint16_t > m_currentFestival;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2019-01-28 20:48:33 +11:00
|
|
|
/*! Max distance at which actors in range of a player are sent */
|
|
|
|
float m_inRangeDistance;
|
|
|
|
|
2019-04-11 00:16:04 +02:00
|
|
|
/*! Map used to find a contentFinderConditionID to a questBattle */
|
|
|
|
QuestBattleIdToContentFinderCondMap m_questBattleToContentFinderMap;
|
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
public:
|
|
|
|
/*! returns a list of instanceContent InstanceIds currently active */
|
|
|
|
InstanceIdList getInstanceContentIdList( uint16_t instanceContentId ) const;
|
2018-02-01 23:32:59 +01:00
|
|
|
|
2018-11-30 23:57:06 +01:00
|
|
|
};
|
2018-01-27 23:52:49 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SAPPHIRE_TERRITORYMGR_H
|