mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-30 08:07:46 +00:00
EObjs are special so they get their own scripts
This commit is contained in:
parent
0a5b71a320
commit
9f2c8daab5
4 changed files with 41 additions and 14 deletions
|
@ -1,38 +1,30 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
#include "Zone/HousingZone.h"
|
||||
#include "Actor/EventObject.h"
|
||||
|
||||
using namespace Sapphire;
|
||||
|
||||
class HousingEstateEntranceWarpTaxi :
|
||||
public Sapphire::ScriptAPI::EventScript
|
||||
public Sapphire::ScriptAPI::EventObjectScript
|
||||
{
|
||||
public:
|
||||
HousingEstateEntranceWarpTaxi() :
|
||||
Sapphire::ScriptAPI::EventScript( 0x0002004c )
|
||||
Sapphire::ScriptAPI::EventObjectScript( 2002737 )
|
||||
{
|
||||
}
|
||||
|
||||
void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
|
||||
void onTalk( uint32_t eventId, Entity::Player& player, Entity::EventObject& eobj ) override
|
||||
{
|
||||
auto zone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() );
|
||||
if( !zone )
|
||||
return;
|
||||
player.sendDebug( "Found plot entrance for plot: " + std::to_string( eobj.getHousingLink() >> 8 ) );
|
||||
|
||||
auto eobj = zone->getEObj( actorId );
|
||||
if( !eobj )
|
||||
return;
|
||||
|
||||
player.sendDebug( "Found plot entrance for plot: " + std::to_string( eobj->getHousingLink() >> 8 ) );
|
||||
|
||||
player.playScene( getId(), 0, 0, []( Entity::Player& player, const Event::SceneResult& result )
|
||||
player.playScene( eventId, 0, 0, []( Entity::Player& player, const Event::SceneResult& result )
|
||||
{
|
||||
if( result.param2 != 1 )
|
||||
return;
|
||||
|
||||
// param2 == 1, zone into instance
|
||||
|
||||
} );
|
||||
}
|
||||
};
|
|
@ -143,6 +143,17 @@ namespace Sapphire::ScriptAPI
|
|||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
EventObjectScript::EventObjectScript( uint32_t eobjId ) :
|
||||
ScriptObject( eobjId, typeid( EventObjectScript ).hash_code() )
|
||||
{
|
||||
}
|
||||
|
||||
void EventObjectScript::onTalk( uint32_t eventId, Sapphire::Entity::Player& player, Entity::EventObject& eobj )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
BattleNpcScript::BattleNpcScript( uint32_t npcId ) :
|
||||
ScriptObject( npcId, typeid( BattleNpcScript ).hash_code() )
|
||||
{
|
||||
|
|
|
@ -182,6 +182,16 @@ namespace Sapphire::ScriptAPI
|
|||
uint32_t catalogId );
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief The base class for scripts that implement behaviour related to Event Objects (EObjs)
|
||||
*/
|
||||
class EventObjectScript : public ScriptObject
|
||||
{
|
||||
public:
|
||||
explicit EventObjectScript( uint32_t eobjId );
|
||||
|
||||
virtual void onTalk( uint32_t eventId, Sapphire::Entity::Player& player, Entity::EventObject& eobj );
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief The base class for any scripts that implement behaviour related to BattleNPCs
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Zone/Zone.h"
|
||||
#include "Zone/InstanceContent.h"
|
||||
#include "Actor/Player.h"
|
||||
#include "Actor/EventObject.h"
|
||||
#include "ServerMgr.h"
|
||||
#include "Event/EventHandler.h"
|
||||
#include "Event/EventHelper.h"
|
||||
|
@ -168,6 +169,19 @@ void Sapphire::Scripting::ScriptMgr::onPlayerFirstEnterWorld( Entity::Player& pl
|
|||
|
||||
bool Sapphire::Scripting::ScriptMgr::onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId )
|
||||
{
|
||||
// check if the actor is an eobj and call its script if we have one
|
||||
auto zone = player.getCurrentZone();
|
||||
if( auto eobj = zone->getEObj( actorId ) )
|
||||
{
|
||||
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::EventObjectScript >( eobj->getObjectId() );
|
||||
if( script )
|
||||
{
|
||||
script->onTalk( eventId, player, *eobj );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// check for a direct eventid match first, otherwise default to base type
|
||||
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::EventScript >( eventId );
|
||||
if( script )
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue