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"
|
2018-11-10 19:00:13 +01:00
|
|
|
#include "HousingMgr.h"
|
2018-07-15 23:59:15 +02:00
|
|
|
#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-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
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-29 21:40:59 +02:00
|
|
|
{
|
2018-11-05 23:07:39 +01:00
|
|
|
auto pObject = make_Land( m_territoryTypeId, getWardNum(), landId, m_landSetId, info );
|
2018-11-01 23:56:43 +01:00
|
|
|
m_landPtrMap[ landId ] = pObject;
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-11-10 19:00:13 +01:00
|
|
|
auto pHousingMgr = g_fw.get< HousingMgr >();
|
|
|
|
pHousingMgr->insertHousingZone( (HousingZonePtr)this );
|
|
|
|
|
2018-08-29 21:40:59 +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
|
|
|
{
|
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;
|
|
|
|
//memcpy( , &getLand( i )->getLand(), sizeof( Common::LandStruct ) );
|
|
|
|
}
|
2018-11-10 19:00:13 +01:00
|
|
|
|
2018-11-11 23:55:34 +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-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-05 23:07:39 +01:00
|
|
|
landsetInitializePacket->data().zoneId = m_territoryTypeId;
|
2018-11-01 00:18:19 +01:00
|
|
|
//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-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-07 11:56:49 +01:00
|
|
|
void Core::HousingZone::sendLandUpdate( uint8_t landId )
|
|
|
|
{
|
|
|
|
for( const auto& playerIt : m_playerMap )
|
|
|
|
{
|
|
|
|
auto pPlayer = playerIt.second;
|
|
|
|
|
|
|
|
auto landUpdatePacket = makeZonePacket< FFXIVIpcLandUpdate >( pPlayer->getId() );
|
|
|
|
landUpdatePacket->data().landId = landId;
|
|
|
|
landUpdatePacket->data().land = getLand( landId )->getLand();
|
|
|
|
|
|
|
|
pPlayer->queuePacket( landUpdatePacket );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-01 00:18:19 +01:00
|
|
|
bool Core::HousingZone::isPlayerSubInstance( Entity::Player& player )
|
|
|
|
{
|
|
|
|
return player.getPos().x < -15000.0f; //ToDo: get correct pos
|
|
|
|
}
|
|
|
|
|
2018-11-11 17:20:47 +01:00
|
|
|
Core::LandPurchaseResult Core::HousingZone::purchseLand( Entity::Player& player, uint8_t plot, uint8_t state )
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
2018-11-10 23:47:19 +01:00
|
|
|
|
|
|
|
auto plotPrice = getLand( plot )->getCurrentPrice();
|
|
|
|
auto gilAvailable = player.getCurrency( CurrencyType::Gil );
|
|
|
|
auto pLand = getLand( plot );
|
|
|
|
|
|
|
|
if( !pLand )
|
2018-11-11 17:20:47 +01:00
|
|
|
return LandPurchaseResult::ERR_INTERNAL;
|
2018-11-10 23:47:19 +01:00
|
|
|
|
|
|
|
if( pLand->getState() != HouseState::forSale )
|
2018-11-11 17:20:47 +01:00
|
|
|
return LandPurchaseResult::ERR_NOT_AVAILABLE;
|
2018-11-10 23:47:19 +01:00
|
|
|
|
|
|
|
if( gilAvailable < plotPrice )
|
2018-11-11 17:20:47 +01:00
|
|
|
return LandPurchaseResult::ERR_NOT_ENOUGH_GIL;
|
2018-11-10 23:47:19 +01:00
|
|
|
|
|
|
|
auto pHousing = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() );
|
|
|
|
|
2018-11-11 17:20:47 +01:00
|
|
|
switch( static_cast< LandPurchaseMode >( state ) )
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
2018-11-11 17:20:47 +01:00
|
|
|
case LandPurchaseMode::FC:
|
2018-11-10 19:00:13 +01:00
|
|
|
player.sendDebug( "Free company house purchase aren't supported at this time." );
|
2018-11-11 17:20:47 +01:00
|
|
|
return LandPurchaseResult::ERR_INTERNAL;
|
|
|
|
|
|
|
|
case LandPurchaseMode::PRIVATE:
|
|
|
|
{
|
|
|
|
|
|
|
|
auto pHousingMgr = g_fw.get< HousingMgr >();
|
|
|
|
auto pOldLand = pHousingMgr->getLandByOwnerId( player.getId() );
|
|
|
|
|
|
|
|
if( pOldLand )
|
|
|
|
return LandPurchaseResult::ERR_NO_MORE_LANDS_FOR_CHAR;
|
2018-11-10 19:00:13 +01:00
|
|
|
|
|
|
|
player.removeCurrency( CurrencyType::Gil, plotPrice );
|
2018-11-10 23:47:19 +01:00
|
|
|
pLand->setPlayerOwner( player.getId() );
|
|
|
|
pLand->setState( HouseState::sold );
|
2018-11-11 23:55:34 +01:00
|
|
|
player.setLandPermissions( LandPermissionSlot::Private, 0x00, plot,
|
2018-11-10 23:47:19 +01:00
|
|
|
pHousing->getWardNum(), pHousing->getTerritoryTypeId() );
|
2018-11-10 19:00:13 +01:00
|
|
|
player.sendLandPermissions();
|
2018-11-12 09:54:15 +01:00
|
|
|
pLand->setLandName( "Private Estate" + std::to_string( pHousing->getWardNum() ) + "-" + std::to_string( plot ) );
|
2018-11-10 23:47:19 +01:00
|
|
|
pLand->UpdateLandDb();
|
2018-11-10 19:00:13 +01:00
|
|
|
sendLandUpdate( plot );
|
2018-11-11 17:20:47 +01:00
|
|
|
return LandPurchaseResult::SUCCESS;
|
|
|
|
}
|
2018-11-10 23:47:19 +01:00
|
|
|
|
|
|
|
default:
|
2018-11-11 17:20:47 +01:00
|
|
|
return LandPurchaseResult::ERR_INTERNAL;
|
2018-11-10 19:00:13 +01:00
|
|
|
}
|
2018-11-10 23:47:19 +01:00
|
|
|
|
2018-11-10 19:00:13 +01:00
|
|
|
}
|
|
|
|
|
2018-11-01 00:18:19 +01:00
|
|
|
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;
|
|
|
|
}
|