1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 22:57:45 +00:00

Show svent on questbattle completion, remove inactive questbattle instances

This commit is contained in:
Mordred 2019-04-07 16:01:53 +02:00
parent 6c8124373c
commit e4b919e319
7 changed files with 77 additions and 30 deletions

View file

@ -69,6 +69,14 @@ class ManFst005 : public Sapphire::ScriptAPI::EventScript
Scene00002( player );
}
void onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override
{
if( player.getQuestSeq( eventId ) == Seq2 )
{
Scene00005( player );
}
}
private:
//////////////////////////////////////////////////////////////////////
// Available Scenes in this quest, not necessarly all are used
@ -129,9 +137,14 @@ class ManFst005 : public Sapphire::ScriptAPI::EventScript
void Scene00005( Entity::Player& player )
{
player.playScene( getId(), 5, HIDE_HOTBAR,
player.playScene( getId(), 5, NO_DEFAULT_CAMERA | CONDITION_CUTSCENE | SILENT_ENTER_TERRI_ENV |
HIDE_HOTBAR | SILENT_ENTER_TERRI_BGM | SILENT_ENTER_TERRI_SE |
DISABLE_STEALTH | 0x00100000 | LOCK_HUD | LOCK_HOTBAR |
// todo: wtf is 0x00100000
DISABLE_CANCEL_EMOTE,
[ & ]( Entity::Player& player, const Event::SceneResult& result )
{
player.updateQuest( result.eventId, Seq3 );
} );
}

View file

@ -189,7 +189,7 @@ bool Sapphire::World::Manager::TerritoryMgr::createDefaultTerritories()
InstanceIdToZonePtrMap instanceMap;
instanceMap[ guid ] = pZone;
m_instanceIdToZonePtrMap[ guid ] = pZone;
m_guIdToZonePtrMap[ guid ] = pZone;
m_territoryTypeIdToInstanceGuidMap[ territoryTypeId ] = instanceMap;
m_zoneSet.insert( { pZone } );
@ -235,7 +235,7 @@ bool Sapphire::World::Manager::TerritoryMgr::createHousingTerritories()
InstanceIdToZonePtrMap instanceMap;
instanceMap[ guid ] = pHousingZone;
m_instanceIdToZonePtrMap[ guid ] = pHousingZone;
m_guIdToZonePtrMap[ guid ] = pHousingZone;
m_territoryTypeIdToInstanceGuidMap[ territoryTypeId ][ guid ] = pHousingZone;
m_landSetIdToZonePtrMap[ pHousingZone->getLandSetId() ] = pHousingZone;
m_zoneSet.insert( { pHousingZone } );
@ -266,7 +266,7 @@ Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::createTerritoryInstanc
auto pZone = make_Zone( territoryTypeId, getNextInstanceId(), pTeri->name, pPlaceName->name, framework() );
pZone->init();
m_instanceIdToZonePtrMap[ pZone->getGuId() ] = pZone;
m_guIdToZonePtrMap[ pZone->getGuId() ] = pZone;
m_territoryTypeIdToInstanceGuidMap[ pZone->getTerritoryTypeId() ][ pZone->getGuId() ] = pZone;
m_zoneSet.insert( { pZone } );
@ -305,8 +305,8 @@ Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::createQuestBattle( uin
pTeri->name, pQuestInfo->name, questBattleId, framework() );
pZone->init();
m_instanceContentIdToInstanceMap[ questBattleId ][ pZone->getGuId() ] = pZone;
m_instanceIdToZonePtrMap[ pZone->getGuId() ] = pZone;
m_questBattleIdToInstanceMap[ questBattleId ][ pZone->getGuId() ] = pZone;
m_guIdToZonePtrMap[ pZone->getGuId() ] = pZone;
m_instanceZoneSet.insert( pZone );
return pZone;
@ -340,7 +340,7 @@ Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::createInstanceContent(
pZone->init();
m_instanceContentIdToInstanceMap[ instanceContentId ][ pZone->getGuId() ] = pZone;
m_instanceIdToZonePtrMap[ pZone->getGuId() ] = pZone;
m_guIdToZonePtrMap[ pZone->getGuId() ] = pZone;
m_instanceZoneSet.insert( pZone );
return pZone;
@ -413,19 +413,19 @@ Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::findOrCreateHousingInt
zone->init();
m_landIdentToZonePtrMap[ ident ] = zone;
m_instanceIdToZonePtrMap[ zone->getGuId() ] = zone;
m_guIdToZonePtrMap[ zone->getGuId() ] = zone;
m_zoneSet.insert( { zone } );
return zone;
}
bool Sapphire::World::Manager::TerritoryMgr::removeTerritoryInstance( uint32_t instanceId )
bool Sapphire::World::Manager::TerritoryMgr::removeTerritoryInstance( uint32_t guId )
{
ZonePtr pZone;
if( ( pZone = getInstanceZonePtr( instanceId ) ) == nullptr )
if( ( pZone = getInstanceZonePtr( guId ) ) == nullptr )
return false;
m_instanceIdToZonePtrMap.erase( pZone->getGuId() );
m_guIdToZonePtrMap.erase( pZone->getGuId() );
m_instanceZoneSet.erase( pZone );
m_zoneSet.erase( pZone );
@ -438,14 +438,13 @@ bool Sapphire::World::Manager::TerritoryMgr::removeTerritoryInstance( uint32_t i
else
m_territoryTypeIdToInstanceGuidMap[ pZone->getTerritoryTypeId() ].erase( pZone->getGuId() );
return true;
}
Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::getInstanceZonePtr( uint32_t instanceId ) const
Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::getInstanceZonePtr( uint32_t guId ) const
{
auto it = m_instanceIdToZonePtrMap.find( instanceId );
if( it == m_instanceIdToZonePtrMap.end() )
auto it = m_guIdToZonePtrMap.find( guId );
if( it == m_guIdToZonePtrMap.end() )
return nullptr;
return it->second;
@ -532,9 +531,37 @@ void Sapphire::World::Manager::TerritoryMgr::updateTerritoryInstances( uint64_t
else
it++;
}
// remove internal house zones with nobody in them
for( auto it = m_questBattleIdToInstanceMap.begin(); it != m_questBattleIdToInstanceMap.end(); ++it )
{
for( auto inIt = it->second.begin(); inIt != it->second.end(); )
{
auto zone = std::dynamic_pointer_cast< QuestBattle >( inIt->second );
if( !zone )
continue;
auto diff = std::difftime( tickCount, zone->getLastActivityTime() );
// todo: make this timeout configurable, though should be pretty relaxed in any case
if( diff > 6000 )
{
Logger::info( "Removing QuestBattle#{0} - has been inactive for 60 seconds", zone->getGuId() );
// remove zone from maps
m_instanceZoneSet.erase( zone );
m_guIdToZonePtrMap.erase( zone->getGuId() );
inIt = m_questBattleIdToInstanceMap[ zone->getQuestBattleId() ].erase( inIt );
}
else
inIt++;
}
}
}
Sapphire::World::Manager::TerritoryMgr::InstanceIdList Sapphire::World::Manager::TerritoryMgr::getInstanceContentIdList( uint16_t instanceContentId ) const
Sapphire::World::Manager::TerritoryMgr::InstanceIdList
Sapphire::World::Manager::TerritoryMgr::getInstanceContentIdList( uint16_t instanceContentId ) const
{
std::vector< uint32_t > idList;
auto zoneMap = m_instanceContentIdToInstanceMap.find( instanceContentId );

View file

@ -111,10 +111,10 @@ namespace Sapphire::World::Manager
ZonePtr findOrCreateHousingInterior( const Common::LandIdent landIdent );
/*! removes instance by instanceId, return true if successful */
bool removeTerritoryInstance( uint32_t territoryTypeId );
bool removeTerritoryInstance( uint32_t guId );
/*! returns a ZonePtr to the instance or nullptr if not found */
ZonePtr getInstanceZonePtr( uint32_t instanceId ) const;
ZonePtr getInstanceZonePtr( uint32_t guId ) const;
/*! returns the cached detail of a territory, nullptr if not found */
Data::TerritoryTypePtr getTerritoryDetail( uint32_t territoryTypeId ) const;
@ -165,6 +165,7 @@ namespace Sapphire::World::Manager
using LandSetIdToZonePtrMap = std::unordered_map< uint32_t, ZonePtr >;
using TerritoryTypeIdToInstanceMap = std::unordered_map< uint16_t, InstanceIdToZonePtrMap >;
using InstanceContentIdToInstanceMap = std::unordered_map< uint16_t, InstanceIdToZonePtrMap >;
using QuestBattleIdToInstanceMap = std::unordered_map< uint16_t, InstanceIdToZonePtrMap >;
using PlayerIdToInstanceIdMap = std::unordered_map< uint32_t, uint32_t >;
using PositionMap = std::unordered_map< int32_t, ZonePositionPtr >;
using InstanceIdList = std::vector< uint32_t >;
@ -182,8 +183,11 @@ namespace Sapphire::World::Manager
/*! map holding actual instances of InstanceContent */
InstanceContentIdToInstanceMap m_instanceContentIdToInstanceMap;
/*! map holding actual instances of InstanceContent */
QuestBattleIdToInstanceMap m_questBattleIdToInstanceMap;
/*! flat map for easier lookup of instances by guid */
InstanceIdToZonePtrMap m_instanceIdToZonePtrMap;
InstanceIdToZonePtrMap m_guIdToZonePtrMap;
/*! map holding positions for zonelines */
PositionMap m_territoryPositionMap;

View file

@ -39,7 +39,6 @@ Sapphire::World::Territory::Housing::HousingInteriorTerritory::HousingInteriorTe
Zone( territoryTypeId, guId, internalName, contentName, pFw ),
m_landIdent( ident )
{
m_lastActivityTime = 0;
}
Housing::HousingInteriorTerritory::~HousingInteriorTerritory() = default;
@ -105,13 +104,7 @@ void Sapphire::World::Territory::Housing::HousingInteriorTerritory::onPlayerZone
void Sapphire::World::Territory::Housing::HousingInteriorTerritory::onUpdate( uint64_t tickCount )
{
if( m_playerMap.size() > 0 )
m_lastActivityTime = tickCount;
}
uint64_t Sapphire::World::Territory::Housing::HousingInteriorTerritory::getLastActivityTime() const
{
return m_lastActivityTime;
}
const Common::LandIdent Sapphire::World::Territory::Housing::HousingInteriorTerritory::getLandIdent() const

View file

@ -21,8 +21,6 @@ namespace Sapphire::World::Territory::Housing
void onPlayerZoneIn( Entity::Player& player ) override;
void onUpdate( uint64_t tickCount ) override;
uint64_t getLastActivityTime() const;
const Common::LandIdent getLandIdent() const;
void updateHousingObjects();
@ -34,7 +32,6 @@ namespace Sapphire::World::Territory::Housing
private:
Common::LandIdent m_landIdent;
uint64_t m_lastActivityTime;
std::array< Sapphire::Common::HousingObject, 400 > m_housingObjects;
};

View file

@ -69,7 +69,8 @@ Sapphire::Zone::Zone( uint16_t territoryTypeId, uint32_t guId,
m_nextEObjId( 0x400D0000 ),
m_nextActorId( 0x500D0000 ),
m_pFw( pFw ),
m_lastUpdate( 0 )
m_lastUpdate( 0 ),
m_lastActivityTime( Util::getTimeMs() )
{
auto pExdData = m_pFw->get< Data::ExdDataGenerated >();
m_guId = guId;
@ -439,6 +440,10 @@ void Sapphire::Zone::updateBNpcs( uint64_t tickCount )
}
uint64_t Sapphire::Zone::getLastActivityTime() const
{
return m_lastActivityTime;
}
bool Sapphire::Zone::update( uint64_t tickCount )
{
@ -450,6 +455,10 @@ bool Sapphire::Zone::update( uint64_t tickCount )
onUpdate( tickCount );
updateSpawnPoints();
if( m_playerMap.size() > 0 )
m_lastActivityTime = tickCount;
return true;
}

View file

@ -50,6 +50,8 @@ namespace Sapphire
int64_t m_lastMobUpdate;
int64_t m_lastUpdate;
uint64_t m_lastActivityTime;
FestivalPair m_currentFestival;
std::shared_ptr< Data::TerritoryType > m_territoryTypeInfo;
@ -81,6 +83,8 @@ namespace Sapphire
std::shared_ptr< Data::TerritoryType > getTerritoryTypeInfo() const;
uint64_t getLastActivityTime() const;
virtual bool init();
virtual void loadCellCache();