1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00
sapphire/src/servers/sapphire_zone/Zone/HousingZone.cpp

153 lines
4.2 KiB
C++
Raw Normal View History

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>
2018-11-04 23:47:10 +01:00
#include <Exd/ExdDataGenerated.h>
2018-07-15 23:59:15 +02:00
#include <Network/GamePacketNew.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
#include "Actor/Player.h"
2018-11-01 00:18:19 +01:00
#include "Actor/Actor.h"
2018-11-01 23:56:43 +01:00
#include "Land.h"
2018-07-15 23:59:15 +02:00
#include "Forwards.h"
#include "HousingZone.h"
#include "Framework.h"
extern Core::Framework g_fw;
using namespace Core::Common;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
2018-11-04 23:47:10 +01:00
Core::HousingZone::HousingZone( uint8_t wardNum,
2018-07-16 11:58:25 +02:00
uint16_t territoryId,
uint32_t guId,
const std::string& internalName,
2018-07-16 12:37:04 +02:00
const std::string& contentName ) :
Zone( territoryId, guId, internalName, contentName ),
2018-11-04 23:47:10 +01:00
m_wardNum( wardNum ),
m_zoneId( territoryId ),
m_landSetId( ( static_cast< uint32_t >( territoryId ) << 16 ) | wardNum )
2018-07-15 23:59:15 +02:00
{
}
bool Core::HousingZone::init()
{
2018-11-04 23:47:10 +01:00
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
auto res = pDb->query( "SELECT * FROM landset WHERE landsetid = " + std::to_string( m_landSetId ) );
if( !res->next() )
{
pDb->directExecute( "INSERT INTO landset ( landsetid ) VALUES ( " + std::to_string( m_landSetId ) + " );" );
}
int housingIndex;
if( m_zoneId == 339 )
housingIndex = 0;
else if( m_zoneId == 340 )
housingIndex = 1;
else if( m_zoneId == 341 )
housingIndex = 2;
else if( m_zoneId == 641 )
housingIndex = 3;
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
auto info = pExdData->get< Core::Data::HousingLandSet >( housingIndex );
2018-11-01 23:56:43 +01:00
uint32_t landId;
for( landId = 0; landId < 60; landId++ )
{
2018-11-04 23:47:10 +01:00
auto pObject = make_Land( m_territoryId, getWardNum(), landId, m_landSetId, info );
2018-11-01 00:18:19 +01:00
pObject->setHouseSize( 1 );
2018-11-01 23:56:43 +01:00
m_landPtrMap[ landId ] = pObject;
}
2018-07-15 23:59:15 +02:00
return true;
2018-07-15 23:59:15 +02:00
}
Core::HousingZone::~HousingZone()
{
}
2018-11-04 23:47:10 +01:00
void Core::HousingZone::onPlayerZoneIn( Entity::Player& player )
2018-07-15 23:59:15 +02:00
{
auto pLog = g_fw.get< Logger >();
2018-11-01 23:56:43 +01:00
pLog->debug( "HousingZone::onPlayerZoneIn: Zone#" + std::to_string( getGuId() ) + "|"
2018-11-01 00:18:19 +01:00
", Entity#" + std::to_string( player.getId() ) );
2018-07-15 23:59:15 +02:00
uint32_t yardPacketNum;
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
2018-11-01 00:18:19 +01:00
for( yardPacketNum = 0; yardPacketNum < yardPacketTotal; yardPacketNum++ )
{
2018-11-01 23:56:43 +01:00
auto landsetYardInitializePacket = makeZonePacket< FFXIVIpcLandSetYardInitialize >( player.getId() );
2018-11-01 00:18:19 +01:00
landsetYardInitializePacket->data().unknown1 = 0xFFFFFFFF;
landsetYardInitializePacket->data().unknown2 = 0xFFFFFFFF;
landsetYardInitializePacket->data().unknown3 = 0xFF;
landsetYardInitializePacket->data().packetNum = yardPacketNum;
landsetYardInitializePacket->data().packetTotal = yardPacketTotal;
//TODO: Add Objects here
2018-11-03 00:47:45 +01:00
player.queuePacket( landsetYardInitializePacket );
}
2018-07-15 23:59:15 +02:00
2018-11-01 00:18:19 +01:00
}
2018-07-15 23:59:15 +02:00
2018-11-04 23:47:10 +01:00
void Core::HousingZone::sendLandSet( Entity::Player& player )
2018-11-01 00:18:19 +01:00
{
2018-11-01 23:56:43 +01:00
auto landsetInitializePacket = makeZonePacket< FFXIVIpcLandSetInitialize >( player.getId() );
2018-07-16 12:37:04 +02:00
2018-11-01 23:56:43 +01:00
landsetInitializePacket->data().landSetId = m_landSetId;
2018-11-01 00:18:19 +01:00
landsetInitializePacket->data().zoneId = m_territoryId;
//TODO: get current WorldId
landsetInitializePacket->data().worldId = 67;
landsetInitializePacket->data().subInstance = isPlayerSubInstance( player ) == false ? 1 : 2;
2018-07-15 23:59:15 +02:00
2018-11-01 00:18:19 +01:00
uint8_t startIndex = isPlayerSubInstance( player ) == false ? 0 : 30;
2018-11-04 23:47:10 +01:00
for( uint8_t i = startIndex, count = 0; i < ( startIndex + 30 ); i++ )
2018-11-01 00:18:19 +01:00
{
2018-11-04 23:47:10 +01:00
memcpy( &landsetInitializePacket->data().land[ count++ ], &getLand( i )->getLand(), sizeof( Common::LandStruct ) );
}
2018-07-15 23:59:15 +02:00
2018-11-01 00:18:19 +01:00
player.queuePacket( landsetInitializePacket );
}
bool Core::HousingZone::isPlayerSubInstance( Entity::Player& player )
{
return player.getPos().x < -15000.0f; //ToDo: get correct pos
}
void Core::HousingZone::onUpdate( uint32_t currTime )
{
for( uint8_t i = 0; i < 60; i++ )
{
2018-11-01 23:56:43 +01:00
getLand( i )->Update( currTime );
2018-11-01 00:18:19 +01:00
}
2018-07-15 23:59:15 +02:00
}
2018-11-04 23:47:10 +01:00
uint8_t Core::HousingZone::getWardNum() const
{
return m_wardNum;
}
uint32_t Core::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-01 23:56:43 +01:00
Core::LandPtr Core::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;
}