1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 07:37:45 +00:00

Merge pull request #380 from NotAdam/develop

item handin, quest abandoning, sql improvements, durability/stain persistance
This commit is contained in:
Mordred 2018-09-06 14:23:20 +02:00 committed by GitHub
commit 611a68f50d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 156 additions and 42 deletions

View file

@ -175,5 +175,13 @@ void Core::Db::CharaDbConnection::doPrepareStatements()
"INSERT INTO charaglobalitem ( CharacterId, ItemId, catalogId, UPDATE_DATE ) VALUES ( ?, ?, ?, NOW() );", "INSERT INTO charaglobalitem ( CharacterId, ItemId, catalogId, UPDATE_DATE ) VALUES ( ?, ?, ?, NOW() );",
CONNECTION_BOTH ); CONNECTION_BOTH );
prepareStatement( CHARA_ITEMGLOBAL_UP,
"UPDATE charaglobalitem SET stack = ?, durability = ?, stain = ? WHERE ItemId = ?;",
CONNECTION_BOTH );
prepareStatement( CHARA_ITEMGLOBAL_DELETE,
"UPDATE charaglobalitem SET IS_DELETE = 1 WHERE ItemId = ?;",
CONNECTION_BOTH );
} }

View file

@ -74,6 +74,8 @@ enum CharaDbStatements :
CHARA_ITEMINV_INS, CHARA_ITEMINV_INS,
CHARA_ITEMGLOBAL_INS, CHARA_ITEMGLOBAL_INS,
CHARA_ITEMGLOBAL_UP,
CHARA_ITEMGLOBAL_DELETE,
MAX_STATEMENTS MAX_STATEMENTS
}; };

View file

@ -269,6 +269,10 @@ enum ClientTriggerType
AchievementComp = 0x203, AchievementComp = 0x203,
AchievementCatChat = 0x206, AchievementCatChat = 0x206,
QuestJournalUpdateQuestVisibility = 0x2BE,
QuestJournalClosed = 0x2BF,
AbandonQuest = 0x320,
DirectorInitFinish = 0x321, DirectorInitFinish = 0x321,

View file

@ -685,7 +685,7 @@ struct FFXIVIpcInitZone :
uint8_t bitmask; uint8_t bitmask;
uint16_t unknown5; uint16_t unknown5;
uint16_t festivalId; uint16_t festivalId;
uint16_t unknown7; uint16_t additionalFestivalId;
uint32_t unknown8; uint32_t unknown8;
Common::FFXIVARR_POSITION3 pos; Common::FFXIVARR_POSITION3 pos;
}; };
@ -969,7 +969,7 @@ struct FFXIVIpcItemInfo :
uint8_t unknown2; uint8_t unknown2;
uint16_t condition; uint16_t condition;
uint16_t spiritBond; uint16_t spiritBond;
uint16_t color; uint16_t stain;
uint32_t glamourCatalogId; uint32_t glamourCatalogId;
uint16_t materia1; uint16_t materia1;
uint16_t materia2; uint16_t materia2;

View file

@ -29,36 +29,31 @@ private:
// Entities found in the script data of the quest // Entities found in the script data of the quest
static constexpr auto Actor0 = 1000430; static constexpr auto Actor0 = 1000430;
static constexpr auto Ritem0 = 4552; static constexpr uint32_t Ritem0 = 4552;
static constexpr auto Seq0Actor0 = 0; static constexpr auto Seq0Actor0 = 0;
static constexpr auto Seq1Actor0 = 1; static constexpr auto Seq1Actor0 = 1;
static constexpr auto Seq1Actor0Npctradeno = 99; static constexpr auto Seq1Actor0Npctradeno = 99;
static constexpr auto Seq1Actor0Npctradeok = 100; static constexpr auto Seq1Actor0Npctradeok = 100;
public: public:
SubFst029() : SubFst029() : EventScript( 65708 )
EventScript( 65708 ) {};
{
};
~SubFst029() ~SubFst029()
{ {};
};
void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
{ {
auto actor = Event::mapEventActorToRealActor( static_cast< uint32_t >( actorId ) ); auto actor = Event::mapEventActorToRealActor( static_cast< uint32_t >( actorId ) );
//NOT SAFE - CRASH if( actor == SubFst029::Actor0 && !player.hasQuest( getId() ) )
/*if( actor == SubFst029::Actor0 && !player.hasQuest( getId() ) )
{ {
Scene00000( player ); Scene00000( player );
} }
if( actor == SubFst029::Actor0 && player.getQuestSeq ( getId() ) == 255 ) if( actor == SubFst029::Actor0 && player.getQuestSeq ( getId() ) == 255 )
{ {
Scene00001( player ); Scene00001( player );
}*/ }
} }
private: private:
@ -80,7 +75,7 @@ private:
player.playScene( getId(), 1, HIDE_HOTBAR, player.playScene( getId(), 1, HIDE_HOTBAR,
[ & ]( Entity::Player& player, const Event::SceneResult& result ) [ & ]( Entity::Player& player, const Event::SceneResult& result )
{ {
if( result.param2 == 1 ) if( result.param2 == 1 && player.collectHandInItems( { Ritem0 } ) )
{ {
Scene00100( player ); Scene00100( player );
} }

View file

@ -1590,7 +1590,8 @@ void Core::Entity::Player::sendZonePackets()
initZonePacket->data().weatherId = static_cast< uint8_t >( getCurrentZone()->getCurrentWeather() ); initZonePacket->data().weatherId = static_cast< uint8_t >( getCurrentZone()->getCurrentWeather() );
initZonePacket->data().bitmask = 0x1; initZonePacket->data().bitmask = 0x1;
initZonePacket->data().unknown5 = 0x2A; initZonePacket->data().unknown5 = 0x2A;
initZonePacket->data().festivalId = getCurrentZone()->getCurrentFestival(); initZonePacket->data().festivalId = getCurrentZone()->getCurrentFestival().first;
initZonePacket->data().additionalFestivalId = getCurrentZone()->getCurrentFestival().second;
initZonePacket->data().pos.x = getPos().x; initZonePacket->data().pos.x = getPos().x;
initZonePacket->data().pos.y = getPos().y; initZonePacket->data().pos.y = getPos().y;
initZonePacket->data().pos.z = getPos().z; initZonePacket->data().pos.z = getPos().z;

View file

@ -360,6 +360,13 @@ public:
/*! return the current amount of crystals of type */ /*! return the current amount of crystals of type */
uint32_t getCrystal( uint8_t type ) const; uint32_t getCrystal( uint8_t type ) const;
/*!
* Collect real item handins from container
* @param itemIds a vector of each catalog id to collect
* @return true if all items were handed in
*/
bool collectHandInItems( std::vector< uint32_t > itemIds );
// Class / Job / Exp // Class / Job / Exp
////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
/*! returns the level of the currently active class / job */ /*! returns the level of the currently active class / job */

View file

@ -318,9 +318,10 @@ void Core::Entity::Player::sendInventory()
itemInfoPacket->data().slot = itM->first; itemInfoPacket->data().slot = itM->first;
itemInfoPacket->data().quantity = itM->second->getStackSize(); itemInfoPacket->data().quantity = itM->second->getStackSize();
itemInfoPacket->data().catalogId = itM->second->getId(); itemInfoPacket->data().catalogId = itM->second->getId();
itemInfoPacket->data().condition = 30000; itemInfoPacket->data().condition = itM->second->getDurability();
itemInfoPacket->data().spiritBond = 0; itemInfoPacket->data().spiritBond = 0;
itemInfoPacket->data().hqFlag = itM->second->isHq() ? 1 : 0; itemInfoPacket->data().hqFlag = itM->second->isHq() ? 1 : 0;
itemInfoPacket->data().stain = itM->second->getStain();
queuePacket( itemInfoPacket ); queuePacket( itemInfoPacket );
} }
} }
@ -428,15 +429,26 @@ void Core::Entity::Player::writeInventory( InventoryType type )
void Core::Entity::Player::writeItem( Core::ItemPtr pItem ) const void Core::Entity::Player::writeItem( Core::ItemPtr pItem ) const
{ {
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >(); auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
pDb->execute( "UPDATE charaglobalitem SET stack = " + std::to_string( pItem->getStackSize() ) + " " + auto stmt = pDb->getPreparedStatement( Db::CHARA_ITEMGLOBAL_UP );
// TODO: add other attributes
" WHERE itemId = " + std::to_string( pItem->getUId() ) ); // todo: add more fields
stmt->setInt( 1, pItem->getStackSize() );
stmt->setInt( 2, pItem->getDurability() );
stmt->setInt( 3, pItem->getStain() );
stmt->setInt64( 4, pItem->getUId() );
pDb->directExecute( stmt );
} }
void Core::Entity::Player::deleteItemDb( Core::ItemPtr item ) const void Core::Entity::Player::deleteItemDb( Core::ItemPtr item ) const
{ {
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >(); auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
pDb->execute( "UPDATE charaglobalitem SET IS_DELETE = 1 WHERE itemId = " + std::to_string( item->getUId() ) ); auto stmt = pDb->getPreparedStatement( Db::CHARA_ITEMGLOBAL_DELETE );
stmt->setInt64( 1, item->getUId() );
pDb->directExecute( stmt );
} }
@ -464,8 +476,6 @@ Core::ItemPtr Core::Entity::Player::addItem( uint32_t catalogId, uint32_t quanti
// used for item obtain notification // used for item obtain notification
uint32_t originalQuantity = quantity; uint32_t originalQuantity = quantity;
// todo: for now we're just going to add any items to main inv
std::pair< uint16_t, uint8_t > freeBagSlot; std::pair< uint16_t, uint8_t > freeBagSlot;
bool foundFreeSlot = false; bool foundFreeSlot = false;
@ -781,3 +791,37 @@ uint8_t Core::Entity::Player::getFreeSlotsInBags()
} }
return slots; return slots;
} }
bool Core::Entity::Player::collectHandInItems( std::vector< uint32_t > itemIds )
{
// todo: figure out how the game gets the required stack count
const auto& container = m_storageMap[ HandIn ];
std::vector< uint8_t > foundItems;
auto itemMap = container->getItemMap();
for( auto& item : itemMap )
{
for( auto needle : itemIds )
{
if( item.second->getId() == needle )
{
foundItems.push_back( item.first );
break;
}
}
}
// couldn't find all the items required
if( foundItems.size() != itemIds.size() )
return false;
// remove items
for( auto item : foundItems )
{
container->removeItem( item );
}
return true;
}

View file

@ -313,9 +313,11 @@ void Core::DebugCommandHandler::set( char* data, Entity::Player& player, boost::
else if( subCommand == "festival" ) else if( subCommand == "festival" )
{ {
uint16_t festivalId; uint16_t festivalId;
sscanf( params.c_str(), "%hu", &festivalId ); uint16_t additionalId;
pTerriMgr->setCurrentFestival( festivalId ); sscanf( params.c_str(), "%hu %hu", &festivalId, &additionalId );
pTerriMgr->setCurrentFestival( festivalId, additionalId );
} }
else if( subCommand == "festivaldisable" ) else if( subCommand == "festivaldisable" )
{ {

View file

@ -12,7 +12,9 @@ Core::Item::Item( uint64_t uId, uint32_t catalogId, uint64_t model1, uint64_t mo
m_uId( uId ), m_uId( uId ),
m_model1( model1 ), m_model1( model1 ),
m_model2( model2 ), m_model2( model2 ),
m_isHq( isHq ) m_isHq( isHq ),
m_stain( 0 ),
m_durability( 30000 )
{ {
auto pExdData = g_fw.get< Data::ExdDataGenerated >(); auto pExdData = g_fw.get< Data::ExdDataGenerated >();
auto itemInfo = pExdData->get< Core::Data::Item >( catalogId ); auto itemInfo = pExdData->get< Core::Data::Item >( catalogId );
@ -132,3 +134,23 @@ uint32_t Core::Item::getMaxStackSize() const
{ {
return m_maxStackSize; return m_maxStackSize;
} }
uint16_t Core::Item::getDurability() const
{
return m_durability;
}
void Core::Item::setDurability( uint16_t durability )
{
m_durability = durability;
}
uint16_t Core::Item::getStain() const
{
return m_stain;
}
void Core::Item::setStain( uint16_t stain )
{
m_stain = stain;
}

View file

@ -55,6 +55,12 @@ public:
uint32_t getMaxStackSize() const; uint32_t getMaxStackSize() const;
uint16_t getDurability() const;
void setDurability( uint16_t durability );
uint16_t getStain() const;
void setStain( uint16_t stain );
protected: protected:
uint32_t m_id; uint32_t m_id;
@ -78,6 +84,8 @@ protected:
uint16_t m_weaponDmg; uint16_t m_weaponDmg;
float m_autoAttackDmg; float m_autoAttackDmg;
uint16_t m_itemLevel; uint16_t m_itemLevel;
uint16_t m_durability;
uint16_t m_stain;
}; };

View file

@ -256,6 +256,11 @@ void Core::Network::GameConnection::clientTriggerHandler( const Packets::FFXIVAR
player.exitInstance(); player.exitInstance();
break; break;
} }
case ClientTriggerType::AbandonQuest:
{
player.removeQuest( static_cast< uint16_t >( param1 ) );
break;
}
default: default:

View file

@ -417,18 +417,18 @@ Core::ZonePtr Core::TerritoryMgr::getLinkedInstance( uint32_t playerId ) const
return nullptr; return nullptr;
} }
const uint16_t Core::TerritoryMgr::getCurrentFestival() const const std::pair< uint16_t, uint16_t >& Core::TerritoryMgr::getCurrentFestival() const
{ {
return m_currentFestival; return m_currentFestival;
} }
void Core::TerritoryMgr::setCurrentFestival( uint16_t festivalId ) void Core::TerritoryMgr::setCurrentFestival( uint16_t festivalId, uint16_t additionalFestival )
{ {
m_currentFestival = festivalId; m_currentFestival = { festivalId, additionalFestival };
for( const auto& zone : m_zoneSet ) for( const auto& zone : m_zoneSet )
{ {
zone->setCurrentFestival( m_currentFestival ); zone->setCurrentFestival( festivalId, additionalFestival );
} }
} }

View file

@ -123,11 +123,23 @@ public:
/*! returns an instancePtr if the player is still bound to an isntance */ /*! returns an instancePtr if the player is still bound to an isntance */
ZonePtr getLinkedInstance( uint32_t playerId ) const; ZonePtr getLinkedInstance( uint32_t playerId ) const;
void setCurrentFestival( uint16_t festivalId ); /*!
* @brief Sets the current festival for every zone
* @param festivalId A valid festival id from festival.exd
* @param additionalFestival A valid festival id from festival.exd, this is shown in addition to the first festival
*/
void setCurrentFestival( uint16_t festivalId, uint16_t additionalFestival = 0 );
/*!
* @brief Disables the current festival(s) in every zone
*/
void disableCurrentFestival(); void disableCurrentFestival();
const uint16_t getCurrentFestival() const; /*!
* @brief Gets the current festival set on the server
* @return a pair with the 2 festivals currently active
*/
const std::pair< uint16_t, uint16_t >& getCurrentFestival() const;
private: private:
using TerritoryTypeDetailCache = std::unordered_map< uint16_t, Data::TerritoryTypePtr >; using TerritoryTypeDetailCache = std::unordered_map< uint16_t, Data::TerritoryTypePtr >;
@ -165,8 +177,10 @@ private:
/*! set of ZonePtrs for quick iteration*/ /*! set of ZonePtrs for quick iteration*/
std::set< ZonePtr > m_instanceZoneSet; std::set< ZonePtr > m_instanceZoneSet;
/*! id of current festival to set for public zones from festival.exd */ /*! current festival(s) to set for public zones from festival.exd */
uint16_t m_currentFestival; std::pair< uint16_t, uint16_t > m_currentFestival;
public: public:
/*! returns a list of instanceContent InstanceIds currently active */ /*! returns a list of instanceContent InstanceIds currently active */

View file

@ -52,7 +52,6 @@ Core::Zone::Zone() :
m_currentWeather( Weather::FairSkies ), m_currentWeather( Weather::FairSkies ),
m_weatherOverride( Weather::None ), m_weatherOverride( Weather::None ),
m_lastMobUpdate( 0 ), m_lastMobUpdate( 0 ),
m_currentFestivalId( 0 ),
m_nextEObjId( 0x400D0000 ) m_nextEObjId( 0x400D0000 )
{ {
} }
@ -129,20 +128,20 @@ Weather Core::Zone::getCurrentWeather() const
return m_currentWeather; return m_currentWeather;
} }
uint16_t Core::Zone::getCurrentFestival() const const Core::FestivalPair& Core::Zone::getCurrentFestival() const
{ {
return m_currentFestivalId; return m_currentFestival;
} }
void Core::Zone::setCurrentFestival( uint16_t festivalId ) void Core::Zone::setCurrentFestival( uint16_t festivalId, uint16_t additionalFestivalId )
{ {
m_currentFestivalId = festivalId; m_currentFestival = { festivalId, additionalFestivalId };
for( const auto& playerEntry : m_playerMap ) for( const auto& playerEntry : m_playerMap )
{ {
auto player = playerEntry.second; auto player = playerEntry.second;
auto enableFestival = makeActorControl143( player->getId(), SetFestival, m_currentFestivalId ); auto enableFestival = makeActorControl143( player->getId(), SetFestival, festivalId, additionalFestivalId );
playerEntry.second->queuePacket( enableFestival ); playerEntry.second->queuePacket( enableFestival );
} }
} }

View file

@ -23,6 +23,8 @@ class Session;
class ZonePosition; class ZonePosition;
using SessionSet = std::set< SessionPtr >; using SessionSet = std::set< SessionPtr >;
using FestivalPair = std::pair< uint16_t, uint16_t >;
namespace Data { namespace Data {
struct InstanceContent; struct InstanceContent;
struct TerritoryType; struct TerritoryType;
@ -48,7 +50,8 @@ protected:
uint64_t m_lastMobUpdate; uint64_t m_lastMobUpdate;
uint16_t m_currentFestivalId; FestivalPair m_currentFestival;
boost::shared_ptr< Data::TerritoryType > m_territoryTypeInfo; boost::shared_ptr< Data::TerritoryType > m_territoryTypeInfo;
std::map< uint8_t, int32_t > m_weatherRateMap; std::map< uint8_t, int32_t > m_weatherRateMap;
@ -67,9 +70,9 @@ public:
Common::Weather getCurrentWeather() const; Common::Weather getCurrentWeather() const;
uint16_t getCurrentFestival() const; const FestivalPair& getCurrentFestival() const;
void setCurrentFestival( uint16_t festivalId ); void setCurrentFestival( uint16_t festivalId, uint16_t additionalFestivalId = 0 );
virtual bool init(); virtual bool init();