From 7f48101dcd89b57fbde645689fde8bb6171ce46c Mon Sep 17 00:00:00 2001 From: Mordred Date: Sat, 4 Feb 2023 22:42:11 +0100 Subject: [PATCH] removed merge errors --- src/servers/sapphire_api/Forwards.h | 102 -- .../sapphire_zone/Action/EventAction.cpp | 138 -- src/servers/sapphire_zone/Actor/Player.cpp | 1598 ----------------- src/servers/sapphire_zone/Actor/Player.h | 652 ------- .../sapphire_zone/Actor/PlayerEvent.cpp | 361 ---- .../sapphire_zone/Event/EventHelper.cpp | 72 - src/servers/sapphire_zone/Forwards.h | 81 - .../sapphire_zone/Script/ScriptManager.cpp | 483 ----- 8 files changed, 3487 deletions(-) delete mode 100644 src/servers/sapphire_api/Forwards.h delete mode 100644 src/servers/sapphire_zone/Action/EventAction.cpp delete mode 100644 src/servers/sapphire_zone/Actor/Player.cpp delete mode 100644 src/servers/sapphire_zone/Actor/Player.h delete mode 100644 src/servers/sapphire_zone/Actor/PlayerEvent.cpp delete mode 100644 src/servers/sapphire_zone/Event/EventHelper.cpp delete mode 100644 src/servers/sapphire_zone/Forwards.h delete mode 100644 src/servers/sapphire_zone/Script/ScriptManager.cpp diff --git a/src/servers/sapphire_api/Forwards.h b/src/servers/sapphire_api/Forwards.h deleted file mode 100644 index bdffff9f..00000000 --- a/src/servers/sapphire_api/Forwards.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef _FORWARDS_H -#define _FORWARDS_H - -#include - -namespace Core -{ - - class Cell; - class Zone; - class Item; - class ItemContainer; - class Inventory; - class Session; - class XMLConfig; - class ZonePosition; - - typedef boost::shared_ptr ZonePtr; - typedef boost::shared_ptr ItemPtr; - typedef boost::shared_ptr ItemContainerPtr; - typedef boost::shared_ptr InventoryPtr; - typedef boost::shared_ptr SessionPtr; - typedef boost::shared_ptr XMLConfigPtr; - typedef boost::shared_ptr ZonePositionPtr; - - namespace StatusEffect - { - class StatusEffect; - class StatusEffectContainer; - - typedef boost::shared_ptr StatusEffectPtr; - typedef boost::shared_ptr StatusEffectContainerPtr; - } - - namespace Entity - { - class Actor; - class Player; - class BattleNpc; - - typedef boost::shared_ptr ActorPtr; - typedef boost::shared_ptr PlayerPtr; - typedef boost::shared_ptr BattleNpcPtr; - } - - namespace Event - { - class EventHandler; - - typedef boost::shared_ptr EventPtr; - } - - namespace Action - { - class Action; - class ActionTeleport; - class EventAction; - - typedef boost::shared_ptr ActionPtr; - typedef boost::shared_ptr ActionTeleportPtr; - typedef boost::shared_ptr EventActionPtr; - } - - - namespace Network - { - class Hive; - class Acceptor; - class Connection; - class WorldConnection; - class SessionConnection; - class ZoneConnection; - - typedef boost::shared_ptr HivePtr; - typedef boost::shared_ptr AcceptorPtr; - typedef boost::shared_ptr ConnectionPtr; - typedef boost::shared_ptr WorldConnectionPtr; - typedef boost::shared_ptr ZoneConnectionPtr; - typedef boost::shared_ptr SessionConnectionPtr; - - namespace Packets - { - class GamePacket; - - - typedef boost::shared_ptr GamePacketPtr; - - - } - } - - namespace Scripting - { - typedef std::function< void( Entity::Player&, uint32_t, uint16_t, uint16_t, uint16_t, uint16_t ) > EventReturnCallback; - } - - typedef std::function< void( Entity::Player&, uint32_t, uint64_t ) > ActionCallback; - -} - - -#endif diff --git a/src/servers/sapphire_zone/Action/EventAction.cpp b/src/servers/sapphire_zone/Action/EventAction.cpp deleted file mode 100644 index 0aa85bfc..00000000 --- a/src/servers/sapphire_zone/Action/EventAction.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include -#include - -#include "EventAction.h" -#include "Network/PacketWrappers/ActorControlPacket142.h" -#include "Network/PacketWrappers/ActorControlPacket143.h" -#include "Actor/Player.h" -#include "Event/EventHandler.h" - -extern Core::Logger g_log; -extern Core::Data::ExdData g_exdData; - -using namespace Core::Common; -using namespace Core::Network; -using namespace Core::Network::Packets; -using namespace Core::Network::Packets::Server; - -Core::Action::EventAction::EventAction() -{ - m_handleActionType = HandleActionType::Event; -} - -Core::Action::EventAction::EventAction( Entity::ActorPtr pActor, uint32_t eventId, uint16_t action, - ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional ) -{ - m_additional = additional; - m_handleActionType = HandleActionType::Event; - m_eventId = eventId; - m_id = action; - m_castTime = g_exdData.m_EventActionInfoMap[action].castTime; // TODO: Add security checks. - m_onActionFinishClb = finishRef; - m_onActionInterruptClb = interruptRef; - m_pSource = pActor; - m_bInterrupt = false; -} - -Core::Action::EventAction::~EventAction() -{ - -} - -void Core::Action::EventAction::onStart() -{ - if( !m_pSource ) - return; - - m_startTime = Util::getTimeMs(); - - auto control = ActorControlPacket142( m_pSource->getId(), Common::ActorControlType::CastStart, - 1, m_id, 0x4000004E ); - - if( m_pSource->isPlayer() ) - { - m_pSource->sendToInRangeSet( control, true ); - m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::SomeFlag ); - m_pSource->getAsPlayer()->sendStateFlags(); - } - else - m_pSource->sendToInRangeSet( control ); -} - -void Core::Action::EventAction::onFinish() -{ - if( !m_pSource ) - return; - - try - { - auto pEvent = m_pSource->getAsPlayer()->getEvent( m_eventId ); - - pEvent->setPlayedScene( false ); - - if( m_onActionFinishClb ) - m_onActionFinishClb( *m_pSource->getAsPlayer(), m_eventId, m_additional ); - - auto control = ActorControlPacket142( m_pSource->getId(), Common::ActorControlType::CastStart, 0, m_id ); - - if( !pEvent->hasPlayedScene() ) - m_pSource->getAsPlayer()->eventFinish( m_eventId, 1 ); - else - pEvent->setPlayedScene( false ); - - if( m_pSource->isPlayer() ) - { - m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::SomeFlag ); - m_pSource->getAsPlayer()->sendStateFlags(); - m_pSource->sendToInRangeSet( control, true ); - } - else - m_pSource->sendToInRangeSet( control ); - } - catch( std::exception& e ) - { - g_log.error( e.what() ); - } - -} - -void Core::Action::EventAction::onInterrupt() -{ - if( !m_pSource ) - return; - - try - { - - auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, - 0x219, 0x04, m_id ); - - if( m_pSource->isPlayer() ) - { - auto control1 = ActorControlPacket143( m_pSource->getId(), ActorControlType::FreeEventPos, m_eventId ); - - m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::NoCombat ); - m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Occupied1 ); - m_pSource->getAsPlayer()->sendStateFlags(); - m_pSource->sendToInRangeSet( control ); - m_pSource->sendToInRangeSet( control1 ); - - m_pSource->getAsPlayer()->queuePacket( control1 ); - m_pSource->getAsPlayer()->queuePacket( control ); - m_pSource->getAsPlayer()->eventFinish( m_eventId, 1 ); - - } - else - m_pSource->sendToInRangeSet( control ); - - if( m_onActionInterruptClb ) - m_onActionInterruptClb( *m_pSource->getAsPlayer(), m_eventId, m_additional ); - - } - catch( std::exception& e ) - { - g_log.error( e.what() ); - } - -} diff --git a/src/servers/sapphire_zone/Actor/Player.cpp b/src/servers/sapphire_zone/Actor/Player.cpp deleted file mode 100644 index eecd4f2c..00000000 --- a/src/servers/sapphire_zone/Actor/Player.cpp +++ /dev/null @@ -1,1598 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Session.h" -#include "Player.h" -#include "BattleNpc.h" - -#include "Zone/ZoneMgr.h" -#include "Zone/Zone.h" - -#include "ServerZone.h" - -#include "Network/GameConnection.h" -#include "Network/PacketWrappers/ActorControlPacket142.h" -#include "Network/PacketWrappers/ActorControlPacket143.h" -#include "Network/PacketWrappers/InitUIPacket.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" -#include "Network/PacketWrappers/ChatPacket.h" -#include "Network/PacketWrappers/ModelEquipPacket.h" -#include "Network/PacketWrappers/UpdateHpMpTpPacket.h" -#include "Network/PacketWrappers/PlayerStateFlagsPacket.h" -#include "Network/PacketWrappers/PlayerSpawnPacket.h" - -#include "Script/ScriptManager.h" - -#include "Inventory/Item.h" - -#include "Inventory/Inventory.h" -#include "Event/EventHandler.h" -#include "Action/Action.h" -#include "Action/EventAction.h" -#include "Action/EventItemAction.h" -#include "Zone/ZonePosition.h" -#include "Math/CalcStats.h" -#include "Math/CalcBattle.h" -#include - -extern Core::Logger g_log; -extern Core::ServerZone g_serverZone; -extern Core::ZoneMgr g_zoneMgr; -extern Core::Data::ExdData g_exdData; -extern Core::Scripting::ScriptManager g_scriptMgr; - -using namespace Core::Common; -using namespace Core::Network::Packets; -using namespace Core::Network::Packets::Server; - -// player constructor -Core::Entity::Player::Player() : - Actor(), - m_lastWrite( 0 ), - m_lastPing( 0 ), - m_bIsLogin( false ), - m_contentId( 0 ), - m_modelMainWeapon( 0 ), - m_modelSubWeapon( 0 ), - m_homePoint( 0 ), - m_startTown( 0 ), - m_townWarpFstFlags( 0 ), - m_playTime( 0 ), - m_bInCombat( false ), - m_bLoadingComplete( false ), - m_bMarkedForZoning( false ), - m_zoningType( Common::ZoneingType::None ), - m_bAutoattack( false ), - m_markedForRemoval( false ), - m_mount( 0 ) -{ - m_id = 0; - m_objKind = ObjKind::Player; - m_currentStance = Stance::Passive; - m_onlineStatus = 0; - m_queuedZoneing = nullptr; - m_status = ActorStatus::Idle; - m_invincibilityType = InvincibilityType::InvincibilityNone; - - memset( m_questTracking, 0, sizeof( m_questTracking ) ); - memset( m_name, 0, sizeof( m_name ) ); - memset( m_stateFlags, 0, sizeof( m_stateFlags ) ); - memset( m_searchMessage, 0, sizeof( m_searchMessage ) ); - memset( m_classArray, 0, sizeof( m_classArray ) ); - memset( m_expArray, 0, sizeof( m_expArray ) ); -} - -Core::Entity::Player::~Player() -{ - g_log.debug( "PlayerObj destroyed" ); -} - -// TODO: add a proper calculation based on race / job / level / gear -uint32_t Core::Entity::Player::getMaxHp() -{ - return m_baseStats.max_hp; -} - -uint32_t Core::Entity::Player::getMaxMp() -{ - return m_baseStats.max_mp; -} - -uint16_t Core::Entity::Player::getZoneId() const -{ - return m_zoneId; -} - -uint8_t Core::Entity::Player::getGmRank() const -{ - return m_gmRank; -} - -void Core::Entity::Player::setGmRank( uint8_t rank ) -{ - m_gmRank = rank; -} - -uint8_t Core::Entity::Player::getMode() const -{ - return m_mode; -} - -void Core::Entity::Player::setMode( uint8_t mode ) -{ - m_mode = mode; -} - -uint8_t Core::Entity::Player::getStartTown() const -{ - return m_startTown; -} - -void Core::Entity::Player::setMarkedForRemoval() -{ - m_markedForRemoval = true; -} - -bool Core::Entity::Player::isMarkedForRemoval() const -{ - return m_markedForRemoval; -} - -Core::Common::OnlineStatus Core::Entity::Player::getOnlineStatus() -{ - uint64_t newMask = uint64_t( 1 ) << static_cast< uint32_t >( OnlineStatus::NewAdventurer ); - uint64_t afkMask = uint64_t( 1 ) << static_cast< uint32_t >( OnlineStatus::AwayfromKeyboard ); - uint64_t busyMask = uint64_t( 1 ) << static_cast< uint32_t >( OnlineStatus::Busy ); - uint64_t dcMask = uint64_t( 1 ) << static_cast< uint32_t >( OnlineStatus::Disconnected ); - uint64_t meldMask = uint64_t( 1 ) << static_cast< uint32_t >( OnlineStatus::LookingtoMeldMateria ); - uint64_t ptMask = uint64_t( 1 ) << static_cast< uint32_t >( OnlineStatus::LookingforParty ); - uint64_t rpMask = uint64_t( 1 ) << static_cast< uint32_t >( OnlineStatus::Roleplaying ); - - OnlineStatus status = OnlineStatus::Online; - - //if( hasStateFlag( Common::PlayerStateFlag::NewAdventurer ) ) - if( m_onlineStatus & newMask ) - status = OnlineStatus::NewAdventurer; - - if( m_onlineStatus & afkMask ) - status = OnlineStatus::AwayfromKeyboard; - - if( m_onlineStatus & busyMask ) - status = OnlineStatus::Busy; - - if( m_onlineStatus & dcMask ) - status = OnlineStatus::Disconnected; - - if( m_onlineStatus & meldMask ) - status = OnlineStatus::LookingtoMeldMateria; - - if( m_onlineStatus & ptMask ) - status = OnlineStatus::LookingforParty; - - if( m_onlineStatus & rpMask ) - status = OnlineStatus::Roleplaying; - - if( hasStateFlag( PlayerStateFlag::WatchingCutscene ) || hasStateFlag( PlayerStateFlag::WatchingCutscene1 ) ) - status = OnlineStatus::ViewingCutscene; - - // TODO: add all the logic for returning the proper online status, there probably is a better way for this alltogether - return status; -} - -void Core::Entity::Player::setOnlineStatusMask( uint64_t status ) -{ - m_onlineStatus = status; -} - -uint64_t Core::Entity::Player::getOnlineStatusMask() const -{ - return m_onlineStatus; -} - -void Core::Entity::Player::prepareZoning( uint16_t targetZone, bool fadeOut, uint8_t fadeOutTime, uint16_t animation ) -{ - ZoneChannelPacket< FFXIVIpcPrepareZoning > preparePacket( getId() ); - preparePacket.data().targetZone = targetZone; - preparePacket.data().fadeOutTime = fadeOutTime; - preparePacket.data().animation = animation; - preparePacket.data().fadeOut = static_cast< uint8_t >( fadeOut ? 1 : 0 ); - queuePacket( preparePacket ); -} - -void Core::Entity::Player::calculateStats() -{ - uint8_t tribe = getLookAt( Common::CharaLook::Tribe ); - uint8_t level = getLevel(); - uint8_t job = static_cast< uint8_t >( getClass() ); - - auto classInfoIt = g_exdData.m_classJobInfoMap.find( job ); - auto tribeInfoIt = g_exdData.m_tribeInfoMap.find( tribe ); - auto paramGrowthInfoIt = g_exdData.m_paramGrowthInfoMap.find( level ); - - if( tribeInfoIt == g_exdData.m_tribeInfoMap.end() || - classInfoIt == g_exdData.m_classJobInfoMap.end() || - paramGrowthInfoIt == g_exdData.m_paramGrowthInfoMap.end() ) - return; - - auto tribeInfo = tribeInfoIt->second; - auto classInfo = classInfoIt->second; - auto paramGrowthInfo = paramGrowthInfoIt->second; - - // TODO: put formula somewhere else... - float base = Math::CalcStats::calculateBaseStat( getAsPlayer() ); - - m_baseStats.str = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_str ) / 100 ) + tribeInfo.mod_str ); - m_baseStats.dex = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_dex ) / 100 ) + tribeInfo.mod_dex ); - m_baseStats.vit = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_vit ) / 100 ) + tribeInfo.mod_vit ); - m_baseStats.inte = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_int ) / 100 ) + tribeInfo.mod_int ); - m_baseStats.mnd = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_mnd ) / 100 ) + tribeInfo.mod_mnd ); - m_baseStats.pie = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_pie ) / 100 ) + tribeInfo.mod_pie ); - - m_baseStats.skillSpeed = paramGrowthInfo.base_secondary; - m_baseStats.spellSpeed = paramGrowthInfo.base_secondary; - m_baseStats.accuracy = paramGrowthInfo.base_secondary; - m_baseStats.critHitRate = paramGrowthInfo.base_secondary; - m_baseStats.attackPotMagic = paramGrowthInfo.base_secondary; - m_baseStats.healingPotMagic = paramGrowthInfo.base_secondary; - m_baseStats.tenacity = paramGrowthInfo.base_secondary; - - m_baseStats.max_mp = Math::CalcStats::calculateMaxMp( getAsPlayer() ); - - m_baseStats.max_hp = Math::CalcStats::calculateMaxHp( getAsPlayer() ); - - if( m_mp > m_baseStats.max_mp ) - m_mp = m_baseStats.max_mp; - - if( m_hp > m_baseStats.max_hp ) - m_hp = m_baseStats.max_hp; - - - m_baseStats.determination = static_cast< uint32_t >( base ); - -} - - -void Core::Entity::Player::setAutoattack(bool mode) -{ - m_bAutoattack = mode; - m_lastAttack = Util::getTimeMs(); -} - -bool Core::Entity::Player::isAutoattackOn() const -{ - return m_bAutoattack; -} - -void Core::Entity::Player::sendStats() -{ - ZoneChannelPacket< FFXIVIpcPlayerStats > statPacket( getId() ); - statPacket.data().strength = m_baseStats.str; - statPacket.data().dexterity = m_baseStats.dex; - statPacket.data().vitality = m_baseStats.vit; - statPacket.data().intelligence = m_baseStats.inte; - statPacket.data().mind = m_baseStats.mnd; - statPacket.data().piety = m_baseStats.pie; - statPacket.data().determination = m_baseStats.determination; - statPacket.data().hp = m_baseStats.max_hp; - statPacket.data().mp = m_baseStats.max_mp; - statPacket.data().accuracy = m_baseStats.accuracy; - statPacket.data().attack = m_baseStats.attack; - statPacket.data().attackMagicPotency = m_baseStats.attackPotMagic; - statPacket.data().healingMagicPotency = m_baseStats.healingPotMagic; - statPacket.data().skillSpeed = m_baseStats.skillSpeed; - statPacket.data().spellSpeed = m_baseStats.spellSpeed; - statPacket.data().spellSpeed1 = m_baseStats.spellSpeed; - statPacket.data().spellSpeedMod = 100; - - statPacket.data().criticalHitRate = m_baseStats.spellSpeed; - statPacket.data().defense = m_baseStats.spellSpeed; - statPacket.data().magicDefense = m_baseStats.spellSpeed; - statPacket.data().attack = m_baseStats.spellSpeed; - - queuePacket( statPacket ); -} - -void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type ) -{ - auto data = g_exdData.getAetheryteInfo( aetheryteId ); - - if( data == nullptr ) - { - return; - } - - setStateFlag( PlayerStateFlag::BetweenAreas ); - sendStateFlags(); - - auto z_pos = g_zoneMgr.getZonePosition( data->levelId ); - - Common::FFXIVARR_POSITION3 pos; - pos.x = 0; - pos.y = 0; - pos.z = 0; - float rot = 0; - - if( z_pos != nullptr ) - { - pos = z_pos->getTargetPosition(); - rot = z_pos->getTargetRotation(); - } - - sendDebug( "Teleport: " + data->placename + " " + data->placename_aethernet + - "(" + std::to_string( data->levelId ) + ")" ); - - // TODO: this should be simplified and a type created in server_common/common.h. - if( type == 1 ) // teleport - { - prepareZoning( data->target_zone, true, 1, 112 ); - sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x04 ) ); - setZoningType( Common::ZoneingType::Teleport ); - } - else if( type == 2 ) // aethernet - { - prepareZoning( data->target_zone, true, 1, 112 ); - sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x04 ) ); - setZoningType( Common::ZoneingType::Teleport ); - } - else if( type == 3 ) // return - { - prepareZoning( data->target_zone, true, 1, 111 ); - sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x03 ) ); - setZoningType( Common::ZoneingType::Return ); - } - - m_queuedZoneing = boost::make_shared< QueuedZoning >( data->target_zone, pos, Util::getTimeMs(), rot ); - - -} - -void Core::Entity::Player::forceZoneing( uint32_t zoneId ) -{ - m_queuedZoneing = boost::make_shared< QueuedZoning >( zoneId, getPos(), Util::getTimeMs(), 0.f ); - //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(); - - auto pZone = g_zoneMgr.getZone( zoneId ); - - - if( !pZone /*|| ( ( pZone == m_pCurrentZone ) && m_lastPing )*/ ) - { - g_log.error( "Zone " + std::to_string( zoneId ) + " not found on this server." ); - return; - } - - m_zoneId = zoneId; - - // mark character as zoning in progress - setLoadingComplete( false ); - - if( m_lastPing != 0 ) - m_pCurrentZone->removeActor( shared_from_this() ); - - m_pCurrentZone = pZone; - m_pCurrentZone->pushActor( shared_from_this() ); - - ZoneChannelPacket< FFXIVIpcInit > initPacket( getId() ); - initPacket.data().charId = getId(); - queuePacket( initPacket ); - - sendInventory(); - - if( isLogin() ) - { - queuePacket(ActorControlPacket143( getId(), SetCharaGearParamUI, m_equipDisplayFlags, 1 ) ); - } - - // set flags, will be reset automatically by zoning ( only on client side though ) - pPlayer->setStateFlag( PlayerStateFlag::BetweenAreas ); - pPlayer->setStateFlag( PlayerStateFlag::BetweenAreas1 ); - pPlayer->sendStateFlags(); - - pPlayer->sendStats(); - - // only initialize the UI if the player in fact just logged in. - if( isLogin() ) - { - ZoneChannelPacket< FFXIVIpcCFAvailableContents > contentFinderList( getId() ); - for( auto i = 0; i < sizeof( contentFinderList.data().contents ); i++ ) - { - // unlock all contents for now - contentFinderList.data().contents[i] = 0xFF; - } - queuePacket( contentFinderList ); - - Server::InitUIPacket initUIPacket( *pPlayer ); - queuePacket( initUIPacket ); - - ZoneChannelPacket< FFXIVIpcPlayerClassInfo > classInfoPacket( getId() ); - classInfoPacket.data().classId = static_cast< uint8_t >( getClass() ); - classInfoPacket.data().unknown = 1; - classInfoPacket.data().level = getLevel(); - classInfoPacket.data().level1 = getLevel(); - queuePacket( classInfoPacket ); - - ZoneChannelPacket< FFXIVGCAffiliation > gcAffPacket( getId() ); - gcAffPacket.data().gcId = m_gc; - gcAffPacket.data().gcRank[0] = m_gcRank[0]; - gcAffPacket.data().gcRank[1] = m_gcRank[1]; - gcAffPacket.data().gcRank[2] = m_gcRank[2]; - queuePacket( gcAffPacket ); - - m_itemLevel = getInventory()->calculateEquippedGearItemLevel(); - sendItemLevel(); - } - - ZoneChannelPacket< FFXIVIpcInitZone > initZonePacket( getId() ); - initZonePacket.data().zoneId = getCurrentZone()->getLayoutId(); - initZonePacket.data().weatherId = static_cast< uint8_t >( getCurrentZone()->getCurrentWeather() ); - initZonePacket.data().bitmask = 0x1; - initZonePacket.data().unknown5 = 0x2A; - initZonePacket.data().pos.x = getPos().x; - initZonePacket.data().pos.y = getPos().y; - initZonePacket.data().pos.z = getPos().z; - queuePacket( initZonePacket ); - - if( isLogin() ) - { - ZoneChannelPacket< FFXIVARR_IPC_UNK322 > unk322( getId() ); - queuePacket( unk322 ); - - ZoneChannelPacket< FFXIVARR_IPC_UNK320 > unk320( getId() ); - queuePacket( unk320 ); - } - - if( getLastPing() == 0 ) - sendQuestInfo(); - - m_bMarkedForZoning = false; -} - -uint32_t Core::Entity::Player::getPlayTime() const -{ - return m_playTime; -} - -uint8_t Core::Entity::Player::getRace() const -{ - return getLookAt( CharaLook::Race ); -} - -uint8_t Core::Entity::Player::getGender() const -{ - return getLookAt( CharaLook::Gender ); -} - -void Core::Entity::Player::initSpawnIdQueue() -{ - while( !m_freeSpawnIdQueue.empty() ) - { - m_freeSpawnIdQueue.pop(); - } - - for( int32_t i = 1; i < MAX_DISPLAYED_ACTORS; i++ ) - { - m_freeSpawnIdQueue.push( i ); - } -} - -uint8_t Core::Entity::Player::getSpawnIdForActorId( uint32_t actorId ) -{ - if( m_freeSpawnIdQueue.empty() ) - return 0; - - uint8_t spawnId = m_freeSpawnIdQueue.front(); - m_freeSpawnIdQueue.pop(); - m_playerIdToSpawnIdMap[actorId] = spawnId; - return spawnId; -} - -void Core::Entity::Player::assignSpawnIdToPlayerId( uint32_t actorId, uint8_t spawnId ) -{ - m_playerIdToSpawnIdMap[actorId] = spawnId; -} - -void Core::Entity::Player::registerAetheryte( uint8_t aetheryteId ) -{ - - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( aetheryteId, value, index ); - - m_aetheryte[index] |= value; - queuePacket( ActorControlPacket143( getId(), LearnTeleport, aetheryteId, 1 ) ); - -} - -bool Core::Entity::Player::isAetheryteRegistered( uint8_t aetheryteId ) const -{ - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( aetheryteId, value, index ); - - return ( m_aetheryte[index] & value ) != 0; -} - -uint8_t * Core::Entity::Player::getDiscoveryBitmask() -{ - return m_discovery; -} - -void Core::Entity::Player::discover( int16_t map_id, int16_t sub_id ) -{ - // map.exd field 12 -> index in one of the two discovery sections, if field 15 is false, need to use 2nd section - // section 1 starts at 4 - 2 bytes each - - // section to starts at 320 - 4 bytes long - - int32_t offset = 4; - - auto info = g_exdData.m_zoneInfoMap[getCurrentZone()->getId()]; - if( info.is_two_byte ) - offset = 4 + 2 * info.discovery_index; - else - offset = 324 + 4 * info.discovery_index; - - int32_t index = offset + sub_id / 8; - uint8_t bitIndex = sub_id % 8; - - uint8_t value = 1 << bitIndex; - - m_discovery[index] |= value; - - uint16_t level = getLevel(); - - uint32_t exp = ( g_exdData.m_paramGrowthInfoMap[level].needed_exp * 5 / 100 ); - - gainExp( exp ); - - - -} - -bool Core::Entity::Player::isNewAdventurer() const -{ - return m_bNewAdventurer; -} - -void Core::Entity::Player::setNewAdventurer( bool state ) -{ - //if( !state ) - //{ - // unsetStateFlag( PlayerStateFlag::NewAdventurer ); - //} - //else - //{ - // setStateFlag( PlayerStateFlag::NewAdventurer ); - //} - sendStateFlags(); - m_bNewAdventurer = state; -} - -void Core::Entity::Player::resetDiscovery() -{ - memset( m_discovery, 0, sizeof( m_discovery ) ); -} - -void Core::Entity::Player::changePosition( float x, float y, float z, float o ) -{ - Common::FFXIVARR_POSITION3 pos; - pos.x = x; - pos.y = y; - pos.z = z; - m_queuedZoneing = boost::make_shared( getZoneId(), pos, Util::getTimeMs(), o ); -} - -void Core::Entity::Player::learnAction( uint8_t actionId ) -{ - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( actionId, value, index ); - - m_unlocks[index] |= value; - - queuePacket( ActorControlPacket143( getId(), ToggleActionUnlock, actionId, 1 ) ); -} - -void Core::Entity::Player::learnSong( uint8_t songId, uint32_t itemId ) -{ - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( songId, value, index ); - - m_orchestrion[index] |= value; - - queuePacket( ActorControlPacket143( getId(), ToggleOrchestrionUnlock, songId, 1, itemId ) ); -} - -bool Core::Entity::Player::isActionLearned( uint8_t actionId ) const -{ - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( actionId, value, index ); - - return ( m_unlocks[index] & value ) != 0; -} - -void Core::Entity::Player::gainExp( uint32_t amount ) -{ - uint32_t currentExp = getExp(); - - uint16_t level = getLevel(); - - uint32_t neededExpToLevel = g_exdData.m_paramGrowthInfoMap[level].needed_exp; - - uint32_t neededExpToLevelplus1 = g_exdData.m_paramGrowthInfoMap[level + 1].needed_exp; - - queuePacket( ActorControlPacket143( getId(), GainExpMsg, static_cast< uint8_t >( getClass() ), amount ) ); - - if( level >= 70 ) // temporary fix for leveling over levelcap - { - queuePacket( ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), amount ) ); - return; - } - - if( ( currentExp + amount ) >= neededExpToLevel ) - { - // levelup - amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelplus1 ? - neededExpToLevelplus1 - 1 : - ( currentExp + amount - neededExpToLevel ); - setExp( amount ); - gainLevel(); - queuePacket( ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), amount ) ); - - } - else - { - queuePacket( ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), currentExp + amount ) ); - setExp( currentExp + amount ); - } - - sendStatusUpdate(); -} - -void Core::Entity::Player::gainLevel() -{ - setLevel( getLevel() + 1 ); - - calculateStats(); - sendStats(); - sendStatusUpdate(); - - m_hp = getMaxHp(); - m_mp = getMaxMp(); - - ZoneChannelPacket< FFXIVIpcStatusEffectList > effectListPacket( getId() ); - effectListPacket.data().classId = static_cast< uint8_t > ( getClass() ); - effectListPacket.data().classId1 = static_cast< uint8_t > ( getClass() ); - effectListPacket.data().level = getLevel(); - effectListPacket.data().current_hp = getMaxHp(); - effectListPacket.data().current_mp = getMaxMp(); - effectListPacket.data().currentTp = 1000; - effectListPacket.data().max_hp = getMaxHp(); - effectListPacket.data().max_mp = getMaxMp(); - sendToInRangeSet( effectListPacket, true ); - - sendToInRangeSet( ActorControlPacket142( getId(), LevelUpEffect, static_cast< uint8_t >( getClass() ), - getLevel(), getLevel() - 1 ), true ); - - - ZoneChannelPacket< FFXIVIpcUpdateClassInfo > classInfoPacket( getId() ); - classInfoPacket.data().classId = static_cast< uint8_t > ( getClass() ); - classInfoPacket.data().classId1 = static_cast< uint8_t > ( getClass() ); - classInfoPacket.data().level = getLevel(); - classInfoPacket.data().nextLevelIndex = getLevel(); - classInfoPacket.data().currentExp = getExp(); - queuePacket( classInfoPacket ); - -} - -void Core::Entity::Player::unlock() -{ - queuePacket( PlayerStateFlagsPacket( *getAsPlayer(), PlayerStateFlagList{} ) ); -} - -void Core::Entity::Player::sendStatusUpdate( bool toSelf ) -{ - // CGamePacket* pPE = new CGamePacket(0x140, 0x0128, getId(), getId()); - - //pPE->setInt8At(0x20, static_cast(getClass())); - - // pPE->setInt8At(0x21, getLevel()); - // pPE->setInt8At(0x22, getLevel()); - - // // current exp - // pPE->setInt32At(0x28, getExp()); - - // // rested exp - // //pPE->setInt32At(0x2C, m_hp); - - // pPE->setInt32At(0x24, m_hp); - // pPE->setInt32At(0x28, getMaxHp()); - // pPE->setInt16At(0x2C, m_mp); - // pPE->setInt16At(0x2E, getMaxMp()); - // pPE->setInt16At(0x30, m_tp); - - // sendToInRangeSet(pPE, toSelf); - - sendToInRangeSet( UpdateHpMpTpPacket( shared_from_this() ), true ); - -} - -uint8_t Core::Entity::Player::getLevel() const -{ - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( getClass() )].exp_idx; - return static_cast< uint8_t >( m_classArray[classJobIndex] ); -} - -uint8_t Core::Entity::Player::getLevelForClass( Common::ClassJob pClass ) const -{ - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( pClass )].exp_idx; - return static_cast< uint8_t >( m_classArray[classJobIndex] ); -} - -uint32_t Core::Entity::Player::getExp() const -{ - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( getClass() )].exp_idx; - return m_expArray[classJobIndex]; -} - -void Core::Entity::Player::setExp( uint32_t amount ) -{ - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( getClass() )].exp_idx; - m_expArray[classJobIndex] = amount; -} - -bool Core::Entity::Player::isInCombat() const -{ - return m_bInCombat; -} - -void Core::Entity::Player::setInCombat( bool mode ) -{ - //m_lastAttack = GetTickCount(); - m_bInCombat = mode; -} - -void Core::Entity::Player::setClassJob( Common::ClassJob classJob ) -{ - m_class = classJob; - uint8_t level = getLevel(); - - if( getHp() > getMaxHp() ) - m_hp = getMaxHp(); - - if( getMp() > getMaxMp() ) - m_mp = getMaxMp(); - - m_tp = 0; - - ZoneChannelPacket< FFXIVIpcPlayerClassInfo > classInfoPacket( getId() ); - classInfoPacket.data().classId = static_cast< uint8_t >( getClass() ); - classInfoPacket.data().level = getLevel(); - queuePacket( classInfoPacket ); - - sendToInRangeSet( ActorControlPacket142( getId(), ClassJobChange, 0x04 ), true ); - - sendStatusUpdate( true ); -} - -void Core::Entity::Player::setLevel( uint8_t level ) -{ - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( static_cast< uint8_t >( getClass() ) )].exp_idx; - m_classArray[classJobIndex] = level; -} - -void Core::Entity::Player::setLevelForClass( uint8_t level, Common::ClassJob classjob ) -{ - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( classjob )].exp_idx; - - if( m_classArray[classJobIndex] == 0 ) - insertDbClass( classJobIndex ); - - m_classArray[classJobIndex] = level; -} - -void Core::Entity::Player::sendModel() -{ - ModelEquipPacket modelEquip( *getAsPlayer() ); - sendToInRangeSet( modelEquip, true ); -} - -uint32_t Core::Entity::Player::getModelForSlot( Inventory::EquipSlot slot ) -{ - return m_modelEquip[slot]; -} - -void Core::Entity::Player::setModelForSlot( Inventory::EquipSlot slot, uint32_t val ) -{ - m_modelEquip[slot] = val; -} - -uint64_t Core::Entity::Player::getModelMainWeapon() const -{ - return m_modelMainWeapon; -} - -uint64_t Core::Entity::Player::getModelSubWeapon() const -{ - return m_modelSubWeapon; -} - -uint64_t Core::Entity::Player::getModelSystemWeapon() const -{ - return m_modelSystemWeapon; -} - -int8_t Core::Entity::Player::getAetheryteMaskAt( uint8_t index ) const -{ - if( index > sizeof( m_aetheryte ) ) - return 0; - return m_aetheryte[index]; -} - -uint8_t Core::Entity::Player::getBirthDay() const -{ - return m_birthDay; -} - -uint8_t Core::Entity::Player::getBirthMonth() const -{ - return m_birthMonth; -} - -uint8_t Core::Entity::Player::getGuardianDeity() const -{ - return m_guardianDeity; -} - -uint8_t Core::Entity::Player::getLookAt( uint8_t index ) const -{ - return m_customize[index]; -} - -void Core::Entity::Player::setLookAt( uint8_t index, uint8_t value ) -{ - m_customize[index] = value; -} - -// spawn this player for pTarget -void Core::Entity::Player::spawn( Entity::PlayerPtr pTarget ) -{ - g_log.debug( "[" + std::to_string( pTarget->getId() ) + "] Spawning " + - getName() + " for " + - pTarget->getName() ); - - PlayerSpawnPacket spawnActor( *getAsPlayer(), *pTarget ); - pTarget->queuePacket( spawnActor ); -} - -// despawn -void Core::Entity::Player::despawn( Entity::ActorPtr pTarget ) -{ - auto pPlayer = pTarget->getAsPlayer(); - - pPlayer->freePlayerSpawnId( getId() ); - - pPlayer->queuePacket( ActorControlPacket143( getId(), DespawnZoneScreenMsg, 0x04, getId(), 0x01 ) ); -} - -Core::Entity::ActorPtr Core::Entity::Player::lookupTargetById( uint64_t targetId ) -{ - ActorPtr targetActor; - auto inRange = getInRangeActors( true ); - for( auto actor : inRange ) - { - if( actor->getId() == targetId ) - targetActor = actor; - } - return targetActor; -} - -void Core::Entity::Player::setLastPing( uint32_t ping ) -{ - m_lastPing = ping; -} - -uint32_t Core::Entity::Player::getLastPing() const -{ - return m_lastPing; -} - -void Core::Entity::Player::setVoiceId( uint8_t voiceId ) -{ - m_voice = voiceId; -} - -void Core::Entity::Player::setGc( uint8_t gc ) -{ - m_gc = gc; - - ZoneChannelPacket< FFXIVGCAffiliation > gcAffPacket( getId() ); - gcAffPacket.data().gcId = m_gc; - gcAffPacket.data().gcRank[0] = m_gcRank[0]; - gcAffPacket.data().gcRank[1] = m_gcRank[1]; - gcAffPacket.data().gcRank[2] = m_gcRank[2]; - queuePacket( gcAffPacket ); -} - -void Core::Entity::Player::setGcRankAt( uint8_t index, uint8_t rank ) -{ - m_gcRank[index] = rank; - - ZoneChannelPacket< FFXIVGCAffiliation > gcAffPacket( getId() ); - gcAffPacket.data().gcId = m_gc; - gcAffPacket.data().gcRank[0] = m_gcRank[0]; - gcAffPacket.data().gcRank[1] = m_gcRank[1]; - gcAffPacket.data().gcRank[2] = m_gcRank[2]; - queuePacket( gcAffPacket ); -} - -const uint8_t* Core::Entity::Player::getStateFlags() const -{ - return m_stateFlags; -} - -bool Core::Entity::Player::actionHasCastTime( uint32_t actionId ) //TODO: Add logic for special cases -{ - auto actionInfoPtr = g_exdData.getActionInfo( actionId ); - if( actionInfoPtr->is_instant ) - return false; - - return actionInfoPtr->cast_time != 0; - -} - -bool Core::Entity::Player::hasStateFlag( Common::PlayerStateFlag flag ) const -{ - int32_t iFlag = static_cast< uint32_t >( flag ); - - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( iFlag, value, index ); - - return ( m_stateFlags[index] & value ) != 0; -} - -void Core::Entity::Player::setStateFlag( Common::PlayerStateFlag flag ) -{ - int32_t iFlag = static_cast< uint32_t >( flag ); - - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( iFlag, value, index ); - - m_stateFlags[index] |= value; - -} - -void Core::Entity::Player::setStateFlags( std::vector< Common::PlayerStateFlag > flags ) -{ - for( const auto& flag : flags ) - { - int iFlag = static_cast< uint32_t >( flag ); - - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( iFlag, value, index ); - - m_stateFlags[index] |= value; - } -} - -void Core::Entity::Player::sendStateFlags() -{ - queuePacket( PlayerStateFlagsPacket( *getAsPlayer() ) ); -} - -void Core::Entity::Player::unsetStateFlag( Common::PlayerStateFlag flag ) -{ - if( !hasStateFlag( flag ) ) - return; - - int32_t iFlag = static_cast< uint32_t >( flag ); - - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( iFlag, value, index ); - - m_stateFlags[index] ^= value; - -} - -void Core::Entity::Player::update( int64_t currTime ) -{ - - // a zoning is pending, lets do it - if( m_queuedZoneing && ( currTime - m_queuedZoneing->m_queueTime ) > 800 ) - { - Common::FFXIVARR_POSITION3 targetPos = m_queuedZoneing->m_targetPosition; - if( getCurrentZone()->getId() != m_queuedZoneing->m_targetZone ) - { - performZoning( m_queuedZoneing->m_targetZone, targetPos, m_queuedZoneing->m_targetRotation); - } - else - { - ZoneChannelPacket< FFXIVIpcActorSetPos > setActorPosPacket( getId() ); - setActorPosPacket.data().r16 = Math::Util::floatToUInt16Rot( m_queuedZoneing->m_targetRotation ); - setActorPosPacket.data().waitForLoad = 0x04; - setActorPosPacket.data().x = targetPos.x; - setActorPosPacket.data().y = targetPos.y; - setActorPosPacket.data().z = targetPos.z; - sendToInRangeSet( setActorPosPacket, true ); - setPosition( targetPos ); - } - m_queuedZoneing.reset(); - return; - } - - if( m_hp <= 0 && m_status != ActorStatus::Dead ) - die(); - - if( !isAlive() ) - return; - - updateStatusEffects(); - - m_lastUpdate = currTime; - - if( !checkAction() ) - { - if( m_targetId && m_currentStance == Entity::Actor::Stance::Active && isAutoattackOn() ) - { - auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0, Inventory::EquipSlot::MainHand ); - - // @TODO i dislike this, iterating over all in range actors when you already know the id of the actor you need... - for( auto actor : m_inRangeActors ) - { - if( actor->getId() == m_targetId && actor->isAlive() && mainWeap ) - { - // default autoattack range - // TODO make this dependant on bnpc size - uint32_t range = 7; - - // default autoattack range for ranged classes - if( getClass() == ClassJob::Machinist || - getClass() == ClassJob::Bard || - getClass() == ClassJob::Archer ) - range = 25; - - - if( Math::Util::distance(getPos().x, getPos().y, getPos().z, - actor->getPos().x, actor->getPos().y, actor->getPos().z) <= range ) - { - - if( ( currTime - m_lastAttack ) > mainWeap->getDelay() ) - { - m_lastAttack = currTime; - autoAttack( actor ); - } - - } - } - } - } - } - - if( ( currTime - m_lastTickTime ) > 3000 ) - { - // add 3 seconds to total play time - m_playTime += 3; - m_lastTickTime = currTime; - onTick(); - } -} - -void Core::Entity::Player::onMobKill( uint16_t nameId ) -{ - g_scriptMgr.onMobKill( *getAsPlayer(), nameId ); -} - -void Core::Entity::Player::freePlayerSpawnId( uint32_t actorId ) -{ - uint8_t spawnId = m_playerIdToSpawnIdMap[actorId]; - m_playerIdToSpawnIdMap.erase( actorId ); - m_freeSpawnIdQueue.push( spawnId ); - - ZoneChannelPacket< FFXIVIpcActorFreeSpawn > freeActorSpawnPacket( getId() ); - freeActorSpawnPacket.data().actorId = actorId; - freeActorSpawnPacket.data().spawnId = spawnId; - queuePacket( freeActorSpawnPacket ); - -} - -uint8_t * Core::Entity::Player::getAetheryteArray() -{ - return m_aetheryte; -} - -/*! set homepoint */ -void Core::Entity::Player::setHomepoint( uint8_t aetheryteId ) -{ - m_homePoint = aetheryteId; - - queuePacket( ActorControlPacket143( getId(), SetHomepoint, aetheryteId ) ); -} - -/*! get homepoint */ -uint8_t Core::Entity::Player::getHomepoint() const -{ - return m_homePoint; -} - -uint16_t* Core::Entity::Player::getClassArray() -{ - return m_classArray; -} - -const uint16_t* Core::Entity::Player::getClassArray() const -{ - return m_classArray; -} - -const uint8_t* Core::Entity::Player::getLookArray() const -{ - return m_customize; -} - -const uint32_t* Core::Entity::Player::getModelArray() const -{ - return m_modelEquip; -} - -uint32_t* Core::Entity::Player::getExpArray() -{ - return m_expArray; -} - -const uint32_t* Core::Entity::Player::getExpArray() const -{ - return m_expArray; -} - -uint8_t* Core::Entity::Player::getHowToArray() -{ - return m_howTo; -} - -const uint8_t* Core::Entity::Player::getHowToArray() const -{ - return m_howTo; -} - -const uint8_t* Core::Entity::Player::getUnlockBitmask() const -{ - return m_unlocks; -} - -const uint8_t* Core::Entity::Player::getOrchestrionBitmask() const -{ - return m_orchestrion; -} - -const uint8_t* Core::Entity::Player::getMountGuideBitmask() const -{ - return m_mountGuide; -} - -uint64_t Core::Entity::Player::getContentId() const -{ - return m_contentId; -} - -uint8_t Core::Entity::Player::getVoiceId() const -{ - return m_voice; -} - -uint8_t Core::Entity::Player::getGc() const -{ - return m_gc; -} - -const uint8_t* Core::Entity::Player::getGcRankArray() const -{ - return m_gcRank; -} - -void Core::Entity::Player::queuePacket( Network::Packets::GamePacketPtr pPacket ) -{ - auto pSession = g_serverZone.getSession( m_id ); - - if( !pSession ) - return; - - auto pZoneCon = pSession->getZoneConnection(); - - if( pZoneCon ) - pZoneCon->queueOutPacket( pPacket ); - -} - -void Core::Entity::Player::queueChatPacket( Network::Packets::GamePacketPtr pPacket ) -{ - auto pSession = g_serverZone.getSession( m_id ); - - if( !pSession ) - return; - - auto pChatCon = pSession->getChatConnection(); - - if( pChatCon ) - pChatCon->queueOutPacket( pPacket ); -} - -bool Core::Entity::Player::isLoadingComplete() const -{ - return m_bLoadingComplete; -} - -void Core::Entity::Player::setLoadingComplete( bool bComplete ) -{ - m_bLoadingComplete = bComplete; -} - -void Core::Entity::Player::performZoning( uint16_t zoneId, const Common::FFXIVARR_POSITION3 &pos, float rotation ) -{ - m_pos = pos; - m_zoneId = zoneId; - m_bMarkedForZoning = true; - setRotation( rotation ); - setZone( zoneId ); -} - -bool Core::Entity::Player::isMarkedForZoning() const -{ - return m_bMarkedForZoning; -} - -ZoneingType Core::Entity::Player::getZoningType() const -{ - return m_zoningType; -} - -void Core::Entity::Player::setZoningType( Common::ZoneingType zoneingType ) -{ - m_zoningType = zoneingType; -} - -void Core::Entity::Player::setSearchInfo( uint8_t selectRegion, uint8_t selectClass, const char* searchMessage ) -{ - m_searchSelectRegion = selectRegion; - m_searchSelectClass = selectClass; - memset( &m_searchMessage[0], 0, sizeof( searchMessage ) ); - strcpy( &m_searchMessage[0], searchMessage ); -} - -const char* Core::Entity::Player::getSearchMessage() const -{ - return &m_searchMessage[0]; -} - -uint8_t Core::Entity::Player::getSearchSelectRegion() const -{ - return m_searchSelectRegion; -} - -uint8_t Core::Entity::Player::getSearchSelectClass() const -{ - return m_searchSelectClass; -} - -void Core::Entity::Player::sendNotice( const std::string& message ) //Purple Text -{ - queuePacket( ServerNoticePacket( getId(), message ) ); -} - -void Core::Entity::Player::sendUrgent( const std::string& message ) //Red Text -{ - queuePacket( ChatPacket( *getAsPlayer(), ChatType::ServerUrgent, message ) ); -} - -void Core::Entity::Player::sendDebug( const std::string& message ) //Grey Text -{ - queuePacket( ChatPacket( *getAsPlayer(), ChatType::ServerDebug, message ) ); -} - -void Core::Entity::Player::updateHowtosSeen( uint32_t howToId ) -{ - uint8_t index = howToId / 8; - uint8_t bitIndex = howToId % 8; - - uint8_t value = 1 << bitIndex; - - m_howTo[index] |= value; -} - - -void Core::Entity::Player::onMobAggro( BattleNpcPtr pBNpc ) -{ - hateListAdd( pBNpc ); - - queuePacket( ActorControlPacket142( getId(), ToggleAggro, 1 ) ); -} - -void Core::Entity::Player::onMobDeaggro( BattleNpcPtr pBNpc ) -{ - hateListRemove( pBNpc ); - - if( m_actorIdTohateSlotMap.empty() ) - queuePacket( ActorControlPacket142( getId(), ToggleAggro ) ); -} - -void Core::Entity::Player::hateListAdd( BattleNpcPtr pBNpc ) - -{ - if( m_freeHateSlotQueue.empty() ) - return; - uint8_t hateId = m_freeHateSlotQueue.front(); - m_freeHateSlotQueue.pop(); - m_actorIdTohateSlotMap[pBNpc->getId()] = hateId; - sendHateList(); - -} - -void Core::Entity::Player::hateListRemove( BattleNpcPtr pBNpc ) -{ - - auto it = m_actorIdTohateSlotMap.begin(); - for( ; it != m_actorIdTohateSlotMap.end(); ++it ) - { - if( it->first == pBNpc->getId() ) - { - uint8_t hateSlot = it->second; - m_freeHateSlotQueue.push( hateSlot ); - m_actorIdTohateSlotMap.erase( it ); - sendHateList(); - - return; - } - } -} - -bool Core::Entity::Player::hateListHasMob( BattleNpcPtr pBNpc ) -{ - - auto it = m_actorIdTohateSlotMap.begin(); - for( ; it != m_actorIdTohateSlotMap.end(); ++it ) - { - if( it->first == pBNpc->getId() ) - return true; - } - return false; -} - -void Core::Entity::Player::initHateSlotQueue() -{ - m_freeHateSlotQueue = std::queue< uint8_t >(); - for( int32_t i = 1; i < 26; i++ ) - m_freeHateSlotQueue.push( i ); -} - -void Core::Entity::Player::sendHateList() -{ - ZoneChannelPacket< FFXIVIpcHateList > hateListPacket( getId() ); - hateListPacket.data().numEntries = m_actorIdTohateSlotMap.size(); - auto it = m_actorIdTohateSlotMap.begin(); - for( int32_t i = 0; it != m_actorIdTohateSlotMap.end(); ++it, i++ ) - { - hateListPacket.data().entry[i].actorId = it->first; - hateListPacket.data().entry[i].hatePercent = 100; - } - queuePacket( hateListPacket ); -} - -bool Core::Entity::Player::isLogin() const -{ - return m_bIsLogin; -} - -void Core::Entity::Player::setIsLogin( bool bIsLogin ) -{ - m_bIsLogin = bIsLogin; -} - -uint8_t* Core::Entity::Player::getTitleList() -{ - return m_titleList; -} - -uint16_t Core::Entity::Player::getTitle() const -{ - return m_activeTitle; -} - -void Core::Entity::Player::addTitle( uint16_t titleId ) -{ - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( titleId, value, index ); - - m_titleList[index] |= value; -} - -void Core::Entity::Player::setTitle( uint16_t titleId ) -{ - uint16_t index; - uint8_t value; - Util::valueToFlagByteIndexValue( titleId, value, index ); - - if ( ( m_titleList[index] & value ) == 0 ) // Player doesn't have title - bail - return; - - m_activeTitle = titleId; - - sendToInRangeSet( ActorControlPacket142( getId(), SetTitle, titleId ), true ); -} - -void Core::Entity::Player::setEquipDisplayFlags( uint8_t state ) -{ - m_equipDisplayFlags = state; - ZoneChannelPacket< FFXIVIpcEquipDisplayFlags > paramPacket( getId() ); - paramPacket.data().bitmask = m_equipDisplayFlags; - sendToInRangeSet( paramPacket, true ); -} - -uint8_t Core::Entity::Player::getEquipDisplayFlags() const -{ - return m_equipDisplayFlags; -} - -void Core::Entity::Player::mount( uint32_t id ) -{ - m_mount = id; - sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus, static_cast< uint8_t >( Entity::Actor::ActorStatus::Mounted )), true ); - sendToInRangeSet( ActorControlPacket143( getId(), 0x39e, 12 ), true ); //? - - ZoneChannelPacket< FFXIVIpcMount > mountPacket( getId() ); - mountPacket.data().id = id; - sendToInRangeSet( mountPacket, true ); -} - -void Core::Entity::Player::dismount() -{ - sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus, - static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle )), true ); - sendToInRangeSet( ActorControlPacket143( getId(), ActorControlType::Dismount, 1 ), true ); - m_mount = 0; -} - -uint8_t Core::Entity::Player::getCurrentMount() const -{ - return m_mount; -} - -void Core::Entity::Player::autoAttack( ActorPtr pTarget ) -{ - - auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0, - Inventory::EquipSlot::MainHand ); - - pTarget->onActionHostile( shared_from_this() ); - //uint64_t tick = Util::getTimeMs(); - //srand(static_cast< uint32_t >(tick)); - - uint32_t damage = static_cast< uint32_t >( mainWeap->getAutoAttackDmg() ); - uint32_t variation = 0 + rand() % 3; - - if( getClass() == ClassJob::Machinist || - getClass() == ClassJob::Bard || - getClass() == ClassJob::Archer ) - { - ZoneChannelPacket< FFXIVIpcEffect > effectPacket(getId()); - effectPacket.data().targetId = pTarget->getId(); - effectPacket.data().actionAnimationId = 8; - // effectPacket.data().unknown_2 = variation; - effectPacket.data().numEffects = 1; - effectPacket.data().unknown_61 = 1; - effectPacket.data().unknown_62 = 1; - effectPacket.data().actionTextId = 8; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot(getRotation()); - effectPacket.data().effectTargetId = pTarget->getId(); - effectPacket.data().effectTarget = pTarget->getId(); - effectPacket.data().effects[0].value = damage; - effectPacket.data().effects[0].effectType = Common::ActionEffectType::Damage; - effectPacket.data().effects[0].hitSeverity = Common::ActionHitSeverityType::NormalDamage; - effectPacket.data().effects[0].unknown_3 = 7; - - sendToInRangeSet(effectPacket, true); - } - else - { - - ZoneChannelPacket< FFXIVIpcEffect > effectPacket(getId()); - effectPacket.data().targetId = pTarget->getId(); - effectPacket.data().actionAnimationId = 7; - // effectPacket.data().unknown_2 = variation; - effectPacket.data().numEffects = 1; - effectPacket.data().unknown_61 = 1; - effectPacket.data().unknown_62 = 1; - effectPacket.data().actionTextId = 7; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot(getRotation()); - effectPacket.data().effectTarget = pTarget->getId(); - effectPacket.data().effects[0].value = damage; - effectPacket.data().effects[0].effectType = Common::ActionEffectType::Damage; - effectPacket.data().effects[0].hitSeverity = Common::ActionHitSeverityType::NormalDamage; - effectPacket.data().effects[0].unknown_3 = 71; - - sendToInRangeSet(effectPacket, true); - } - - pTarget->takeDamage(damage); - -} - - -///////////////////////////// -// Content Finder -///////////////////////////// -uint32_t Core::Entity::Player::getCFPenaltyTimestamp() const -{ - return m_cfPenaltyUntil; -} - -void Core::Entity::Player::setCFPenaltyTimestamp( uint32_t timestamp ) -{ - m_cfPenaltyUntil = timestamp; -} - -uint32_t Core::Entity::Player::getCFPenaltyMinutes() const -{ - auto currentTimestamp = Core::Util::getTimeSeconds(); - auto endTimestamp = getCFPenaltyTimestamp(); - - // check if penalty timestamp already passed current time - if( currentTimestamp > endTimestamp ) - return 0; - - auto deltaTime = endTimestamp - currentTimestamp; - return static_cast< uint32_t > ( ceil( static_cast< float > (deltaTime) / 60 ) ); -} - -void Core::Entity::Player::setCFPenaltyMinutes( uint32_t minutes ) -{ - auto currentTimestamp = Core::Util::getTimeSeconds(); - setCFPenaltyTimestamp( static_cast< uint32_t >( currentTimestamp + minutes * 60 ) ); -} - -uint8_t Core::Entity::Player::getOpeningSequence() const -{ - return m_openingSequence; -} - -void Core::Entity::Player::setOpeningSequence( uint8_t seq ) -{ - m_openingSequence = seq; -} - -uint16_t Core::Entity::Player::getItemLevel() const -{ - return m_itemLevel; -} - -/// Tells client to offset their eorzean time by given timestamp. -void Core::Entity::Player::setEorzeaTimeOffset( uint64_t timestamp ) -{ - // TODO: maybe change to persistent? - ZoneChannelPacket< FFXIVIpcEorzeaTimeOffset > packet ( getId() ); - packet.data().timestamp = timestamp; - - // Send to single player - queuePacket( packet ); -} diff --git a/src/servers/sapphire_zone/Actor/Player.h b/src/servers/sapphire_zone/Actor/Player.h deleted file mode 100644 index 03e00b15..00000000 --- a/src/servers/sapphire_zone/Actor/Player.h +++ /dev/null @@ -1,652 +0,0 @@ -#ifndef _PLAYER_H -#define _PLAYER_H - -#include "Forwards.h" - -#include - -#include "Actor.h" -#include "Inventory/Inventory.h" -#include "Event/EventHandler.h" -#include -#include - -namespace Core { - -namespace Entity { - -struct QueuedZoning -{ - uint16_t m_targetZone; - Common::FFXIVARR_POSITION3 m_targetPosition; - float m_targetRotation; - uint64_t m_queueTime; - - QueuedZoning( uint16_t targetZone, const Common::FFXIVARR_POSITION3& targetPosition, uint64_t queuedTime, float targetRotation ) - : m_targetZone( targetZone ) - , m_targetPosition( targetPosition ) - , m_queueTime( queuedTime ) - , m_targetRotation( targetRotation ) {} -}; - -/** Class representing the Player -* Inheriting from Actor -* -*/ -class Player : public Actor -{ -public: - /*! Contructor */ - Player(); - - /*! Destructor */ - ~Player(); - - void autoAttack( ActorPtr pTarget ) override; - - // EventHandlers - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! start an event action */ - void eventActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, ActionCallback interruptCallback, uint64_t additional ); - /*! start an event item action */ - void eventItemActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, ActionCallback interruptCallback, uint64_t additional ); - /*! start/register a normal event */ - void eventStart( uint64_t actorId, uint32_t eventId, Event::EventHandler::EventType eventParam, uint8_t eventParam1, uint32_t eventParam2 ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam2, uint32_t eventParam3 ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, - uint32_t eventParam2, uint32_t eventParam3, Event::EventHandler::SceneReturnCallback eventReturnCallback ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, - uint32_t eventParam2, uint32_t eventParam3, uint32_t eventParam4, - Event::EventHandler::SceneReturnCallback eventReturnCallback ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, - Event::EventHandler::SceneReturnCallback eventReturnCallback ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags ); - /*! finish / unregister an event */ - void eventFinish( uint32_t eventId, uint32_t freePlayer ); - /*! add an event to the event array */ - void addEvent( Event::EventHandlerPtr pEvent ); - /*! retrieve an event from the event array */ - Event::EventHandlerPtr getEvent( uint32_t eventId ); - /*! get number of active events */ - size_t getEventCount(); - /*! remove an event from the event array */ - void removeEvent( uint32_t eventId ); - /*! return the eventlist */ - std::map< uint32_t, Event::EventHandlerPtr >& eventList(); - - void checkEvent( uint32_t eventId ); - - - - // Events - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! Event to be called when zoning process gets triggered */ - void onZoneStart(); - /*! Event to be called when zoning process is finished */ - void onZoneDone(); - /*! Event to be called on login */ - void onLogin(); - /*! Event to be called on update tick */ - void onTick() override; - /*! Event to be called upon player death */ - void onDeath() override; - /*! Event called on every session iteration */ - void update( int64_t currTime ) override; - /*! Event to be called upon Bnpc kill */ - void onMobKill( uint16_t nameId ); - - - // Quest - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! load data for currently active quests */ - bool loadActiveQuests(); - /*! update quest ( register it as active quest if new ) */ - void updateQuest( uint16_t questId, uint8_t sequence ); - /*! return true if quest is currently active */ - bool hasQuest( uint16_t questId ); - /*! return the current quest sequence */ - uint8_t getQuestSeq( uint16_t questId ); - /*! send the quest tracker packet */ - void sendQuestTracker(); - /*! set quest tracker flag for a specified slot */ - void setQuestTracker( uint16_t index, int16_t flag ); - /*! return the index of a given quest in the players quest list */ - int8_t getQuestIndex( uint16_t questId ); - /*! finish a given quest */ - void finishQuest( uint16_t questId ); - /*! finish a given quest */ - void unfinishQuest( uint16_t questId ); - /*! remove a given quest */ - void removeQuest( uint16_t questId ); - /*! add a quest to the completed quests mask */ - void updateQuestsCompleted( uint32_t questId ); - /*! remove a quest from the completed quest mask */ - void removeQuestsCompleted( uint32_t questId ); - /*! get the curent opening sequence */ - uint8_t getOpeningSequence() const; - /*! set te current opening sequence */ - void setOpeningSequence( uint8_t seq ); - - bool giveQuestRewards( uint32_t questId, uint32_t optionalChoice ); - - boost::shared_ptr< Common::QuestActive > getQuestActive( uint16_t index ); - - uint8_t getQuestUI8A( uint16_t questId ); - uint8_t getQuestUI8B( uint16_t questId ); - uint8_t getQuestUI8C( uint16_t questId ); - uint8_t getQuestUI8D( uint16_t questId ); - uint8_t getQuestUI8E( uint16_t questId ); - uint8_t getQuestUI8F( uint16_t questId ); - uint8_t getQuestUI8AH( uint16_t questId ); - uint8_t getQuestUI8BH( uint16_t questId ); - uint8_t getQuestUI8CH( uint16_t questId ); - uint8_t getQuestUI8DH( uint16_t questId ); - uint8_t getQuestUI8EH( uint16_t questId ); - uint8_t getQuestUI8FH( uint16_t questId ); - uint8_t getQuestUI8AL( uint16_t questId ); - uint8_t getQuestUI8BL( uint16_t questId ); - uint8_t getQuestUI8CL( uint16_t questId ); - uint8_t getQuestUI8DL( uint16_t questId ); - uint8_t getQuestUI8EL( uint16_t questId ); - uint8_t getQuestUI8FL( uint16_t questId ); - uint16_t getQuestUI16A( uint16_t questId ); - uint16_t getQuestUI16B( uint16_t questId ); - uint16_t getQuestUI16C( uint16_t questId ); - uint32_t getQuestUI32A( uint16_t questId ); - - uint8_t getQuestBitFlag8( uint16_t questId ); - uint8_t getQuestBitFlag16( uint16_t questId ); - uint8_t getQuestBitFlag24( uint16_t questId ); - uint8_t getQuestBitFlag32( uint16_t questId ); - uint8_t getQuestBitFlag40( uint16_t questId ); - uint8_t getQuestBitFlag48( uint16_t questId ); - - - void setQuestUI8A( uint16_t questId, uint8_t val ); - void setQuestUI8B( uint16_t questId, uint8_t val ); - void setQuestUI8C( uint16_t questId, uint8_t val ); - void setQuestUI8D( uint16_t questId, uint8_t val ); - void setQuestUI8E( uint16_t questId, uint8_t val ); - void setQuestUI8F( uint16_t questId, uint8_t val ); - void setQuestUI8AH( uint16_t questId, uint8_t val ); - void setQuestUI8BH( uint16_t questId, uint8_t val ); - void setQuestUI8CH( uint16_t questId, uint8_t val ); - void setQuestUI8DH( uint16_t questId, uint8_t val ); - void setQuestUI8EH( uint16_t questId, uint8_t val ); - void setQuestUI8FH( uint16_t questId, uint8_t val ); - void setQuestUI8AL( uint16_t questId, uint8_t val ); - void setQuestUI8BL( uint16_t questId, uint8_t val ); - void setQuestUI8CL( uint16_t questId, uint8_t val ); - void setQuestUI8DL( uint16_t questId, uint8_t val ); - void setQuestUI8EL( uint16_t questId, uint8_t val ); - void setQuestUI8FL( uint16_t questId, uint8_t val ); - void setQuestUI16A( uint16_t questId, uint16_t val ); - void setQuestUI16B( uint16_t questId, uint16_t val ); - void setQuestUI16C( uint16_t questId, uint16_t val ); - void setQuestUI32A( uint16_t questId, uint32_t val ); - - void setQuestBitFlag8( uint16_t questId, uint8_t val ); - void setQuestBitFlag16( uint16_t questId, uint8_t val ); - void setQuestBitFlag24( uint16_t questId, uint8_t val ); - void setQuestBitFlag32( uint16_t questId, uint8_t val ); - void setQuestBitFlag40( uint16_t questId, uint8_t val ); - void setQuestBitFlag48( uint16_t questId, uint8_t val ); - - // Inventory / Item / Currency - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! add an item to the first free slot in one of the 4 main containers */ - bool tryAddItem( uint16_t catalogId, uint32_t quantity ); - /*! add an item to a given container */ - bool addItem( uint16_t containerId, uint16_t catalogId, uint32_t quantity ); - /*! equip an item to a specified slot */ - void equipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem, bool sendModel ); - /*! remove an item from an equipment slot */ - void unequipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem ); - /*! equip a weapon, possibly forcing a job change */ - void equipWeapon( ItemPtr pItem ); - /*! get player ilvl */ - uint16_t getItemLevel() const; - /*! send player ilvl */ - void sendItemLevel(); - /*! get a const pointer to the inventory object */ - InventoryPtr getInventory() const; - /*! get the current main hand model */ - uint64_t getModelMainWeapon() const; - /*! get the current off hand model */ - uint64_t getModelSubWeapon() const; - /*! get the current system hand model */ - uint64_t getModelSystemWeapon() const; - /*! return a const pointer to the model array */ - const uint32_t* getModelArray() const; - /*! return the equipment model in a specified equipment slot */ - uint32_t getModelForSlot( Inventory::EquipSlot slot ); - /*! set the equipment model in a specified equipment slot */ - void setModelForSlot( Inventory::EquipSlot slot, uint32_t val ); - /*! return the current amount of currency of type */ - uint32_t getCurrency( uint8_t type ) const; - /*! add amount to the currency of type */ - void addCurrency( uint8_t type, uint32_t amount ); - /*! remove amount from the currency of type */ - void removeCurrency( uint8_t type, uint32_t amount ); - /*! return the current amount of crystals of type */ - uint32_t getCrystal( uint8_t type ) const; - /*! add amount to the crystals of type */ - void addCrystal( uint8_t type, uint32_t amount ); - /*! remove amount from the crystals of type */ - void removeCrystal( uint8_t type, uint32_t amount ); - - // Class / Job / Exp - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! returns the level of the currently active class / job */ - uint8_t getLevel() const override; - /*! returns the level of the provided class / job */ - uint8_t getLevelForClass( Common::ClassJob pClass ) const; - /*! returns the exp of the currently active class / job */ - uint32_t getExp() const; - /*! sets the exp of the currently active class / job */ - void setExp( uint32_t amount ); - /*! adds exp to the currently active class / job */ - void gainExp( uint32_t amount ); - /*! gain a level on the currently active class / job */ - void gainLevel(); - /*! set level on the currently active class / job to given level */ - void setLevel( uint8_t level ); - /*! set level on the provided class / job to given level */ - void setLevelForClass( uint8_t level, Common::ClassJob classjob ); - /*! change class or job to given class / job */ - void setClassJob( Common::ClassJob classJob ); - /*! returns a pointer to the class array */ - uint16_t* getClassArray(); - /*! returns a const pointer to the class array */ - const uint16_t* getClassArray() const; - /*! returns a pointer to the exp array */ - uint32_t* getExpArray(); - /*! returns a const pointer to the exp array */ - const uint32_t* getExpArray() const; - - // Base Look / Stats / Params - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! return the birth day */ - uint8_t getBirthDay() const; - /*! return the birth month */ - uint8_t getBirthMonth() const; - /*! return the guardian diety Id */ - uint8_t getGuardianDeity() const; - /*! get look at specified index */ - uint8_t getLookAt( uint8_t index ) const; - /*! return the race */ - uint8_t getRace() const; - /*! return gender 0 male, 1 female */ - uint8_t getGender() const; - /*! return the id of the home town */ - uint8_t getStartTown() const; - /*! return the voice id */ - uint8_t getVoiceId() const; - /*! return the grand company */ - uint8_t getGc() const; - /*! return the grand company rank */ - const uint8_t* getGcRankArray() const; - /*! set look at index */ - void setLookAt( uint8_t index, uint8_t value ); - /*! set the voice Id */ - void setVoiceId( uint8_t voiceId ); - /*! set the grand company */ - void setGc( uint8_t gc ); - /*! set the grand company rank */ - void setGcRankAt( uint8_t index, uint8_t rank ); - /*! return a const pointer to the look array */ - const uint8_t* getLookArray() const; - /*! returns true if the player is currently in combat */ - bool isInCombat() const; - /*! sets players combat state */ - void setInCombat( bool mode ); - /*! return current online status depending on current state / activity */ - Common::OnlineStatus getOnlineStatus(); - /*! sets the players zone, initiating a zoning process */ - 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 */ - uint64_t getContentId() const; - /*! return max hp */ - uint32_t getMaxHp(); - /*! return max mp */ - uint32_t getMaxMp(); - /*! return a players total play time */ - uint32_t getPlayTime() const; - /*! return true if the player has "new adventurere" status */ - bool isNewAdventurer() const; - /*! change the players "new adventurere" status */ - void setNewAdventurer( bool state ); - /*! sets the list of current online status */ - void setOnlineStatusMask( uint64_t status ); - /*! returns the current online status */ - uint64_t getOnlineStatusMask() const; - /*! perform a teleport of a specified type ( teleport,return,aethernet ) */ - void teleport( uint16_t aetheryteId, uint8_t type = 1 ); - /*! prepares zoning / fades out the screen */ - void prepareZoning( uint16_t targetZone, bool fadeOut, uint8_t fadoutTime = 0, uint16_t animation = 0 ); - /*! get player's title list (available titles) */ - uint8_t* getTitleList(); - /*! get player's active title */ - uint16_t getTitle() const; - /*! add title to player title list */ - void addTitle( uint16_t titleId ); - /*! change player's active title */ - void setTitle( uint16_t titleId ); - /*! change gear param state */ - void setEquipDisplayFlags( uint8_t state ); - /*! get gear param state */ - uint8_t getEquipDisplayFlags() const; - /*! mount the specified mount and send the packets */ - void mount( uint32_t id ); - /*! dismount the current mount and send the packets */ - void dismount(); - /*! get the current mount */ - uint8_t getCurrentMount() const; - - void calculateStats() override; - void sendStats(); - - - // Aetheryte / Action / Attribute bitmasks - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! register aetheryte aetheryteId and send update */ - void registerAetheryte( uint8_t aetheryteId ); - /*! check if aetheryte is already registered */ - bool isAetheryteRegistered( uint8_t aetheryteId ) const; - /*! return a const pointer to the aetheryte unlock bitmask array */ - int8_t getAetheryteMaskAt( uint8_t index ) const; - /*! return a pointer to the aetheryte unlock bitmask array */ - uint8_t* getAetheryteArray(); - /*! set homepoint */ - void setHomepoint( uint8_t aetheryteId ); - /*! get homepoint */ - uint8_t getHomepoint() const; - /*! discover subarea subid fo map map_id, also send udpate packet */ - void discover( int16_t map_id, int16_t sub_id ); - /*! return a pointer to the discovery bitmask array */ - uint8_t* getDiscoveryBitmask(); - /*! helper/debug function to reset all discovered areas */ - void resetDiscovery(); - /*! get a pointer to the howto bitmask array */ - uint8_t* getHowToArray(); - /*! get a const pointer to the howto bitmask array */ - const uint8_t* getHowToArray() const; - /*! update bitmask for how-to's seen */ - void updateHowtosSeen( uint32_t howToId ); - /*! learn an action / update the unlock bitmask. */ - void learnAction( uint8_t actionId ); - /*! learn a song / update the unlock bitmask. */ - void learnSong( uint8_t songId, uint32_t itemId ); - /*! check if an action is already unlocked in the bitmask. */ - bool isActionLearned( uint8_t actionId ) const; - /*! return a const pointer to the unlock bitmask array */ - const uint8_t* getUnlockBitmask() const; - /*! return a const pointer to the orchestrion bitmask array */ - const uint8_t* getOrchestrionBitmask() const; - /*! return a const pointer to the mount guide bitmask array */ - const uint8_t* getMountGuideBitmask() const; - - - // Spawn handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! initialize the spawnId queue */ - void initSpawnIdQueue(); - /*! get the spawn id mapped to a specific actorId */ - uint8_t getSpawnIdForActorId( uint32_t actorId ); - /*! assigns the given spawnId to the actor */ - void assignSpawnIdToPlayerId( uint32_t actorId, uint8_t spawnId ); - /*! frees the spawnId assigned to the given actor */ - void freePlayerSpawnId( uint32_t actorId ); - /*! send spawn packets to pTarget */ - void spawn( PlayerPtr pTarget ) override; - /*! send despawn packets to pTarget */ - void despawn( ActorPtr pTarget ) override; - - // Player State Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /* return a const pointer to the state flag array */ - const uint8_t* getStateFlags() const; - /* set a specified state flag */ - void setStateFlag( Common::PlayerStateFlag flag ); - /* set a specified state flag */ - void setStateFlags( std::vector< Common::PlayerStateFlag > flags ); - /* check if a specified flag is set */ - bool hasStateFlag( Common::PlayerStateFlag flag ) const; - /* reset a specified flag */ - void unsetStateFlag( Common::PlayerStateFlag flag ); - /* helper function, send an empty state flag update */ - void unlock(); - - // Player Session Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! return the userlevel */ - uint8_t getUserLevel() const; - /*! set timestamp for last received ping */ - void setLastPing( uint32_t ping ); - /*! get timestamp of last received ping */ - uint32_t getLastPing() const; - - // Player Database Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! generate the update sql based on update flags */ - void updateSql(); - /*! load player from db, by id */ - bool load( uint32_t charId, SessionPtr pSession ); - /*! load active class data */ - bool loadClassData(); - /*! load search info */ - bool loadSearchInfo(); - - // Player Network Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! send current models ( equipment ) */ - void sendModel(); - /*! send active state flags */ - void sendStateFlags(); - /*! send status update */ - void sendStatusUpdate( bool toSelf = true ) override; - /*! send the entire inventory sequence */ - void sendInventory() const; - /*! send active quest list */ - void sendQuestInfo(); - /*! send a quest specific message */ - void sendQuestMessage( uint32_t questId, int8_t msgId, uint8_t type, uint32_t var1, uint32_t var2 ); - /*! queue a packet for the player */ - void queuePacket( Network::Packets::GamePacketPtr pPacket ); - /*! queue a char connection packet for the player */ - void queueChatPacket( Network::Packets::GamePacketPtr pPacket ); - /*! returns true if loading is complete ( 0x69 has been received ) */ - bool isLoadingComplete() const; - /*! set the loading complete bool */ - void setLoadingComplete( bool bComplete ); - /*! mark this player for zoning, notify worldserver */ - void performZoning(uint16_t zoneId, const Common::FFXIVARR_POSITION3& pos, float rotation); - /*! return true if the player is marked for zoning */ - bool isMarkedForZoning() const; - - Common::ZoneingType getZoningType() const; - void setZoningType( Common::ZoneingType zoneingType ); - - void setSearchInfo( uint8_t selectRegion, uint8_t selectClass, const char* searchMessage ); - const char* getSearchMessage() const; - uint8_t getSearchSelectRegion() const; - uint8_t getSearchSelectClass() const; - - void sendNotice( const std::string& message ); - void sendUrgent( const std::string& message ); - void sendDebug( const std::string& message ); - - // Player Battle Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - void onMobAggro( BattleNpcPtr pBNpc ); - void onMobDeaggro( BattleNpcPtr pBNpc ); - - void initHateSlotQueue(); - void hateListAdd( BattleNpcPtr pBNpc ); - void hateListRemove( BattleNpcPtr pBNpc ); - - bool hateListHasMob( BattleNpcPtr pBNpc ); - - void sendHateList(); - - bool actionHasCastTime( uint32_t actionId ); - - Core::Entity::ActorPtr lookupTargetById( uint64_t targetId ); - - bool isLogin() const; - void setIsLogin( bool bIsLogin ); - - uint16_t getZoneId() const; - - uint8_t getGmRank() const; - void setGmRank( uint8_t rank ); - - uint8_t getMode() const; - void setMode( uint8_t mode ); - - void setAutoattack( bool mode ); - bool isAutoattackOn() const; - - // Content Finder handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! Get an unix time when the player can register into content finder again. */ - uint32_t getCFPenaltyTimestamp() const; - - /*! Set an unix time when the player can register into content finder again. */ - void setCFPenaltyTimestamp( uint32_t timestamp ); - - uint32_t getCFPenaltyMinutes() const; - void setCFPenaltyMinutes( uint32_t minutes ); - - void setEorzeaTimeOffset( uint64_t timestamp ); - - // Database - void updateDbAllQuests() const; - void deleteQuest( uint16_t questId ) const; - void insertQuest( uint16_t questId, uint8_t index, uint8_t seq ) const; - void updateDbSearchInfo() const; - void updateDbClass() const; - void insertDbClass( const uint8_t classJobIndex ) const; - - void setMarkedForRemoval(); - bool isMarkedForRemoval() const; - -private: - uint32_t m_lastWrite; - uint32_t m_lastPing; - - bool m_bIsLogin; - - uint64_t m_contentId; // This id will be the name of the folder for character settings in "My Games" - - uint8_t m_mode; - - bool m_markedForRemoval; - -private: - - uint8_t m_voice; - - uint64_t m_modelMainWeapon; - uint64_t m_modelSubWeapon; - uint64_t m_modelSystemWeapon; - - uint32_t m_modelEquip[10]; - - bool m_bNewGame; - - uint8_t m_guardianDeity; - uint8_t m_birthDay; - uint8_t m_birthMonth; - - struct RetainerInfo - { - uint32_t retainerId; - char retainerName[32]; - uint32_t createUnixTime; - bool isActive; - bool isRename; - uint8_t status; - } m_retainerInfo[8]; - - uint16_t m_activeTitle; - uint8_t m_titleList[48]; - uint8_t m_howTo[33]; - uint8_t m_minions[35]; - uint8_t m_mountGuide[14]; - uint8_t m_homePoint; - uint8_t m_startTown; - uint16_t m_townWarpFstFlags; - uint8_t m_questCompleteFlags[200]; - uint8_t m_discovery[420]; - uint32_t m_playTime; - - uint16_t m_classArray[25]; - uint32_t m_expArray[25]; - uint8_t m_aetheryte[16]; - uint8_t m_unlocks[64]; - uint8_t m_orchestrion[40]; - - uint8_t m_openingSequence; - - uint16_t m_itemLevel; - InventoryPtr m_pInventory; - - std::map< uint32_t, Event::EventHandlerPtr > m_eventMap; - std::map< uint32_t, uint8_t > m_playerIdToSpawnIdMap; // maps player to spawn id - std::queue< uint8_t > m_freeSpawnIdQueue; // queue with spawn ids free to be assigned - std::queue< uint8_t > m_freeHateSlotQueue; // queue with "hate slots" free to be assigned - std::map< uint32_t, uint8_t > m_actorIdTohateSlotMap; - - std::map< uint32_t, uint8_t > m_questIdToQuestIdx; // quest mapping, quest id to quest container index - std::map< uint8_t, uint32_t > m_questIdxToQuestId; // quest mapping, quest container index to questId - boost::shared_ptr< Common::QuestActive > m_activeQuests[30]; - int16_t m_questTracking[5]; - - uint8_t m_stateFlags[7]; - uint8_t m_gmRank; - uint16_t zoneId; - - uint8_t m_equipDisplayFlags; - - bool m_bInCombat; - bool m_bLoadingComplete; - bool m_bAutoattack; - - Common::ZoneingType m_zoningType; - - bool m_bMarkedForZoning; - bool m_bNewAdventurer; - uint64_t m_onlineStatus; - boost::shared_ptr< QueuedZoning > m_queuedZoneing; - - // search info - char m_searchMessage[193]; // searchmessage to show in profile - uint8_t m_searchSelectRegion; // regions selected to show up in profile - uint8_t m_searchSelectClass; // class selected to show up in profile - - // gc info - uint8_t m_gc; - uint8_t m_gcRank[3]; - - // content finder info - uint32_t m_cfPenaltyUntil; // unix time - - uint8_t m_mount; -}; - -} -} - -#endif diff --git a/src/servers/sapphire_zone/Actor/PlayerEvent.cpp b/src/servers/sapphire_zone/Actor/PlayerEvent.cpp deleted file mode 100644 index b1ec4f57..00000000 --- a/src/servers/sapphire_zone/Actor/PlayerEvent.cpp +++ /dev/null @@ -1,361 +0,0 @@ -#include -#include -#include -#include -#include - -#include "Player.h" - -#include "Zone/Zone.h" - -#include "Forwards.h" - -#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" - -#include "Action/EventAction.h" -#include "Action/EventItemAction.h" - -#include "Event/EventHandler.h" -#include "Event/EventHandler.h" -#include "ServerZone.h" - -extern Core::Logger g_log; -extern Core::ServerZone g_serverZone; - -using namespace Core::Common; -using namespace Core::Network::Packets; -using namespace Core::Network::Packets::Server; - -void Core::Entity::Player::addEvent( Event::EventHandlerPtr pEvent ) -{ - m_eventMap[pEvent->getId()] = pEvent; -} - -std::map< uint32_t, Core::Event::EventHandlerPtr >& Core::Entity::Player::eventList() -{ - return m_eventMap; -} - -Core::Event::EventHandlerPtr Core::Entity::Player::getEvent( uint32_t eventId ) -{ - auto it = m_eventMap.find( eventId ); - if( it != m_eventMap.end() ) - return it->second; - - return Event::EventHandlerPtr( nullptr ); -} - -size_t Core::Entity::Player::getEventCount() -{ - return m_eventMap.size(); -} - -void Core::Entity::Player::removeEvent( uint32_t eventId ) -{ - auto it = m_eventMap.find( eventId ); - if( it != m_eventMap.end() ) - { - auto tmpEvent = it->second; - m_eventMap.erase( it ); - } -} - -void Core::Entity::Player::checkEvent( uint32_t eventId ) -{ - auto pEvent = getEvent( eventId ); - - if( pEvent && !pEvent->hasPlayedScene() ) - eventFinish( eventId, 1 ); -} - - -void Core::Entity::Player::eventStart( uint64_t actorId, uint32_t eventId, - Event::EventHandler::EventType eventType, uint8_t eventParam1, - uint32_t eventParam2 ) -{ - Event::EventHandlerPtr newEvent( new Event::EventHandler( actorId, eventId, eventType, eventParam2 ) ); - addEvent( newEvent ); - - setStateFlag( PlayerStateFlag::Occupied2 ); - sendStateFlags(); - - 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, - uint32_t flags, Event::EventHandler::SceneReturnCallback eventCallback ) -{ - 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, - uint32_t eventParam3, Event::EventHandler::SceneReturnCallback eventCallback ) -{ - if( flags & 0x02 ) - { - setStateFlag( PlayerStateFlag::WatchingCutscene ); - sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, - static_cast< uint8_t >( getOnlineStatus() ) ), true ); - } - - auto pEvent = getEvent( eventId ); - if( !pEvent && getEventCount() ) - { - // We're trying to play a nested event, need to start it first. - eventStart( getId(), eventId, Event::EventHandler::Nest, 0, 0 ); - 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, - uint32_t eventParam3, uint32_t eventParam4, Event::EventHandler::SceneReturnCallback eventCallback ) -{ - if( flags & 0x02 ) - { - setStateFlag( PlayerStateFlag::WatchingCutscene ); - sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, - static_cast< uint8_t >( getOnlineStatus() ) ), true ); - } - - auto pEvent = getEvent( eventId ); - if( !pEvent && getEventCount() ) - { - // We're trying to play a nested event, need to start it first. - eventStart( getId(), eventId, Event::EventHandler::Nest, 0, 0 ); - 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; - } - - if( getEventCount() > 1 && pEvent->getEventType() != Event::EventHandler::Nest ) - { - // this is the parent of a nested event, we can't finish it until the parent finishes - return; - } - - switch( pEvent->getEventType() ) - { - case Event::EventHandler::Nest: - { - queuePacket( EventFinishPacket( getId(), pEvent->getId(), pEvent->getEventType(), pEvent->getEventParam3() ) ); - 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 - queuePacket( EventFinishPacket( getId(), it.second->getId(), it.second->getEventType(), it.second->getEventParam3() ) ); - removeEvent( it.second->getId() ); - } - } - - break; - } - default: - { - queuePacket( EventFinishPacket( getId(), pEvent->getId(), pEvent->getEventType(), pEvent->getEventParam3() ) ); - break; - } - } - - if( hasStateFlag( PlayerStateFlag::WatchingCutscene ) ) - { - unsetStateFlag( PlayerStateFlag::WatchingCutscene ); - sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, - static_cast< uint8_t >( getOnlineStatus() ) ), true ); - } - - removeEvent( pEvent->getId() ); - - if( freePlayer == 1 ) - { - unsetStateFlag( PlayerStateFlag::Occupied2 ); - sendStateFlags(); - } -} - -void Core::Entity::Player::eventActionStart( uint32_t eventId, - uint32_t action, - ActionCallback finishCallback, - ActionCallback interruptCallback, - uint64_t additional ) -{ - Action::ActionPtr pEventAction( new Action::EventAction( shared_from_this(), eventId, action, - finishCallback, interruptCallback, additional ) ); - - setCurrentAction( pEventAction ); - auto pEvent = getEvent( eventId ); - - if( !pEvent && getEventCount() ) - { - // We're trying to play a nested event, need to start it first. - eventStart( getId(), eventId, Event::EventHandler::Nest, 0, 0 ); - 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 ) -{ - Action::ActionPtr pEventItemAction( new Action::EventItemAction( shared_from_this(), eventId, action, - finishCallback, interruptCallback, additional ) ); - - setCurrentAction( pEventItemAction ); - - pEventItemAction->onStart(); -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void Core::Entity::Player::onLogin() -{ - for( auto& child : g_serverZone.getConfig()->getChild( "Settings.Parameters.MotDArray" ) ) - { - sendNotice( child.second.data() ); - } -} - -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; - - 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; - - if( !m_actorIdTohateSlotMap.empty() ) - { - addHp = static_cast< uint32_t >( getMaxHp() * 0.01f + 1 ); - addMp = static_cast< uint32_t >( getMaxMp() * 0.02f + 1 ); - addTp = 60; - } - - 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(); -} diff --git a/src/servers/sapphire_zone/Event/EventHelper.cpp b/src/servers/sapphire_zone/Event/EventHelper.cpp deleted file mode 100644 index 6438ab6f..00000000 --- a/src/servers/sapphire_zone/Event/EventHelper.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "EventHelper.h" -#include "EventHandler.h" -#include -#include - -extern Core::Data::ExdData g_exdData; - -using namespace Core::Common; - -std::string Core::Event::getEventName( uint32_t eventId ) -{ - uint16_t eventType = eventId >> 16; - - auto unknown = std::string{ "unknown" }; - - switch( eventType ) - { - case EventType::Quest: - { - auto questInfo = g_exdData.getQuestInfo( eventId ); - if( !questInfo ) - return unknown + "Quest"; - - std::string name = questInfo->name_intern; - std::size_t pos = name.find_first_of( "_" ); - - return questInfo->name_intern.substr( 0, pos ); - } - case EventType::CustomTalk: - { - auto customTalkInfo = g_exdData.getCustomTalkInfo( eventId ); - if( !customTalkInfo ) - return unknown + "CustomTalk"; - - std::string name = customTalkInfo->name_intern; - std::size_t pos = name.find_first_of( "_" ); - - return customTalkInfo->name_intern.substr( 0, pos ); - } - case EventType::Opening: - { - auto openingInfo = g_exdData.getOpeningInfo( eventId ); - if( openingInfo ) - return openingInfo->name; - return unknown + "Opening"; - } - case EventType::Aetheryte: - { - auto aetherInfo = g_exdData.getAetheryteInfo( eventId & 0xFFFF ); - if( aetherInfo->isAetheryte ) - return "Aetheryte"; - return "Aethernet"; - } - case EventType::Warp: - { - return "ChocoboTaxi"; - } - default: - { - return unknown; - } - } -} - -uint32_t Core::Event::mapEventActorToRealActor( uint32_t eventActorId ) -{ - auto levelInfo = g_exdData.getLevelInfo( eventActorId ); - if( levelInfo ) - return levelInfo->actor_id; - - return 0; -} diff --git a/src/servers/sapphire_zone/Forwards.h b/src/servers/sapphire_zone/Forwards.h deleted file mode 100644 index 40fcc5c0..00000000 --- a/src/servers/sapphire_zone/Forwards.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _FORWARDS_H -#define _FORWARDS_H - -#include -#include - -#define TYPE_FORWARD( x ) \ -class x; \ -typedef boost::shared_ptr< x > x ## Ptr; \ -typedef std::vector< x > x ## PtrList; - -namespace Core -{ - TYPE_FORWARD( Cell ); - TYPE_FORWARD( Zone ); - TYPE_FORWARD( Item ); - TYPE_FORWARD( ItemContainer ); - TYPE_FORWARD( Inventory ); - TYPE_FORWARD( Session ); - TYPE_FORWARD( XMLConfig ); - TYPE_FORWARD( ZonePosition ) - - namespace StatusEffect - { - TYPE_FORWARD( StatusEffect ); - TYPE_FORWARD( StatusEffectContainer ); - } - - namespace Entity - { - TYPE_FORWARD( Actor ); - TYPE_FORWARD( Player ); - TYPE_FORWARD( BattleNpc ); - TYPE_FORWARD( BattleNpcTemplate ); - } - - namespace Event - { - TYPE_FORWARD( EventHandler ); - } - - namespace Action - { - TYPE_FORWARD( Action ); - TYPE_FORWARD( ActionTeleport ); - TYPE_FORWARD( ActionCast ); - TYPE_FORWARD( ActionMount ); - TYPE_FORWARD( EventAction ); - } - - namespace Network - { - TYPE_FORWARD( Hive ); - TYPE_FORWARD( Acceptor ); - TYPE_FORWARD( Connection ); - TYPE_FORWARD( GameConnection ); - TYPE_FORWARD( SessionConnection ); - TYPE_FORWARD( CustomMsgClientConnection ); - - namespace Packets - { - TYPE_FORWARD( GamePacket ); - } - } - - namespace ContentFinder - { - TYPE_FORWARD( ContentFinder ); - } - - namespace Scripting - { - class NativeScriptManager; - } - - typedef std::function< void( Entity::Player&, uint32_t, uint64_t ) > ActionCallback; - -} - - -#endif diff --git a/src/servers/sapphire_zone/Script/ScriptManager.cpp b/src/servers/sapphire_zone/Script/ScriptManager.cpp deleted file mode 100644 index 3073c2e5..00000000 --- a/src/servers/sapphire_zone/Script/ScriptManager.cpp +++ /dev/null @@ -1,483 +0,0 @@ -#include -#include -#include - -#include "NativeScriptManager.h" - -#include "Zone/Zone.h" -#include "Actor/Player.h" -#include "Actor/BattleNpc.h" -#include "ServerZone.h" -#include "Event/EventHandler.h" -#include "Event/EventHelper.h" -#include "StatusEffect/StatusEffect.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" -#include "Script/ScriptManager.h" - -#include -#include -#include -#include -#include - - -// enable the ambiguity fix for every platform to avoid #define nonsense -#define WIN_AMBIGUITY_FIX -#include - -extern Core::Logger g_log; -extern Core::Data::ExdData g_exdData; -extern Core::ServerZone g_serverZone; - -Core::Scripting::ScriptManager::ScriptManager() : - m_firstScriptChangeNotificiation( false ) -{ - m_nativeScriptManager = createNativeScriptMgr(); -} - -Core::Scripting::ScriptManager::~ScriptManager() -{ - Watchdog::unwatchAll(); -} - -void Core::Scripting::ScriptManager::update() -{ - m_nativeScriptManager->processLoadQueue(); -} - -bool Core::Scripting::ScriptManager::init() -{ - std::set< std::string > files; - - loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ), - files, m_nativeScriptManager->getModuleExtension() ); - - uint32_t scriptsFound = 0; - uint32_t scriptsLoaded = 0; - - for( auto itr = files.begin(); itr != files.end(); ++itr ) - { - auto& path = *itr; - - scriptsFound++; - - if( m_nativeScriptManager->loadScript( path ) ) - scriptsLoaded++; - } - - g_log.info( "ScriptManager: Loaded " + std::to_string( scriptsLoaded ) + "/" + std::to_string( scriptsFound ) + " scripts successfully" ); - - watchDirectories(); - - return true; -} - -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() ); - - m_nativeScriptManager->queueScriptReload( path.stem( ).string( )); - } - else - { - g_log.debug( "Loading new script: " + path.stem().string() ); - - m_nativeScriptManager->loadScript( path.string() ); - } - } - }); -} - -void Core::Scripting::ScriptManager::loadDir( const std::string& dirname, std::set &files, const std::string& ext ) -{ - - g_log.info( "ScriptEngine: loading scripts from " + dirname ); - - boost::filesystem::path targetDir( dirname ); - - boost::filesystem::directory_iterator iter( targetDir ); - boost::filesystem::directory_iterator eod; - - BOOST_FOREACH( boost::filesystem::path const& i, make_pair( iter, eod ) ) - { - if( is_regular_file( i ) && boost::filesystem::extension( i.string() ) == ext ) - { - files.insert( i.string() ); - } - } -} - -void Core::Scripting::ScriptManager::onPlayerFirstEnterWorld( Entity::Player& player ) -{ -// try -// { -// std::string test = m_onFirstEnterWorld( player ); -// } -// catch( const std::exception &e ) -// { -// std::string what = e.what(); -// g_log.Log( LoggingSeverity::error, what ); -// } -} - -bool Core::Scripting::ScriptManager::registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, - uint32_t bnpcNameId, uint32_t modelId, std::string aiName ) -{ - return g_serverZone.registerBnpcTemplate( templateName, bnpcBaseId, bnpcNameId, modelId, aiName ); -} - -bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId ) -{ - std::string eventName = "onTalk"; - std::string objName = Event::getEventName( eventId ); - - player.sendDebug( "Actor: " + - std::to_string( actorId ) + " -> " + - std::to_string( Event::mapEventActorToRealActor( static_cast< uint32_t >( actorId ) ) ) + - " \neventId: " + - std::to_string( eventId ) + - " (0x" + boost::str( boost::format( "%|08X|" ) - % static_cast< uint64_t >( eventId & 0xFFFFFFF ) ) + ")" ); - - uint16_t eventType = eventId >> 16; - uint32_t scriptId = eventId; - - // aethernet/aetherytes need to be handled separately - if( eventType == Common::EventType::Aetheryte ) - { - auto aetherInfo = g_exdData.getAetheryteInfo( eventId & 0xFFFF ); - scriptId = EVENTSCRIPT_AETHERYTE_ID; - if( !aetherInfo->isAetheryte ) - scriptId = EVENTSCRIPT_AETHERNET_ID; - } - - auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, scriptId ); - if( script ) - { - player.sendDebug( "Calling: " + objName + "." + eventName ); - - player.eventStart( actorId, eventId, Event::EventHandler::Talk, 0, 0 ); - - script->onTalk( eventId, player, actorId ); - - player.checkEvent( eventId ); - } - else - { - if ( eventType == Common::EventType::Quest ) - { - auto questInfo = g_exdData.getQuestInfo( eventId ); - if ( questInfo ) - { - player.sendUrgent( "Quest not implemented: " + questInfo->name + " (" + questInfo->name_intern + ")" ); - - } - } - - return false; - } - - return true; -} - -bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, uint32_t eventId, - uint16_t param1, uint16_t param2 ) -{ - std::string eventName = "onEnterTerritory"; - std::string objName = Event::getEventName( eventId ); - - player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) ); - - auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId ); - if( script ) - { - player.eventStart( player.getId(), eventId, Event::EventHandler::EnterTerritory, 0, player.getZoneId() ); - - script->onEnterZone( player, eventId, param1, param2 ); - - player.checkEvent( eventId ); - - return true; - } - - return false; -} - -bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, - float x, float y, float z ) -{ - - std::string eventName = "onWithinRange"; - std::string objName = Event::getEventName( eventId ); - player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) + " p1: " + std::to_string( param1 ) ); - - auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId ); - if( script ) - { - player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 ); - - script->onWithinRange( player, eventId, param1, x, y, z ); - - player.checkEvent( eventId ); - - return true; - } - - return false; -} - -bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, - float x, float y, float z ) -{ - std::string eventName = "onOutsideRange"; - std::string objName = Event::getEventName( eventId ); - player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) ); - - auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId ); - if( script ) - { - player.eventStart( player.getId(), eventId, Event::EventHandler::WithinRange, 1, param1 ); - - script->onOutsideRange( player, eventId, param1, x, y, z ); - - player.checkEvent( eventId ); - - return true; - } - - return false; -} - -bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t actorId, - uint32_t eventId, uint8_t emoteId ) -{ - std::string eventName = "onEmote"; - std::string objName = Event::getEventName( eventId ); - - auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId ); - if( script ) - { - player.sendDebug( "Calling: " + objName + "." + eventName ); - - player.eventStart( actorId, eventId, Event::EventHandler::Emote, 0, emoteId ); - - script->onEmote( actorId, eventId, emoteId, player ); - - player.checkEvent( eventId ); - } - else - { - uint16_t eventType = eventId >> 16; - - if( eventType == Common::EventType::Quest ) - { - auto questInfo = g_exdData.getQuestInfo( eventId ); - if( questInfo ) - { - player.sendUrgent( "Quest not implemented: " + questInfo->name ); - return false; - } - } - return false; - } - - return true; -} - -bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& player, uint32_t eventId, - uint16_t subEvent, uint16_t param1, uint16_t param2, - uint16_t param3 ) -{ - - 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 ) ); - - try - { - auto pEvent = player.getEvent( eventId ); - 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 ) - { - eventCallback( player, eventId, param1, param2, param3 ); - if( !pEvent->hasPlayedScene() ) - player.eventFinish( eventId, 1 ); - else - pEvent->setPlayedScene( false ); - } - // else, finish the event. - else - player.eventFinish( eventId, 1 ); - } - } - catch( std::exception& e ) - { - player.sendNotice( e.what() ); - return false; - } - - return true; -} - -bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, - uint16_t subEvent, uint16_t param, uint32_t catalogId ) -{ - auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId ); - if( script ) - { - script->onEventHandlerTradeReturn( player, eventId, subEvent, param, catalogId ); - - return true; - } - - return false; -} - -bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32_t eventItemId, - uint32_t eventId, uint32_t castTime, uint64_t targetId ) -{ - std::string eventName = "onEventItem"; - std::string objName = Event::getEventName( eventId ); - player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) ); - - auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, eventId ); - if( script ) - { - player.eventStart( targetId, eventId, Event::EventHandler::Item, 0, 0 ); - - script->onEventItem( player, eventItemId, eventId, castTime, targetId ); - - return true; - } - - return false; -} - -bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t nameId ) -{ - std::string eventName = "onBnpcKill_" + std::to_string( nameId ); - - - // loop through all active quests and try to call available onMobKill callbacks - for( size_t i = 0; i < 30; i++ ) - { - auto activeQuests = player.getQuestActive( static_cast< uint16_t >( i ) ); - if( !activeQuests ) - continue; - - uint16_t questId = activeQuests->c.questId; - - auto script = m_nativeScriptManager->getScript< EventScript >( ScriptType::ScriptedEvent, questId ); - if( script ) - { - std::string objName = Event::getEventName( 0x00010000 | questId ); - - player.sendDebug("Calling: " + objName + "." + eventName); - - script->onNpcKill( nameId, player ); - } - } - - return true; -} - -bool Core::Scripting::ScriptManager::onCastFinish( Entity::Player& player, Entity::ActorPtr pTarget, uint32_t actionId ) -{ - auto script = m_nativeScriptManager->getScript< ActionScript >( ScriptType::ScriptedAction, actionId ); - - if( script ) - script->onCastFinish( player, *pTarget ); - - return true; -} - -bool Core::Scripting::ScriptManager::onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId ) -{ - auto script = m_nativeScriptManager->getScript< StatusEffectScript >( ScriptType::ScriptedStatusEffect, effectId ); - - if( script ) - { - if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendDebug( "Calling status receive for statusid: " + std::to_string( effectId ) ); - - script->onApply( *pActor ); - - return true; - } - - return false; -} - -bool Core::Scripting::ScriptManager::onStatusTick( Entity::ActorPtr pActor, Core::StatusEffect::StatusEffect& effect ) -{ - auto script = m_nativeScriptManager->getScript< StatusEffectScript >( ScriptType::ScriptedStatusEffect, effect.getId() ); - if( script ) - { - if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendDebug( "Calling status tick for statusid: " + std::to_string( effect.getId() ) ); - - script->onTick( *pActor ); - - return true; - } - - return false; -} - -bool Core::Scripting::ScriptManager::onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId ) -{ - auto script = m_nativeScriptManager->getScript< StatusEffectScript >( ScriptType::ScriptedStatusEffect, effectId ); - if( script ) - { - if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendDebug( "Calling status timeout for statusid: " + std::to_string( effectId ) ); - - script->onExpire( *pActor ); - - return true; - } - - return false; -} - -bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone ) -{ - auto script = m_nativeScriptManager->getScript< ZoneScript >( ScriptType::ScriptedZone, pZone->getId() ); - if( script ) - { - script->onZoneInit(); - - return true; - } - - return false; -} - -Scripting::NativeScriptManager& Core::Scripting::ScriptManager::getNativeScriptHandler() -{ - return *m_nativeScriptManager; -}