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

GiveQuestRewards is no longer used in quests, but called automatically on finish

This commit is contained in:
Mordred 2021-12-21 01:05:08 +01:00
parent 342bd7d6ad
commit 296dbb9904
51 changed files with 97 additions and 173 deletions

View file

@ -91,8 +91,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -143,8 +143,7 @@ private:
{
if( result.getResult( 0 ) == 1 ) // finish quest
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -211,10 +211,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
{
player.finishQuest( getId() );
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -210,10 +210,7 @@ private:
{
if( result.getResult( 0 ) == 1 ) // finish quest
{
if( player.giveQuestRewards( getId(), 0 ) )
{
player.finishQuest( getId() );
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -238,10 +238,7 @@ private:
void Scene00010Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result )
{
if( result.getResult( 0 ) == 1 )
if( player.giveQuestRewards( getId(), 0 ) )
{
player.finishQuest( getId() );
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
//////////////////////////////////////////////////////////////////////

View file

@ -129,8 +129,7 @@ private:
{
if( result.getResult( 0 ) == 1 ) // finish quest
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
} );
}

View file

@ -203,10 +203,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
{
player.finishQuest( getId() );
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
} );
}

View file

@ -220,10 +220,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
{
player.finishQuest( getId() );
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
} );
}

View file

@ -141,8 +141,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -213,10 +213,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
{
player.finishQuest( getId() );
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -226,10 +226,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
{
player.finishQuest( getId() );
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
} );
}

View file

@ -229,10 +229,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
{
player.finishQuest( getId() );
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
} );
}

View file

@ -466,8 +466,7 @@ class ClsArc004 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), result.getResult(1)) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -269,8 +269,7 @@ class ClsArc005 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), result.getResult(1)) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -341,8 +341,7 @@ class ClsArc006 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), result.getResult(1)) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -133,8 +133,7 @@ private:
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -125,9 +125,7 @@ private:
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
quest.setUI8BH( 0 );
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -145,8 +145,7 @@ class SubFst004 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -84,8 +84,7 @@ private:
{
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -147,8 +147,7 @@ private:
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), result.getResult( 1 ) ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -123,8 +123,7 @@ class SubFst009 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -86,8 +86,7 @@ class SubFst010 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -191,8 +191,7 @@ class SubFst013 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -270,8 +270,7 @@ class SubFst014 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -246,8 +246,7 @@ class SubFst015 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -91,8 +91,7 @@ class SubFst019 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -119,8 +119,7 @@ class SubFst029 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -167,8 +167,7 @@ class SubFst030 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -164,12 +164,7 @@ class SubFst043 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
{
quest.setUI8BH(0);
player.finishQuest(getId());
}
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -88,8 +88,7 @@ class SubFst045 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -169,8 +169,7 @@ class SubFst046 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -167,8 +167,7 @@ class SubFst048 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), result.getResult(1)) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -411,8 +411,7 @@ class SubSea001 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -123,8 +123,7 @@ class SubWil000 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -93,8 +93,7 @@ class SubWil001 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -127,8 +127,7 @@ class SubWil002 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -250,8 +250,7 @@ class SubWil004 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -140,8 +140,7 @@ class SubWil006 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -404,8 +404,7 @@ class SubWil007 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -341,8 +341,7 @@ class SubWil018 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -89,8 +89,7 @@ class SubWil019 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -416,8 +416,7 @@ class SubWil020 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -123,8 +123,7 @@ class SubWil021 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -123,8 +123,7 @@ class SubWil022 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -89,8 +89,7 @@ class SubWil027 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -107,8 +107,7 @@ class SubWil028 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -128,8 +128,7 @@ class SubWil029 : public Sapphire::ScriptAPI::QuestScript
if( result.getResult( 0 ) == 1 )
{
if( player.giveQuestRewards( getId(), 0 ) )
player.finishQuest( getId() );
player.finishQuest( getId(), result.getResult( 1 ) );
}
}

View file

@ -114,7 +114,7 @@ namespace Sapphire::Entity
int16_t getQuestTracking( uint8_t index ) const;
/*! finish a given quest */
void finishQuest( uint16_t questId, uint8_t optionalChoice = 0 );
void finishQuest( uint16_t questId, uint32_t optionalChoice = 0 );
/*! finish a given quest */
void unfinishQuest( uint16_t questId );
@ -134,8 +134,6 @@ namespace Sapphire::Entity
/*! set te current opening sequence */
void setOpeningSequence( uint8_t seq );
bool giveQuestRewards( uint32_t questId, uint32_t optionalChoice );
std::array< World::Quest, 30 >& getQuestArrayRef();
QuestComplete& getQuestCompleteFlags();

View file

@ -17,12 +17,14 @@ using namespace Sapphire::Common;
using namespace Sapphire::Network::Packets;
using namespace Sapphire::Network::Packets::WorldPackets::Server;
void Sapphire::Entity::Player::finishQuest( uint16_t questId, uint8_t optionalChoice )
void Sapphire::Entity::Player::finishQuest( uint16_t questId, uint32_t optionalChoice )
{
removeQuest( questId );
auto& questMgr = Common::Service< World::Manager::QuestMgr >::ref();
questMgr.onCompleteQuest( *this, questId );
//@todo should probably be changed to a bool function in case reward can not be obtained as quests will not complete in that case
questMgr.onCompleteQuest( *this, questId, optionalChoice );
updateQuestsCompleted( questId );
}
@ -167,56 +169,6 @@ void Sapphire::Entity::Player::removeQuestsCompleted( uint32_t questId )
}
bool Sapphire::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optionalChoice )
{
auto& exdData = Common::Service< Data::ExdData >::ref();
uint32_t playerLevel = getLevel();
auto questInfo = exdData.getRow< Component::Excel::Quest >( questId );
if( !questInfo )
return false;
auto paramGrowth = exdData.getRow< Component::Excel::ParamGrow >( questInfo->data().ClassLevel );
uint32_t exp =
( questInfo->data().Reward.ExpBonus * paramGrowth->data().BaseExp * paramGrowth->data().EventExpRate ) / 100;
//exp = questInfo->data().Reward.ExpBonus;
//auto rewardItemCount = questInfo->data().Reward.itemReward0.size();
//uint16_t optionalItemCount = static_cast< uint16_t >( questInfo->itemReward1.size() );
uint32_t gilReward = questInfo->data().Reward.Gil;
// TODO: check if there is room in inventory, else return false;
if( exp > 0 )
gainExp( exp );
for( uint32_t i = 0; i < 6; i++ )
{
if( questInfo->data().Reward.Item[ i ] != 0 )
addItem( questInfo->data().Reward.Item[ i ], questInfo->data().Reward.ItemNum[ i ] );
}
for( uint32_t i = 0; i < 5; i++ )
{
auto itemId = questInfo->data().Reward.OptionalItem[ i ];
if( itemId == optionalChoice )
{
addItem( itemId, questInfo->data().Reward.OptionalItemNum[ i ] );
break;
}
}
if( gilReward > 0 )
addCurrency( CurrencyType::Gil, gilReward );
return true;
}
Sapphire::World::Quest& Sapphire::Entity::Player::getQuestByIndex( uint16_t index )
{
return m_quests[ index ];

View file

@ -32,7 +32,7 @@ void Sapphire::World::Manager::QuestMgr::onUpdateQuest( Entity::Player& player,
sendQuestTracker( player );
}
void Sapphire::World::Manager::QuestMgr::onCompleteQuest( Entity::Player& player, uint16_t questId )
void Sapphire::World::Manager::QuestMgr::onCompleteQuest( Entity::Player& player, uint16_t questId, uint32_t optionalChoice )
{
auto& server = Common::Service< World::WorldServer >::ref();
auto questFinishPacket = makeZonePacket< FFXIVIpcQuestFinish >( player.getId() );
@ -40,9 +40,11 @@ void Sapphire::World::Manager::QuestMgr::onCompleteQuest( Entity::Player& player
questFinishPacket->data().flag1 = 1;
questFinishPacket->data().flag2 = 1;
server.queueForPlayer( player.getCharacterId(), questFinishPacket );
giveQuestRewards( player, questId, optionalChoice );
}
void Sapphire::World::Manager::QuestMgr::onRemoveQuest( Sapphire::Entity::Player &player, uint8_t questIndex )
void Sapphire::World::Manager::QuestMgr::onRemoveQuest( Entity::Player &player, uint8_t questIndex )
{
auto& server = Common::Service< World::WorldServer >::ref();
auto questUpdatePacket = makeZonePacket< FFXIVIpcQuest >( player.getId() );
@ -54,6 +56,44 @@ void Sapphire::World::Manager::QuestMgr::onRemoveQuest( Sapphire::Entity::Player
sendQuestTracker( player );
}
bool Sapphire::World::Manager::QuestMgr::giveQuestRewards( Entity::Player& player, uint16_t questId, uint32_t optionalChoice )
{
auto& exdData = Common::Service< Data::ExdData >::ref();
uint32_t playerLevel = player.getLevel();
auto questInfo = exdData.getRow< Component::Excel::Quest >( static_cast< uint32_t >( Event::EventHandler::EventHandlerType::Quest ) << 16 | questId );
if( !questInfo )
return false;
auto paramGrowth = exdData.getRow< Component::Excel::ParamGrow >( questInfo->data().ClassLevel );
uint32_t exp = ( questInfo->data().Reward.ExpBonus * paramGrowth->data().BaseExp * paramGrowth->data().EventExpRate ) / 100;
uint32_t gilReward = questInfo->data().Reward.Gil;
// TODO: check if there is room in inventory, else return false;
if( exp > 0 )
player.gainExp( exp );
for( uint32_t i = 0; i < 6; i++ )
{
if( questInfo->data().Reward.Item[ i ] != 0 )
player.addItem( questInfo->data().Reward.Item[ i ], questInfo->data().Reward.ItemNum[ i ] );
}
for( uint32_t i = 0; i < 5; i++ )
{
auto itemId = questInfo->data().Reward.OptionalItem[ i ];
if( itemId == optionalChoice )
{
player.addItem( itemId, questInfo->data().Reward.OptionalItemNum[ i ] );
break;
}
}
if( gilReward > 0 )
player.addCurrency( CurrencyType::Gil, gilReward );
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
void Sapphire::World::Manager::QuestMgr::sendQuestTracker( Entity::Player& player )

View file

@ -15,7 +15,7 @@ namespace Sapphire::World::Manager
/// Perform required actions for events
void onUpdateQuest( Entity::Player& player, uint8_t questIndex );
void onRemoveQuest( Entity::Player& player, uint8_t questIndex );
void onCompleteQuest( Entity::Player& player, uint16_t questId );
void onCompleteQuest( Entity::Player& player, uint16_t questId, uint32_t optionalChoice = 0 );
////////////////////
@ -24,6 +24,8 @@ namespace Sapphire::World::Manager
void sendQuestsInfo( Entity::Player& player );
bool giveQuestRewards( Entity::Player& player, uint16_t questId, uint32_t optionalChoice );
};
}