1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 14:57:44 +00:00

Merge pull request #1 from SapphireMordred/housing

Housing
This commit is contained in:
XeAri 2018-11-11 10:47:21 +01:00 committed by GitHub
commit 93ee3d1e27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 23 deletions

View file

@ -184,7 +184,7 @@ enum ActorControlType :
AchievementPopup = 0x203,
Unk7 = 0x205, // LogMessage?
LogMsg = 0x205, // LogMessage?
AchievementMsg = 0x206,
SetItemLevel = 0x209,

View file

@ -2,6 +2,9 @@
#include <Actor/Player.h>
#include <Zone/Zone.h>
#include <Zone/HousingZone.h>
#include <Network/PacketWrappers/ActorControlPacket143.h>
#include <Network/CommonActorControl.h>
using namespace Core;
@ -25,7 +28,27 @@ public:
auto pTerritory = player.getCurrentZone();
auto pHousing = std::dynamic_pointer_cast< HousingZone >( pTerritory );
pHousing->playerPurchseLand( player, activeLand.plot, result.param2 );
PurchaseResult res = pHousing->purchseLand( player, activeLand.plot,
static_cast< uint8_t >( result.param2 ) );
switch( res )
{
case PurchaseResult::SUCCESS:
{
auto screenMsgPkt = Network::Packets::Server::makeActorControl143( player.getId(),
Network::ActorControl::DutyQuestScreenMsg,
m_id, 0x98 );
player.queuePacket( screenMsgPkt );
}
case PurchaseResult::ERR_NOT_ENOUGH_GIL:
{
auto errorMsg = Network::Packets::Server::makeActorControl143( player.getId(),
Network::ActorControl::LogMsg,
4027 );
player.queuePacket( errorMsg );
}
}
}
};

View file

@ -106,7 +106,7 @@ Core::Entity::Player::~Player()
{
}
void Core::Entity::Player::injectPacket( std::string path )
void Core::Entity::Player::injectPacket( const std::string& path )
{
auto pServerZone = g_fw.get< ServerZone >();
auto session = pServerZone->getSession( getId() );

View file

@ -46,7 +46,7 @@ namespace Core::Entity
void autoAttack( CharaPtr pTarget ) override;
void injectPacket( std::string path );
void injectPacket( const std::string& path );
// EventHandlers
//////////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -58,7 +58,7 @@ Core::LandPtr Core::HousingMgr::getLandByOwnerId( uint32_t id )
for( const auto& hZoneIt : m_housingZonePtrMap )
{
auto pHousingZone = hZoneIt.second;
for( uint8_t landId = 0;landId < 60;landId++ )
for( uint8_t landId = 0; landId < 60; landId++ )
{
if( pHousingZone->getLand( landId )->getPlayerOwner() == id )
{

View file

@ -154,29 +154,45 @@ bool Core::HousingZone::isPlayerSubInstance( Entity::Player& player )
return player.getPos().x < -15000.0f; //ToDo: get correct pos
}
void Core::HousingZone::playerPurchseLand( Entity::Player & player, uint8_t plot, uint8_t state )
Core::PurchaseResult Core::HousingZone::purchseLand( Entity::Player& player, uint8_t plot, uint8_t state )
{
uint32_t plotPrice = getLand( plot )->getCurrentPrice();
if( plotPrice <= player.getCurrency( CurrencyType::Gil ) )
auto plotPrice = getLand( plot )->getCurrentPrice();
auto gilAvailable = player.getCurrency( CurrencyType::Gil );
auto pLand = getLand( plot );
if( !pLand )
return PurchaseResult::ERR_INTERNAL;
if( pLand->getState() != HouseState::forSale )
return PurchaseResult::ERR_NOT_AVAILABLE;
if( gilAvailable < plotPrice )
return PurchaseResult::ERR_NOT_ENOUGH_GIL;
auto pHousing = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() );
switch( state )
{
auto pHousing = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() );
if( state == 1 ) //TODO: add Free company purchase
case 1:
player.sendDebug( "Free company house purchase aren't supported at this time." );
if( state == 2 ) //Private Purchase
{
getLand( plot )->setPlayerOwner( player.getId() );
getLand( plot )->setState( HouseState::sold );
return PurchaseResult::ERR_INTERNAL;
case 2:
player.removeCurrency( CurrencyType::Gil, plotPrice );
player.setLandPermissions( LandPermissionSlot::Private, 0x0B, plot, pHousing->getWardNum(), pHousing->getTerritoryTypeId() );
pLand->setPlayerOwner( player.getId() );
pLand->setState( HouseState::sold );
player.setLandPermissions( LandPermissionSlot::Private, 0x0B, plot,
pHousing->getWardNum(), pHousing->getTerritoryTypeId() );
player.sendLandPermissions();
getLand( plot )->UpdateLandDb();
pLand->UpdateLandDb();
sendLandUpdate( plot );
}
return PurchaseResult::SUCCESS;
default:
return PurchaseResult::ERR_INTERNAL;
}
//else
//TOD: add error msg - insufficient gil
}
void Core::HousingZone::onUpdate( uint32_t currTime )

View file

@ -6,6 +6,14 @@
namespace Core
{
enum class PurchaseResult
{
SUCCESS,
ERR_NOT_ENOUGH_GIL,
ERR_NOT_AVAILABLE,
ERR_INTERNAL,
};
class HousingZone : public Zone
{
public:
@ -26,7 +34,7 @@ namespace Core
void sendLandUpdate( uint8_t landId );
bool isPlayerSubInstance( Entity::Player& player );
void playerPurchseLand( Entity::Player& player, uint8_t plot, uint8_t state );
PurchaseResult purchseLand( Entity::Player& player, uint8_t plot, uint8_t state );
/* returns current ward number for this zone */
uint8_t getWardNum() const;

View file

@ -32,7 +32,7 @@ Core::Land::Land( uint16_t zoneId, uint8_t wardNum, uint8_t landId, uint32_t lan
m_landId( landId ),
m_currentPrice( 0 ),
m_minPrice( 0 ),
m_nextDrop( Util::getTimeSeconds() + 21600 ),
m_nextDrop( static_cast< uint32_t >( Util::getTimeSeconds() ) + 21600 ),
m_ownerPlayerId( 0 ),
m_landSetId( landSetId ),
m_landInfo( info )
@ -260,7 +260,7 @@ uint32_t Core::Land::getMaxItems()
uint32_t Core::Land::getDevaluationTime()
{
return m_nextDrop - Util::getTimeSeconds();
return m_nextDrop - static_cast< uint32_t >( Util::getTimeSeconds() );
}
void Core::Land::setLandTag( uint8_t slot, uint8_t tag )