1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 16:37:45 +00:00

Added a onPlayerDeath function, to be reworked when battlescripts arrive

This commit is contained in:
Mordred 2023-01-15 22:03:44 +01:00
parent 4d64ece25a
commit bd1753423e
8 changed files with 51 additions and 1 deletions

View file

@ -96,6 +96,9 @@ namespace Sapphire::Network::ActorControl
FateReqFailMsg = 0x76,
DutyQuestScreenMsg = 0x7B,
SetContentClearFlag = 0x82,
SetContentOpenFlag = 0x83,
ItemObtainIcon = 0x84,
FateItemFailMsg = 0x85,
ItemFailMsg = 0x86,

View file

@ -1005,7 +1005,10 @@ void Player::unsetStateFlag( Common::PlayerStateFlag flag )
void Player::update( uint64_t tickCount )
{
if( m_hp <= 0 && m_status != ActorStatus::Dead )
{
die();
Service< World::Manager::PlayerMgr >::ref().onDeath( *this );
}
if( !isAlive() )
return;

View file

@ -270,7 +270,11 @@ void PlayerMgr::onLogin( Entity::Player &player )
}
}
void PlayerMgr::onDeath( Entity::Player &player )
{
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
scriptMgr.onPlayerDeath( player );
}
////////// Helper ///////////

View file

@ -44,6 +44,8 @@ class PlayerMgr
void onLogin( Sapphire::Entity::Player& player );
void onDeath( Sapphire::Entity::Player& player );
//////////// Helpers
static void sendServerNotice( Sapphire::Entity::Player& player, const std::string& message );

View file

@ -182,6 +182,10 @@ namespace Sapphire::ScriptAPI
{
}
void QuestScript::onPlayerDeath( World::Quest& quest, Sapphire::Entity::Player& player )
{
}
///////////////////////////////////////////////////////////////////
EventObjectScript::EventObjectScript( uint32_t eobjId ) :

View file

@ -254,6 +254,8 @@ namespace Sapphire::ScriptAPI
virtual void onOutsideRange( World::Quest& quest, Sapphire::Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z );
virtual void onPlayerDeath( World::Quest& quest, Sapphire::Entity::Player& player );
virtual void onEventHandlerTradeReturn( Sapphire::Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param,
uint32_t catalogId );

View file

@ -491,6 +491,36 @@ bool Sapphire::Scripting::ScriptMgr::onBNpcKill( Entity::Player& player, Entity:
return true;
}
bool Sapphire::Scripting::ScriptMgr::onPlayerDeath( Entity::Player& player )
{
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();
// loop through all active quests and try to call available onPlayerDeath callbacks
for( size_t i = 0; i < 30; i++ )
{
auto quest = player.getQuestByIndex( static_cast< uint16_t >( i ) );
if( quest.getId() == 0 )
continue;
uint32_t questId = quest.getId() | Event::EventHandler::EventHandlerType::Quest << 16;
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestScript >( questId );
if( script )
{
std::string objName = eventMgr.getEventName( questId );
PlayerMgr::sendDebug( player, "Calling: {0}.onPlayerDeath name: {1}", objName, player.getName() );
World::Quest preQ = quest;
script->onPlayerDeath( quest, player );
if( quest != preQ )
player.updateQuest( quest );
}
}
return true;
}
bool Sapphire::Scripting::ScriptMgr::onEObjHit( Sapphire::Entity::Player& player, uint64_t actorId, uint32_t actionId )
{
auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref();

View file

@ -70,6 +70,8 @@ namespace Sapphire::Scripting
bool onBNpcKill( Entity::Player& player, Entity::BNpc& bnpc );
bool onPlayerDeath( Entity::Player& player );
void onTriggerOwnerDeaggro( Entity::Player& player, Entity::BNpc& bnpc );
bool onEObjHit( Entity::Player& player, uint64_t actorId, uint32_t actionId );