diff --git a/bin/scripts/chai/skill/skillDef_3.chai b/bin/scripts/chai/skill/skillDef_3.chai index a05967ab..fc1543a4 100644 --- a/bin/scripts/chai/skill/skillDef_3.chai +++ b/bin/scripts/chai/skill/skillDef_3.chai @@ -10,7 +10,7 @@ class skillDef_3Def def onFinish( player, target ) { - player.addStatusEffectById(50, 20000); + player.addStatusEffectById(50, 20000, 3791585310); } }; diff --git a/bin/scripts/chai/skill/skillDef_6.chai b/bin/scripts/chai/skill/skillDef_6.chai new file mode 100644 index 00000000..4f39b99b --- /dev/null +++ b/bin/scripts/chai/skill/skillDef_6.chai @@ -0,0 +1,18 @@ +// Skill Name: Sprint +// Skill ID: 3 + +class skillDef_6Def +{ + def skillDef_6Def() + { + + } + + def onFinish( player, target ) + { + player.returnToHomepoint(); + } + +}; + +GLOBAL skillDef_6 = skillDef_6Def(); diff --git a/src/servers/Server_Zone/Actor.cpp b/src/servers/Server_Zone/Actor.cpp index 077d8df9..1512e22f 100644 --- a/src/servers/Server_Zone/Actor.cpp +++ b/src/servers/Server_Zone/Actor.cpp @@ -605,9 +605,10 @@ void Core::Entity::Actor::addStatusEffect( StatusEffect::StatusEffectPtr pEffect } /*! \param StatusEffectPtr to be applied to the actor */ -void Core::Entity::Actor::addStatusEffectById( int32_t id, int32_t duration ) +void Core::Entity::Actor::addStatusEffectById( int32_t id, int32_t duration, uint32_t power ) { StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, shared_from_this(), shared_from_this(), duration, 3000 ) ); + effect->setPower( power ); addStatusEffect( effect ); } diff --git a/src/servers/Server_Zone/Actor.h b/src/servers/Server_Zone/Actor.h index de27049d..0ea3acf8 100644 --- a/src/servers/Server_Zone/Actor.h +++ b/src/servers/Server_Zone/Actor.h @@ -290,7 +290,7 @@ public: void addStatusEffect( StatusEffect::StatusEffectPtr pEffect ); // add a status effect by id - void addStatusEffectById( int32_t id, int32_t duration ); + void addStatusEffectById( int32_t id, int32_t duration, uint32_t power = 0 ); // TODO: Why did i even declare them publicly here?! std::set< ActorPtr > m_inRangeActors; diff --git a/src/servers/Server_Zone/GameCommandHandler.cpp b/src/servers/Server_Zone/GameCommandHandler.cpp index 1a567b95..f8d77348 100644 --- a/src/servers/Server_Zone/GameCommandHandler.cpp +++ b/src/servers/Server_Zone/GameCommandHandler.cpp @@ -84,7 +84,7 @@ void Core::GameCommandHandler::execCommand( char * data, Core::Entity::PlayerPtr if( it == m_commandMap.end() ) // no command found, do something... or not - g_log.error( "[" + std::to_string( pPlayer->getId() ) + "] " + "Command not found" ); + pPlayer->sendUrgent( "Command not found." ); // TODO Notify the client of the failed command else { @@ -249,8 +249,6 @@ void Core::GameCommandHandler::set( char * data, Core::Entity::PlayerPtr pPlayer sscanf( params.c_str(), "%d", &id ); - g_log.debug( std::to_string( pPlayer->getLevelForClass( static_cast ( id ) ) ) ); - if( pPlayer->getLevelForClass( static_cast ( id ) ) == 0 ) { pPlayer->setLevelForClass( 1, static_cast ( id ) ); diff --git a/src/servers/Server_Zone/PacketHandlers.cpp b/src/servers/Server_Zone/PacketHandlers.cpp index db3d27b9..95d23962 100644 --- a/src/servers/Server_Zone/PacketHandlers.cpp +++ b/src/servers/Server_Zone/PacketHandlers.cpp @@ -842,8 +842,7 @@ void Core::Network::GameConnection::actionHandler( Core::Network::Packets::GameP } case 0xC8: // return dead { - pPlayer->setZoningType( Common::ZoneingType::Return ); - pPlayer->teleport( pPlayer->getHomepoint(), 3 ); + pPlayer->returnToHomepoint(); break; } case 0xC9: // Finish zoning diff --git a/src/servers/Server_Zone/Player.cpp b/src/servers/Server_Zone/Player.cpp index 185ea137..6a45489d 100644 --- a/src/servers/Server_Zone/Player.cpp +++ b/src/servers/Server_Zone/Player.cpp @@ -341,6 +341,12 @@ void Core::Entity::Player::forceZoneing( uint32_t zoneId ) //performZoning( zoneId, Common::ZoneingType::None, getPos() ); } +void Core::Entity::Player::returnToHomepoint() +{ + setZoningType( Common::ZoneingType::Return ); + teleport( getHomepoint(), 3 ); +} + void Core::Entity::Player::setZone( uint32_t zoneId ) { auto pPlayer = getAsPlayer(); diff --git a/src/servers/Server_Zone/Player.h b/src/servers/Server_Zone/Player.h index 1d7b8d22..fd8f53e1 100644 --- a/src/servers/Server_Zone/Player.h +++ b/src/servers/Server_Zone/Player.h @@ -302,6 +302,8 @@ public: void setZone( uint32_t zoneId ); void forceZoneing( uint32_t zoneId ); + /*! return player to preset homepoint */ + void returnToHomepoint(); /*! change position, sends update too */ void changePosition( float x, float y, float z, float o ); /*! return the contentId */ diff --git a/src/servers/Server_Zone/ScriptManager.cpp b/src/servers/Server_Zone/ScriptManager.cpp index 78e3bf75..94293955 100644 --- a/src/servers/Server_Zone/ScriptManager.cpp +++ b/src/servers/Server_Zone/ScriptManager.cpp @@ -396,6 +396,69 @@ bool Core::Scripting::ScriptManager::onCastFinish( Entity::PlayerPtr pPlayer, En return true; } +bool Core::Scripting::ScriptManager::onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId ) +{ + std::string eventName = "onReceive"; + + try + { + auto obj = m_pChaiHandler->eval( "statusDef_" + std::to_string( effectId ) ); + std::string objName = "statusDef_" + std::to_string( effectId ); + + pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); + auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor&) > >( eventName ); + fn( obj, *pActor ); + } + catch( std::exception& e ) + { + pActor->getAsPlayer()->sendUrgent( e.what() ); + } + + return true; +} + +bool Core::Scripting::ScriptManager::onStatusTick( Entity::ActorPtr pActor, uint32_t effectId ) +{ + std::string eventName = "onTick"; + + try + { + auto obj = m_pChaiHandler->eval( "statusDef_" + std::to_string( effectId ) ); + std::string objName = "statusDef_" + std::to_string( effectId ); + + pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); + auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor& ) > >( eventName ); + fn( obj, *pActor ); + } + catch( std::exception& e ) + { + pActor->getAsPlayer()->sendUrgent( e.what() ); + } + + return true; +} + +bool Core::Scripting::ScriptManager::onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId ) +{ + std::string eventName = "onTimeOut"; + + try + { + auto obj = m_pChaiHandler->eval( "statusDef_" + std::to_string( effectId ) ); + std::string objName = "statusDef_" + std::to_string( effectId ); + + pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); + auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor& ) > >( eventName ); + fn( obj, *pActor ); + } + catch( std::exception& e ) + { + pActor->getAsPlayer()->sendUrgent( e.what() ); + } + + return true; +} + bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone ) { std::string eventName = "onZoneInit_" + pZone->getInternalName(); diff --git a/src/servers/Server_Zone/ScriptManager.h b/src/servers/Server_Zone/ScriptManager.h index cd6b0e5c..b398d4a4 100644 --- a/src/servers/Server_Zone/ScriptManager.h +++ b/src/servers/Server_Zone/ScriptManager.h @@ -52,6 +52,10 @@ namespace Core bool onCastFinish( Entity::PlayerPtr pPlayer, Entity::ActorPtr pTarget, uint32_t actionId ); + bool onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId ); + bool onStatusTick( Entity::ActorPtr pActor, uint32_t effectId ); + bool onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId ); + bool onZoneInit( ZonePtr pZone ); bool onEventHandlerReturn( Entity::PlayerPtr pPlayer, uint32_t eventId, uint16_t subEvent, uint16_t param1, uint16_t param2, uint16_t param3 ); diff --git a/src/servers/Server_Zone/ScriptManagerInit.cpp b/src/servers/Server_Zone/ScriptManagerInit.cpp index 07d705f5..f4e56ba9 100644 --- a/src/servers/Server_Zone/ScriptManagerInit.cpp +++ b/src/servers/Server_Zone/ScriptManagerInit.cpp @@ -48,6 +48,7 @@ int Core::Scripting::ScriptManager::init() m_pChaiHandler->add( chaiscript::fun( &Entity::Player::learnAction ), "learnAction" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getHomepoint ), "getHomepoint" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setHomepoint ), "setHomepoint" ); + m_pChaiHandler->add( chaiscript::fun( &Entity::Player::returnToHomepoint ), "returnToHomepoint" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::teleport ), "teleport" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::prepareZoning ), "prepareZoning" ); diff --git a/src/servers/Server_Zone/StatusEffect.cpp b/src/servers/Server_Zone/StatusEffect.cpp index 33576896..f5ec4a05 100644 --- a/src/servers/Server_Zone/StatusEffect.cpp +++ b/src/servers/Server_Zone/StatusEffect.cpp @@ -10,6 +10,7 @@ #include "Actor.h" #include "StatusEffect.h" +#include "ScriptManager.h" extern Core::Logger g_log; extern Core::Data::ExdData g_exdData; @@ -17,6 +18,8 @@ extern Core::Data::ExdData g_exdData; using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; +extern Core::Scripting::ScriptManager g_scriptMgr; + Core::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::ActorPtr sourceActor, Entity::ActorPtr targetActor, uint32_t duration, uint32_t tickRate ) @@ -51,6 +54,7 @@ Core::StatusEffect::StatusEffect::~StatusEffect() void Core::StatusEffect::StatusEffect::onTick() { m_lastTick = Util::getTimeMs(); + g_scriptMgr.onStatusTick( m_targetActor, m_id ); } uint32_t Core::StatusEffect::StatusEffect::getSrcActorId() const @@ -63,6 +67,11 @@ uint32_t Core::StatusEffect::StatusEffect::getTargetActorId() const return m_targetActor->getId(); } +uint32_t Core::StatusEffect::StatusEffect::getPower() const +{ + return m_power; +} + void Core::StatusEffect::StatusEffect::applyStatus() { m_startTime = Util::getTimeMs(); @@ -86,11 +95,13 @@ void Core::StatusEffect::StatusEffect::applyStatus() //m_sourceActor->sendToInRangeSet( effectPacket, true ); g_log.debug( "StatusEffect applied: " + m_name ); + g_scriptMgr.onStatusReceive( m_targetActor, m_id ); } void Core::StatusEffect::StatusEffect::removeStatus() { g_log.debug( "StatusEffect removed: " + m_name ); + g_scriptMgr.onStatusTimeOut( m_targetActor, m_id ); } uint32_t Core::StatusEffect::StatusEffect::getId() const @@ -123,6 +134,12 @@ void Core::StatusEffect::StatusEffect::setLastTick( uint64_t lastTick ) m_lastTick = lastTick; } +void Core::StatusEffect::StatusEffect::setPower( uint32_t power ) +{ + m_power = power; +} + + const std::string& Core::StatusEffect::StatusEffect::getName() const { return m_name; diff --git a/src/servers/Server_Zone/StatusEffect.h b/src/servers/Server_Zone/StatusEffect.h index 7b9d88f7..4c6cc500 100644 --- a/src/servers/Server_Zone/StatusEffect.h +++ b/src/servers/Server_Zone/StatusEffect.h @@ -30,7 +30,9 @@ public: uint32_t getTargetActorId() const; uint64_t getLastTickMs() const; uint64_t getStartTimeMs() const; + uint32_t getPower() const; void setLastTick( uint64_t lastTick ); + void setPower( uint32_t power ); const std::string& getName() const; private: @@ -41,6 +43,7 @@ private: uint64_t m_startTime; uint32_t m_tickRate; uint64_t m_lastTick; + uint32_t m_power; //Figure out what this actually is supposed to be std::string m_name; }; diff --git a/src/servers/Server_Zone/StatusEffectContainer.cpp b/src/servers/Server_Zone/StatusEffectContainer.cpp index 25799233..ba381f17 100644 --- a/src/servers/Server_Zone/StatusEffectContainer.cpp +++ b/src/servers/Server_Zone/StatusEffectContainer.cpp @@ -68,6 +68,8 @@ void Core::StatusEffect::StatusEffectContainer::addStatusEffect( StatusEffectPtr statusEffectAdd.data().max_hp = m_pOwner->getMaxHp(); statusEffectAdd.data().max_mp = m_pOwner->getMaxMp(); statusEffectAdd.data().max_something = 1; + //statusEffectAdd.data().unknown2 = 28; + statusEffectAdd.data().power = pEffect->getPower(); bool sendToSelf = m_pOwner->isPlayer() ? true : false; m_pOwner->sendToInRangeSet( statusEffectAdd, sendToSelf );