1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 08:27:46 +00:00

Merge pull request #786 from Skyliegirl33/feature-impl

[3.x] Implement FcTalk and SmallTalk, add method to check quest completion
This commit is contained in:
Mordred 2022-02-17 09:11:24 +01:00 committed by GitHub
commit 4dac573fd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 7 deletions

View file

@ -3339,6 +3339,7 @@ namespace Excel
struct SwitchTalk
{
SwitchTalkCaseStruct TalkCase[16];
uint32_t Unknown1;
};
/* 362351 */

View file

@ -0,0 +1,48 @@
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Exd/ExdData.h>
using namespace Sapphire;
class FcTalk :
public Sapphire::ScriptAPI::EventScript
{
public:
FcTalk() :
Sapphire::ScriptAPI::EventScript( 0x001F0000 )
{
}
void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
{
auto& exdData = Common::Service< Data::ExdData >::ref();
auto switchTalk = exdData.getRow< Excel::SwitchTalk >( eventId );
uint32_t talkEvent = 0;
if( !switchTalk )
return;
for( auto entry = 15; entry >= 0; entry-- )
{
auto caseCondition = switchTalk->data().TalkCase[ entry ].CaseCondition;
if( ( caseCondition >> 16 ) == Event::EventHandler::EventHandlerType::Quest && player.isQuestCompleted( caseCondition ) )
{
talkEvent = switchTalk->data().TalkCase[ entry ].Talk;
break;
}
else
{
talkEvent = switchTalk->data().TalkCase[ 0 ].Talk;
}
}
if( talkEvent == 0 )
return;
eventMgr().playScene( player, talkEvent, 0, HIDE_HOTBAR | NO_DEFAULT_CAMERA, { 0 }, nullptr );
}
};
EXPOSE_SCRIPT( FcTalk );

View file

@ -0,0 +1,21 @@
#include <ScriptObject.h>
#include <Actor/Player.h>
using namespace Sapphire;
class SmallTalk :
public Sapphire::ScriptAPI::EventScript
{
public:
SmallTalk() :
Sapphire::ScriptAPI::EventScript( 0x000B0000 )
{
}
void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
{
eventMgr().playScene( player, eventId, 0, HIDE_HOTBAR, { 0 }, nullptr );
}
};
EXPOSE_SCRIPT( SmallTalk );

View file

@ -29,8 +29,7 @@ private:
enum Variables : uint8_t
{
Coral,
ObtainedKey
Coral
};
enum Sequence : uint8_t
@ -38,7 +37,8 @@ private:
Seq1 = 1,
Seq2 = 3,
Seq3 = 7,
Seq4 = 15,
Seq4 = 23,
Seq5 = 31,
SeqFinish = 255
};
@ -210,7 +210,7 @@ public:
[ & ]( Entity::Player& player, uint32_t eventId, uint64_t additional )
{
eobj.setPermissionInvisibility( 1 );
instance.setCustomVar( ObtainedKey, true );
instance.setVar( 0, Seq4 );
instance.sendEventLogMessage( player, instance, 2031, { 2000512 } );
},
nullptr, getId() );
@ -223,7 +223,7 @@ public:
[ & ]( Entity::Player& player, uint32_t eventId, uint64_t additional )
{
eobj.setPermissionInvisibility( 1 );
instance.setVar( 0, Seq4 );
instance.setVar( 0, Seq5 );
instance.sendEventLogMessage( player, instance, 2031, { 2000513 } );
denn = instance.createBNpcFromInstanceId( 3978771, 1000, Common::BNpcType::Enemy );
},
@ -231,8 +231,8 @@ public:
}
// Open the door if the right key has been obtained
if( ( eobj.getName() == "Captainsquarters" && instance.getCustomVar( ObtainedKey ) ) ||
( eobj.getName() == "WaveriderGate" && instance.getDirectorVar( 0 ) == Seq4 ) )
if( ( eobj.getName() == "Captainsquarters" && instance.getDirectorVar( 0 ) == Seq4 ) ||
( eobj.getName() == "WaveriderGate" && instance.getDirectorVar( 0 ) == Seq5 ) )
{
eventMgr().playScene( player, eventId, 1, HIDE_HOTBAR, { 1 },
[ & ]( Entity::Player& player, const Event::SceneResult& result )

View file

@ -107,6 +107,8 @@ namespace Sapphire::Entity
/*! remove a given quest */
void removeQuest( uint16_t questId );
bool isQuestCompleted( uint32_t questId );
/*! add a quest to the completed quests mask */
void updateQuestsCompleted( uint32_t questId );

View file

@ -152,6 +152,16 @@ void Sapphire::Entity::Player::updateQuestsCompleted( uint32_t questId )
m_questCompleteFlags[ index ] |= value;
}
bool Sapphire::Entity::Player::isQuestCompleted( uint32_t questId )
{
uint8_t index = questId / 8;
uint8_t bitIndex = ( questId ) % 8;
uint8_t value = 0x80 >> bitIndex;
return m_questCompleteFlags[ index ] & value;
}
void Sapphire::Entity::Player::removeQuestsCompleted( uint32_t questId )
{
uint8_t index = questId / 8;

View file

@ -136,6 +136,11 @@ std::string EventMgr::getEventName( uint32_t eventId )
}*/
//return unknown + "GilShop";
}
case Event::EventHandler::EventHandlerType::FcTalk:
{
return "FcTalk";
}
default:
{
return unknown;