1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 14:07:46 +00:00
sapphire/src/world/Actor/PlayerEvent.cpp

125 lines
2.6 KiB
C++
Raw Normal View History

2018-03-06 22:22:19 +01:00
#include <Network/PacketContainer.h>
#include <Exd/ExdData.h>
#include <utility>
2017-08-08 13:53:47 +02:00
#include "Actor/Player.h"
2017-08-08 13:53:47 +02:00
2019-07-21 22:33:33 +10:00
#include "Territory/Territory.h"
2017-08-08 13:53:47 +02:00
#include "Action/EventAction.h"
#include "Manager/PlayerMgr.h"
#include "Service.h"
#include <Network/Util/PacketUtil.h>
using namespace Sapphire;
using namespace Sapphire::Common;
using namespace Sapphire::Entity;
using namespace Sapphire::Network::Packets;
using namespace Sapphire::Network::Packets::WorldPackets::Server;
using namespace Sapphire::World::Manager;
2017-08-08 13:53:47 +02:00
void Player::addEvent( Event::EventHandlerPtr pEvent )
2017-08-08 13:53:47 +02:00
{
m_eventHandlerMap[ pEvent->getId() ] = pEvent;
2017-08-08 13:53:47 +02:00
}
std::map< uint32_t, Event::EventHandlerPtr >& Player::getEventListRef()
2017-08-08 13:53:47 +02:00
{
return m_eventHandlerMap;
2017-08-08 13:53:47 +02:00
}
Event::EventHandlerPtr Player::getEvent( uint32_t eventId ) const
2017-08-08 13:53:47 +02:00
{
auto it = m_eventHandlerMap.find( eventId );
if( it != m_eventHandlerMap.end() )
return it->second;
2017-08-08 13:53:47 +02:00
return nullptr;
2017-08-08 13:53:47 +02:00
}
size_t Player::getEventCount()
2017-08-08 13:53:47 +02:00
{
return m_eventHandlerMap.size();
2017-08-08 13:53:47 +02:00
}
void Player::removeEvent( uint32_t eventId )
2017-08-08 13:53:47 +02:00
{
auto it = m_eventHandlerMap.find( eventId );
if( it != m_eventHandlerMap.end() )
{
m_eventHandlerMap.erase( it );
}
2017-08-08 13:53:47 +02:00
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Player::onDeath()
2017-08-08 13:53:47 +02:00
{
Service< World::Manager::PlayerMgr >::ref().onDeath( *this );
2017-08-08 13:53:47 +02:00
}
// TODO: slightly ugly here and way too static. Needs too be done properly
void Player::onTick()
2017-08-08 13:53:47 +02:00
{
Chara::onTick();
// add 3 seconds to total play time
m_playTime += 3;
if( !isAlive() || !isLoadingComplete() )
return;
2017-08-08 13:53:47 +02:00
2023-02-25 15:31:57 +01:00
bool sendUpdate = performResting();
if( sendUpdate )
Network::Util::Packet::sendRestingUpdate( *this );
2023-02-25 15:31:57 +01:00
}
bool Player::performResting()
2023-02-25 15:31:57 +01:00
{
bool sendUpdate = false;
2023-01-17 08:28:06 +01:00
auto addHp = static_cast< uint32_t >( static_cast< float >( getMaxHp() ) * 0.1f + 1 );
auto addMp = static_cast< uint32_t >( static_cast< float >( getMaxMp() ) * 0.06f + 1 );
uint32_t addTp = 100;
2017-08-08 13:53:47 +02:00
if( !m_actorIdTohateSlotMap.empty() )
{
2023-01-17 08:28:06 +01:00
addHp = static_cast< uint32_t >( static_cast< float >( getMaxHp() ) * 0.01f + 1 );
addMp = static_cast< uint32_t >( static_cast< float >( getMaxMp() ) * 0.02f + 1 );
addTp = 60;
}
2017-08-08 13:53:47 +02:00
if( m_hp < getMaxHp() )
{
2017-08-08 13:53:47 +02:00
if( m_hp + addHp < getMaxHp() )
m_hp += addHp;
else
m_hp = getMaxHp();
2017-08-08 13:53:47 +02:00
sendUpdate = true;
}
2017-08-08 13:53:47 +02:00
if( m_mp < getMaxMp() )
{
2017-08-08 13:53:47 +02:00
if( m_mp + addMp < getMaxMp() )
m_mp += addMp;
else
m_mp = getMaxMp();
2017-08-08 13:53:47 +02:00
sendUpdate = true;
}
2017-08-08 13:53:47 +02:00
if( m_tp < 1000 )
{
if( m_tp + addTp < 1000 )
m_tp += addTp;
else
m_tp = 1000;
2017-08-08 13:53:47 +02:00
sendUpdate = true;
}
2023-02-25 15:31:57 +01:00
return sendUpdate;
2017-08-08 13:53:47 +02:00
}