diff --git a/src/scripts/CMakeLists.txt b/src/scripts/CMakeLists.txt index 31cc1334..cea505bd 100644 --- a/src/scripts/CMakeLists.txt +++ b/src/scripts/CMakeLists.txt @@ -46,7 +46,7 @@ foreach(_scriptDir ${children}) MODULE ${SCRIPT_BUILD_FILES} "${SCRIPT_INCLUDE_FILES}" - "${_scriptDir}/ScriptLoader.cpp" ) + "${_scriptDir}/ScriptLoader.cpp" "arena/IfritNormal.cpp") target_link_libraries( "script_${_name}" world ) diff --git a/src/scripts/arena/IfritNormal.cpp b/src/scripts/arena/IfritNormal.cpp new file mode 100644 index 00000000..261fcfb4 --- /dev/null +++ b/src/scripts/arena/IfritNormal.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +using namespace Sapphire; + +class IfritNormal : public Sapphire::ScriptAPI::InstanceArenaScript +{ +public: + IfritNormal() : Sapphire::ScriptAPI::InstanceArenaScript( 20001 ) + { } + + void onInit( InstanceContent& instance ) override + { + auto boss = instance.createBNpcFromLayoutId( 4126276, 13884, Common::BNpcType::Enemy ); + boss->setFlag( Entity::NoDeaggro ); + + //instance.sendForward(); + } + + void onUpdate( InstanceContent& instance, uint64_t tickCount ) override + { + auto boss = instance.getActiveBNpcByLayoutId( 4126276 ); + + if( boss; boss->hateListGetHighestValue() != 0 ) + { + if( instance.getDirectorVar( 0 ) == 0 ) + onBattleStart( instance ); + + boss->setRot( boss->getRot() + 0.5f ); + boss->setPos( boss->getPos() ); + + boss->sendPositionUpdate(); + + playerMgr().sendDebug( *boss->hateListGetHighest()->getAsPlayer(), std::to_string( boss->getRot() ) ); + + if( boss->getRot() >= 4.f && instance.getDirectorVar( 0 ) == 1 ) + { + instance.setDirectorVar( 0, 0 ); + boss->hateListGetHighest()->die(); + boss->hateListClear(); + onReset( instance ); + + } + + } + } + + void onReset( InstanceContent& instance ) override + { + auto boss = instance.getActiveBNpcByLayoutId( 4126276 ); + instance.removeActor( boss ); + + onInit( instance ); + } + + void onBattleStart( InstanceContent& instance ) override + { + auto boss = instance.getActiveBNpcByLayoutId( 4126276 ); + + instance.setDirectorVar( 0, 1 ); + + auto pPlayer = boss->hateListGetHighest()->getAsPlayer(); + + instance.sendEventLogMessage( *pPlayer, instance, 4847, { 0, 0 } ); + instance.sendEventLogMessage( *pPlayer, instance, 170, { 0, boss->getId() } ); + } +}; + +EXPOSE_SCRIPT( IfritNormal ); \ No newline at end of file diff --git a/src/world/Script/NativeScriptApi.cpp b/src/world/Script/NativeScriptApi.cpp index 87997387..2d68c7ac 100644 --- a/src/world/Script/NativeScriptApi.cpp +++ b/src/world/Script/NativeScriptApi.cpp @@ -291,5 +291,27 @@ namespace Sapphire::ScriptAPI { } + /////////////////////////////////////////////////////////////////// + + InstanceArenaScript::InstanceArenaScript( uint32_t instanceContentId ) : ScriptObject( uint32_t{ 0x8003 } << 16 | instanceContentId, typeid( InstanceArenaScript ).hash_code() ) + { + } + + void InstanceArenaScript::onInit( InstanceContent& instance ) + { + } + + void InstanceArenaScript::onUpdate( InstanceContent& instance, uint64_t tickCount ) + { + } + + void InstanceArenaScript::onReset( InstanceContent& instance ) + { + } + + void InstanceArenaScript::onBattleStart( InstanceContent& instance ) + { + } + } diff --git a/src/world/Script/NativeScriptApi.h b/src/world/Script/NativeScriptApi.h index 531a9b40..d28739f3 100644 --- a/src/world/Script/NativeScriptApi.h +++ b/src/world/Script/NativeScriptApi.h @@ -375,7 +375,7 @@ namespace Sapphire::ScriptAPI }; /*! - * @brief The base class for any scripts that implement behaviour related to instance content zones + * @brief The base class for any scripts that implement behaviour related to quest battles */ class QuestBattleScript : public ScriptObject { @@ -406,6 +406,48 @@ namespace Sapphire::ScriptAPI } }; + /*! + * @brief The base class for any scripts that implement behaviour related to a generic arena + */ + class ArenaScript : public ScriptObject + { + public: + explicit ArenaScript( uint32_t battleId ); + + virtual void onInit( Sapphire::Territory& instance ); + + virtual void onUpdate( Sapphire::Territory& instance, uint64_t tickCount ); + + virtual void onReset( Sapphire::Territory& instance ); + + World::Manager::PlayerMgr& playerMgr() + { + return Common::Service< World::Manager::PlayerMgr >::ref(); + } + }; + + /*! + * @brief The base class for any scripts that implement behaviour related to an instance arena + */ + class InstanceArenaScript : public ScriptObject + { + public: + explicit InstanceArenaScript( uint32_t instanceContentId ); + + virtual void onInit( Sapphire::InstanceContent& instance ); + + virtual void onUpdate( Sapphire::InstanceContent& instance, uint64_t tickCount ); + + virtual void onReset( Sapphire::InstanceContent& instance ); + + virtual void onBattleStart( Sapphire::InstanceContent& instance ); + + World::Manager::PlayerMgr& playerMgr() + { + return Common::Service< World::Manager::PlayerMgr >::ref(); + } + }; + } #endif diff --git a/src/world/Script/ScriptLoader.cpp b/src/world/Script/ScriptLoader.cpp index 164520f3..be462921 100644 --- a/src/world/Script/ScriptLoader.cpp +++ b/src/world/Script/ScriptLoader.cpp @@ -241,7 +241,7 @@ Sapphire::ScriptAPI::ScriptObject** Sapphire::Scripting::ScriptLoader::getScript } else { - Logger::warn( "did not find a win32initLinkshell export on a windows script target - the server will likely crash!" ); + Logger::warn( "did not find a win32initWarp export on a windows script target - the server will likely crash!" ); } #else auto func = reinterpret_cast< getScripts >( dlsym( handle, "getScripts" ) ); diff --git a/src/world/Script/ScriptMgr.cpp b/src/world/Script/ScriptMgr.cpp index e6d9c1c1..6747e503 100644 --- a/src/world/Script/ScriptMgr.cpp +++ b/src/world/Script/ScriptMgr.cpp @@ -680,10 +680,17 @@ bool Sapphire::Scripting::ScriptMgr::onZoneInit( const Territory& zone ) bool Sapphire::Scripting::ScriptMgr::onInstanceInit( InstanceContent& instance ) { + auto instId = instance.getDirectorId(); auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::InstanceContentScript >( instance.getDirectorId() ); + if( script ) { script->onInit( instance ); + + auto arenaScript = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::InstanceArenaScript >( instance.getDirectorId() ); + if( arenaScript ) + arenaScript->onInit( instance ); + return true; } @@ -697,6 +704,10 @@ bool Sapphire::Scripting::ScriptMgr::onInstanceUpdate( InstanceContent& instance if( script ) { script->onUpdate( instance, tickCount ); + + auto arenaScript = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::InstanceArenaScript >( instance.getDirectorId() ); + if( arenaScript ) + arenaScript->onUpdate( instance, tickCount ); return true; }