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-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-07-15 23:59:15 +02:00
|
|
|
|
|
|
|
#include "Forwards.h"
|
|
|
|
#include "HousingZone.h"
|
2018-11-10 19:00:13 +01:00
|
|
|
#include "HousingMgr.h"
|
2018-07-15 23:59:15 +02:00
|
|
|
#include "Framework.h"
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
extern Sapphire::Framework g_fw;
|
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;
|
|
|
|
using namespace Sapphire::Network::Packets::Server;
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::HousingZone::HousingZone( uint8_t wardNum,
|
2018-11-05 23:07:39 +01:00
|
|
|
uint16_t territoryTypeId,
|
2018-07-16 11:58:25 +02:00
|
|
|
uint32_t guId,
|
|
|
|
const std::string& internalName,
|
2018-07-16 12:37:04 +02:00
|
|
|
const std::string& contentName ) :
|
2018-11-05 23:07:39 +01:00
|
|
|
Zone( territoryTypeId, guId, internalName, contentName ),
|
2018-11-04 23:47:10 +01:00
|
|
|
m_wardNum( wardNum ),
|
2018-11-05 23:07:39 +01:00
|
|
|
m_zoneId( territoryTypeId ),
|
|
|
|
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
|
|
|
|
|
|
|
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 >();
|
2018-11-29 16:55:48 +01:00
|
|
|
auto info = pExdData->get< Sapphire::Data::HousingLandSet >( housingIndex );
|
2018-11-04 23:47:10 +01:00
|
|
|
|
2018-11-01 23:56:43 +01:00
|
|
|
uint32_t landId;
|
|
|
|
for( landId = 0; landId < 60; landId++ )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2018-11-30 22:52:08 +11:00
|
|
|
auto pLand = make_Land( m_territoryTypeId, getWardNum(), landId, m_landSetId, info );
|
|
|
|
m_landPtrMap[ landId ] = pLand;
|
|
|
|
|
|
|
|
if( auto house = pLand->getHouse() )
|
|
|
|
{
|
|
|
|
auto eobj = registerEObj( "entrance", 2002737, 0, 4, pLand->getMapMarkerPosition(), 1.f, 0.f );
|
|
|
|
eobj->setHousingLink( landId << 8 );
|
|
|
|
}
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-07-15 23:59:15 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::HousingZone::~HousingZone()
|
2018-07-15 23:59:15 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::HousingZone::onPlayerZoneIn( Entity::Player& player )
|
2018-07-15 23:59:15 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pLog = g_fw.get< Logger >();
|
2018-11-05 23:39:08 +01:00
|
|
|
pLog->debug(
|
|
|
|
"HousingZone::onPlayerZoneIn: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryTypeId() ) +
|
|
|
|
", Entity#" + std::to_string( player.getId() ) );
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-08-29 21:40:59 +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-08-29 21:40:59 +02:00
|
|
|
{
|
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-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-11-06 23:25:37 +01:00
|
|
|
auto landSetMap = makeZonePacket< FFXIVIpcLandSetMap >( player.getId() );
|
2018-11-10 19:00:13 +01:00
|
|
|
landSetMap->data().subdivision = isPlayerSubInstance( player ) == false ? 2 : 1;
|
2018-11-06 23:25:37 +01:00
|
|
|
uint8_t startIndex = isPlayerSubInstance( player ) == false ? 0 : 30;
|
|
|
|
for( uint8_t i = startIndex, count = 0; i < ( startIndex + 30 ); i++, count++ )
|
|
|
|
{
|
|
|
|
landSetMap->data().landInfo[ count ].status = 1;
|
|
|
|
}
|
2018-11-10 19:00:13 +01:00
|
|
|
|
2018-11-19 09:40:44 +01:00
|
|
|
player.queuePacket( landSetMap );
|
2018-11-06 23:25:37 +01: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
|
|
|
{
|
2018-11-01 23:56:43 +01:00
|
|
|
auto landsetInitializePacket = makeZonePacket< FFXIVIpcLandSetInitialize >( player.getId() );
|
2018-07-16 12:37:04 +02:00
|
|
|
|
2018-11-26 23:15:42 +01:00
|
|
|
landsetInitializePacket->data().landIdent.wardNum = m_wardNum;
|
|
|
|
//landsetInitializePacket->data().landIdent.landSetId = m_landSetId;
|
|
|
|
landsetInitializePacket->data().landIdent.territoryTypeId = m_territoryTypeId;
|
2018-11-01 00:18:19 +01:00
|
|
|
//TODO: get current WorldId
|
2018-11-26 23:15:42 +01:00
|
|
|
landsetInitializePacket->data().landIdent.worldId = 67;
|
2018-11-01 00:18:19 +01:00
|
|
|
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
|
|
|
|
2018-11-14 09:22:17 +01:00
|
|
|
for( uint8_t i = startIndex, count = 0; i < ( startIndex + 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
|
|
|
|
auto& landData = landsetInitializePacket->data().land[ count ];
|
|
|
|
|
|
|
|
landData.plotSize = pLand->getSize();
|
|
|
|
landData.houseState = pLand->getState();
|
|
|
|
landData.iconAddIcon = pLand->getSharing();
|
|
|
|
landData.fcId = pLand->getFcId();
|
|
|
|
landData.fcIcon = pLand->getFcIcon();
|
|
|
|
landData.fcIconColor = pLand->getFcColor();
|
|
|
|
|
|
|
|
if( auto house = pLand->getHouse() )
|
|
|
|
{
|
2018-11-30 22:52:08 +11:00
|
|
|
landData.flags = 1;
|
|
|
|
|
2018-11-26 17:56:29 +11:00
|
|
|
auto& parts = house->getHouseParts();
|
|
|
|
|
|
|
|
for( auto i = 0; i != parts.size(); i++ )
|
|
|
|
{
|
2018-11-26 23:32:22 +11:00
|
|
|
landData.housePart[ i ] = parts[ i ].first;
|
|
|
|
landData.houseColour[ i ] = parts[ i ].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
|
|
|
|
2018-11-01 00:18:19 +01:00
|
|
|
player.queuePacket( landsetInitializePacket );
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::HousingZone::sendLandUpdate( uint8_t landId )
|
2018-11-07 11:56:49 +01:00
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
auto landUpdatePacket = makeZonePacket< FFXIVIpcLandUpdate >( pPlayer->getId() );
|
2018-11-26 23:15:42 +01:00
|
|
|
landUpdatePacket->data().landIdent.landId = landId;
|
2018-11-26 17:56:29 +11:00
|
|
|
|
|
|
|
auto& landData = landUpdatePacket->data().land;
|
|
|
|
|
|
|
|
landData.plotSize = pLand->getSize();
|
|
|
|
landData.houseState = pLand->getState();
|
|
|
|
landData.iconAddIcon = pLand->getSharing();
|
|
|
|
landData.fcId = pLand->getFcId();
|
|
|
|
landData.fcIcon = pLand->getFcIcon();
|
|
|
|
landData.fcIconColor = pLand->getFcColor();
|
|
|
|
|
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-11-26 17:56:29 +11:00
|
|
|
auto& parts = house->getHouseParts();
|
|
|
|
|
|
|
|
for( auto i = 0; i != parts.size(); i++ )
|
2018-11-25 01:55:53 +11:00
|
|
|
{
|
2018-11-26 23:32:22 +11:00
|
|
|
landData.housePart[ i ] = parts[ i ].first;
|
|
|
|
landData.houseColour[ i ] = parts[ i ].second;
|
2018-11-25 01:55:53 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 11:56:49 +01:00
|
|
|
pPlayer->queuePacket( landUpdatePacket );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
bool Sapphire::HousingZone::isPlayerSubInstance( Entity::Player& player )
|
2018-11-01 00:18:19 +01:00
|
|
|
{
|
|
|
|
return player.getPos().x < -15000.0f; //ToDo: get correct pos
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::HousingZone::onUpdate( uint32_t currTime )
|
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
|
|
|
{
|
2018-11-15 12:40:02 +01:00
|
|
|
pLandItr.second->update( currTime );
|
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-11-30 22:52:08 +11:00
|
|
|
}
|