1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 15:17:46 +00:00

Cleanup and errorhandling

This commit is contained in:
Mordred 2018-11-10 23:47:19 +01:00
parent ca87619161
commit 3cb4e79211
8 changed files with 70 additions and 23 deletions

View file

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

View file

@ -2,6 +2,9 @@
#include <Actor/Player.h> #include <Actor/Player.h>
#include <Zone/Zone.h> #include <Zone/Zone.h>
#include <Zone/HousingZone.h> #include <Zone/HousingZone.h>
#include <Network/PacketWrappers/ActorControlPacket143.h>
#include <Network/CommonActorControl.h>
using namespace Core; using namespace Core;
@ -25,7 +28,27 @@ public:
auto pTerritory = player.getCurrentZone(); auto pTerritory = player.getCurrentZone();
auto pHousing = std::dynamic_pointer_cast< HousingZone >( pTerritory ); 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 pServerZone = g_fw.get< ServerZone >();
auto session = pServerZone->getSession( getId() ); auto session = pServerZone->getSession( getId() );

View file

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

View file

@ -58,7 +58,7 @@ Core::LandPtr Core::HousingMgr::getLandByOwnerId( uint32_t id )
for( const auto& hZoneIt : m_housingZonePtrMap ) for( const auto& hZoneIt : m_housingZonePtrMap )
{ {
auto pHousingZone = hZoneIt.second; 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 ) 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 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() ); case 1:
if( state == 1 ) //TODO: add Free company purchase
player.sendDebug( "Free company house purchase aren't supported at this time." ); player.sendDebug( "Free company house purchase aren't supported at this time." );
if( state == 2 ) //Private Purchase return PurchaseResult::ERR_INTERNAL;
{
getLand( plot )->setPlayerOwner( player.getId() );
getLand( plot )->setState( HouseState::sold );
case 2:
player.removeCurrency( CurrencyType::Gil, plotPrice ); 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(); player.sendLandPermissions();
pLand->UpdateLandDb();
getLand( plot )->UpdateLandDb();
sendLandUpdate( plot ); sendLandUpdate( plot );
} return PurchaseResult::SUCCESS;
default:
return PurchaseResult::ERR_INTERNAL;
} }
//else
//TOD: add error msg - insufficient gil
} }
void Core::HousingZone::onUpdate( uint32_t currTime ) void Core::HousingZone::onUpdate( uint32_t currTime )

View file

@ -6,6 +6,14 @@
namespace Core namespace Core
{ {
enum class PurchaseResult
{
SUCCESS,
ERR_NOT_ENOUGH_GIL,
ERR_NOT_AVAILABLE,
ERR_INTERNAL,
};
class HousingZone : public Zone class HousingZone : public Zone
{ {
public: public:
@ -26,7 +34,7 @@ namespace Core
void sendLandUpdate( uint8_t landId ); void sendLandUpdate( uint8_t landId );
bool isPlayerSubInstance( Entity::Player& player ); 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 */ /* returns current ward number for this zone */
uint8_t getWardNum() const; 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_landId( landId ),
m_currentPrice( 0 ), m_currentPrice( 0 ),
m_minPrice( 0 ), m_minPrice( 0 ),
m_nextDrop( Util::getTimeSeconds() + 21600 ), m_nextDrop( static_cast< uint32_t >( Util::getTimeSeconds() ) + 21600 ),
m_ownerPlayerId( 0 ), m_ownerPlayerId( 0 ),
m_landSetId( landSetId ), m_landSetId( landSetId ),
m_landInfo( info ) m_landInfo( info )
@ -260,7 +260,7 @@ uint32_t Core::Land::getMaxItems()
uint32_t Core::Land::getDevaluationTime() 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 ) void Core::Land::setLandTag( uint8_t slot, uint8_t tag )