1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-23 13:17:45 +00:00
sapphire/src/servers/sapphire_zone/Actor/Player.cpp

1723 lines
48 KiB
C++
Raw Normal View History

#include <boost/make_shared.hpp>
2018-03-06 22:22:19 +01:00
#include <Common.h>
#include <Util/Util.h>
#include <Util/UtilMath.h>
#include <Config/XMLConfig.h>
#include <Network/GamePacket.h>
#include <Logging/Logger.h>
#include <Exd/ExdDataGenerated.h>
#include <Network/PacketContainer.h>
#include "Session.h"
2017-08-08 13:53:47 +02:00
#include "Player.h"
2018-01-27 23:52:49 +01:00
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h"
#include "Zone/ZonePosition.h"
#include "Network/GameConnection.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
2018-02-18 01:50:20 +01:00
#include "Network/PacketWrappers/ActorControlPacket144.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/ScriptMgr.h"
#include "Inventory/Item.h"
#include "Inventory/Inventory.h"
2018-01-09 23:50:54 +01:00
#include "Event/EventHandler.h"
#include "Action/Action.h"
#include "Action/ActionTeleport.h"
#include "Action/EventAction.h"
#include "Action/EventItemAction.h"
#include "Math/CalcStats.h"
#include "Math/CalcBattle.h"
2017-08-08 13:53:47 +02:00
#include "ServerZone.h"
#include "Framework.h"
2018-03-09 00:06:44 +01:00
extern Core::Framework g_fw;
2017-08-08 13:53:47 +02:00
using namespace Core::Common;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
// player constructor
Core::Entity::Player::Player() :
Chara( ObjKind::Player ),
2017-08-08 13:53:47 +02:00
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 ),
2017-11-21 17:39:10 +11:00
m_markedForRemoval( false ),
m_mount( 0 ),
m_directorInitialized( false ),
2018-02-24 23:53:32 +01:00
m_onEnterEventDone( false )
2017-08-08 13:53:47 +02:00
{
m_id = 0;
m_currentStance = Stance::Passive;
m_onlineStatus = 0;
m_queuedZoneing = nullptr;
m_status = ActorStatus::Idle;
2017-10-01 01:14:43 +02:00
m_invincibilityType = InvincibilityType::InvincibilityNone;
m_modelType = ModelType::Human;
2017-08-08 13:53:47 +02:00
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 ) );
m_objSpawnIndexAllocator.init( MAX_DISPLAYED_EOBJS );
m_actorSpawnIndexAllocator.init( MAX_DISPLAYED_ACTORS, true );
2017-08-08 13:53:47 +02:00
}
Core::Entity::Player::~Player()
{
}
2018-03-05 22:10:14 +11:00
void Core::Entity::Player::injectPacket( std::string path )
{
2018-03-09 00:06:44 +01:00
auto pServerZone = g_fw.get< ServerZone >();
auto session = pServerZone->getSession( getId() );
2018-03-05 22:10:14 +11:00
if( session )
session->getZoneConnection()->injectPacket( path, *this );
}
2017-08-08 13:53:47 +02:00
// 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;
}
2017-09-11 18:59:50 +02:00
uint8_t Core::Entity::Player::getGmRank() const
{
return m_gmRank;
}
void Core::Entity::Player::setGmRank( uint8_t rank )
{
m_gmRank = rank;
}
bool Core::Entity::Player::getGmInvis() const
{
return m_gmInvis;
}
void Core::Entity::Player::setGmInvis( bool invis )
{
m_gmInvis = invis;
}
2017-08-08 13:53:47 +02:00
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;
}
2017-08-08 13:53:47 +02:00
Core::Common::OnlineStatus Core::Entity::Player::getOnlineStatus()
{
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
if( !pExdData )
return OnlineStatus::Online;
uint32_t statusDisplayOrder = 0xFF14;
uint32_t applicableStatus = 0;
2018-04-19 23:02:24 +10:00
for( uint32_t i = 0; i < std::numeric_limits< decltype( m_onlineStatus ) >::digits; i++ )
{
bool bit = ( m_onlineStatus >> i ) & 1;
if( !bit )
continue;
auto pOnlineStatus = pExdData->get< Data::OnlineStatus >( i );
if( !pOnlineStatus )
continue;
2017-08-08 13:53:47 +02:00
if( pOnlineStatus->priority < statusDisplayOrder )
{
// todo: also check that the status can actually be set here, otherwise we need to ignore it (and ban the player obv)
statusDisplayOrder = pOnlineStatus->priority;
applicableStatus = i;
return static_cast< OnlineStatus >( applicableStatus );
}
}
2017-08-08 13:53:47 +02:00
}
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 )
2017-08-08 13:53:47 +02:00
{
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcPrepareZoning > preparePacket( getId() );
2017-08-08 13:53:47 +02:00
preparePacket.data().targetZone = targetZone;
preparePacket.data().fadeOutTime = fadeOutTime;
preparePacket.data().animation = animation;
2017-10-01 18:38:58 +02:00
preparePacket.data().fadeOut = static_cast< uint8_t >( fadeOut ? 1 : 0 );
2017-08-08 13:53:47 +02:00
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() );
2017-08-08 13:53:47 +02:00
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
auto classInfo = pExdData->get< Core::Data::ClassJob >( job );
auto tribeInfo = pExdData->get< Core::Data::Tribe >( tribe );
auto paramGrowthInfo = pExdData->get< Core::Data::ParamGrow >( level );
2017-08-08 13:53:47 +02:00
// TODO: put formula somewhere else...
float base = Math::CalcStats::calculateBaseStat( getAsPlayer() );
2017-08-08 13:53:47 +02:00
2018-01-31 11:43:22 +01:00
m_baseStats.str = static_cast< uint32_t >( base * ( static_cast< float >( classInfo->modifierStrength ) / 100 ) + tribeInfo->sTR );
m_baseStats.dex = static_cast< uint32_t >( base * ( static_cast< float >( classInfo->modifierDexterity ) / 100 ) + tribeInfo->dEX );
m_baseStats.vit = static_cast< uint32_t >( base * ( static_cast< float >( classInfo->modifierVitality ) / 100 ) + tribeInfo->vIT );
m_baseStats.inte = static_cast< uint32_t >( base * ( static_cast< float >( classInfo->modifierIntelligence ) / 100 ) + tribeInfo->iNT );
m_baseStats.mnd = static_cast< uint32_t >( base * ( static_cast< float >( classInfo->modifierMind ) / 100 ) + tribeInfo->mND );
m_baseStats.pie = static_cast< uint32_t >( base * ( static_cast< float >( classInfo->modifierPiety ) / 100 ) + tribeInfo->pIE );
m_baseStats.skillSpeed = paramGrowthInfo->baseSpeed;
m_baseStats.spellSpeed = paramGrowthInfo->baseSpeed;
m_baseStats.accuracy = paramGrowthInfo->baseSpeed;
m_baseStats.critHitRate = paramGrowthInfo->baseSpeed;
m_baseStats.attackPotMagic = paramGrowthInfo->baseSpeed;
m_baseStats.healingPotMagic = paramGrowthInfo->baseSpeed;
m_baseStats.tenacity = paramGrowthInfo->baseSpeed;
2017-08-08 13:53:47 +02:00
m_baseStats.max_mp = Math::CalcStats::calculateMaxMp( getAsPlayer() );
m_baseStats.max_hp = Math::CalcStats::calculateMaxHp( getAsPlayer() );
2017-08-08 13:53:47 +02:00
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 );
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::setAutoattack( bool mode )
2017-08-08 13:53:47 +02:00
{
m_bAutoattack = mode;
m_lastAttack = Util::getTimeMs();
}
bool Core::Entity::Player::isAutoattackOn() const
{
return m_bAutoattack;
}
void Core::Entity::Player::sendStats()
{
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcPlayerStats > statPacket( getId() );
2017-08-08 13:53:47 +02:00
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 )
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
auto pTeriMgr = g_fw.get< TerritoryMgr >();
auto data = pExdData->get< Core::Data::Aetheryte >( aetheryteId );
2017-08-08 13:53:47 +02:00
if( data == nullptr )
2017-08-08 13:53:47 +02:00
{
return;
}
setStateFlag( PlayerStateFlag::BetweenAreas );
2018-03-09 00:06:44 +01:00
auto targetPos = pTeriMgr->getTerritoryPosition( data->levelId );
Common::FFXIVARR_POSITION3 pos;
pos.x = 0;
pos.y = 0;
pos.z = 0;
float rot = 0;
2018-02-18 01:50:20 +01:00
if( targetPos != nullptr )
{
2018-02-18 01:50:20 +01:00
pos = targetPos->getTargetPosition();
rot = targetPos->getTargetRotation();
}
2017-08-08 13:53:47 +02:00
2018-03-09 00:06:44 +01:00
sendDebug( "Teleport: " + pExdData->get< Core::Data::PlaceName >( data->placeName )->name + " " +
pExdData->get< Core::Data::PlaceName >( data->aethernetName )->name +
2018-01-31 11:43:22 +01:00
"(" + std::to_string( data->territory ) + ")" );
2017-08-08 13:53:47 +02:00
// TODO: this should be simplified and a type created in server_common/common.h.
if( type == 1 ) // teleport
{
2018-01-31 11:43:22 +01:00
prepareZoning( data->territory, true, 1, 112 ); // TODO: Really?
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x04 ) );
setZoningType( Common::ZoneingType::Teleport );
}
else if( type == 2 ) // aethernet
{
2018-01-31 11:43:22 +01:00
prepareZoning( data->territory, true, 1, 112 );
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x04 ) );
setZoningType( Common::ZoneingType::Teleport );
}
else if( type == 3 ) // return
{
2018-01-31 11:43:22 +01:00
prepareZoning( data->territory, true, 1, 111 );
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x03 ) );
setZoningType( Common::ZoneingType::Return );
2017-08-08 13:53:47 +02:00
}
2018-01-31 11:43:22 +01:00
m_queuedZoneing = boost::make_shared< QueuedZoning >( data->territory, pos, Util::getTimeMs(), rot );
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::forceZoneing( uint32_t zoneId )
{
m_queuedZoneing = boost::make_shared< QueuedZoning >( zoneId, getPos(), Util::getTimeMs(), 0.f );
2017-08-08 13:53:47 +02:00
//performZoning( zoneId, Common::ZoneingType::None, getPos() );
}
2017-08-10 16:31:48 +02:00
void Core::Entity::Player::returnToHomepoint()
{
setZoningType( Common::ZoneingType::Return );
teleport( getHomepoint(), 3 );
}
2017-08-08 13:53:47 +02:00
void Core::Entity::Player::setZone( uint32_t zoneId )
{
2018-03-09 00:06:44 +01:00
auto pTeriMgr = g_fw.get< TerritoryMgr >();
2018-02-24 23:53:32 +01:00
m_onEnterEventDone = false;
2018-03-09 00:06:44 +01:00
if( !pTeriMgr->movePlayer( zoneId, getAsPlayer() ) )
{
// todo: this will require proper handling, for now just return the player to their previous area
m_pos = m_prevPos;
m_rot = m_prevRot;
m_zoneId = m_prevZoneId;
2018-03-09 00:06:44 +01:00
if( !pTeriMgr->movePlayer( m_zoneId, getAsPlayer() ) )
return;
}
2018-01-28 22:36:43 +01:00
sendZonePackets();
2017-08-08 13:53:47 +02:00
}
bool Core::Entity::Player::setInstance( uint32_t instanceContentId )
{
2018-03-09 00:06:44 +01:00
auto pTeriMgr = g_fw.get< TerritoryMgr >();
2018-02-24 23:53:32 +01:00
m_onEnterEventDone = false;
2018-03-09 00:06:44 +01:00
auto instance = pTeriMgr->getInstanceZonePtr( instanceContentId );
if( !instance )
return false;
return setInstance( instance );
}
bool Core::Entity::Player::setInstance( ZonePtr instance )
{
2018-02-24 23:53:32 +01:00
m_onEnterEventDone = false;
if( !instance )
return false;
2018-03-09 00:06:44 +01:00
auto pTeriMgr = g_fw.get< TerritoryMgr >();
// zoning within the same zone won't cause the prev data to be overwritten
if( instance->getTerritoryId() != m_zoneId )
{
m_prevPos = m_pos;
m_prevRot = m_rot;
m_prevZoneId = m_zoneId;
}
2018-03-09 00:06:44 +01:00
if( !pTeriMgr->movePlayer( instance, getAsPlayer() ) )
return false;
sendZonePackets();
return true;
}
bool Core::Entity::Player::exitInstance()
{
2018-03-09 00:06:44 +01:00
auto pTeriMgr = g_fw.get< TerritoryMgr >();
if( !pTeriMgr->movePlayer( m_prevZoneId, getAsPlayer() ) )
return false;
m_pos = m_prevPos;
m_rot = m_prevRot;
m_zoneId = m_prevZoneId;
sendZonePackets();
return true;
}
2017-08-08 13:53:47 +02:00
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()
{
m_actorSpawnIndexAllocator.freeAllSpawnIndexes();
2017-08-08 13:53:47 +02:00
}
uint8_t Core::Entity::Player::getSpawnIdForActorId( uint32_t actorId )
{
return m_actorSpawnIndexAllocator.getNextFreeSpawnIndex( actorId );
2017-08-08 13:53:47 +02:00
}
bool Core::Entity::Player::isActorSpawnIdValid( uint8_t spawnIndex )
2017-08-08 13:53:47 +02:00
{
return m_actorSpawnIndexAllocator.isSpawnIndexValid( spawnIndex );
2017-08-08 13:53:47 +02:00
}
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;
2017-08-08 13:53:47 +02:00
}
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
2017-08-08 13:53:47 +02:00
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
2017-08-08 13:53:47 +02:00
int32_t offset = 4;
2018-03-09 00:06:44 +01:00
auto info = pExdData->get< Core::Data::Map >( pExdData->get< Core::Data::TerritoryType >( getCurrentZone()->getTerritoryId() )->map );
2018-01-31 11:43:22 +01:00
if( info->discoveryArrayByte )
offset = 4 + 2 * info->discoveryIndex;
2017-08-08 13:53:47 +02:00
else
2018-01-31 11:43:22 +01:00
offset = 324 + 4 * info->discoveryIndex;
2017-08-08 13:53:47 +02:00
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();
2018-03-09 00:06:44 +01:00
uint32_t exp = ( pExdData->get< Core::Data::ParamGrow >( level )->expToNext * 5 / 100 );
2017-08-08 13:53:47 +02:00
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 );
//}
2017-08-08 13:53:47 +02:00
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<QueuedZoning>( 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 ) );
}
2017-10-09 20:17:43 +02:00
void Core::Entity::Player::learnSong( uint8_t songId, uint32_t itemId )
2017-10-09 20:09:49 +02:00
{
uint16_t index;
uint8_t value;
Util::valueToFlagByteIndexValue( songId, value, index );
m_orchestrion[index] |= value;
2017-10-09 20:17:43 +02:00
queuePacket( ActorControlPacket143( getId(), ToggleOrchestrionUnlock, songId, 1, itemId ) );
2017-10-09 20:09:49 +02:00
}
2017-08-08 13:53:47 +02:00
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;
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::gainExp( uint32_t amount )
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
2017-08-08 13:53:47 +02:00
uint32_t currentExp = getExp();
uint16_t level = getLevel();
2018-03-09 00:06:44 +01:00
uint32_t neededExpToLevel = pExdData->get< Core::Data::ParamGrow >( level )->expToNext;
2017-08-08 13:53:47 +02:00
2018-03-09 00:06:44 +01:00
uint32_t neededExpToLevelplus1 = pExdData->get< Core::Data::ParamGrow >( level + 1 )->expToNext;
2017-08-08 13:53:47 +02:00
queuePacket( ActorControlPacket143( getId(), GainExpMsg, static_cast< uint8_t >( getClass() ), amount ) );
if( level >= 70 ) // temporary fix for leveling over levelcap
2017-08-08 13:53:47 +02:00
{
queuePacket( ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), amount ) );
return;
}
if( ( currentExp + amount ) >= neededExpToLevel )
{
// levelup
2017-10-01 18:38:58 +02:00
amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelplus1 ?
neededExpToLevelplus1 - 1 :
( currentExp + amount - neededExpToLevel );
2017-08-08 13:53:47 +02:00
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()
{
2018-02-13 19:37:04 +01:00
setLevel( getLevel() + 1 );
2017-08-08 13:53:47 +02:00
calculateStats();
sendStats();
sendStatusUpdate();
m_hp = getMaxHp();
m_mp = getMaxMp();
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcStatusEffectList > effectListPacket( getId() );
effectListPacket.data().classId = static_cast< uint8_t > ( getClass() );
effectListPacket.data().level1 = getLevel();
2017-08-08 13:53:47 +02:00
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 );
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcUpdateClassInfo > classInfoPacket( getId() );
classInfoPacket.data().classId = static_cast< uint8_t > ( getClass() );
classInfoPacket.data().level1 = getLevel();
2017-08-08 13:53:47 +02:00
classInfoPacket.data().level = getLevel();
classInfoPacket.data().nextLevelIndex = getLevel();
classInfoPacket.data().currentExp = getExp();
queuePacket( classInfoPacket );
}
void Core::Entity::Player::sendStatusUpdate( bool toSelf )
{
sendToInRangeSet( UpdateHpMpTpPacket( *this ), true );
2017-08-08 13:53:47 +02:00
}
uint8_t Core::Entity::Player::getLevel() const
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
uint8_t classJobIndex = pExdData->get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
2017-08-08 13:53:47 +02:00
return static_cast< uint8_t >( m_classArray[classJobIndex] );
}
uint8_t Core::Entity::Player::getLevelForClass( Common::ClassJob pClass ) const
2017-08-09 14:38:46 +02:00
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
uint8_t classJobIndex = pExdData->get< Core::Data::ClassJob >( static_cast< uint8_t >( pClass ) )->expArrayIndex;
return static_cast< uint8_t >( m_classArray[classJobIndex] );
2017-08-09 14:38:46 +02:00
}
2017-08-08 13:53:47 +02:00
uint32_t Core::Entity::Player::getExp() const
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
uint8_t classJobIndex = pExdData->get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
2017-08-08 13:53:47 +02:00
return m_expArray[classJobIndex];
}
void Core::Entity::Player::setExp( uint32_t amount )
2018-03-09 00:06:44 +01:00
{ auto pExdData = g_fw.get< Data::ExdDataGenerated >();
uint8_t classJobIndex = pExdData->get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
2017-08-08 13:53:47 +02:00
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 )
2017-08-08 13:53:47 +02:00
{
m_class = classJob;
uint8_t level = getLevel();
if( getHp() > getMaxHp() )
m_hp = getMaxHp();
if( getMp() > getMaxMp() )
m_mp = getMaxMp();
m_tp = 0;
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcPlayerClassInfo > classInfoPacket( getId() );
classInfoPacket.data().classId = static_cast< uint8_t >( getClass() );
2017-08-08 13:53:47 +02:00
classInfoPacket.data().level = getLevel();
queuePacket( classInfoPacket );
sendToInRangeSet( ActorControlPacket142( getId(), ClassJobChange, 0x04 ), true );
sendStatusUpdate( true );
}
void Core::Entity::Player::setLevel( uint8_t level )
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
uint8_t classJobIndex = pExdData->get< Core::Data::ClassJob >( static_cast< uint8_t >( getClass() ) )->expArrayIndex;
2017-08-08 13:53:47 +02:00
m_classArray[classJobIndex] = level;
}
void Core::Entity::Player::setLevelForClass( uint8_t level, Common::ClassJob classjob )
2017-08-09 14:38:46 +02:00
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
uint8_t classJobIndex = pExdData->get< Core::Data::ClassJob >( static_cast< uint8_t >( classjob ) )->expArrayIndex;
if( m_classArray[classJobIndex] == 0 )
insertDbClass( classJobIndex );
m_classArray[classJobIndex] = level;
2017-08-09 14:38:46 +02:00
}
2017-08-08 13:53:47 +02:00
void Core::Entity::Player::sendModel()
{
ModelEquipPacket modelEquip( *getAsPlayer() );
2017-08-08 13:53:47 +02:00
sendToInRangeSet( modelEquip, true );
}
uint32_t Core::Entity::Player::getModelForSlot( Inventory::EquipSlot slot )
{
return m_modelEquip[slot];
}
2017-10-02 16:00:26 +02:00
void Core::Entity::Player::setModelForSlot( Inventory::EquipSlot slot, uint32_t val )
{
m_modelEquip[slot] = val;
}
2017-08-08 13:53:47 +02:00
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 ) )
2017-08-08 13:53:47 +02:00
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 )
2017-08-08 13:53:47 +02:00
{
2018-03-09 00:06:44 +01:00
auto pLog = g_fw.get< Logger >();
pLog->debug( "[" + std::to_string( pTarget->getId() ) + "] Spawning " +
2017-08-08 13:53:47 +02:00
getName() + " for " +
pTarget->getName() );
PlayerSpawnPacket spawnActor( *getAsPlayer(), *pTarget );
2017-08-08 13:53:47 +02:00
pTarget->queuePacket( spawnActor );
}
// despawn
void Core::Entity::Player::despawn( Entity::PlayerPtr pTarget )
2017-08-08 13:53:47 +02:00
{
auto pPlayer = pTarget;
2018-03-09 00:06:44 +01:00
auto pLog = g_fw.get< Logger >();
pLog->debug( "despawning " + getName() + " for " + pTarget->getName() );
2018-02-21 18:06:52 +01:00
2017-08-08 13:53:47 +02:00
pPlayer->freePlayerSpawnId( getId() );
pPlayer->queuePacket( ActorControlPacket143( getId(), DespawnZoneScreenMsg, 0x04, getId(), 0x01 ) );
}
Core::Entity::ActorPtr Core::Entity::Player::lookupTargetById( uint64_t targetId )
2017-08-10 22:06:05 +02:00
{
ActorPtr targetActor;
auto inRange = getInRangeActors(true);
2017-08-10 22:06:05 +02:00
for( auto actor : inRange )
{
if( actor->getId() == targetId )
targetActor = actor;
}
return targetActor;
2017-08-10 22:06:05 +02:00
}
2017-08-08 13:53:47 +02:00
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;
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVGCAffiliation > gcAffPacket( getId() );
2017-08-08 13:53:47 +02:00
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;
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVGCAffiliation > gcAffPacket( getId() );
2017-08-08 13:53:47 +02:00
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 );
}
2017-10-01 18:38:58 +02:00
const uint8_t* Core::Entity::Player::getStateFlags() const
2017-08-08 13:53:47 +02:00
{
return m_stateFlags;
}
2017-08-10 22:06:05 +02:00
bool Core::Entity::Player::actionHasCastTime( uint32_t actionId ) //TODO: Add logic for special cases
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
auto actionInfoPtr = pExdData->get< Core::Data::Action >( actionId );
2018-01-31 11:43:22 +01:00
if( actionInfoPtr->preservesCombo )
2017-08-15 16:19:55 +02:00
return false;
2018-01-31 11:43:22 +01:00
return actionInfoPtr->cast100ms != 0;
2017-08-15 16:19:55 +02:00
2017-08-10 22:06:05 +02:00
}
bool Core::Entity::Player::hasStateFlag( Common::PlayerStateFlag flag ) const
2017-08-08 13:53:47 +02:00
{
int32_t iFlag = static_cast< uint32_t >( flag );
2017-08-08 13:53:47 +02:00
uint16_t index;
uint8_t value;
Util::valueToFlagByteIndexValue( iFlag, value, index );
return ( m_stateFlags[index] & value ) != 0;
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::setStateFlag( Common::PlayerStateFlag flag )
2017-08-08 13:53:47 +02:00
{
2018-01-11 14:59:39 +01:00
auto prevOnlineStatus = getOnlineStatus();
int32_t iFlag = static_cast< uint32_t >( flag );
2017-08-08 13:53:47 +02:00
uint16_t index;
uint8_t value;
Util::valueToFlagByteIndexValue( iFlag, value, index );
m_stateFlags[index] |= value;
2018-01-11 14:59:39 +01:00
sendStateFlags();
auto newOnlineStatus = getOnlineStatus();
if( prevOnlineStatus != newOnlineStatus )
sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon,
static_cast< uint8_t >( getOnlineStatus() ) ), true );
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::setStateFlags( std::vector< Common::PlayerStateFlag > flags )
{
for( const auto& flag : flags )
{
2018-01-11 14:59:39 +01:00
setStateFlag( flag );
}
}
2017-08-08 13:53:47 +02:00
void Core::Entity::Player::sendStateFlags()
{
queuePacket( PlayerStateFlagsPacket( *getAsPlayer() ) );
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::unsetStateFlag( Common::PlayerStateFlag flag )
2017-08-08 13:53:47 +02:00
{
if( !hasStateFlag( flag ) )
return;
2018-01-11 14:59:39 +01:00
auto prevOnlineStatus = getOnlineStatus();
int32_t iFlag = static_cast< uint32_t >( flag );
2017-08-08 13:53:47 +02:00
uint16_t index;
uint8_t value;
Util::valueToFlagByteIndexValue( iFlag, value, index );
m_stateFlags[index] ^= value;
2018-01-11 14:59:39 +01:00
sendStateFlags();
auto newOnlineStatus = getOnlineStatus();
2017-08-08 13:53:47 +02:00
2018-01-11 14:59:39 +01:00
if( prevOnlineStatus != newOnlineStatus )
sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon,
static_cast< uint8_t >( getOnlineStatus() ) ), true );
2017-08-08 13:53:47 +02:00
}
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;
2018-01-27 23:52:49 +01:00
if( getCurrentZone()->getTerritoryId() != m_queuedZoneing->m_targetZone )
2017-08-08 13:53:47 +02:00
{
2017-08-13 23:39:04 +02:00
performZoning( m_queuedZoneing->m_targetZone, targetPos, m_queuedZoneing->m_targetRotation);
2017-08-08 13:53:47 +02:00
}
else
{
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcActorSetPos > setActorPosPacket( getId() );
2017-08-08 13:53:47 +02:00
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 );
setPos( targetPos );
2017-08-08 13:53:47 +02:00
}
m_queuedZoneing.reset();
return;
}
if( m_hp <= 0 && m_status != ActorStatus::Dead )
die();
if( !isAlive() )
return;
updateStatusEffects();
2017-08-08 13:53:47 +02:00
m_lastUpdate = currTime;
if( !checkAction() )
{
if( m_targetId && m_currentStance == Entity::Chara::Stance::Active && isAutoattackOn() )
2017-08-08 13:53:47 +02:00
{
auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0, Inventory::EquipSlot::MainHand );
2017-10-01 18:38:58 +02:00
// @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_inRangeActor )
2017-08-08 13:53:47 +02:00
{
if( actor->getId() == m_targetId && actor->getAsChara()->isAlive() && mainWeap )
2017-08-08 13:53:47 +02:00
{
// 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 )
2017-08-08 13:53:47 +02:00
range = 25;
if( Math::Util::distance(getPos().x, getPos().y, getPos().z,
actor->getPos().x, actor->getPos().y, actor->getPos().z) <= range )
2017-08-08 13:53:47 +02:00
{
if( ( currTime - m_lastAttack ) > mainWeap->getDelay() )
{
m_lastAttack = currTime;
autoAttack( actor->getAsChara() );
2017-08-08 13:53:47 +02:00
}
}
}
}
}
}
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 )
{
2018-03-09 00:06:44 +01:00
auto pScriptMgr = g_fw.get< Scripting::ScriptMgr >();
pScriptMgr->onMobKill( *getAsPlayer(), nameId );
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::freePlayerSpawnId( uint32_t actorId )
{
auto spawnId = m_actorSpawnIndexAllocator.freeUsedSpawnIndex( actorId );
2017-08-08 13:53:47 +02:00
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcActorFreeSpawn > freeActorSpawnPacket( getId() );
2017-08-08 13:53:47 +02:00
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()
2017-08-08 13:53:47 +02:00
{
return m_classArray;
}
const uint16_t* Core::Entity::Player::getClassArray() const
2017-08-08 13:53:47 +02:00
{
return m_classArray;
}
const uint8_t* Core::Entity::Player::getLookArray() const
2017-08-08 13:53:47 +02:00
{
return m_customize;
}
const uint32_t* Core::Entity::Player::getModelArray() const
2017-08-08 13:53:47 +02:00
{
return m_modelEquip;
}
uint32_t* Core::Entity::Player::getExpArray()
2017-08-08 13:53:47 +02:00
{
return m_expArray;
}
const uint32_t* Core::Entity::Player::getExpArray() const
2017-08-08 13:53:47 +02:00
{
return m_expArray;
}
uint8_t* Core::Entity::Player::getHowToArray()
2017-08-08 13:53:47 +02:00
{
return m_howTo;
}
const uint8_t* Core::Entity::Player::getHowToArray() const
2017-08-08 13:53:47 +02:00
{
return m_howTo;
}
const uint8_t* Core::Entity::Player::getUnlockBitmask() const
2017-08-08 13:53:47 +02:00
{
return m_unlocks;
}
const uint8_t* Core::Entity::Player::getOrchestrionBitmask() const
2017-10-09 20:09:49 +02:00
{
return m_orchestrion;
}
const uint8_t* Core::Entity::Player::getMountGuideBitmask() const
{
return m_mountGuide;
}
2017-08-08 13:53:47 +02:00
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
2017-08-08 13:53:47 +02:00
{
return m_gcRank;
}
void Core::Entity::Player::queuePacket( Network::Packets::GamePacketPtr pPacket )
2017-08-08 13:53:47 +02:00
{
2018-03-09 00:06:44 +01:00
auto pServerZone = g_fw.get< ServerZone >();
auto pSession = pServerZone->getSession( m_id );
2017-08-08 13:53:47 +02:00
2017-11-28 00:09:36 +01:00
if( !pSession )
return;
auto pZoneCon = pSession->getZoneConnection();
if( pZoneCon )
pZoneCon->queueOutPacket( pPacket );
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::queueChatPacket( Network::Packets::GamePacketPtr pPacket )
{
2018-03-09 00:06:44 +01:00
auto pServerZone = g_fw.get< ServerZone >();
auto pSession = pServerZone->getSession( m_id );
2017-11-28 00:09:36 +01:00
if( !pSession )
return;
2017-11-28 00:09:36 +01:00
auto pChatCon = pSession->getChatConnection();
if( pChatCon )
pChatCon->queueOutPacket( pPacket );
}
2017-08-08 13:53:47 +02:00
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 )
2017-08-08 13:53:47 +02:00
{
m_pos = pos;
m_zoneId = zoneId;
m_bMarkedForZoning = true;
setRot( rotation );
2017-08-08 13:53:47 +02:00
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 ) );
2017-08-08 13:53:47 +02:00
}
void Core::Entity::Player::sendDebug( const std::string& message ) //Grey Text
{
queuePacket( ChatPacket( *getAsPlayer(), ChatType::ServerDebug, message ) );
2017-08-08 13:53:47 +02:00
}
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::initHateSlotQueue()
{
m_freeHateSlotQueue = std::queue< uint8_t >();
for( int32_t i = 1; i < 26; i++ )
2017-08-08 13:53:47 +02:00
m_freeHateSlotQueue.push( i );
}
void Core::Entity::Player::sendHateList()
{
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcHateList > hateListPacket( getId() );
2017-08-08 13:53:47 +02:00
hateListPacket.data().numEntries = m_actorIdTohateSlotMap.size();
auto it = m_actorIdTohateSlotMap.begin();
for( int32_t i = 0; it != m_actorIdTohateSlotMap.end(); ++it, i++ )
2017-08-08 13:53:47 +02:00
{
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()
2017-10-09 00:31:31 -03:00
{
return m_titleList;
}
2018-02-17 01:20:40 +01:00
const uint8_t* Core::Entity::Player::getTitleList() const
{
return m_titleList;
}
2017-10-09 14:13:23 +02:00
uint16_t Core::Entity::Player::getTitle() const
2017-10-09 02:06:31 -03:00
{
return m_activeTitle;
2017-10-09 02:06:31 -03:00
}
2017-10-09 00:31:31 -03:00
void Core::Entity::Player::addTitle( uint16_t titleId )
{
uint16_t index;
uint8_t value;
Util::valueToFlagByteIndexValue( titleId, value, index );
2017-10-09 00:31:31 -03:00
m_titleList[index] |= value;
2017-10-09 00:31:31 -03:00
}
2017-10-04 23:30:45 -03:00
void Core::Entity::Player::setTitle( uint16_t titleId )
2017-10-04 23:19:38 -03:00
{
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;
2017-10-04 23:19:38 -03:00
sendToInRangeSet( ActorControlPacket142( getId(), SetTitle, titleId ), true );
}
2017-10-06 00:13:29 +02:00
void Core::Entity::Player::setEquipDisplayFlags( uint8_t state )
{
2017-10-06 00:13:29 +02:00
m_equipDisplayFlags = state;
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcEquipDisplayFlags > paramPacket( getId() );
2017-10-06 00:13:29 +02:00
paramPacket.data().bitmask = m_equipDisplayFlags;
sendToInRangeSet( paramPacket, true );
}
2017-10-06 00:13:29 +02:00
uint8_t Core::Entity::Player::getEquipDisplayFlags() const
{
2017-10-06 00:13:29 +02:00
return m_equipDisplayFlags;
}
void Core::Entity::Player::mount( uint32_t id )
{
2017-11-21 17:39:10 +11:00
m_mount = id;
sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus, static_cast< uint8_t >( Entity::Chara::ActorStatus::Mounted )), true );
2017-10-18 17:54:17 +02:00
sendToInRangeSet( ActorControlPacket143( getId(), 0x39e, 12 ), true ); //?
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcMount > mountPacket( getId() );
2017-11-21 17:39:10 +11:00
mountPacket.data().id = id;
sendToInRangeSet( mountPacket, true );
2017-10-18 17:54:17 +02:00
}
void Core::Entity::Player::dismount()
{
2017-11-28 00:09:36 +01:00
sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus,
static_cast< uint8_t >( Entity::Chara::ActorStatus::Idle )), true );
2017-10-18 17:54:17 +02:00
sendToInRangeSet( ActorControlPacket143( getId(), ActorControlType::Dismount, 1 ), true );
2017-11-21 17:39:10 +11:00
m_mount = 0;
2017-10-18 17:54:17 +02:00
}
uint8_t Core::Entity::Player::getCurrentMount() const
{
2017-11-21 17:39:10 +11:00
return m_mount;
}
void Core::Entity::Player::autoAttack( CharaPtr pTarget )
2017-08-08 13:53:47 +02:00
{
2017-11-28 00:09:36 +01:00
auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0,
Inventory::EquipSlot::MainHand );
pTarget->onActionHostile( *this );
2017-08-08 13:53:47 +02:00
//uint64_t tick = Util::getTimeMs();
//srand(static_cast< uint32_t >(tick));
uint32_t damage = static_cast< uint32_t >( mainWeap->getAutoAttackDmg() );
2017-08-08 13:53:47 +02:00
uint32_t variation = 0 + rand() % 3;
if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer )
2017-08-08 13:53:47 +02:00
{
ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() );
2017-08-08 13:53:47 +02:00
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( getRot() );
2017-08-08 13:53:47 +02:00
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;
2017-08-08 13:53:47 +02:00
effectPacket.data().effects[0].unknown_3 = 7;
sendToInRangeSet(effectPacket, true);
}
else
{
ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() );
2017-08-08 13:53:47 +02:00
effectPacket.data().targetId = pTarget->getId();
effectPacket.data().actionAnimationId = 7;
2017-11-28 00:09:36 +01:00
// effectPacket.data().unknown_2 = variation;
2017-08-08 13:53:47 +02:00
effectPacket.data().numEffects = 1;
effectPacket.data().unknown_61 = 1;
effectPacket.data().unknown_62 = 1;
effectPacket.data().actionTextId = 7;
effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRot() );
2017-08-08 13:53:47 +02:00
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;
2017-08-08 13:53:47 +02:00
effectPacket.data().effects[0].unknown_3 = 71;
sendToInRangeSet(effectPacket, true);
}
pTarget->takeDamage(damage);
2017-08-08 13:53:47 +02:00
}
2017-08-14 17:10:19 +02:00
/////////////////////////////
// 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
2017-11-28 00:09:36 +01:00
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();
2017-11-28 00:09:36 +01:00
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?
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcEorzeaTimeOffset > packet ( getId() );
packet.data().timestamp = timestamp;
// Send to single player
queuePacket( packet );
}
2018-01-28 22:36:43 +01:00
2018-02-17 01:20:40 +01:00
void Core::Entity::Player::setTerritoryId( uint32_t territoryId )
2018-01-28 22:36:43 +01:00
{
m_zoneId = territoryId;
}
2018-02-17 01:20:40 +01:00
uint32_t Core::Entity::Player::getTerritoryId() const
2018-01-28 22:36:43 +01:00
{
return m_zoneId;
}
2018-02-17 01:20:40 +01:00
void Core::Entity::Player::sendZonePackets()
2018-01-28 22:36:43 +01:00
{
2018-03-05 22:10:14 +11:00
getCurrentZone()->onBeforePlayerZoneIn( *this );
2018-01-28 22:36:43 +01:00
ZoneChannelPacket< FFXIVIpcInit > initPacket( getId() );
initPacket.data().charId = getId();
queuePacket( initPacket );
sendInventory();
if( isLogin() )
{
2018-03-05 22:10:14 +11:00
queuePacket( ActorControlPacket143( getId(), SetCharaGearParamUI, m_equipDisplayFlags, 1 ) );
2018-01-28 22:36:43 +01:00
}
// set flags, will be reset automatically by zoning ( only on client side though )
//setStateFlag( PlayerStateFlag::BetweenAreas );
//setStateFlag( PlayerStateFlag::BetweenAreas1 );
2018-01-28 22:36:43 +01:00
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( *this );
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 );
m_itemLevel = getInventory()->calculateEquippedGearItemLevel();
sendItemLevel();
}
ZoneChannelPacket< FFXIVIpcInitZone > initZonePacket( getId() );
initZonePacket.data().zoneId = getCurrentZone()->getTerritoryId();
initZonePacket.data().weatherId = static_cast< uint8_t >( getCurrentZone()->getCurrentWeather() );
initZonePacket.data().bitmask = 0x1;
initZonePacket.data().unknown5 = 0x2A;
2018-02-03 02:11:29 +11:00
initZonePacket.data().festivalId = getCurrentZone()->getCurrentFestival();
2018-01-28 22:36:43 +01:00
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();
2018-03-05 22:10:14 +11:00
getCurrentZone()->onPlayerZoneIn( *this );
2018-01-28 22:36:43 +01:00
m_bMarkedForZoning = false;
}
2018-02-17 01:20:40 +01:00
void Core::Entity::Player::setDirectorInitialized( bool isInitialized )
{
m_directorInitialized = isInitialized;
}
2018-02-17 01:20:40 +01:00
bool Core::Entity::Player::isDirectorInitialized() const
{
return m_directorInitialized;
}
2018-02-17 01:20:40 +01:00
2018-02-18 01:50:20 +01:00
void Core::Entity::Player::sendTitleList()
2018-02-17 01:20:40 +01:00
{
ZoneChannelPacket< FFXIVIpcPlayerTitleList > titleListPacket( getId() );
memcpy( titleListPacket.data().titleList, getTitleList(), sizeof( titleListPacket.data().titleList ) );
queuePacket( titleListPacket );
}
2018-02-18 01:50:20 +01:00
2018-04-19 22:34:45 +10:00
void Core::Entity::Player::sendZoneInPackets( uint32_t param1, uint32_t param2 = 0, uint32_t param3 = 0, uint32_t param4 = 0, bool shouldSetStatus = false )
{
auto zoneInPacket = ActorControlPacket143( getId(), ZoneIn, param1, param2, param3, param4 );
auto SetStatusPacket = ActorControlPacket142( getId(), SetStatus, static_cast< uint8_t >( Entity::Chara::ActorStatus::Idle ) );
2018-04-19 22:30:23 +10:00
if( getGmInvis() )
sendToInRangeSet( zoneInPacket, true );
2018-04-19 22:34:45 +10:00
if( shouldSetStatus )
sendToInRangeSet( SetStatusPacket );
else
queuePacket( zoneInPacket );
2018-04-19 22:34:45 +10:00
if ( shouldSetStatus )
queuePacket( SetStatusPacket );
setZoningType( Common::ZoneingType::None );
unsetStateFlag( PlayerStateFlag::BetweenAreas );
}
2018-02-18 01:50:20 +01:00
void Core::Entity::Player::finishZoning()
{
switch( getZoningType() )
{
case ZoneingType::None:
sendZoneInPackets( 0x01 );
2018-02-18 01:50:20 +01:00
break;
case ZoneingType::Teleport:
sendZoneInPackets( 0x01, 0, 0, 110 );
2018-02-18 01:50:20 +01:00
break;
case ZoneingType::Return:
case ZoneingType::ReturnDead:
{
if( getStatus() == Entity::Chara::ActorStatus::Dead )
2018-02-18 01:50:20 +01:00
{
resetHp();
resetMp();
setStatus( Entity::Chara::ActorStatus::Idle );
sendZoneInPackets( 0x01, 0x01, 0, 111, true );
2018-02-18 01:50:20 +01:00
}
else
sendZoneInPackets( 0x01, 0x00, 0, 111 );
2018-02-18 01:50:20 +01:00
}
break;
2018-02-18 01:50:20 +01:00
case ZoneingType::FadeIn:
break;
}
}
2018-02-24 23:53:32 +01:00
void Core::Entity::Player::emote( uint32_t emoteId, uint64_t targetId )
2018-02-18 01:50:20 +01:00
{
sendToInRangeSet( ActorControlPacket144( getId(), ActorControlType::Emote, emoteId, 0, 0, 0, targetId ) );
}
2018-02-24 23:53:32 +01:00
void Core::Entity::Player::teleportQuery( uint16_t aetheryteId )
2018-02-18 01:50:20 +01:00
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
2018-02-18 01:50:20 +01:00
// TODO: only register this action if enough gil is in possession
2018-03-09 00:06:44 +01:00
auto targetAetheryte = pExdData->get< Core::Data::Aetheryte >( aetheryteId );
2018-02-18 01:50:20 +01:00
if( targetAetheryte )
{
2018-03-09 00:06:44 +01:00
auto fromAetheryte = pExdData->get< Core::Data::Aetheryte >(
pExdData->get< Core::Data::TerritoryType >( getZoneId() )->aetheryte );
2018-02-18 01:50:20 +01:00
// calculate cost - does not apply for favorite points or homepoints neither checks for aether tickets
auto cost = static_cast< uint16_t > ( ( sqrt( pow( fromAetheryte->aetherstreamX - targetAetheryte->aetherstreamX, 2 ) +
pow( fromAetheryte->aetherstreamY - targetAetheryte->aetherstreamY, 2 ) ) / 2 ) + 100 );
// cap at 999 gil
cost = cost > uint16_t{999} ? uint16_t{999} : cost;
bool insufficientGil = getCurrency( Inventory::CurrencyType::Gil ) < cost;
// TODO: figure out what param1 really does
queuePacket( ActorControlPacket143( getId(), TeleportStart, insufficientGil ? 2 : 0, aetheryteId ) );
if( !insufficientGil )
{
Action::ActionPtr pActionTeleport;
pActionTeleport = Action::make_ActionTeleport( getAsPlayer(), aetheryteId, cost );
setCurrentAction( pActionTeleport );
}
}
}
uint8_t Core::Entity::Player::getNextObjSpawnIndexForActorId( uint32_t actorId )
{
return m_objSpawnIndexAllocator.getNextFreeSpawnIndex( actorId );
}
void Core::Entity::Player::resetObjSpawnIndex()
{
m_objSpawnIndexAllocator.freeAllSpawnIndexes();
}
void Core::Entity::Player::freeObjSpawnIndexForActorId( uint32_t actorId )
{
2018-03-01 23:17:35 +01:00
auto spawnId = m_objSpawnIndexAllocator.freeUsedSpawnIndex( actorId );
ZoneChannelPacket< FFXIVIpcObjectDespawn > freeObjectSpawnPacket( getId() );
freeObjectSpawnPacket.data().spawnIndex = spawnId;
queuePacket( freeObjectSpawnPacket );
}
bool Core::Entity::Player::isObjSpawnIndexValid( uint8_t index )
{
return m_objSpawnIndexAllocator.isSpawnIndexValid( index );
2018-02-24 23:53:32 +01:00
}
void Core::Entity::Player::setOnEnterEventDone( bool isDone )
{
m_onEnterEventDone = isDone;
}
bool Core::Entity::Player::isOnEnterEventDone() const
{
return m_onEnterEventDone;
}