2017-12-18 12:36:52 +01:00
|
|
|
#include <common/Common.h>
|
|
|
|
#include <common/Network/GamePacket.h>
|
|
|
|
#include <common/Logging/Logger.h>
|
|
|
|
#include <common/Network/PacketContainer.h>
|
|
|
|
#include <common/Config/XMLConfig.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
#include "Player.h"
|
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Zone/Zone.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Forwards.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Network/GameConnection.h"
|
|
|
|
#include "Network/PacketWrappers/ActorControlPacket142.h"
|
|
|
|
#include "Network/PacketWrappers/InitUIPacket.h"
|
|
|
|
#include "Network/PacketWrappers/ServerNoticePacket.h"
|
|
|
|
#include "Network/PacketWrappers/EventStartPacket.h"
|
|
|
|
#include "Network/PacketWrappers/EventPlayPacket.h"
|
|
|
|
#include "Network/PacketWrappers/EventFinishPacket.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Action/EventAction.h"
|
|
|
|
#include "Action/EventItemAction.h"
|
2017-10-01 18:38:58 +02:00
|
|
|
|
2018-01-09 23:50:54 +01:00
|
|
|
#include "Event/EventHandler.h"
|
|
|
|
#include "Event/EventHandler.h"
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "ServerZone.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
extern Core::Logger g_log;
|
2017-09-10 02:24:29 +02:00
|
|
|
extern Core::ServerZone g_serverZone;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
using namespace Core::Common;
|
|
|
|
using namespace Core::Network::Packets;
|
|
|
|
using namespace Core::Network::Packets::Server;
|
|
|
|
|
2018-01-09 23:50:54 +01:00
|
|
|
void Core::Entity::Player::addEvent( Event::EventHandlerPtr pEvent )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-01-14 23:54:26 +01:00
|
|
|
m_eventHandlerMap[pEvent->getId()] = pEvent;
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-01-09 23:50:54 +01:00
|
|
|
std::map< uint32_t, Core::Event::EventHandlerPtr >& Core::Entity::Player::eventList()
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-01-14 23:54:26 +01:00
|
|
|
return m_eventHandlerMap;
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-01-09 23:50:54 +01:00
|
|
|
Core::Event::EventHandlerPtr Core::Entity::Player::getEvent( uint32_t eventId )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-01-14 23:54:26 +01:00
|
|
|
auto it = m_eventHandlerMap.find( eventId );
|
|
|
|
if( it != m_eventHandlerMap.end() )
|
2017-08-08 13:53:47 +02:00
|
|
|
return it->second;
|
|
|
|
|
2018-01-09 23:50:54 +01:00
|
|
|
return Event::EventHandlerPtr( nullptr );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t Core::Entity::Player::getEventCount()
|
|
|
|
{
|
2018-01-14 23:54:26 +01:00
|
|
|
return m_eventHandlerMap.size();
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::removeEvent( uint32_t eventId )
|
|
|
|
{
|
2018-01-14 23:54:26 +01:00
|
|
|
auto it = m_eventHandlerMap.find( eventId );
|
|
|
|
if( it != m_eventHandlerMap.end() )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
auto tmpEvent = it->second;
|
2018-01-14 23:54:26 +01:00
|
|
|
m_eventHandlerMap.erase( it );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::checkEvent( uint32_t eventId )
|
|
|
|
{
|
|
|
|
auto pEvent = getEvent( eventId );
|
2017-11-28 00:09:36 +01:00
|
|
|
|
|
|
|
if( pEvent && !pEvent->hasPlayedScene() )
|
|
|
|
eventFinish( eventId, 1 );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Core::Entity::Player::eventStart( uint64_t actorId, uint32_t eventId,
|
2018-01-09 23:50:54 +01:00
|
|
|
Event::EventHandler::EventType eventType, uint8_t eventParam1,
|
2017-08-08 13:53:47 +02:00
|
|
|
uint32_t eventParam2 )
|
|
|
|
{
|
2018-01-28 00:30:16 +01:00
|
|
|
|
2018-02-10 01:21:31 +01:00
|
|
|
auto newEvent = Event::make_EventHandler( this, actorId, eventId, eventType, eventParam2 );
|
2018-01-28 00:30:16 +01:00
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
addEvent( newEvent );
|
|
|
|
|
2018-02-15 23:50:28 +01:00
|
|
|
setStateFlag( PlayerStateFlag::InNpcEvent );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
EventStartPacket eventStart( getId(), actorId, eventId, eventType, eventParam1, eventParam2 );
|
|
|
|
|
|
|
|
queuePacket( eventStart );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene,
|
|
|
|
uint32_t flags, uint32_t eventParam2,
|
|
|
|
uint32_t eventParam3 )
|
|
|
|
{
|
|
|
|
eventPlay( eventId, scene, flags, eventParam2, eventParam3, nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene,
|
2018-01-09 23:50:54 +01:00
|
|
|
uint32_t flags, Event::EventHandler::SceneReturnCallback eventCallback )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
eventPlay( eventId, scene, flags, 0, 0, eventCallback );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags )
|
|
|
|
{
|
|
|
|
eventPlay( eventId, scene, flags, 0, 0, nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene,
|
|
|
|
uint32_t flags, uint32_t eventParam2,
|
2018-01-09 23:50:54 +01:00
|
|
|
uint32_t eventParam3, Event::EventHandler::SceneReturnCallback eventCallback )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
if( flags & 0x02 )
|
|
|
|
setStateFlag( PlayerStateFlag::WatchingCutscene );
|
|
|
|
|
|
|
|
auto pEvent = getEvent( eventId );
|
|
|
|
if( !pEvent && getEventCount() )
|
|
|
|
{
|
|
|
|
// We're trying to play a nested event, need to start it first.
|
2018-01-09 23:50:54 +01:00
|
|
|
eventStart( getId(), eventId, Event::EventHandler::Nest, 0, 0 );
|
2017-08-08 13:53:47 +02:00
|
|
|
pEvent = getEvent( eventId );
|
|
|
|
}
|
|
|
|
else if( !pEvent )
|
|
|
|
{
|
|
|
|
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pEvent->setPlayedScene( true );
|
|
|
|
pEvent->setEventReturnCallback( eventCallback );
|
|
|
|
EventPlayPacket eventPlay( getId(), pEvent->getActorId(), pEvent->getId(),
|
|
|
|
scene, flags, eventParam2, eventParam3 );
|
|
|
|
|
|
|
|
queuePacket( eventPlay );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene,
|
|
|
|
uint32_t flags, uint32_t eventParam2,
|
2018-01-09 23:50:54 +01:00
|
|
|
uint32_t eventParam3, uint32_t eventParam4, Event::EventHandler::SceneReturnCallback eventCallback )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
if( flags & 0x02 )
|
|
|
|
setStateFlag( PlayerStateFlag::WatchingCutscene );
|
|
|
|
|
|
|
|
auto pEvent = getEvent( eventId );
|
|
|
|
if( !pEvent && getEventCount() )
|
|
|
|
{
|
|
|
|
// We're trying to play a nested event, need to start it first.
|
2018-01-09 23:50:54 +01:00
|
|
|
eventStart( getId(), eventId, Event::EventHandler::Nest, 0, 0 );
|
2017-08-08 13:53:47 +02:00
|
|
|
pEvent = getEvent( eventId );
|
|
|
|
}
|
|
|
|
else if( !pEvent )
|
|
|
|
{
|
|
|
|
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pEvent->setPlayedScene( true );
|
|
|
|
pEvent->setEventReturnCallback( eventCallback );
|
|
|
|
EventPlayPacket eventPlay( getId(), pEvent->getActorId(), pEvent->getId(),
|
|
|
|
scene, flags, eventParam2, eventParam3, eventParam4 );
|
|
|
|
|
|
|
|
queuePacket( eventPlay );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::eventFinish( uint32_t eventId, uint32_t freePlayer )
|
|
|
|
{
|
|
|
|
auto pEvent = getEvent( eventId );
|
|
|
|
|
|
|
|
if( !pEvent )
|
|
|
|
{
|
|
|
|
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-09 23:50:54 +01:00
|
|
|
if( getEventCount() > 1 && pEvent->getEventType() != Event::EventHandler::Nest )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
// this is the parent of a nested event, we can't finish it until the parent finishes
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( pEvent->getEventType() )
|
|
|
|
{
|
2018-01-09 23:50:54 +01:00
|
|
|
case Event::EventHandler::Nest:
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-01-14 23:54:26 +01:00
|
|
|
queuePacket( EventFinishPacket( getId(), pEvent->getId(), pEvent->getEventType(), pEvent->getEventParam() ) );
|
2017-08-08 13:53:47 +02:00
|
|
|
removeEvent( pEvent->getId() );
|
|
|
|
|
|
|
|
auto events = eventList();
|
|
|
|
|
|
|
|
for( auto it : events )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( it.second->hasPlayedScene() == false )
|
|
|
|
{
|
|
|
|
// TODO: not happy with this, this is also prone to break wit more than one remaining event in there
|
2018-01-14 23:54:26 +01:00
|
|
|
queuePacket( EventFinishPacket( getId(), it.second->getId(), it.second->getEventType(),
|
|
|
|
it.second->getEventParam() ) );
|
2017-08-08 13:53:47 +02:00
|
|
|
removeEvent( it.second->getId() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2018-01-14 23:54:26 +01:00
|
|
|
queuePacket( EventFinishPacket( getId(), pEvent->getId(), pEvent->getEventType(), pEvent->getEventParam() ) );
|
2017-08-08 13:53:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( hasStateFlag( PlayerStateFlag::WatchingCutscene ) )
|
|
|
|
unsetStateFlag( PlayerStateFlag::WatchingCutscene );
|
|
|
|
|
|
|
|
removeEvent( pEvent->getId() );
|
|
|
|
|
|
|
|
if( freePlayer == 1 )
|
2018-02-15 23:50:28 +01:00
|
|
|
unsetStateFlag( PlayerStateFlag::InNpcEvent );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2017-10-01 18:38:58 +02:00
|
|
|
void Core::Entity::Player::eventActionStart( uint32_t eventId,
|
|
|
|
uint32_t action,
|
|
|
|
ActionCallback finishCallback,
|
|
|
|
ActionCallback interruptCallback,
|
|
|
|
uint64_t additional )
|
|
|
|
{
|
2018-02-10 01:21:31 +01:00
|
|
|
auto pEventAction = Action::make_EventAction( getAsActor(), eventId, action,
|
|
|
|
finishCallback, interruptCallback, additional );
|
2017-10-01 18:38:58 +02:00
|
|
|
|
|
|
|
setCurrentAction( pEventAction );
|
|
|
|
auto pEvent = getEvent( eventId );
|
|
|
|
|
|
|
|
if( !pEvent && getEventCount() )
|
|
|
|
{
|
|
|
|
// We're trying to play a nested event, need to start it first.
|
2018-01-09 23:50:54 +01:00
|
|
|
eventStart( getId(), eventId, Event::EventHandler::Nest, 0, 0 );
|
2017-10-01 18:38:58 +02:00
|
|
|
pEvent = getEvent( eventId );
|
|
|
|
}
|
|
|
|
else if( !pEvent )
|
|
|
|
{
|
|
|
|
g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pEvent )
|
|
|
|
pEvent->setPlayedScene( true );
|
|
|
|
pEventAction->onStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Core::Entity::Player::eventItemActionStart( uint32_t eventId,
|
|
|
|
uint32_t action,
|
|
|
|
ActionCallback finishCallback,
|
|
|
|
ActionCallback interruptCallback,
|
|
|
|
uint64_t additional )
|
|
|
|
{
|
2018-02-10 01:21:31 +01:00
|
|
|
Action::ActionPtr pEventItemAction = Action::make_EventItemAction( getAsActor(), eventId, action,
|
|
|
|
finishCallback, interruptCallback, additional );
|
2017-10-01 18:38:58 +02:00
|
|
|
|
|
|
|
setCurrentAction( pEventItemAction );
|
|
|
|
|
|
|
|
pEventItemAction->onStart();
|
|
|
|
}
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void Core::Entity::Player::onLogin()
|
|
|
|
{
|
2017-11-28 00:09:36 +01:00
|
|
|
for( auto& child : g_serverZone.getConfig()->getChild( "Settings.Parameters.MotDArray" ) )
|
|
|
|
{
|
2017-09-10 16:47:40 +02:00
|
|
|
sendNotice( child.second.data() );
|
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::onZoneStart()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::onZoneDone()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Entity::Player::onDeath()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: slightly ugly here and way too static. Needs too be done properly
|
|
|
|
void Core::Entity::Player::onTick()
|
|
|
|
{
|
|
|
|
|
|
|
|
bool sendUpdate = false;
|
|
|
|
|
|
|
|
if( !isAlive() || !isLoadingComplete() )
|
|
|
|
return;
|
|
|
|
|
2017-09-15 00:56:29 -03:00
|
|
|
uint32_t addHp = static_cast< uint32_t >( getMaxHp() * 0.1f + 1 );
|
|
|
|
uint32_t addMp = static_cast< uint32_t >( getMaxMp() * 0.06f + 1 );
|
|
|
|
uint32_t addTp = 100;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
if( !m_actorIdTohateSlotMap.empty() )
|
|
|
|
{
|
2017-09-15 00:56:29 -03:00
|
|
|
addHp = static_cast< uint32_t >( getMaxHp() * 0.01f + 1 );
|
|
|
|
addMp = static_cast< uint32_t >( getMaxMp() * 0.02f + 1 );
|
2017-08-11 00:58:35 -03:00
|
|
|
addTp = 60;
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_hp < getMaxHp() )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( m_hp + addHp < getMaxHp() )
|
|
|
|
m_hp += addHp;
|
|
|
|
else
|
|
|
|
m_hp = getMaxHp();
|
|
|
|
|
|
|
|
sendUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_mp < getMaxMp() )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( m_mp + addMp < getMaxMp() )
|
|
|
|
m_mp += addMp;
|
|
|
|
else
|
|
|
|
m_mp = getMaxMp();
|
|
|
|
|
|
|
|
sendUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_tp < 1000 )
|
|
|
|
{
|
|
|
|
if( m_tp + addTp < 1000 )
|
|
|
|
m_tp += addTp;
|
|
|
|
else
|
|
|
|
m_tp = 1000;
|
|
|
|
|
|
|
|
sendUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( sendUpdate )
|
|
|
|
sendStatusUpdate();
|
|
|
|
}
|