2017-12-18 12:36:52 +01:00
|
|
|
#include <common/Logging/Logger.h>
|
|
|
|
#include <common/Exd/ExdData.h>
|
|
|
|
#include <common/Config/XMLConfig.h>
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-13 15:07:03 +11:00
|
|
|
#include "NativeScriptManager.h"
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Zone/Zone.h"
|
|
|
|
#include "Actor/Player.h"
|
|
|
|
#include "Actor/BattleNpc.h"
|
|
|
|
#include "ServerZone.h"
|
2018-01-09 23:50:54 +01:00
|
|
|
#include "Event/EventHandler.h"
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Event/EventHelper.h"
|
|
|
|
#include "StatusEffect/StatusEffect.h"
|
|
|
|
#include "Network/PacketWrappers/ServerNoticePacket.h"
|
|
|
|
#include "Script/ScriptManager.h"
|
2017-08-18 17:29:36 +02:00
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2017-12-10 23:51:06 +11:00
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
// enable the ambiguity fix for every platform to avoid #define nonsense
|
|
|
|
#define WIN_AMBIGUITY_FIX
|
|
|
|
#include <libraries/external/watchdog/Watchdog.h>
|
|
|
|
|
2017-08-18 17:29:36 +02:00
|
|
|
extern Core::Logger g_log;
|
|
|
|
extern Core::Data::ExdData g_exdData;
|
|
|
|
extern Core::ServerZone g_serverZone;
|
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
Core::Scripting::ScriptManager::ScriptManager() :
|
|
|
|
m_firstScriptChangeNotificiation( false )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2017-12-13 15:07:03 +11:00
|
|
|
m_nativeScriptManager = createNativeScriptMgr();
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Core::Scripting::ScriptManager::~ScriptManager()
|
|
|
|
{
|
2017-12-14 22:30:06 +11:00
|
|
|
Watchdog::unwatchAll();
|
|
|
|
}
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
void Core::Scripting::ScriptManager::update()
|
|
|
|
{
|
|
|
|
m_nativeScriptManager->processLoadQueue();
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-10 23:51:06 +11:00
|
|
|
bool Core::Scripting::ScriptManager::init()
|
|
|
|
{
|
|
|
|
std::set< std::string > files;
|
|
|
|
|
2017-12-13 22:19:00 +11:00
|
|
|
loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ),
|
2017-12-13 15:07:03 +11:00
|
|
|
files, m_nativeScriptManager->getModuleExtension() );
|
2017-12-10 23:51:06 +11:00
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
uint32_t scriptsFound = 0;
|
|
|
|
uint32_t scriptsLoaded = 0;
|
|
|
|
|
2017-12-10 23:51:06 +11:00
|
|
|
for( auto itr = files.begin(); itr != files.end(); ++itr )
|
|
|
|
{
|
|
|
|
auto& path = *itr;
|
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
scriptsFound++;
|
|
|
|
|
|
|
|
if( m_nativeScriptManager->loadScript( path ) )
|
|
|
|
scriptsLoaded++;
|
2017-12-10 23:51:06 +11:00
|
|
|
}
|
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
g_log.info( "ScriptManager: Loaded " + std::to_string( scriptsLoaded ) + "/" + std::to_string( scriptsFound ) + " scripts successfully" );
|
|
|
|
|
|
|
|
watchDirectories();
|
|
|
|
|
2017-12-10 23:51:06 +11:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
void Core::Scripting::ScriptManager::watchDirectories()
|
|
|
|
{
|
|
|
|
Watchdog::watchMany( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ) + "*" + m_nativeScriptManager->getModuleExtension(),
|
|
|
|
[ this ]( const std::vector< ci::fs::path >& paths )
|
|
|
|
{
|
|
|
|
if( !m_firstScriptChangeNotificiation )
|
|
|
|
{
|
|
|
|
// for whatever reason, the first time this runs, it detects every file as changed
|
|
|
|
// so we're always going to ignore the first notification
|
|
|
|
m_firstScriptChangeNotificiation = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto path : paths )
|
|
|
|
{
|
|
|
|
if( m_nativeScriptManager->isModuleLoaded( path.stem().string() ) )
|
|
|
|
{
|
|
|
|
g_log.debug( "Reloading changed script: " + path.stem().string() );
|
|
|
|
|
2017-12-14 23:05:53 +11:00
|
|
|
m_nativeScriptManager->queueScriptReload( path.stem( ).string( ));
|
2017-12-14 22:30:06 +11:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_log.debug( "Loading new script: " + path.stem().string() );
|
|
|
|
|
|
|
|
m_nativeScriptManager->loadScript( path.string() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-14 23:05:53 +11:00
|
|
|
void Core::Scripting::ScriptManager::loadDir( const std::string& dirname, std::set<std::string> &files, const std::string& ext )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
|
2017-11-26 00:38:33 +11:00
|
|
|
g_log.info( "ScriptEngine: loading scripts from " + dirname );
|
|
|
|
|
2017-08-18 17:29:36 +02:00
|
|
|
boost::filesystem::path targetDir( dirname );
|
|
|
|
|
2017-12-14 23:05:53 +11:00
|
|
|
boost::filesystem::directory_iterator iter( targetDir );
|
|
|
|
boost::filesystem::directory_iterator eod;
|
2017-08-18 17:29:36 +02:00
|
|
|
|
|
|
|
BOOST_FOREACH( boost::filesystem::path const& i, make_pair( iter, eod ) )
|
2017-12-10 02:49:22 +11:00
|
|
|
{
|
2017-12-10 23:51:06 +11:00
|
|
|
if( is_regular_file( i ) && boost::filesystem::extension( i.string() ) == ext )
|
2017-12-10 02:49:22 +11:00
|
|
|
{
|
2017-12-10 23:51:06 +11:00
|
|
|
files.insert( i.string() );
|
2017-12-10 02:49:22 +11:00
|
|
|
}
|
|
|
|
}
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
void Core::Scripting::ScriptManager::onPlayerFirstEnterWorld( Entity::Player& player )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2017-12-10 01:52:03 +11:00
|
|
|
// try
|
|
|
|
// {
|
|
|
|
// std::string test = m_onFirstEnterWorld( player );
|
|
|
|
// }
|
|
|
|
// catch( const std::exception &e )
|
|
|
|
// {
|
|
|
|
// std::string what = e.what();
|
|
|
|
// g_log.Log( LoggingSeverity::error, what );
|
|
|
|
// }
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-11-28 17:22:19 +01:00
|
|
|
bool Core::Scripting::ScriptManager::registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId,
|
|
|
|
uint32_t bnpcNameId, uint32_t modelId, std::string aiName )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
return g_serverZone.registerBnpcTemplate( templateName, bnpcBaseId, bnpcNameId, modelId, aiName );
|
|
|
|
}
|
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
uint16_t eventType = eventId >> 16;
|
2017-12-12 20:28:57 +11:00
|
|
|
uint32_t scriptId = eventId;
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-12 17:29:31 +11:00
|
|
|
// aethernet/aetherytes need to be handled separately
|
2018-01-10 10:47:47 +01:00
|
|
|
if( eventType == Event::EventHandler::EventHandlerType::Aetheryte )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2017-12-12 17:29:31 +11:00
|
|
|
auto aetherInfo = g_exdData.getAetheryteInfo( eventId & 0xFFFF );
|
2017-12-13 14:05:50 +11:00
|
|
|
scriptId = EVENTSCRIPT_AETHERYTE_ID;
|
2017-12-12 17:29:31 +11:00
|
|
|
if( !aetherInfo->isAetheryte )
|
2017-12-13 14:05:50 +11:00
|
|
|
scriptId = EVENTSCRIPT_AETHERNET_ID;
|
2017-12-12 20:28:57 +11:00
|
|
|
}
|
2017-12-12 17:29:31 +11:00
|
|
|
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, scriptId );
|
2017-12-12 20:28:57 +11:00
|
|
|
if( script )
|
2017-12-10 01:52:03 +11:00
|
|
|
script->onTalk( eventId, player, actorId );
|
|
|
|
else
|
2017-12-12 20:28:57 +11:00
|
|
|
return false;
|
2017-12-10 01:52:03 +11:00
|
|
|
|
2017-08-18 17:29:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, uint32_t eventId,
|
2017-08-18 17:29:36 +02:00
|
|
|
uint16_t param1, uint16_t param2 )
|
|
|
|
{
|
|
|
|
std::string eventName = "onEnterTerritory";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
|
2017-12-13 22:19:00 +11:00
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) );
|
|
|
|
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId );
|
2017-12-10 01:52:03 +11:00
|
|
|
if( script )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2018-01-09 23:50:54 +01:00
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 0, player.getZoneId() );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
script->onEnterZone( player, eventId, param1, param2 );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
player.checkEvent( eventId );
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return true;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1,
|
2017-11-28 17:22:19 +01:00
|
|
|
float x, float y, float z )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2017-12-13 22:19:00 +11:00
|
|
|
|
|
|
|
std::string eventName = "onWithinRange";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) + " p1: " + std::to_string( param1 ) );
|
|
|
|
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId );
|
2017-12-13 22:19:00 +11:00
|
|
|
if( script )
|
|
|
|
{
|
2018-01-09 23:50:54 +01:00
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
|
2017-12-13 22:19:00 +11:00
|
|
|
|
|
|
|
script->onWithinRange( player, eventId, param1, x, y, z );
|
|
|
|
|
|
|
|
player.checkEvent( eventId );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1,
|
2017-11-28 17:22:19 +01:00
|
|
|
float x, float y, float z )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2017-12-13 22:19:00 +11:00
|
|
|
std::string eventName = "onOutsideRange";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) );
|
|
|
|
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId );
|
2017-12-13 22:19:00 +11:00
|
|
|
if( script )
|
|
|
|
{
|
2018-01-09 23:50:54 +01:00
|
|
|
player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 );
|
2017-12-13 22:19:00 +11:00
|
|
|
|
|
|
|
script->onOutsideRange( player, eventId, param1, x, y, z );
|
|
|
|
|
|
|
|
player.checkEvent( eventId );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t actorId,
|
2017-08-18 17:29:36 +02:00
|
|
|
uint32_t eventId, uint8_t emoteId )
|
|
|
|
{
|
|
|
|
std::string eventName = "onEmote";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId );
|
2017-12-10 01:52:03 +11:00
|
|
|
if( script )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2017-12-08 11:46:47 +01:00
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2018-01-09 23:50:54 +01:00
|
|
|
player.eventStart( actorId, eventId, Event::EventHandler::Emote, 0, emoteId );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
script->onEmote( actorId, eventId, emoteId, player );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
player.checkEvent( eventId );
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
2017-12-10 01:52:03 +11:00
|
|
|
else
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
uint16_t eventType = eventId >> 16;
|
|
|
|
|
2018-01-10 10:47:47 +01:00
|
|
|
if( eventType == Event::EventHandler::EventHandlerType::Quest )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
auto questInfo = g_exdData.getQuestInfo( eventId );
|
|
|
|
if( questInfo )
|
|
|
|
{
|
2017-12-10 01:52:03 +11:00
|
|
|
player.sendUrgent( "Quest not implemented: " + questInfo->name );
|
2017-08-18 17:29:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-10 01:52:03 +11:00
|
|
|
|
2017-08-18 17:29:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& player, uint32_t eventId,
|
2017-11-28 17:22:19 +01:00
|
|
|
uint16_t subEvent, uint16_t param1, uint16_t param2,
|
|
|
|
uint16_t param3 )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
player.sendDebug( "eventId: " +
|
|
|
|
std::to_string( eventId ) +
|
|
|
|
" ( 0x" + boost::str( boost::format( "%|08X|" ) % ( uint64_t ) ( eventId & 0xFFFFFFF ) ) + " ) " +
|
|
|
|
" scene: " + std::to_string( subEvent ) +
|
|
|
|
" p1: " + std::to_string( param1 ) +
|
|
|
|
" p2: " + std::to_string( param2 ) +
|
|
|
|
" p3: " + std::to_string( param3 ) );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-12-08 11:46:47 +01:00
|
|
|
auto pEvent = player.getEvent( eventId );
|
2017-08-18 17:29:36 +02:00
|
|
|
if( pEvent )
|
|
|
|
{
|
|
|
|
pEvent->setPlayedScene( false );
|
|
|
|
// try to retrieve a stored callback
|
|
|
|
auto eventCallback = pEvent->getEventReturnCallback();
|
|
|
|
// if there is one, proceed to call it
|
|
|
|
if( eventCallback )
|
|
|
|
{
|
2017-12-08 11:46:47 +01:00
|
|
|
eventCallback( player, eventId, param1, param2, param3 );
|
2017-08-18 17:29:36 +02:00
|
|
|
if( !pEvent->hasPlayedScene() )
|
2017-12-08 11:46:47 +01:00
|
|
|
player.eventFinish( eventId, 1 );
|
2017-08-18 17:29:36 +02:00
|
|
|
else
|
|
|
|
pEvent->setPlayedScene( false );
|
|
|
|
}
|
2017-12-10 01:52:03 +11:00
|
|
|
// else, finish the event.
|
2017-08-18 17:29:36 +02:00
|
|
|
else
|
2017-12-08 11:46:47 +01:00
|
|
|
player.eventFinish( eventId, 1 );
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( std::exception& e )
|
|
|
|
{
|
2017-12-08 11:46:47 +01:00
|
|
|
player.sendNotice( e.what() );
|
2017-08-18 17:29:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId,
|
2017-08-18 17:29:36 +02:00
|
|
|
uint16_t subEvent, uint16_t param, uint32_t catalogId )
|
|
|
|
{
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId );
|
2017-12-13 22:19:00 +11:00
|
|
|
if( script )
|
|
|
|
{
|
|
|
|
script->onEventHandlerTradeReturn( player, eventId, subEvent, param, catalogId );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32_t eventItemId,
|
2017-11-28 17:22:19 +01:00
|
|
|
uint32_t eventId, uint32_t castTime, uint64_t targetId )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2017-12-13 22:19:00 +11:00
|
|
|
std::string eventName = "onEventItem";
|
|
|
|
std::string objName = Event::getEventName( eventId );
|
|
|
|
player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) );
|
|
|
|
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId );
|
2017-12-13 22:19:00 +11:00
|
|
|
if( script )
|
|
|
|
{
|
2018-01-09 23:50:54 +01:00
|
|
|
player.eventStart( targetId, eventId, Event::EventHandler::Item, 0, 0 );
|
2017-12-13 22:19:00 +11:00
|
|
|
|
|
|
|
script->onEventItem( player, eventItemId, eventId, castTime, targetId );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t nameId )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
std::string eventName = "onBnpcKill_" + std::to_string( nameId );
|
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
|
2017-08-18 17:29:36 +02:00
|
|
|
// loop through all active quests and try to call available onMobKill callbacks
|
|
|
|
for( size_t i = 0; i < 30; i++ )
|
|
|
|
{
|
2017-12-08 11:46:47 +01:00
|
|
|
auto activeQuests = player.getQuestActive( static_cast< uint16_t >( i ) );
|
2017-08-18 17:29:36 +02:00
|
|
|
if( !activeQuests )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uint16_t questId = activeQuests->c.questId;
|
2017-12-10 01:52:03 +11:00
|
|
|
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, questId );
|
2017-12-10 01:52:03 +11:00
|
|
|
if( script )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
std::string objName = Event::getEventName( 0x00010000 | questId );
|
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
player.sendDebug("Calling: " + objName + "." + eventName);
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
script->onNpcKill( nameId, player );
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-08 11:46:47 +01:00
|
|
|
bool Core::Scripting::ScriptManager::onCastFinish( Entity::Player& player, Entity::ActorPtr pTarget, uint32_t actionId )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< ActionScript >( ScriptType::ScriptedAction, actionId );
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
if( script )
|
2017-12-11 22:21:37 +11:00
|
|
|
script->onCastFinish( player, *pTarget );
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return true;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::Scripting::ScriptManager::onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId )
|
|
|
|
{
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< StatusEffectScript >( ScriptType::ScriptedStatusEffect, effectId );
|
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
if( script )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
if( pActor->isPlayer() )
|
2017-12-11 22:21:37 +11:00
|
|
|
pActor->getAsPlayer()->sendDebug( "Calling status receive for statusid: " + std::to_string( effectId ) );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-11 22:21:37 +11:00
|
|
|
script->onApply( *pActor );
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return true;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::Scripting::ScriptManager::onStatusTick( Entity::ActorPtr pActor, Core::StatusEffect::StatusEffect& effect )
|
|
|
|
{
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< StatusEffectScript >( ScriptType::ScriptedStatusEffect, effect.getId() );
|
2017-12-10 01:52:03 +11:00
|
|
|
if( script )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
if( pActor->isPlayer() )
|
2017-12-11 22:21:37 +11:00
|
|
|
pActor->getAsPlayer()->sendDebug( "Calling status tick for statusid: " + std::to_string( effect.getId() ) );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-11 22:21:37 +11:00
|
|
|
script->onTick( *pActor );
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return true;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::Scripting::ScriptManager::onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId )
|
|
|
|
{
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< StatusEffectScript >( ScriptType::ScriptedStatusEffect, effectId );
|
2017-12-10 01:52:03 +11:00
|
|
|
if( script )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
|
|
|
if( pActor->isPlayer() )
|
2017-12-11 22:21:37 +11:00
|
|
|
pActor->getAsPlayer()->sendDebug( "Calling status timeout for statusid: " + std::to_string( effectId ) );
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-11 22:21:37 +11:00
|
|
|
script->onExpire( *pActor );
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
return true;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone )
|
|
|
|
{
|
2018-01-04 16:14:14 +11:00
|
|
|
auto script = m_nativeScriptManager->getScript< ZoneScript >( ScriptType::ScriptedZone, pZone->getId() );
|
2017-12-10 01:52:03 +11:00
|
|
|
if( script )
|
2017-08-18 17:29:36 +02:00
|
|
|
{
|
2017-12-10 01:52:03 +11:00
|
|
|
script->onZoneInit();
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
return true;
|
|
|
|
}
|
2017-08-18 17:29:36 +02:00
|
|
|
|
2017-12-10 01:52:03 +11:00
|
|
|
return false;
|
2017-08-18 17:29:36 +02:00
|
|
|
}
|
2017-12-12 01:45:24 +11:00
|
|
|
|
2017-12-13 15:07:03 +11:00
|
|
|
Scripting::NativeScriptManager& Core::Scripting::ScriptManager::getNativeScriptHandler()
|
2017-12-12 01:45:24 +11:00
|
|
|
{
|
2017-12-13 15:07:03 +11:00
|
|
|
return *m_nativeScriptManager;
|
2017-12-12 01:45:24 +11:00
|
|
|
}
|