2018-07-15 23:59:15 +02:00
|
|
|
#include <Common.h>
|
|
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Util/Util.h>
|
|
|
|
#include <Util/UtilMath.h>
|
2018-11-01 00:18:19 +01:00
|
|
|
#include <Database/DatabaseDef.h>
|
2021-11-27 00:53:57 +01:00
|
|
|
#include <Exd/ExdData.h>
|
2019-03-08 15:34:38 +01:00
|
|
|
#include <Network/GamePacket.h>
|
2018-07-15 23:59:15 +02:00
|
|
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
2019-10-09 18:14:53 +02:00
|
|
|
#include <Network/PacketWrappers/ActorControlSelfPacket.h>
|
2018-12-28 11:49:12 +11:00
|
|
|
#include <Network/CommonActorControl.h>
|
2020-03-01 01:00:57 +11:00
|
|
|
#include <Service.h>
|
2018-07-15 23:59:15 +02:00
|
|
|
|
|
|
|
#include "Actor/Player.h"
|
2021-11-27 00:53:57 +01:00
|
|
|
#include "Actor/GameObject.h"
|
2018-11-30 22:52:08 +11:00
|
|
|
#include "Actor/EventObject.h"
|
2018-11-01 23:56:43 +01:00
|
|
|
#include "Land.h"
|
2018-11-25 01:55:53 +11:00
|
|
|
#include "House.h"
|
2018-12-26 00:43:27 +11:00
|
|
|
#include "Inventory/HousingItem.h"
|
|
|
|
#include "Inventory/ItemContainer.h"
|
2021-11-27 00:53:57 +01:00
|
|
|
#include "WorldServer.h"
|
2018-07-15 23:59:15 +02:00
|
|
|
|
|
|
|
#include "Forwards.h"
|
|
|
|
#include "HousingZone.h"
|
2018-12-01 00:27:16 +11:00
|
|
|
#include "Manager/HousingMgr.h"
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Common;
|
|
|
|
using namespace Sapphire::Network::Packets;
|
2021-11-27 00:53:57 +01:00
|
|
|
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
2018-12-01 00:27:16 +11:00
|
|
|
using namespace Sapphire::World::Manager;
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2022-01-18 00:21:38 +01:00
|
|
|
Sapphire::HousingZone::HousingZone( uint8_t wardNum, uint16_t territoryTypeId,
|
2021-11-27 00:53:57 +01:00
|
|
|
const std::string& internalName, const std::string& contentName ) :
|
2022-01-18 00:21:38 +01:00
|
|
|
Territory( territoryTypeId, ( static_cast< uint32_t >( territoryTypeId ) << 16 ) | wardNum, internalName, contentName ),
|
2018-11-04 23:47:10 +01:00
|
|
|
m_wardNum( wardNum ),
|
2020-03-01 01:00:57 +11:00
|
|
|
m_landSetId( ( static_cast< uint32_t >( territoryTypeId ) << 16 ) | wardNum )
|
2018-07-15 23:59:15 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
bool Sapphire::HousingZone::init()
|
2018-07-15 23:59:15 +02:00
|
|
|
{
|
2018-11-04 23:47:10 +01:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
2018-11-04 23:47:10 +01:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto res = db.query( "SELECT * FROM landset WHERE landsetid = " + std::to_string( m_landSetId ) );
|
2018-12-22 00:48:43 +11:00
|
|
|
if( !res->next() )
|
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
db.directExecute( "INSERT INTO landset ( landsetid ) VALUES ( " + std::to_string( m_landSetId ) + " );" );
|
2018-12-22 00:48:43 +11:00
|
|
|
}
|
2018-11-04 23:47:10 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 00:48:43 +11:00
|
|
|
|
2018-11-04 23:47:10 +01:00
|
|
|
int housingIndex;
|
2018-12-02 15:32:22 +11:00
|
|
|
if( m_territoryTypeId == 339 )
|
2018-11-04 23:47:10 +01:00
|
|
|
housingIndex = 0;
|
2018-12-02 15:32:22 +11:00
|
|
|
else if( m_territoryTypeId == 340 )
|
2018-11-04 23:47:10 +01:00
|
|
|
housingIndex = 1;
|
2018-12-02 15:32:22 +11:00
|
|
|
else if( m_territoryTypeId == 341 )
|
2018-11-04 23:47:10 +01:00
|
|
|
housingIndex = 2;
|
2018-12-02 15:32:22 +11:00
|
|
|
else if( m_territoryTypeId == 641 )
|
2018-11-04 23:47:10 +01:00
|
|
|
housingIndex = 3;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& exdData = Common::Service< Data::ExdData >::ref();
|
2022-01-27 21:24:54 +01:00
|
|
|
auto info = exdData.getRow< Excel::HousingLandSet >( housingIndex );
|
2018-11-04 23:47:10 +01:00
|
|
|
|
2018-12-26 00:43:27 +11:00
|
|
|
// build yard objects array indices
|
|
|
|
int16_t cursor = -1;
|
|
|
|
uint16_t index = 0;
|
2021-11-27 00:53:57 +01:00
|
|
|
for( const auto entry : info->data().Lands )
|
2018-12-26 00:43:27 +11:00
|
|
|
{
|
|
|
|
uint16_t itemMax = 0;
|
2021-11-27 00:53:57 +01:00
|
|
|
switch( entry.Size )
|
2018-12-26 00:43:27 +11:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
itemMax = 20;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
itemMax = 30;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
itemMax = 40;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t start = cursor + 1;
|
|
|
|
int16_t end = cursor + itemMax;
|
|
|
|
|
|
|
|
m_yardObjectArrayBounds[ index++ ] = std::make_pair( start, end );
|
|
|
|
|
|
|
|
// reset cursor for subdivision
|
|
|
|
if( index == 30 )
|
|
|
|
{
|
|
|
|
cursor = -1;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor += itemMax;
|
|
|
|
}
|
|
|
|
|
2018-12-26 22:39:00 +11:00
|
|
|
// zero out the yard obj arrays so we don't leak memory like SE does :^)
|
2021-11-27 00:53:57 +01:00
|
|
|
Common::Furniture obj {};
|
|
|
|
memset( &obj, 0x0, sizeof( Common::Furniture ) );
|
2018-12-26 22:39:00 +11:00
|
|
|
|
|
|
|
for( auto& arr : m_yardObjects )
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
memcpy( &arr, &m_yardObjects, sizeof( Common::Furniture ) );
|
2018-12-26 22:39:00 +11:00
|
|
|
}
|
2018-12-26 00:43:27 +11:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& housingMgr = Common::Service< World::Manager::HousingMgr >::ref();
|
|
|
|
auto landCache = housingMgr.getLandCacheMap();
|
2018-12-22 00:48:43 +11:00
|
|
|
|
2018-12-22 12:00:03 +11:00
|
|
|
// make sure the landset exists
|
|
|
|
auto landSetCache = landCache.find( m_landSetId );
|
|
|
|
if( landSetCache == landCache.end() )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2019-01-04 22:37:01 +11:00
|
|
|
Logger::fatal( "LandSet {0} is missing from the land cache.", m_landSetId );
|
2018-12-22 12:00:03 +11:00
|
|
|
return false;
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-12-22 12:00:03 +11:00
|
|
|
// init the lands
|
2018-12-22 14:35:42 +11:00
|
|
|
for( HousingMgr::LandCacheEntry& entry : landSetCache->second )
|
2018-12-22 00:48:43 +11:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto land = make_Land( m_territoryTypeId, getWardNum(), entry.m_landId, m_landSetId, info );
|
2018-12-22 14:35:42 +11:00
|
|
|
|
|
|
|
// setup house
|
|
|
|
if( entry.m_houseId )
|
|
|
|
{
|
2022-01-18 23:47:35 +01:00
|
|
|
auto house = make_House( entry.m_houseId, m_landSetId, land->getLandIdent(), entry.m_estateName, entry.m_estateComment );
|
2020-03-01 01:00:57 +11:00
|
|
|
housingMgr.updateHouseModels( house );
|
2018-12-22 15:58:54 +11:00
|
|
|
land->setHouse( house );
|
2018-12-22 14:35:42 +11:00
|
|
|
}
|
|
|
|
|
2018-12-22 12:00:03 +11:00
|
|
|
land->init( entry.m_type, entry.m_size, entry.m_status, entry.m_currentPrice, entry.m_ownerId, entry.m_houseId );
|
2018-12-22 00:48:43 +11:00
|
|
|
|
2018-12-22 12:00:03 +11:00
|
|
|
m_landPtrMap[ entry.m_landId ] = land;
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
// TODO: Fixme
|
2023-01-25 17:11:23 +01:00
|
|
|
if( entry.m_houseId > 0 )
|
|
|
|
registerEstateEntranceEObj( entry.m_landId );
|
2018-12-26 00:43:27 +11:00
|
|
|
|
2018-12-26 22:39:00 +11:00
|
|
|
updateYardObjects( land->getLandIdent() );
|
2018-12-22 00:48:43 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-07-15 23:59:15 +02:00
|
|
|
}
|
|
|
|
|
2023-01-23 14:28:00 +01:00
|
|
|
bool Sapphire::HousingZone::isPlayerSubInstance( Entity::Player& player )
|
|
|
|
{
|
|
|
|
return player.getPos().x < -15000.0f; //ToDo: get correct pos
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::HousingZone::onPlayerZoneIn( Entity::Player& player )
|
2018-07-15 23:59:15 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
2019-07-21 22:33:33 +10:00
|
|
|
Logger::debug( "HousingZone::onPlayerZoneIn: Territory#{0}|{1}, Entity#{2}",
|
2019-01-04 22:37:01 +11:00
|
|
|
getGuId(), getTerritoryTypeId(), player.getId() );
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2023-01-23 14:28:00 +01:00
|
|
|
auto isInSubdivision = isPlayerSubInstance( player );
|
2018-12-25 23:43:39 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
uint32_t yardPacketNum;
|
2023-01-23 14:28:00 +01:00
|
|
|
uint32_t yardPacketTotal = 8;
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-11-04 23:47:10 +01:00
|
|
|
sendLandSet( player );
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2023-01-23 14:28:00 +01:00
|
|
|
for( yardPacketNum = 0; yardPacketNum < yardPacketTotal; yardPacketNum++ )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto housingObjectInit = makeZonePacket< FFXIVIpcYardObjectList >( player.getId() );
|
|
|
|
housingObjectInit->data().PacketIndex = yardPacketNum;
|
|
|
|
auto yardObjectSize = sizeof( Common::Furniture );
|
2023-01-23 14:28:00 +01:00
|
|
|
housingObjectInit->data().PacketIndex = yardPacketNum;
|
|
|
|
housingObjectInit->data().PacketEnd = yardPacketTotal;
|
2018-12-25 23:43:39 +11:00
|
|
|
|
2023-01-23 14:28:00 +01:00
|
|
|
auto& objects = m_yardObjects[ isInSubdivision ? 1 : 0 ];
|
2018-12-25 23:43:39 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
memcpy( &housingObjectInit->data().YardObjects, &objects + ( yardPacketNum * 400 ), yardObjectSize * 400 );
|
2018-11-01 00:18:19 +01:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
server.queueForPlayer( player.getCharacterId(), housingObjectInit );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-11-01 00:18:19 +01:00
|
|
|
}
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::HousingZone::sendLandSet( Entity::Player& player )
|
2018-11-01 00:18:19 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
|
|
|
auto landsetInitializePacket = makeZonePacket< FFXIVIpcHouseList >( player.getId() );
|
2018-07-16 12:37:04 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
landsetInitializePacket->data().LandSetId.wardNum = m_wardNum;
|
|
|
|
landsetInitializePacket->data().LandSetId.landId = m_landSetId;
|
|
|
|
landsetInitializePacket->data().LandSetId.territoryTypeId = m_territoryTypeId;
|
2022-01-18 23:47:35 +01:00
|
|
|
landsetInitializePacket->data().LandSetId.worldId = server.getWorldId();
|
2023-01-24 21:49:44 +01:00
|
|
|
|
|
|
|
auto isInSubdivision = isPlayerSubInstance( player );
|
|
|
|
landsetInitializePacket->data().Subdivision = isInSubdivision ? 2 : 1;
|
2021-11-27 00:53:57 +01:00
|
|
|
for( uint8_t i = 0, count = 0; i < 30; ++i, ++count )
|
2018-11-01 00:18:19 +01:00
|
|
|
{
|
2018-11-15 12:40:02 +01:00
|
|
|
auto pLand = getLand( i );
|
2018-11-26 17:56:29 +11:00
|
|
|
|
|
|
|
// todo: move this and sendLandUpdate building logic to its own function
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& landData = landsetInitializePacket->data().Houses[ count ];
|
2018-11-26 17:56:29 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
landData.size = pLand->getSize();
|
|
|
|
landData.status = pLand->getStatus();
|
|
|
|
landData.flags = pLand->getSharing();
|
2023-01-24 21:49:44 +01:00
|
|
|
landData.fcCrestId = 1;
|
2021-11-27 00:53:57 +01:00
|
|
|
/* //disbaled until we managed fc's
|
|
|
|
landData.fcCrestId = pLand->getFcId();
|
2018-11-26 17:56:29 +11:00
|
|
|
landData.fcIcon = pLand->getFcIcon();
|
|
|
|
landData.fcIconColor = pLand->getFcColor();
|
2021-11-27 00:53:57 +01:00
|
|
|
*/
|
2018-11-26 17:56:29 +11:00
|
|
|
|
|
|
|
if( auto house = pLand->getHouse() )
|
|
|
|
{
|
2018-11-30 22:52:08 +11:00
|
|
|
landData.flags = 1;
|
|
|
|
|
2018-12-22 15:58:54 +11:00
|
|
|
auto& parts = house->getHouseModels();
|
2018-11-26 17:56:29 +11:00
|
|
|
|
2022-01-27 18:35:19 -03:00
|
|
|
for( auto ii = 0; ii != parts.size(); ++ii )
|
2018-11-26 17:56:29 +11:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
landData.patternIds[ ii ] = parts[ ii ].first;
|
|
|
|
landData.colors[ ii ] = parts[ ii ].second;
|
2018-11-26 17:56:29 +11:00
|
|
|
}
|
|
|
|
}
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
server.queueForPlayer( player.getCharacterId(), landsetInitializePacket );
|
2018-11-01 00:18:19 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::HousingZone::sendLandUpdate( uint8_t landId )
|
2018-11-07 11:56:49 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
2018-11-15 22:30:59 +01:00
|
|
|
auto pLand = getLand( landId );
|
2018-11-07 11:56:49 +01:00
|
|
|
for( const auto& playerIt : m_playerMap )
|
|
|
|
{
|
|
|
|
auto pPlayer = playerIt.second;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto landUpdatePacket = makeZonePacket< FFXIVIpcHouse >( pPlayer->getId() );
|
|
|
|
landUpdatePacket->data().Block = landId;
|
2018-11-26 17:56:29 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& landData = landUpdatePacket->data().House;
|
2018-11-26 17:56:29 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
landData.size = pLand->getSize();
|
|
|
|
landData.status = pLand->getStatus();
|
|
|
|
landData.flags = pLand->getSharing();
|
|
|
|
/*
|
2018-11-26 17:56:29 +11:00
|
|
|
landData.fcId = pLand->getFcId();
|
|
|
|
landData.fcIcon = pLand->getFcIcon();
|
|
|
|
landData.fcIconColor = pLand->getFcColor();
|
2021-11-27 00:53:57 +01:00
|
|
|
*/
|
2018-11-07 11:56:49 +01:00
|
|
|
|
2018-11-25 01:55:53 +11:00
|
|
|
if( auto house = pLand->getHouse() )
|
|
|
|
{
|
2018-11-30 22:52:08 +11:00
|
|
|
landData.flags = 1;
|
|
|
|
|
2018-12-22 15:58:54 +11:00
|
|
|
auto& parts = house->getHouseModels();
|
2018-11-26 17:56:29 +11:00
|
|
|
|
2022-01-27 18:35:19 -03:00
|
|
|
for( auto i = 0; i != parts.size(); ++i )
|
2018-11-25 01:55:53 +11:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
landData.patternIds[ i ] = parts[ i ].first;
|
|
|
|
landData.colors[ i ] = parts[ i ].second;
|
2018-11-25 01:55:53 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
server.queueForPlayer( pPlayer->getCharacterId(), landUpdatePacket );
|
2018-11-07 11:56:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 23:29:52 +02:00
|
|
|
void Sapphire::HousingZone::onUpdate( uint64_t tickCount )
|
2018-11-01 00:18:19 +01:00
|
|
|
{
|
2018-11-15 12:40:02 +01:00
|
|
|
for( auto pLandItr : m_landPtrMap )
|
2018-11-01 00:18:19 +01:00
|
|
|
{
|
2019-04-04 23:29:52 +02:00
|
|
|
pLandItr.second->update( tickCount );
|
2018-11-01 00:18:19 +01:00
|
|
|
}
|
2018-07-15 23:59:15 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint8_t Sapphire::HousingZone::getWardNum() const
|
2018-11-04 23:47:10 +01:00
|
|
|
{
|
|
|
|
return m_wardNum;
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::HousingZone::getLandSetId() const
|
2018-07-15 23:59:15 +02:00
|
|
|
{
|
2018-11-01 23:56:43 +01:00
|
|
|
return m_landSetId;
|
2018-07-15 23:59:15 +02:00
|
|
|
}
|
2018-11-01 00:18:19 +01:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::LandPtr Sapphire::HousingZone::getLand( uint8_t id )
|
2018-11-01 00:18:19 +01:00
|
|
|
{
|
2018-11-01 23:56:43 +01:00
|
|
|
auto it = m_landPtrMap.find( id );
|
|
|
|
if( it == m_landPtrMap.end() )
|
2018-11-01 00:18:19 +01:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return it->second;
|
2018-12-07 20:36:52 +11:00
|
|
|
}
|
|
|
|
|
2018-12-25 23:43:39 +11:00
|
|
|
Sapphire::Entity::EventObjectPtr Sapphire::HousingZone::registerEstateEntranceEObj( uint8_t landId )
|
2018-12-07 20:36:52 +11:00
|
|
|
{
|
2018-12-25 23:43:39 +11:00
|
|
|
auto land = getLand( landId );
|
2018-12-07 20:36:52 +11:00
|
|
|
assert( land );
|
|
|
|
|
2022-02-16 11:56:59 +01:00
|
|
|
auto eObj = Entity::make_EventObject( getNextEObjId(), 2002737, 0, 0, 4, land->getMapMarkerPosition(), 0.f, "entrance", 0 );
|
2023-01-25 22:03:29 +01:00
|
|
|
eObj->setHousingLink( static_cast< uint32_t >( landId ) << 8 );
|
2018-12-07 20:36:52 +11:00
|
|
|
eObj->setScale( 1.f );
|
|
|
|
|
2022-02-16 11:56:59 +01:00
|
|
|
addEObj( eObj );
|
2018-12-07 20:36:52 +11:00
|
|
|
|
|
|
|
return eObj;
|
2018-12-26 00:43:27 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sapphire::HousingZone::updateYardObjects( Sapphire::Common::LandIdent ident )
|
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& housingMgr = Common::Service< World::Manager::HousingMgr >::ref();
|
|
|
|
auto& landStorage = housingMgr.getEstateInventory( ident );
|
2018-12-26 00:43:27 +11:00
|
|
|
|
|
|
|
auto yardContainer = landStorage[ InventoryType::HousingExteriorPlacedItems ];
|
|
|
|
|
2018-12-26 22:39:00 +11:00
|
|
|
auto arrayBounds = m_yardObjectArrayBounds[ ident.landId ];
|
|
|
|
|
2018-12-26 00:43:27 +11:00
|
|
|
for( const auto& item : yardContainer->getItemMap() )
|
|
|
|
{
|
2018-12-26 22:39:00 +11:00
|
|
|
auto housingItem = std::dynamic_pointer_cast< Inventory::HousingItem >( item.second );
|
|
|
|
assert( housingItem );
|
2018-12-26 00:43:27 +11:00
|
|
|
|
2018-12-26 22:39:00 +11:00
|
|
|
auto idx = item.first + arrayBounds.first;
|
2021-11-27 00:53:57 +01:00
|
|
|
m_yardObjects[ idx ] = housingMgr.getYardObjectForItem( housingItem );
|
2018-12-26 00:43:27 +11:00
|
|
|
}
|
2018-12-26 18:11:18 +11:00
|
|
|
}
|
|
|
|
|
2018-12-27 22:28:31 +11:00
|
|
|
void Sapphire::HousingZone::spawnYardObject( uint8_t landId, uint16_t slotId, Inventory::HousingItem& item )
|
2018-12-26 18:11:18 +11:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
2018-12-26 18:11:18 +11:00
|
|
|
auto bounds = m_yardObjectArrayBounds[ landId ];
|
|
|
|
auto offset = bounds.first + slotId;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
Common::Furniture obj {};
|
2018-12-26 18:11:18 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
obj.patternId = item.getAdditionalData();
|
|
|
|
obj.dir = Util::floatToUInt16Rot( item.getRot() );
|
2018-12-26 18:11:18 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
obj.pos[ 0 ] = Util::floatToUInt16( item.getPos().x );
|
|
|
|
obj.pos[ 1 ] = Util::floatToUInt16( item.getPos().y );
|
|
|
|
obj.pos[ 2 ] = Util::floatToUInt16( item.getPos().z );
|
2018-12-26 18:11:18 +11:00
|
|
|
|
|
|
|
// link obj
|
2021-11-27 00:53:57 +01:00
|
|
|
m_yardObjects[ offset ] = obj;
|
2018-12-26 18:11:18 +11:00
|
|
|
|
|
|
|
// spawn obj in zone
|
|
|
|
for( const auto& player : m_playerMap )
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto packet = makeZonePacket< FFXIVIpcYardObject >( player.second->getId() );
|
2018-12-26 18:11:18 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
packet->data().YardObject = obj;
|
2018-12-26 18:11:18 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
server.queueForPlayer( player.second->getCharacterId(), packet );
|
2018-12-27 22:28:31 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 23:48:55 +11:00
|
|
|
void Sapphire::HousingZone::updateYardObjectPos( Entity::Player& sourcePlayer, uint16_t slot, uint16_t landId,
|
|
|
|
Inventory::HousingItem& item )
|
2018-12-27 22:28:31 +11:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
2018-12-27 22:28:31 +11:00
|
|
|
auto bounds = m_yardObjectArrayBounds[ landId ];
|
|
|
|
auto offset = bounds.first + slot;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& obj = m_yardObjects[ offset ];
|
2018-12-27 22:28:31 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
obj.dir = Util::floatToUInt16( item.getRot() );
|
|
|
|
obj.pos[ 0 ] = Util::floatToUInt16( item.getPos().x );
|
|
|
|
obj.pos[ 1 ] = Util::floatToUInt16( item.getPos().y );
|
|
|
|
obj.pos[ 2 ] = Util::floatToUInt16( item.getPos().z );
|
2018-12-27 22:28:31 +11:00
|
|
|
|
|
|
|
for( const auto& player : m_playerMap )
|
|
|
|
{
|
2018-12-27 23:48:55 +11:00
|
|
|
// don't send it from the origin player, it already has the position from the move request
|
|
|
|
if( player.second->getId() == sourcePlayer.getId() )
|
|
|
|
continue;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto packet = makeZonePacket< FFXIVIpcHousingObjectTransform >( player.second->getId() );
|
2018-12-27 22:28:31 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
packet->data().Dir = Util::floatToUInt16( item.getRot() );
|
|
|
|
packet->data().Pos[ 0 ] = Util::floatToUInt16( item.getPos().x );
|
|
|
|
packet->data().Pos[ 1 ] = Util::floatToUInt16( item.getPos().y );
|
|
|
|
packet->data().Pos[ 2 ] = Util::floatToUInt16( item.getPos().z );
|
2018-12-27 22:28:31 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
packet->data().UserData1 = static_cast< uint8_t >( landId );
|
|
|
|
packet->data().UserData2 = static_cast< uint8_t >( slot );
|
2018-12-27 22:28:31 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
server.queueForPlayer( player.second->getCharacterId(), packet );
|
2018-12-26 18:11:18 +11:00
|
|
|
}
|
2018-12-28 11:49:12 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sapphire::HousingZone::despawnYardObject( uint16_t landId, uint16_t slot )
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& server = Common::Service< World::WorldServer >::ref();
|
2018-12-28 11:49:12 +11:00
|
|
|
auto bounds = m_yardObjectArrayBounds[ landId ];
|
|
|
|
auto offset = bounds.first + slot;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
memset( &m_yardObjects[ offset ], 0x00, sizeof( Common::Furniture ) );
|
2018-12-28 11:49:12 +11:00
|
|
|
|
|
|
|
for( const auto& player : m_playerMap )
|
|
|
|
{
|
|
|
|
auto param = ( landId << 16 ) | slot;
|
2021-11-27 00:53:57 +01:00
|
|
|
auto pkt = makeActorControlSelf( player.second->getId(), Network::ActorControl::RemoveExteriorHousingItem, param );
|
2018-12-28 11:49:12 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
server.queueForPlayer( player.second->getCharacterId(), pkt );
|
2018-12-28 11:49:12 +11:00
|
|
|
}
|
2019-03-08 15:34:38 +01:00
|
|
|
}
|