1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-07 19:27:45 +00:00

little map manager rework

This commit is contained in:
Taezen 2021-09-07 16:50:13 +02:00
parent 55247a41f6
commit 774d16667d
10 changed files with 501 additions and 652 deletions

View file

@ -4582,9 +4582,11 @@ Sapphire::Data::GuildleveAssignment::GuildleveAssignment( uint32_t row_id, Sapph
{
auto row = exdData->m_GuildleveAssignmentDat.get_row( row_id );
type = exdData->getField< std::string >( row, 0 );
typeId = exdData->getField< uint8_t >( row, 1 );
assignmentTalk = exdData->getField< uint32_t >( row, 2 );
quest.push_back( exdData->getField< uint32_t >( row, 3 ) );
quest.push_back( exdData->getField< uint32_t >( row, 4 ) );
grandCompanyRank = exdData->getField< uint8_t >( row, 10 );
}
Sapphire::Data::GuildleveAssignmentCategory::GuildleveAssignmentCategory( uint32_t row_id, Sapphire::Data::ExdDataGenerated* exdData )
@ -7669,13 +7671,16 @@ Sapphire::Data::Quest::Quest( uint32_t row_id, Sapphire::Data::ExdDataGenerated*
classJobCategory1 = exdData->getField< uint8_t >( row, 6 );
classJobLevel1 = exdData->getField< uint16_t >( row, 7 );
previousQuestJoin = exdData->getField< uint8_t >( row, 8 );
previousQuest0 = exdData->getField< uint32_t >( row, 9 );
previousQuest1 = exdData->getField< uint32_t >( row, 11 );
previousQuest2 = exdData->getField< uint32_t >( row, 12 );
previousQuest.push_back( exdData->getField< uint32_t >( row, 9 ) );
previousQuest0Sequence = exdData->getField< uint8_t >( row, 10 );
previousQuest.push_back( exdData->getField< uint32_t >( row, 11 ) );
previousQuest.push_back( exdData->getField< uint32_t >( row, 12 ) );
questLockJoin = exdData->getField< uint8_t >( row, 13 );
questLock.push_back( exdData->getField< uint32_t >( row, 14 ) );
questLock.push_back( exdData->getField< uint32_t >( row, 15 ) );
header = exdData->getField< uint16_t >( row, 16 );
startTown = exdData->getField< uint8_t >( row, 17 );
classJobUnlockFlag = exdData->getField< uint8_t >( row, 18 );
classJobUnlock = exdData->getField< uint8_t >( row, 19 );
grandCompany = exdData->getField< uint8_t >( row, 20 );
grandCompanyRank = exdData->getField< uint8_t >( row, 21 );
@ -7691,6 +7696,8 @@ Sapphire::Data::Quest::Quest( uint32_t row_id, Sapphire::Data::ExdDataGenerated*
beastTribe = exdData->getField< uint8_t >( row, 31 );
beastReputationRank = exdData->getField< uint8_t >( row, 32 );
beastReputationValue = exdData->getField< uint16_t >( row, 33 );
satisfactionNpc = exdData->getField< uint8_t >( row, 34 );
satisfactionLevel = exdData->getField< uint8_t >( row, 35 );
mountRequired = exdData->getField< int32_t >( row, 36 );
isHouseRequired = exdData->getField< bool >( row, 37 );
deliveryQuest = exdData->getField< uint8_t >( row, 38 );

View file

@ -4366,8 +4366,10 @@ struct GuideTitle
struct GuildleveAssignment
{
std::string type;
uint8_t typeId;
uint32_t assignmentTalk;
std::vector< uint32_t > quest;
uint8_t grandCompanyRank;
GuildleveAssignment( uint32_t row_id, Sapphire::Data::ExdDataGenerated* exdData );
};
@ -6324,12 +6326,13 @@ struct Quest
uint8_t classJobCategory1;
uint16_t classJobLevel1;
uint8_t previousQuestJoin;
uint32_t previousQuest0;
uint32_t previousQuest1;
uint32_t previousQuest2;
std::vector< uint32_t > previousQuest;
uint8_t previousQuest0Sequence;
uint8_t questLockJoin;
std::vector< uint32_t > questLock;
uint16_t header;
uint8_t startTown;
uint8_t classJobUnlockFlag;
uint8_t classJobUnlock;
uint8_t grandCompany;
uint8_t grandCompanyRank;
@ -6343,6 +6346,8 @@ struct Quest
uint8_t beastTribe;
uint8_t beastReputationRank;
uint16_t beastReputationValue;
uint8_t satisfactionNpc;
uint8_t satisfactionLevel;
int32_t mountRequired;
bool isHouseRequired;
uint8_t deliveryQuest;

View file

@ -85,6 +85,13 @@ namespace Sapphire::Event
QuestBattleDirector = 0x8006,
};
enum class EventState : uint8_t
{
Invisible,
Available,
Locked
};
using SceneReturnCallback = std::function< void( Entity::Player&, const SceneResult& ) >;
using SceneChainCallback = std::function< void( Entity::Player& ) >;
using EventFinishCallback = std::function< void( Entity::Player&, uint64_t ) >;

File diff suppressed because it is too large Load diff

View file

@ -3,12 +3,14 @@
#include "ForwardsZone.h"
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
namespace Sapphire::World::Manager
{
using QuestMap = std::unordered_map< uint32_t, Data::ExdDataGenerated::QuestPtr >;
class MapMgr
{
public:
@ -34,81 +36,20 @@ namespace Sapphire::World::Manager
{
uint32_t iconId;
uint32_t levelId;
uint32_t actorId;
};
struct QuestData
{
uint8_t previousQuestJoin; // 1 = requires all previous quest, 2 = requires any previous quest
uint32_t previousQuestKeys[3];
uint8_t previousQuest0Sequence;
uint8_t questLockJoin; // 1 = only locks when all previous quests are done, 2 = locks when any previous quest is done
uint32_t questLockKeys[2];
struct
{
std::bitset< Common::CLASSJOB_TOTAL + 1 > classJobCategoryMask;
uint16_t classJobLevel;
} classJobRequirements[2];
uint8_t classJobUnlockFlag;
uint8_t classJobUnlock;
uint8_t requiredGC;
uint8_t requiredGCRank;
uint8_t startTown;
uint16_t header;
uint8_t instanceContentJoin; // 1 = requires all needed instances to be completed, 2 = requires any needed instance to be completed
uint32_t instanceContent[3];
uint8_t festival;
uint8_t festivalBegin;
uint8_t festivalEnd;
uint16_t bellStart;
uint16_t bellEnd;
uint8_t repeatIntervalType;
uint8_t questRepeatFlag;
uint8_t beastTribe;
uint8_t beastReputationRank;
uint16_t beastReputationValue;
int32_t mount;
uint8_t satisfactionNpc;
uint8_t satisfactionRank;
uint32_t issuer;
uint8_t deliveryQuest;
uint8_t expansion;
uint8_t type;
bool isRepeatable;
bool isHouseRequired;
uint32_t iconValid;
uint32_t iconInvalid;
uint32_t eventId;
};
struct less
{
constexpr bool operator()( const uint32_t& _Left, const uint32_t& _Right ) const
constexpr bool operator()( const EventData& _Left, const EventData& _Right ) const
{
const uint16_t left = _Left;
const uint16_t right = _Right;
const uint16_t left = _Left.eventId;
const uint16_t right = _Right.eventId;
if( left == right )
{
const uint16_t typeLeft = _Left >> 16;
const uint16_t typeRight = _Right >> 16;
const uint16_t typeLeft = _Left.eventId >> 16;
const uint16_t typeRight = _Right.eventId >> 16;
return typeLeft < typeRight;
}
@ -117,14 +58,18 @@ namespace Sapphire::World::Manager
}
};
std::map< uint16_t, std::multimap< uint32_t, EventData, less > > m_mapData;
std::map< uint32_t, QuestData > m_questData;
using EventSet = std::multiset< EventData, less >;
bool isQuestAvailable( Entity::Player& player, std::pair< const uint32_t, EventData >& eventData );
bool isTripleTriadAvailable( Entity::Player& player, std::pair< const uint32_t, EventData >& eventData );
QuestMap m_quests;
void fillPacket( std::multimap< uint32_t, EventData, less >& mapData, uint32_t* iconIds, uint32_t* levelIds, uint32_t* eventIds );
void sendPackets( Entity::Player& player, std::multimap< uint32_t, EventData, less >& mapData, UpdateMode updateMode );
void insertQuest( Entity::Player& player, uint32_t questId, EventSet& mapData );
bool isQuestVisible( Entity::Player& player, uint32_t questId, Data::ExdDataGenerated::QuestPtr questPtr );
bool isQuestAvailable( Entity::Player& player, uint32_t questId, Data::ExdDataGenerated::QuestPtr questPtr );
bool isTripleTriadAvailable( Entity::Player& player, uint32_t tripleTriadId );
void fillPacket( EventSet& mapData, uint32_t* iconIds, uint32_t* levelIds, uint32_t* eventIds );
void sendPackets( Entity::Player& player, EventSet& mapData, UpdateMode updateMode );
};
}

View file

@ -1,7 +1,6 @@
#include <string>
#include <typeinfo>
#include <typeindex>
#include <Event/EventHandler.h>
#include "NativeScriptApi.h"
#include <cassert>
@ -138,6 +137,11 @@ namespace Sapphire::ScriptAPI
{
}
Event::EventHandler::EventState EventScript::checkExtraConditions( Sapphire::Entity::Player& player, uint32_t eventId )
{
return Event::EventHandler::EventState::Available;
}
///////////////////////////////////////////////////////////////////
EventObjectScript::EventObjectScript( uint32_t eobjId ) :

View file

@ -2,6 +2,7 @@
#define NATIVE_SCRIPT_API
#include <string>
#include <Event/EventHandler.h>
#include "ForwardsZone.h"
#ifdef _MSC_VER
@ -168,6 +169,8 @@ namespace Sapphire::ScriptAPI
virtual void onEObjHit( Sapphire::Entity::Player& player, uint64_t actorId, uint32_t actionId );
virtual void onEventYield( Sapphire::Entity::Player& player, uint16_t scene, std::vector< uint32_t > param );
virtual Event::EventHandler::EventState checkExtraConditions( Sapphire::Entity::Player& player, uint32_t eventId );
};
/*!

View file

@ -174,7 +174,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
auto pInstanceObjCache = std::make_shared< Sapphire::InstanceObjectCache >();
Common::Service< Sapphire::InstanceObjectCache >::set( pInstanceObjCache );
Logger::info( "MapMgr: Caching map data" );
Logger::info( "MapMgr: Caching quests" );
auto pMapMgr = std::make_shared< Manager::MapMgr >();
Common::Service< Manager::MapMgr >::set( pMapMgr );

View file

@ -41,16 +41,23 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
// TODO: it does feel like this needs to be streamlined into the datReader instead of being done here...
std::string bgLgbPath( path + "/level/bg.lgb" );
std::string planmapLgbPath( path + "/level/planmap.lgb" );
std::string planeventLgbPath( path + "/level/planevent.lgb" );
std::string plannerLgbPath( path + "/level/planner.lgb" );
std::vector< char > bgSection;
std::vector< char > planmapSection;
std::vector< char > planeventSection;
std::vector< char > plannerSection;
std::unique_ptr< xiv::dat::File > bgFile;
std::unique_ptr< xiv::dat::File > planmap_file;
std::unique_ptr< xiv::dat::File > planevent_file;
std::unique_ptr< xiv::dat::File > planner_file;
try
{
bgFile = exdData.getGameData()->getFile( bgLgbPath );
planmap_file = exdData.getGameData()->getFile( planmapLgbPath );
planevent_file = exdData.getGameData()->getFile( planeventLgbPath );
}
catch( std::runtime_error& )
{
@ -60,6 +67,7 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
bgSection = bgFile->access_data_sections().at( 0 );
planmapSection = planmap_file->access_data_sections().at( 0 );
planeventSection = planevent_file->access_data_sections().at( 0 );
std::vector< std::string > stringList;
@ -67,8 +75,23 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
LGB_FILE bgLgb( &bgSection[ 0 ], "bg" );
LGB_FILE planmapLgb( &planmapSection[ 0 ], "planmap" );
LGB_FILE planeventLgb( &planeventSection[ 0 ], "planevent" );
std::vector< LGB_FILE > lgbList;
try
{
planner_file = exdData.getGameData()->getFile( plannerLgbPath );
plannerSection = planner_file->access_data_sections().at( 0 );
LGB_FILE plannerLgb( &plannerSection[ 0 ], "planner" );
lgbList = { bgLgb, planmapLgb, planeventLgb, plannerLgb };
}
catch( std::runtime_error& )
{
lgbList = { bgLgb, planmapLgb, planeventLgb };
}
std::vector< LGB_FILE > lgbList{ bgLgb, planmapLgb };
uint32_t max_index = 0;
for( const auto& lgb : lgbList )
@ -92,6 +115,16 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
auto pPopRange = std::reinterpret_pointer_cast< LGB_POP_RANGE_ENTRY >( pEntry );
m_popRangeCache.insert( id, pPopRange );
}
else if( pEntry->getType() == LgbEntryType::EventNpc )
{
auto pEventNpc = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry );
m_eventNpcCache.insert( id, pEventNpc );
}
else if( pEntry->getType() == LgbEntryType::EventObject )
{
auto pEventObj = std::reinterpret_pointer_cast< LGB_EOBJ_ENTRY >( pEntry );
m_eventObjCache.insert( id, pEventObj );
}
}
}
}
@ -99,8 +132,8 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
std::cout << "\n";
Logger::debug(
"InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {}",
m_mapRangeCache.size(), m_exitRangeCache.size(), m_popRangeCache.size()
"InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {} ENpc: {} Eobj: {}",
m_mapRangeCache.size(), m_exitRangeCache.size(), m_popRangeCache.size(), m_eventNpcCache.size(), m_eventObjCache.size()
);
}
@ -121,4 +154,28 @@ Sapphire::InstanceObjectCache::PopRangePtr
Sapphire::InstanceObjectCache::getPopRange( uint16_t zoneId, uint32_t popRangeId )
{
return m_popRangeCache.get( zoneId, popRangeId );
}
Sapphire::InstanceObjectCache::EventNpcPtr
Sapphire::InstanceObjectCache::getEventNpc( uint16_t zoneId, uint32_t eventNpcId )
{
return m_eventNpcCache.get( zoneId, eventNpcId );
}
Sapphire::InstanceObjectCache::EventObjPtr
Sapphire::InstanceObjectCache::getEventObj( uint16_t zoneId, uint32_t eventObjId )
{
return m_eventObjCache.get( zoneId, eventObjId );
}
Sapphire::InstanceObjectCache::EventNpcMapPtr
Sapphire::InstanceObjectCache::getAllEventNpc( uint16_t zoneId )
{
return m_eventNpcCache.getAll( zoneId );
}
Sapphire::InstanceObjectCache::EventObjMapPtr
Sapphire::InstanceObjectCache::getAllEventObj( uint16_t zoneId )
{
return m_eventObjCache.getAll( zoneId );
}

View file

@ -7,6 +7,8 @@
struct LGB_MAP_RANGE_ENTRY;
struct LGB_EXIT_RANGE_ENTRY;
struct LGB_POP_RANGE_ENTRY;
struct LGB_ENPC_ENTRY;
struct LGB_EOBJ_ENTRY;
namespace Sapphire
@ -37,6 +39,16 @@ namespace Sapphire
}
return nullptr;
}
ObjectMap* getAll( uint16_t zoneId )
{
auto it = m_objectCache.find( zoneId );
if( it != m_objectCache.end() )
{
return &it->second;
}
return nullptr;
}
void insert( uint16_t zoneId, std::shared_ptr< T > entry )
{
@ -65,6 +77,11 @@ namespace Sapphire
using MapRangePtr = std::shared_ptr< LGB_MAP_RANGE_ENTRY >;
using ExitRangePtr = std::shared_ptr< LGB_EXIT_RANGE_ENTRY >;
using PopRangePtr = std::shared_ptr< LGB_POP_RANGE_ENTRY >;
using EventNpcPtr = std::shared_ptr< LGB_ENPC_ENTRY >;
using EventObjPtr = std::shared_ptr< LGB_EOBJ_ENTRY >;
using EventNpcMapPtr = std::unordered_map< uint32_t, EventNpcPtr >*;
using EventObjMapPtr = std::unordered_map< uint32_t, EventObjPtr >*;
InstanceObjectCache();
~InstanceObjectCache() = default;
@ -72,11 +89,18 @@ namespace Sapphire
MapRangePtr getMapRange( uint16_t zoneId, uint32_t mapRangeId );
ExitRangePtr getExitRange( uint16_t zoneId, uint32_t exitRangeId );
PopRangePtr getPopRange( uint16_t zoneId, uint32_t popRangeId );
EventNpcPtr getEventNpc( uint16_t zoneId, uint32_t eventNpcId );
EventObjPtr getEventObj( uint16_t zoneId, uint32_t eventObjId );
EventNpcMapPtr getAllEventNpc( uint16_t zoneId );
EventObjMapPtr getAllEventObj( uint16_t zoneId );
private:
ObjectCache< LGB_MAP_RANGE_ENTRY > m_mapRangeCache;
ObjectCache< LGB_EXIT_RANGE_ENTRY > m_exitRangeCache;
ObjectCache< LGB_POP_RANGE_ENTRY > m_popRangeCache;
ObjectCache< LGB_ENPC_ENTRY > m_eventNpcCache;
ObjectCache< LGB_EOBJ_ENTRY > m_eventObjCache;
std::shared_ptr< Framework > m_pFramework;
};