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"
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
extern Core::Framework g_fw;
|
|
|
|
|
|
|
|
using namespace Core::Common;
|
|
|
|
|
2018-11-25 01:55:53 +11:00
|
|
|
Core::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId, uint32_t landSetId,
|
2018-11-04 23:47:10 +01:00
|
|
|
Core::Data::HousingLandSetPtr info ) :
|
2018-11-25 01:55:53 +11:00
|
|
|
m_territoryTypeId( territoryTypeId ),
|
2018-11-01 23:56:43 +01:00
|
|
|
m_wardNum( wardNum ),
|
|
|
|
m_landId( landId ),
|
|
|
|
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-11-10 19:00:13 +01:00
|
|
|
m_ownerPlayerId( 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 ),
|
|
|
|
m_iconAddIcon( 0 )
|
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-11-01 23:56:43 +01:00
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::Land::~Land()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Land::load()
|
|
|
|
{
|
2018-11-04 23:47:10 +01:00
|
|
|
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
2018-11-10 19:00:13 +01:00
|
|
|
auto res = pDb->query( "SELECT * FROM land WHERE LandSetId = " + std::to_string( m_landSetId ) + " "
|
|
|
|
"AND LandId = " + std::to_string( m_landId ) );
|
2018-11-04 23:47:10 +01:00
|
|
|
if( !res->next() )
|
|
|
|
{
|
2018-11-25 23:20:56 +11:00
|
|
|
pDb->directExecute( "INSERT INTO land ( landsetid, landid, type, size, status, landprice, UpdateTime, OwnerId, HouseId ) "
|
2018-11-04 23:47:10 +01:00
|
|
|
"VALUES ( " + std::to_string( m_landSetId ) + "," + std::to_string( m_landId ) + ","
|
2018-11-13 19:48:22 +01:00
|
|
|
+ std::to_string( static_cast< uint8_t >( m_type ) ) + ","
|
2018-11-23 21:16:02 +01:00
|
|
|
+ std::to_string( m_landInfo->plotSize[ m_landId ] ) + ","
|
2018-11-25 23:20:56 +11:00
|
|
|
+ " 1, " + std::to_string( m_landInfo->initialPrice[ m_landId ] ) + ", 0, 0, 0 );" );
|
2018-11-04 23:47:10 +01:00
|
|
|
|
2018-11-23 21:16:02 +01:00
|
|
|
m_currentPrice = m_landInfo->initialPrice[ m_landId ];
|
|
|
|
m_minPrice = m_landInfo->minPrice[ m_landId ];
|
|
|
|
m_size = m_landInfo->plotSize[ m_landId ];
|
2018-11-14 09:22:17 +01:00
|
|
|
m_state = HouseState::forSale;
|
2018-11-04 23:47:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-13 19:48:22 +01:00
|
|
|
m_type = static_cast< Common::LandType >( res->getUInt( "Type" ) );
|
2018-11-14 09:22:17 +01:00
|
|
|
m_size = res->getUInt( "Size" );
|
|
|
|
m_state = res->getUInt( "Status" );
|
2018-11-10 19:00:13 +01:00
|
|
|
m_currentPrice = res->getUInt( "LandPrice" );
|
|
|
|
m_ownerPlayerId = res->getUInt( "OwnerId" );
|
2018-11-23 21:16:02 +01:00
|
|
|
m_minPrice = m_landInfo->minPrice[ m_landId ];
|
|
|
|
m_maxPrice = m_landInfo->initialPrice[ m_landId ];
|
2018-11-04 23:47:10 +01:00
|
|
|
}
|
|
|
|
init();
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-24 15:17:18 +11:00
|
|
|
uint32_t Core::Land::convertItemIdToHousingItemId( uint32_t itemId )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
|
|
|
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
|
|
|
|
auto info = pExdData->get< Core::Data::Item >( itemId );
|
|
|
|
return info->additionalData;
|
|
|
|
}
|
|
|
|
|
2018-11-04 23:47:10 +01:00
|
|
|
uint32_t Core::Land::getCurrentPrice() const
|
|
|
|
{
|
|
|
|
return m_currentPrice;
|
|
|
|
}
|
|
|
|
|
2018-11-17 01:16:44 +01:00
|
|
|
uint32_t Core::Land::getMaxPrice() const
|
|
|
|
{
|
|
|
|
return m_maxPrice;
|
|
|
|
}
|
|
|
|
|
2018-11-01 23:56:43 +01:00
|
|
|
//Primary State
|
2018-11-14 10:00:16 +01:00
|
|
|
void Core::Land::setSize( uint8_t 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
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Land::setState( uint8_t state )
|
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
m_state = state;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Land::setSharing( uint8_t state )
|
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
m_iconAddIcon = state;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:48:22 +01:00
|
|
|
void Core::Land::setLandType( Common::LandType type )
|
|
|
|
{
|
|
|
|
m_type = type;
|
|
|
|
}
|
|
|
|
|
2018-11-14 10:00:16 +01:00
|
|
|
uint8_t Core::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-11-13 19:48:22 +01:00
|
|
|
uint8_t Core::Land::getState() 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-13 19:48:22 +01:00
|
|
|
uint8_t Core::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-13 19:48:22 +01:00
|
|
|
uint32_t Core::Land::getLandSetId() const
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
|
|
|
return m_landSetId;
|
|
|
|
}
|
|
|
|
|
2018-11-13 19:48:22 +01:00
|
|
|
uint8_t Core::Land::getWardNum() const
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
|
|
|
return m_wardNum;
|
|
|
|
}
|
|
|
|
|
2018-11-13 19:48:22 +01:00
|
|
|
uint8_t Core::Land::getLandId() const
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
|
|
|
return m_landId;
|
|
|
|
}
|
|
|
|
|
2018-11-25 01:55:53 +11:00
|
|
|
uint16_t Core::Land::getTerritoryTypeId() const
|
2018-11-10 19:00:13 +01:00
|
|
|
{
|
2018-11-25 01:55:53 +11:00
|
|
|
return m_territoryTypeId;
|
2018-11-10 19:00:13 +01:00
|
|
|
}
|
|
|
|
|
2018-11-19 09:40:44 +01:00
|
|
|
Core::HousePtr Core::Land::getHouse() const
|
|
|
|
{
|
2018-11-19 11:55:29 +01:00
|
|
|
return m_pHouse;
|
2018-11-19 09:40:44 +01:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:48:22 +01:00
|
|
|
Core::Common::LandType Core::Land::getLandType() const
|
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
2018-11-01 23:56:43 +01:00
|
|
|
//Free Comapny
|
|
|
|
void Core::Land::setFreeCompany( uint32_t id, uint32_t icon, uint32_t color )
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Core::Land::getFcId()
|
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_fcIcon;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Core::Land::getFcIcon()
|
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_fcIcon;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Core::Land::getFcColor()
|
|
|
|
{
|
2018-11-14 09:22:17 +01:00
|
|
|
return m_fcIconColor;
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Player
|
|
|
|
void Core::Land::setPlayerOwner( uint32_t id )
|
|
|
|
{
|
|
|
|
m_ownerPlayerId = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Core::Land::getPlayerOwner()
|
|
|
|
{
|
|
|
|
return m_ownerPlayerId;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Core::Land::getMaxItems()
|
|
|
|
{
|
|
|
|
return m_maxItems;
|
|
|
|
}
|
|
|
|
|
2018-11-07 11:08:07 +01:00
|
|
|
uint32_t Core::Land::getDevaluationTime()
|
|
|
|
{
|
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-17 01:16:44 +01:00
|
|
|
void Core::Land::setCurrentPrice( uint32_t currentPrice )
|
|
|
|
{
|
|
|
|
m_currentPrice = currentPrice;
|
|
|
|
}
|
|
|
|
|
2018-11-10 19:00:13 +01:00
|
|
|
void Core::Land::setLandTag( uint8_t slot, uint8_t tag )
|
|
|
|
{
|
|
|
|
m_tag[ slot ] = tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t Core::Land::getLandTag( uint8_t slot )
|
|
|
|
{
|
|
|
|
return m_tag[ slot ];
|
|
|
|
}
|
|
|
|
|
2018-11-03 00:47:45 +01:00
|
|
|
void Core::Land::init()
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
|
|
|
|
2018-11-14 10:00:16 +01:00
|
|
|
switch( m_size )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-03 23:44:43 +01:00
|
|
|
case HouseSize::small:
|
2018-11-01 23:56:43 +01:00
|
|
|
m_maxItems = 20;
|
|
|
|
break;
|
2018-11-03 23:44:43 +01:00
|
|
|
case HouseSize::medium:
|
2018-11-01 23:56:43 +01:00
|
|
|
m_maxItems = 30;
|
|
|
|
break;
|
2018-11-03 23:44:43 +01:00
|
|
|
case HouseSize::big:
|
2018-11-01 23:56:43 +01:00
|
|
|
m_maxItems = 40;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:40:02 +01:00
|
|
|
void Core::Land::updateLandDb()
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-25 01:55:53 +11:00
|
|
|
uint32_t houseId = 0;
|
|
|
|
|
|
|
|
if( getHouse() )
|
|
|
|
houseId = getHouse()->getHouseId();
|
|
|
|
|
2018-11-10 19:00:13 +01:00
|
|
|
auto pDb = g_fw.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-11-10 19:00:13 +01:00
|
|
|
+ ", LandPrice = " + std::to_string( getCurrentPrice() )
|
|
|
|
+ ", UpdateTime = " + std::to_string( getDevaluationTime() )
|
2018-11-24 15:17:18 +11:00
|
|
|
+ ", OwnerId = " + std::to_string( getPlayerOwner() )
|
2018-11-25 01:55:53 +11:00
|
|
|
+ ", HouseId = " + std::to_string( houseId )
|
2018-11-13 19:48:22 +01:00
|
|
|
+ ", Type = " + std::to_string( static_cast< uint32_t >( m_type ) ) //TODO: add house id
|
2018-11-10 19:00:13 +01:00
|
|
|
+ " WHERE LandSetId = " + std::to_string( m_landSetId )
|
|
|
|
+ " AND LandId = " + std::to_string( m_landId ) + ";" );
|
2018-11-01 23:56:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-15 12:40:02 +01:00
|
|
|
void Core::Land::update( uint32_t currTime )
|
2018-11-01 23:56:43 +01:00
|
|
|
{
|
2018-11-07 11:08:07 +01:00
|
|
|
if( getState() == HouseState::forSale )
|
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;
|
|
|
|
m_currentPrice = ( m_currentPrice / 100 ) * 99.58;
|
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-11-25 01:55:53 +11:00
|
|
|
uint32_t Core::Land::getNextHouseId()
|
|
|
|
{
|
|
|
|
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
|
|
|
auto pQR = pDb->query( "SELECT MAX( HouseId ) FROM house" );
|
|
|
|
|
|
|
|
if( !pQR->next() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return pQR->getUInt( 1 ) + 1;
|
|
|
|
}
|
|
|
|
|
2018-11-24 15:17:18 +11:00
|
|
|
bool Core::Land::setPreset( uint32_t itemId )
|
|
|
|
{
|
|
|
|
auto housingItemId = convertItemIdToHousingItemId( itemId );
|
|
|
|
|
|
|
|
auto exdData = g_fw.get< Core::Data::ExdDataGenerated >();
|
|
|
|
if( !exdData )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto housingPreset = exdData->get< Core::Data::HousingPreset >( housingItemId );
|
2018-11-25 01:55:53 +11:00
|
|
|
if( !housingPreset )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !getHouse() )
|
|
|
|
{
|
|
|
|
// todo: i guess we'd create a house here?
|
|
|
|
auto newId = getNextHouseId();
|
|
|
|
m_pHouse = make_House( newId, getLandSetId(), getLandId(), getWardNum(), getTerritoryTypeId() );
|
|
|
|
}
|
|
|
|
|
2018-11-26 17:56:29 +11:00
|
|
|
getHouse()->setHousePart( Common::HousePartSlot::ExteriorRoof, convertItemIdToHousingItemId( housingPreset->exteriorRoof ) );
|
|
|
|
getHouse()->setHousePart( Common::HousePartSlot::ExteriorWall, convertItemIdToHousingItemId( housingPreset->exteriorWall ) );
|
|
|
|
getHouse()->setHousePart( Common::HousePartSlot::ExteriorWindow, convertItemIdToHousingItemId( housingPreset->exteriorWindow ) );
|
|
|
|
getHouse()->setHousePart( Common::HousePartSlot::ExteriorDoor, convertItemIdToHousingItemId( housingPreset->exteriorDoor ) );
|
2018-11-24 15:17:18 +11:00
|
|
|
|
2018-11-25 01:55:53 +11:00
|
|
|
return true;
|
2018-11-24 15:17:18 +11:00
|
|
|
}
|