mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-06 18:57:45 +00:00
Cleanup HousingMgr + Style
This commit is contained in:
parent
d6ebb2345a
commit
df6d019762
6 changed files with 20 additions and 59 deletions
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "Actor/Player.h"
|
#include "Actor/Player.h"
|
||||||
|
|
||||||
|
#include "TerritoryMgr.h"
|
||||||
#include "Zone.h"
|
#include "Zone.h"
|
||||||
#include "HousingZone.h"
|
#include "HousingZone.h"
|
||||||
#include "HousingMgr.h"
|
#include "HousingMgr.h"
|
||||||
|
@ -26,8 +27,7 @@ using namespace Core::Network::Packets::Server;
|
||||||
|
|
||||||
extern Core::Framework g_fw;
|
extern Core::Framework g_fw;
|
||||||
|
|
||||||
Core::HousingMgr::HousingMgr() :
|
Core::HousingMgr::HousingMgr()
|
||||||
m_lastLandId( 0 )
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,61 +43,32 @@ bool Core::HousingMgr::init()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Core::HousingMgr::getNextLandId()
|
|
||||||
{
|
|
||||||
return ++m_lastLandId;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Core::HousingMgr::toLandSetId( uint16_t territoryTypeId, uint8_t wardId ) const
|
uint32_t Core::HousingMgr::toLandSetId( uint16_t territoryTypeId, uint8_t wardId ) const
|
||||||
{
|
{
|
||||||
return ( static_cast< uint32_t >( territoryTypeId ) << 16 ) | wardId;
|
return ( static_cast< uint32_t >( territoryTypeId ) << 16 ) | wardId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::HousingMgr::insertHousingZone( Core::Data::HousingZonePtr hZone )
|
|
||||||
{
|
|
||||||
uint16_t id = getNextLandId();
|
|
||||||
m_housingZonePtrMap[id] = hZone;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::Data::HousingZonePtr Core::HousingMgr::getHousingZone( uint16_t id )
|
|
||||||
{
|
|
||||||
auto it = m_housingZonePtrMap.find( id );
|
|
||||||
if( it == m_housingZonePtrMap.end() )
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::Data::HousingZonePtr Core::HousingMgr::getHousingZoneByLandSetId( uint32_t id )
|
Core::Data::HousingZonePtr Core::HousingMgr::getHousingZoneByLandSetId( uint32_t id )
|
||||||
{
|
{
|
||||||
for( const auto& hZoneIt : m_housingZonePtrMap )
|
auto pTeriMgr = g_fw.get< TerritoryMgr >();
|
||||||
{
|
return std::dynamic_pointer_cast< HousingZone >( pTeriMgr->getZoneByLandSetId( id ) );
|
||||||
auto pHousingZone = hZoneIt.second;
|
|
||||||
for( uint8_t landId = 0; landId < 60; landId++ )
|
|
||||||
{
|
|
||||||
if( pHousingZone->getLandSetId() == id )
|
|
||||||
{
|
|
||||||
return pHousingZone;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::LandPtr Core::HousingMgr::getLandByOwnerId( uint32_t id )
|
Core::LandPtr Core::HousingMgr::getLandByOwnerId( uint32_t id )
|
||||||
{
|
{
|
||||||
for( const auto& hZoneIt : m_housingZonePtrMap )
|
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
||||||
{
|
auto res = pDb->query( "SELECT LandSetId, LandId FROM land WHERE OwnerId = " + std::to_string( id ) );
|
||||||
auto pHousingZone = hZoneIt.second;
|
|
||||||
for( uint8_t landId = 0; landId < 60; landId++ )
|
if( !res->next() )
|
||||||
{
|
|
||||||
if( pHousingZone->getLand( landId )->getPlayerOwner() == id )
|
|
||||||
{
|
|
||||||
return pHousingZone->getLand( landId );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
auto hZone = getHousingZoneByLandSetId( res->getUInt( 1 ) );
|
||||||
|
|
||||||
|
if( !hZone )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return hZone->getLand( res->getUInt( 2 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::HousingMgr::sendLandSignOwned( Entity::Player& player, uint8_t wardId, uint8_t plotId, uint16_t territoryTypeId )
|
void Core::HousingMgr::sendLandSignOwned( Entity::Player& player, uint8_t wardId, uint8_t plotId, uint16_t territoryTypeId )
|
||||||
|
|
|
@ -23,9 +23,6 @@ namespace Core
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
uint32_t toLandSetId( uint16_t territoryTypeId, uint8_t wardId ) const;
|
uint32_t toLandSetId( uint16_t territoryTypeId, uint8_t wardId ) const;
|
||||||
uint16_t getNextLandId();
|
|
||||||
void insertHousingZone( Core::Data::HousingZonePtr hZone );
|
|
||||||
Core::Data::HousingZonePtr getHousingZone( uint16_t id );
|
|
||||||
Core::Data::HousingZonePtr getHousingZoneByLandSetId( uint32_t id );
|
Core::Data::HousingZonePtr getHousingZoneByLandSetId( uint32_t id );
|
||||||
Core::LandPtr getLandByOwnerId( uint32_t id );
|
Core::LandPtr getLandByOwnerId( uint32_t id );
|
||||||
|
|
||||||
|
@ -36,9 +33,7 @@ namespace Core
|
||||||
bool relinquishLand( Entity::Player& player, uint8_t plot );
|
bool relinquishLand( Entity::Player& player, uint8_t plot );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using HousingZonePtrMap = std::unordered_map< uint16_t, Core::Data::HousingZonePtr >;
|
|
||||||
uint16_t m_lastLandId;
|
|
||||||
HousingZonePtrMap m_housingZonePtrMap;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,9 +65,6 @@ bool Core::HousingZone::init()
|
||||||
m_landPtrMap[ landId ] = pObject;
|
m_landPtrMap[ landId ] = pObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pHousingMgr = g_fw.get< HousingMgr >();
|
|
||||||
pHousingMgr->insertHousingZone( (HousingZonePtr)this );
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,9 +154,7 @@ uint16_t Core::Land::getZoneId() const
|
||||||
|
|
||||||
Core::HousePtr Core::Land::getHouse() const
|
Core::HousePtr Core::Land::getHouse() const
|
||||||
{
|
{
|
||||||
if( !m_house )
|
return m_pHouse;
|
||||||
return nullptr;
|
|
||||||
return m_house;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Common::LandType Core::Land::getLandType() const
|
Core::Common::LandType Core::Land::getLandType() const
|
||||||
|
|
|
@ -80,7 +80,7 @@ namespace Core
|
||||||
uint32_t m_ownerPlayerId;
|
uint32_t m_ownerPlayerId;
|
||||||
Core::Data::HousingLandSetPtr m_landInfo;
|
Core::Data::HousingLandSetPtr m_landInfo;
|
||||||
|
|
||||||
Core::HousePtr m_house;
|
Core::HousePtr m_pHouse;
|
||||||
|
|
||||||
//item storage
|
//item storage
|
||||||
Core::ItemContainerPtr ItemsOutdoorContainer;
|
Core::ItemContainerPtr ItemsOutdoorContainer;
|
||||||
|
|
Loading…
Add table
Reference in a new issue