2018-11-01 23:56:43 +01:00
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <Common.h>
|
|
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Util/Util.h>
|
|
|
|
#include <Util/UtilMath.h>
|
|
|
|
#include <Exd/ExdDataGenerated.h>
|
|
|
|
#include <Database/DatabaseDef.h>
|
|
|
|
|
|
|
|
#include <MySqlBase.h>
|
|
|
|
#include <Connection.h>
|
|
|
|
|
|
|
|
#include <Network/GamePacketNew.h>
|
|
|
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
|
|
|
|
|
|
|
#include "Actor/Player.h"
|
|
|
|
#include "Inventory/ItemContainer.h"
|
|
|
|
#include "Inventory/Item.h"
|
2018-12-23 13:26:33 +01:00
|
|
|
|
|
|
|
#include "Manager/ItemMgr.h"
|
2018-11-01 23:56:43 +01:00
|
|
|
|
|
|
|
#include "Forwards.h"
|
|
|
|
#include "Land.h"
|
|
|
|
#include "Framework.h"
|
2018-11-25 01:55:53 +11:00
|
|
|
#include "House.h"
|
2018-11-01 23:56:43 +01:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Common;
|
2018-11-01 23:56:43 +01:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId, uint32_t landSetId,
|
2018-12-29 00:53:52 +01:00
|
|
|
Sapphire::Data::HousingLandSetPtr info, FrameworkPtr pFw ) :
|
2018-11-01 23:56:43 +01:00
|
|
|
m_currentPrice( 0 ),
|
2018-11-09 10:53:11 +01:00
|
|
|
m_minPrice( 0 ),
|
2018-11-10 23:47:19 +01:00
|
|
|
m_nextDrop( static_cast< uint32_t >( Util::getTimeSeconds() ) + 21600 ),
|
2018-12-19 16:03:35 +11:00
|
|
|
m_ownerId( 0 ),
|
2018-11-04 23:47:10 +01:00
|
|
|
m_landSetId( landSetId ),
|
2018-11-13 19:48:22 +01:00
|
|
|
m_landInfo( info ),
|
2018-11-25 23:20:56 +11:00
|
|
|
m_type( Common::LandType::none ),
|
2018-11-25 01:55:53 +11:00
|
|
|
m_fcIcon( 0 ),
|
|
|
|
m_fcIconColor( 0 ),
|
|
|
|
m_fcId( 0 ),
|
2018-12-29 00:53:52 +01:00
|
|
|
m_iconAddIcon( 0 ),
|
|
|
|
m_pFw( pFw )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-10 19:00:13 +01:00
|
|
|
memset( &m_tag, 0x00, 3 );
|
2018-11-11 14:27:39 +01:00
|
|
|
|
2018-12-21 22:08:05 +11:00
|
|
|
m_landIdent.landId = landId;
|
|
|
|
m_landIdent.territoryTypeId = territoryTypeId;
|
|
|
|
m_landIdent.wardNum = wardNum;
|
|
|
|
m_landIdent.worldId = 67; // todo: fix this
|
|
|
|
|
2018-12-22 00:48:43 +11:00
|
|
|
m_minPrice = m_landInfo->minPrice[ m_landIdent.landId ];
|
|
|
|
m_maxPrice = m_landInfo->initialPrice[ m_landIdent.landId ];
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-12-21 22:08:05 +11:00
|
|
|
Sapphire::Land::~Land() = default;
|
2018-11-01 23:56:43 +01:00
|
|
|
|
2018-12-31 21:54:32 +11:00
|
|
|
void Sapphire::Land::init( Common::LandType type, Common::HouseSize size, Common::HouseStatus state, uint32_t currentPrice,
|
2018-12-29 00:53:52 +01:00
|
|
|
uint64_t ownerId, uint64_t houseId )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-12-22 00:48:43 +11:00
|
|
|
m_type = type;
|
|
|
|
m_size = size;
|
|
|
|
m_state = state;
|
|
|
|
m_currentPrice = currentPrice;
|
|
|
|
m_ownerId = ownerId;
|
2018-12-21 23:49:46 +11:00
|
|
|
|
2018-12-29 00:53:52 +01:00
|
|
|
auto pExdData = m_pFw->get< Data::ExdDataGenerated >();
|
2018-12-21 22:08:05 +11:00
|
|
|
auto info = pExdData->get< Sapphire::Data::HousingMapMarkerInfo >( m_landIdent.territoryTypeId, m_landIdent.landId );
|
2018-11-30 22:52:08 +11:00
|
|
|
if( info )
|
|
|
|
{
|
|
|
|
m_mapMarkerPosition.x = info->x;
|
|
|
|
m_mapMarkerPosition.y = info->y;
|
|
|
|
m_mapMarkerPosition.z = info->z;
|
|
|
|
}
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Land::getCurrentPrice() const
|
2018-11-04 23:47:10 +01:00
|
|
|
{
|
|
|
|
return m_currentPrice;
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Land::getMaxPrice() const
|
2018-11-17 01:16:44 +01:00
|
|
|
{
|
|
|
|
return m_maxPrice;
|
|
|
|
}
|
|
|
|
|
2018-11-01 23:56:43 +01:00
|
|
|
//Primary State
|
2018-12-31 21:54:32 +11:00
|
|
|
void Sapphire::Land::setSize( Common::HouseSize size )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
m_size = size;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 21:54:32 +11:00
|
|
|
void Sapphire::Land::setStatus( Common::HouseStatus state )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
m_state = state;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Land::setSharing( uint8_t state )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
m_iconAddIcon = state;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Land::setLandType( Common::LandType type )
|
2018-11-13 19:48:22 +01:00
|
|
|
{
|
|
|
|
m_type = type;
|
|
|
|
}
|
|
|
|
|
2018-12-31 21:54:32 +11:00
|
|
|
Sapphire::Common::HouseSize Sapphire::Land::getSize() const
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_size;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 21:54:32 +11:00
|
|
|
Sapphire::Common::HouseStatus Sapphire::Land::getStatus() const
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_state;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint8_t Sapphire::Land::getSharing() const
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_iconAddIcon;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Land::getLandSetId() const
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
|
|
|
return m_landSetId;
|
|
|
|
}
|
|
|
|
|
2018-12-21 22:08:05 +11:00
|
|
|
Sapphire::Common::LandIdent Sapphire::Land::getLandIdent() const
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
2018-12-21 22:08:05 +11:00
|
|
|
return m_landIdent;
|
2018-11-10 19:00:13 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::HousePtr Sapphire::Land::getHouse() const
|
2018-11-19 09:40:44 +01:00
|
|
|
{
|
2018-11-19 11:55:29 +01:00
|
|
|
return m_pHouse;
|
2018-11-19 09:40:44 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 14:35:42 +11:00
|
|
|
void Sapphire::Land::setHouse( Sapphire::HousePtr house )
|
|
|
|
{
|
|
|
|
m_pHouse = house;
|
|
|
|
}
|
|
|
|
|
2018-11-30 22:52:08 +11:00
|
|
|
FFXIVARR_POSITION3 Sapphire::Land::getMapMarkerPosition()
|
|
|
|
{
|
|
|
|
return m_mapMarkerPosition;
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::Common::LandType Sapphire::Land::getLandType() const
|
2018-11-13 19:48:22 +01:00
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
2018-11-01 23:56:43 +01:00
|
|
|
//Free Comapny
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Land::setFreeCompany( uint32_t id, uint32_t icon, uint32_t color )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
m_fcId = id;
|
|
|
|
m_fcIcon = icon;
|
|
|
|
m_fcIconColor = color; //RGBA
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Land::getFcId()
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_fcIcon;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Land::getFcIcon()
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_fcIcon;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Land::getFcColor()
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_fcIconColor;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Player
|
2018-12-19 16:03:35 +11:00
|
|
|
void Sapphire::Land::setOwnerId( uint64_t id )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-12-19 16:03:35 +11:00
|
|
|
m_ownerId = id;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-12-19 16:03:35 +11:00
|
|
|
uint64_t Sapphire::Land::getOwnerId()
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-12-19 16:03:35 +11:00
|
|
|
return m_ownerId;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Land::getDevaluationTime()
|
2018-11-07 11:08:07 +01:00
|
|
|
{
|
2018-11-10 23:47:19 +01:00
|
|
|
return m_nextDrop - static_cast< uint32_t >( Util::getTimeSeconds() );
|
2018-11-07 11:08:07 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Land::setCurrentPrice( uint32_t currentPrice )
|
2018-11-17 01:16:44 +01:00
|
|
|
{
|
|
|
|
m_currentPrice = currentPrice;
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Land::setLandTag( uint8_t slot, uint8_t tag )
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
|
|
|
m_tag[ slot ] = tag;
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint8_t Sapphire::Land::getLandTag( uint8_t slot )
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
|
|
|
return m_tag[ slot ];
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Land::updateLandDb()
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-25 01:55:53 +11:00
|
|
|
uint32_t houseId = 0;
|
|
|
|
|
|
|
|
if( getHouse() )
|
2018-12-23 20:54:21 +11:00
|
|
|
houseId = getHouse()->getId();
|
2018-11-25 01:55:53 +11:00
|
|
|
|
2018-11-26 23:32:22 +11:00
|
|
|
// todo: change to prepared statement
|
2018-12-29 00:53:52 +01:00
|
|
|
auto pDb = m_pFw->get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
2018-11-14 09:22:17 +01:00
|
|
|
pDb->directExecute( "UPDATE land SET status = " + std::to_string( m_state )
|
2018-12-29 00:53:52 +01:00
|
|
|
+ ", LandPrice = " + std::to_string( getCurrentPrice() )
|
|
|
|
+ ", UpdateTime = " + std::to_string( getDevaluationTime() )
|
|
|
|
+ ", OwnerId = " + std::to_string( getOwnerId() )
|
|
|
|
+ ", HouseId = " + std::to_string( houseId )
|
|
|
|
+ ", Type = " + std::to_string( static_cast< uint32_t >( m_type ) ) //TODO: add house id
|
|
|
|
+ " WHERE LandSetId = " + std::to_string( m_landSetId )
|
|
|
|
+ " AND LandId = " + std::to_string( m_landIdent.landId ) + ";" );
|
2018-11-26 23:32:22 +11:00
|
|
|
|
|
|
|
if( auto house = getHouse() )
|
|
|
|
house->updateHouseDb();
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Land::update( uint32_t currTime )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-12-31 21:54:32 +11:00
|
|
|
if( getStatus() == HouseStatus::HouseForSale )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-09 10:00:36 +01:00
|
|
|
if( m_nextDrop < currTime && m_minPrice < m_currentPrice )
|
2018-11-07 11:08:07 +01:00
|
|
|
{
|
2018-11-09 10:00:36 +01:00
|
|
|
m_nextDrop = currTime + 21600;
|
2018-12-02 02:01:41 +01:00
|
|
|
m_currentPrice = static_cast< uint32_t >( ( m_currentPrice / 100 ) * 99.58f );
|
2018-11-15 12:40:02 +01:00
|
|
|
updateLandDb();
|
2018-11-07 11:08:07 +01:00
|
|
|
}
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
2018-11-14 09:22:17 +01:00
|
|
|
}
|
2018-11-24 15:17:18 +11:00
|
|
|
|
2018-12-23 19:13:30 +11:00
|
|
|
Sapphire::Land::InvMaxItemsPair Sapphire::Land::getInventoryItemMax() const
|
2018-11-24 15:17:18 +11:00
|
|
|
{
|
2018-12-23 19:13:30 +11:00
|
|
|
return std::make_pair( m_maxPlacedExternalItems, m_maxPlacedInternalItems );
|
2018-12-05 19:58:43 +11:00
|
|
|
}
|