2019-07-25 22:46:10 +10:00
|
|
|
#include "EffectBuilder.h"
|
|
|
|
#include "EffectResult.h"
|
|
|
|
|
2019-07-26 20:28:01 +10:00
|
|
|
#include <Actor/Player.h>
|
2019-07-25 22:46:10 +10:00
|
|
|
|
|
|
|
#include <Network/PacketWrappers/EffectPacket.h>
|
2022-01-06 20:25:50 +01:00
|
|
|
#include <Network/PacketWrappers/EffectPacket1.h>
|
2019-07-25 22:46:10 +10:00
|
|
|
|
|
|
|
#include <Territory/Territory.h>
|
|
|
|
|
|
|
|
#include <Util/Util.h>
|
|
|
|
#include <Util/UtilMath.h>
|
|
|
|
|
|
|
|
#include <Logging/Logger.h>
|
2022-01-10 23:50:44 +01:00
|
|
|
#include <Manager/TerritoryMgr.h>
|
|
|
|
#include <Service.h>
|
2019-07-25 22:46:10 +10:00
|
|
|
|
|
|
|
using namespace Sapphire;
|
|
|
|
using namespace Sapphire::World::Action;
|
|
|
|
using namespace Sapphire::Network::Packets;
|
2021-11-27 00:53:57 +01:00
|
|
|
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
2019-07-25 22:46:10 +10:00
|
|
|
|
2019-07-26 20:28:01 +10:00
|
|
|
EffectBuilder::EffectBuilder( Entity::CharaPtr source, uint32_t actionId, uint16_t sequence ) :
|
2019-07-25 22:46:10 +10:00
|
|
|
m_sourceChara( std::move( source ) ),
|
2019-07-26 20:28:01 +10:00
|
|
|
m_actionId( actionId ),
|
|
|
|
m_sequence( sequence )
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-27 13:59:35 +10:00
|
|
|
uint64_t EffectBuilder::getResultDelayMs()
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
|
|
|
// todo: actually figure this retarded shit out
|
|
|
|
|
2019-07-27 13:59:35 +10:00
|
|
|
return Common::Util::getTimeMs() + 850;
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
void EffectBuilder::addResultToActor( Entity::CharaPtr& chara, EffectResultPtr result )
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2022-01-10 19:31:21 -03:00
|
|
|
auto it = m_actorEffectsMap.find( chara->getId() );
|
|
|
|
if( it == m_actorEffectsMap.end() )
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2020-01-06 17:52:45 +09:00
|
|
|
// create a new one
|
2022-01-10 19:31:21 -03:00
|
|
|
auto resultList = std::vector< EffectResultPtr >();
|
2019-07-25 22:46:10 +10:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
resultList.push_back( std::move( result ) );
|
2019-07-25 22:46:10 +10:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
m_actorEffectsMap[ chara->getId() ] = resultList;
|
2020-01-06 17:52:45 +09:00
|
|
|
|
|
|
|
return;
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
it->second.push_back( std::move( result ) );
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|
|
|
|
|
2020-01-05 20:49:50 +09:00
|
|
|
void EffectBuilder::heal( Entity::CharaPtr& effectTarget, Entity::CharaPtr& healingTarget, uint32_t amount, Common::ActionHitSeverityType severity, Common::ActionEffectResultFlag flag )
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2020-01-05 20:49:50 +09:00
|
|
|
EffectResultPtr nextResult = make_EffectResult( healingTarget, getResultDelayMs() );
|
|
|
|
nextResult->heal( amount, severity, flag );
|
2022-01-10 19:31:21 -03:00
|
|
|
addResultToActor( effectTarget, nextResult );
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
2020-01-05 20:49:50 +09:00
|
|
|
void EffectBuilder::restoreMP( Entity::CharaPtr& target, Entity::CharaPtr& restoringTarget, uint32_t amount, Common::ActionEffectResultFlag flag )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2020-01-05 20:49:50 +09:00
|
|
|
EffectResultPtr nextResult = make_EffectResult( restoringTarget, getResultDelayMs() ); // restore mp source actor
|
|
|
|
nextResult->restoreMP( amount, flag );
|
2022-01-10 19:31:21 -03:00
|
|
|
addResultToActor( target, nextResult );
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
2020-01-05 20:49:50 +09:00
|
|
|
void EffectBuilder::damage( Entity::CharaPtr& effectTarget, Entity::CharaPtr& damagingTarget, uint32_t amount, Common::ActionHitSeverityType severity, Common::ActionEffectResultFlag flag )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2020-01-05 20:49:50 +09:00
|
|
|
EffectResultPtr nextResult = make_EffectResult( damagingTarget, getResultDelayMs() );
|
|
|
|
nextResult->damage( amount, severity, flag );
|
2022-01-10 19:31:21 -03:00
|
|
|
addResultToActor( damagingTarget, nextResult );
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
void EffectBuilder::startCombo( Entity::CharaPtr& target, uint16_t actionId )
|
|
|
|
{
|
|
|
|
EffectResultPtr nextResult = make_EffectResult( target, 0 );
|
|
|
|
nextResult->startCombo( actionId );
|
2022-01-10 19:31:21 -03:00
|
|
|
addResultToActor( target, nextResult );
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
2020-01-05 20:49:50 +09:00
|
|
|
void EffectBuilder::comboSucceed( Entity::CharaPtr& target )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
|
|
|
EffectResultPtr nextResult = make_EffectResult( target, 0 );
|
2020-01-05 20:49:50 +09:00
|
|
|
nextResult->comboSucceed();
|
2022-01-10 19:31:21 -03:00
|
|
|
addResultToActor( target, nextResult );
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|
|
|
|
|
2020-01-06 19:25:01 +09:00
|
|
|
void EffectBuilder::applyStatusEffect( Entity::CharaPtr& target, uint16_t statusId, uint8_t param )
|
|
|
|
{
|
|
|
|
EffectResultPtr nextResult = make_EffectResult( target, 0 );
|
|
|
|
nextResult->applyStatusEffect( statusId, param );
|
2022-01-10 19:31:21 -03:00
|
|
|
addResultToActor( target, nextResult );
|
2020-01-06 19:25:01 +09:00
|
|
|
}
|
|
|
|
|
2020-01-23 22:36:01 +09:00
|
|
|
void EffectBuilder::mount( Entity::CharaPtr& target, uint16_t mountId )
|
|
|
|
{
|
|
|
|
EffectResultPtr nextResult = make_EffectResult( target, getResultDelayMs() );
|
|
|
|
nextResult->mount( mountId );
|
2022-01-10 19:31:21 -03:00
|
|
|
addResultToActor( target, nextResult );
|
2020-01-23 22:36:01 +09:00
|
|
|
}
|
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
void EffectBuilder::buildAndSendPackets( const std::vector< Entity::CharaPtr >& targetList )
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2019-07-25 23:21:42 +10:00
|
|
|
Logger::debug( "EffectBuilder result: " );
|
2022-01-10 19:31:21 -03:00
|
|
|
Logger::debug( "Targets afflicted: {}", targetList.size() );
|
2020-01-05 17:09:27 +09:00
|
|
|
|
2022-01-10 23:50:44 +01:00
|
|
|
auto& teriMgr = Common::Service< Sapphire::World::Manager::TerritoryMgr >::ref();
|
|
|
|
auto zone = teriMgr.getZoneByTerritoryTypeId( m_sourceChara->getTerritoryTypeId() );
|
|
|
|
|
|
|
|
auto globalSequence = zone ? zone->getNextEffectSequence() : 0;
|
|
|
|
|
2020-01-06 04:29:45 +09:00
|
|
|
do // we want to send at least one packet even nothing is hit so other players can see
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2022-01-10 19:31:21 -03:00
|
|
|
auto packet = buildNextEffectPacket( targetList );
|
2020-01-05 17:09:27 +09:00
|
|
|
m_sourceChara->sendToInRangeSet( packet, true );
|
|
|
|
}
|
2022-01-10 19:31:21 -03:00
|
|
|
while( !m_actorEffectsMap.empty() );
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
std::shared_ptr< FFXIVPacketBase > EffectBuilder::buildNextEffectPacket( const std::vector< Entity::CharaPtr >& targetList )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2022-01-10 19:31:21 -03:00
|
|
|
auto remainingTargetCount = targetList.size();
|
|
|
|
auto globalSequence = m_sourceChara->getCurrentTerritory()->getNextEffectSequence();
|
2019-07-25 22:46:10 +10:00
|
|
|
|
2022-01-10 23:50:44 +01:00
|
|
|
auto& teriMgr = Common::Service< Sapphire::World::Manager::TerritoryMgr >::ref();
|
|
|
|
auto zone = teriMgr.getZoneByTerritoryTypeId( m_sourceChara->getTerritoryTypeId() );
|
|
|
|
|
2020-01-05 17:09:27 +09:00
|
|
|
if( remainingTargetCount > 1 ) // use AoeEffect packets
|
|
|
|
{
|
2022-01-10 19:31:21 -03:00
|
|
|
auto effectPacket = std::make_shared< EffectPacket >( m_sourceChara->getId(), m_actionId );
|
|
|
|
effectPacket->setRotation( Common::Util::floatToUInt16Rot( m_sourceChara->getRot() ) );
|
|
|
|
effectPacket->setSequence( globalSequence, m_sequence );
|
|
|
|
effectPacket->setTargetActor( targetList[ 0 ]->getId() );
|
2020-01-05 17:09:27 +09:00
|
|
|
|
|
|
|
uint8_t targetIndex = 0;
|
2022-01-10 19:31:21 -03:00
|
|
|
for( auto it = m_actorEffectsMap.begin(); it != m_actorEffectsMap.end(); )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2022-01-10 19:31:21 -03:00
|
|
|
// get all effect results for an actor
|
|
|
|
auto actorResultList = it->second;
|
2020-01-05 17:09:27 +09:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
for( auto i = 0; i < actorResultList.size(); ++i )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2022-01-10 19:31:21 -03:00
|
|
|
auto result = actorResultList.data()[ i ];
|
|
|
|
auto effect = result->buildEffectEntry();
|
|
|
|
|
|
|
|
// if effect result is a source/caster effect
|
|
|
|
if( result->getTarget() == m_sourceChara )
|
|
|
|
{
|
|
|
|
effectPacket->addSourceEffect( effect );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
effectPacket->addTargetEffect( effect, result->getTarget()->getId() );
|
|
|
|
}
|
2022-01-10 23:50:44 +01:00
|
|
|
|
|
|
|
zone->addEffectResult( std::move( result ) );
|
|
|
|
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
actorResultList.clear();
|
|
|
|
it = m_actorEffectsMap.erase( it );
|
2020-01-05 17:09:27 +09:00
|
|
|
targetIndex++;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
if( targetIndex == 15 )
|
2020-01-05 17:09:27 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
return effectPacket;
|
2020-01-05 17:09:27 +09:00
|
|
|
}
|
2022-01-10 19:31:21 -03:00
|
|
|
else if( remainingTargetCount == 1 ) // use Effect for single target
|
2019-07-25 22:46:10 +10:00
|
|
|
{
|
2022-01-10 23:50:44 +01:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
Logger::debug( " - id: {}", targetList[0]->getId() );
|
|
|
|
Logger::debug( "------------------------------------------" );
|
2019-07-26 21:58:13 +10:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
auto effectPacket = std::make_shared< EffectPacket1 >( m_sourceChara->getId(), targetList[ 0 ]->getId(), m_actionId );
|
2019-07-25 22:46:10 +10:00
|
|
|
effectPacket->setRotation( Common::Util::floatToUInt16Rot( m_sourceChara->getRot() ) );
|
2022-01-10 19:31:21 -03:00
|
|
|
effectPacket->setSequence( globalSequence, m_sequence );
|
2019-07-25 22:46:10 +10:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
for( auto it = m_actorEffectsMap.begin(); it != m_actorEffectsMap.end(); )
|
2020-01-05 17:09:27 +09:00
|
|
|
{
|
2022-01-10 19:31:21 -03:00
|
|
|
// get all effect results for an actor
|
|
|
|
auto actorResultList = it->second;
|
2019-07-25 22:46:10 +10:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
for( auto i = 0; i < actorResultList.size(); ++i )
|
|
|
|
{
|
|
|
|
auto result = actorResultList.data()[ i ];
|
|
|
|
auto effect = result->buildEffectEntry();
|
|
|
|
|
|
|
|
// if effect result is a source/caster effect
|
|
|
|
if( result->getTarget() == m_sourceChara )
|
|
|
|
{
|
|
|
|
effectPacket->addSourceEffect( effect );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
effectPacket->addTargetEffect( effect );
|
|
|
|
}
|
|
|
|
|
2022-01-10 23:50:44 +01:00
|
|
|
zone->addEffectResult( std::move( result ) );
|
2022-01-10 19:31:21 -03:00
|
|
|
}
|
2019-07-25 22:46:10 +10:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
actorResultList.clear();
|
|
|
|
it = m_actorEffectsMap.erase( it );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_actorEffectsMap.clear();
|
2019-07-27 13:59:35 +10:00
|
|
|
|
2020-01-06 04:29:45 +09:00
|
|
|
return effectPacket;
|
|
|
|
}
|
|
|
|
else // nothing is hit, this only happens when using aoe and AoeEffect8 is used on retail
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto effectPacket = makeZonePacket< FFXIVIpcActionResult1 >( m_sourceChara->getId() );
|
|
|
|
|
|
|
|
effectPacket->data().ActionKey = m_actionId;
|
|
|
|
effectPacket->data().Action = static_cast< uint16_t >( m_actionId );
|
|
|
|
effectPacket->data().Target = m_sourceChara->getId();
|
|
|
|
effectPacket->data().MainTarget = static_cast< uint64_t >( m_sourceChara->getId() );
|
|
|
|
effectPacket->data().DirTarget = Common::Util::floatToUInt16Rot( m_sourceChara->getRot() );
|
|
|
|
effectPacket->data().Flag = Common::ActionEffectDisplayType::HideActionName;
|
|
|
|
effectPacket->data().RequestId = m_sequence;
|
|
|
|
effectPacket->data().ResultId = globalSequence;
|
2020-01-06 04:29:45 +09:00
|
|
|
|
2022-01-10 19:31:21 -03:00
|
|
|
m_actorEffectsMap.clear();
|
|
|
|
|
2020-01-05 17:09:27 +09:00
|
|
|
return effectPacket;
|
2019-07-27 13:59:35 +10:00
|
|
|
}
|
2019-07-25 22:46:10 +10:00
|
|
|
}
|