1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00

replace old inline generation of effects packet with a wrapper

This commit is contained in:
NotAdam 2018-07-21 23:32:10 +10:00
parent 9d7896043c
commit c84beee30a
8 changed files with 146 additions and 105 deletions

View file

@ -423,6 +423,13 @@ namespace Common {
CritDirectHitDamage = 3 CritDirectHitDamage = 3
}; };
enum ActionEffectDisplayType : uint8_t
{
HideActionName = 0,
ShowActionName = 1,
ShowItemName = 2,
};
enum class ActionCollisionType : uint8_t enum class ActionCollisionType : uint8_t
{ {
None, None,

View file

@ -299,7 +299,7 @@ struct FFXIVIpcUpdateHpMpTp : FFXIVIpcBasePacket<UpdateHpMpTp>
* Structural representation of the packet sent by the server * Structural representation of the packet sent by the server
* for battle actions * for battle actions
*/ */
struct effectEntry struct EffectEntry
{ {
Common::ActionEffectType effectType; Common::ActionEffectType effectType;
Common::ActionHitSeverityType hitSeverity; Common::ActionHitSeverityType hitSeverity;
@ -322,24 +322,19 @@ struct FFXIVIpcEffect : FFXIVIpcBasePacket<Effect>
uint16_t hiddenAnimation; // if 0, always shows animation, otherwise hides it. counts up by 1 for each animation skipped on a caster uint16_t hiddenAnimation; // if 0, always shows animation, otherwise hides it. counts up by 1 for each animation skipped on a caster
int16_t rotation; uint16_t rotation;
uint16_t actionAnimationId; // the animation that is played by the casting character uint16_t actionAnimationId; // the animation that is played by the casting character
uint8_t unknown1E; // can be 0,1,2 - maybe other values? - doesn't do anything? uint8_t unknown1E; // can be 0,1,2 - maybe other values? - doesn't do anything?
/* effectDisplayType Common::ActionEffectDisplayType effectDisplayType;
* 0 = only show damage/heal amount
* 1 = show damage/heal amount + name
* 2 = show damage/heal amount + name but name is from item.exd, name id is actionId
*/
uint8_t effectDisplayType;
uint8_t unknown20; // is read by handler, runs code which gets the LODWORD of animationLockTime (wtf?) uint8_t unknown20; // is read by handler, runs code which gets the LODWORD of animationLockTime (wtf?)
uint8_t numEffects; // ignores effects if 0, otherwise parses all of them uint8_t effectCount; // ignores effects if 0, otherwise parses all of them
uint32_t padding_22[2]; uint32_t padding_22[2];
effectEntry effects[8]; EffectEntry effects[8];
uint16_t padding_6A[3]; uint16_t padding_6A[3];

View file

@ -3,6 +3,7 @@
#include <Util/UtilMath.h> #include <Util/UtilMath.h>
#include <Logging/Logger.h> #include <Logging/Logger.h>
#include <Network/CommonActorControl.h> #include <Network/CommonActorControl.h>
#include <sapphire_zone/Network/PacketWrappers/EffectPacket.h>
#include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket143.h"
@ -73,19 +74,15 @@ void Core::Action::ActionMount::onFinish()
pPlayer->unsetStateFlag( PlayerStateFlag::Casting ); pPlayer->unsetStateFlag( PlayerStateFlag::Casting );
auto effectPacket = makeZonePacket< Server::FFXIVIpcEffect >( getId() ); auto effectPacket = boost::make_shared< Server::EffectPacket >( getId(), pPlayer->getId(), 4 );
effectPacket->setRotation( Math::Util::floatToUInt16Rot( pPlayer->getRot() ) );
effectPacket->data().animationTargetId = pPlayer->getId(); Server::EffectEntry effectEntry{};
effectPacket->data().actionAnimationId = m_id; effectEntry.effectType = ActionEffectType::Mount;
// Affects displaying action name next to number in floating text effectEntry.hitSeverity = ActionHitSeverityType::CritDamage;
//effectPacket->data().unknown_62 = 13; effectEntry.value = m_id;
effectPacket->data().actionAnimationId = 4;
effectPacket->data().numEffects = 1; effectPacket->addEffect( effectEntry );
effectPacket->data().rotation = Math::Util::floatToUInt16Rot( pPlayer->getRot() );
//effectPacket->data().effectTarget = INVALID_GAME_OBJECT_ID;
effectPacket->data().effects[0].effectType = ActionEffectType::Mount;
effectPacket->data().effects[0].hitSeverity = ActionHitSeverityType::CritDamage;
effectPacket->data().effects[0].value = m_id;
pPlayer->sendToInRangeSet( effectPacket, true ); pPlayer->sendToInRangeSet( effectPacket, true );

View file

@ -2,6 +2,8 @@
#include <Exd/ExdDataGenerated.h> #include <Exd/ExdDataGenerated.h>
#include <Logging/Logger.h> #include <Logging/Logger.h>
#include <Network/CommonActorControl.h> #include <Network/CommonActorControl.h>
#include <sapphire_zone/Network/PacketWrappers/EffectPacket.h>
#include <Util/UtilMath.h>
#include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket143.h"
@ -84,19 +86,12 @@ void Core::Action::ActionTeleport::onFinish()
pPlayer->setZoningType( ZoneingType::Teleport ); pPlayer->setZoningType( ZoneingType::Teleport );
auto effectPacket = makeZonePacket< Server::FFXIVIpcEffect >( getId() ); auto effectPacket = boost::make_shared< Server::EffectPacket >( getId(), pPlayer->getId(), 5 );
effectPacket->data().animationTargetId = pPlayer->getId(); effectPacket->setRotation( Math::Util::floatToUInt16Rot( pPlayer->getRot() ) );
effectPacket->data().actionAnimationId = 5;
//effectPacket.data().unknown_3 = 1;
effectPacket->data().actionAnimationId = 5;
effectPacket->data().numEffects = 1;
effectPacket->data().rotation = static_cast< uint16_t >( 0x8000 * ( ( pPlayer->getRot() + 3.1415926 ) ) / 3.1415926 );
effectPacket->data().effectTargetId = pPlayer->getId();
pPlayer->sendToInRangeSet( effectPacket, true ); pPlayer->sendToInRangeSet( effectPacket, true );
pPlayer->teleport( m_targetAetheryte ); pPlayer->teleport( m_targetAetheryte );
} }
void Core::Action::ActionTeleport::onInterrupt() void Core::Action::ActionTeleport::onInterrupt()

View file

@ -7,6 +7,7 @@
#include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/EffectPacket.h"
#include "Actor/Player.h" #include "Actor/Player.h"
@ -69,13 +70,9 @@ void Core::Action::EventItemAction::onFinish()
try try
{ {
auto effectPacket = makeZonePacket< Server::FFXIVIpcEffect >( m_pSource->getId() ); auto effectPacket = boost::make_shared< Server::EffectPacket >( m_pSource->getId(), m_additional, m_id );
effectPacket->data().animationTargetId = static_cast< uint32_t >( m_additional ); effectPacket->setAnimationId( 1 );
effectPacket->data().actionAnimationId = 1; effectPacket->setRotation( Math::Util::floatToUInt16Rot( m_pSource->getRot() ) );
effectPacket->data().actionId = m_id;
effectPacket->data().numEffects = 1;
effectPacket->data().rotation = Math::Util::floatToUInt16Rot( m_pSource->getRot() );
effectPacket->data().effectTargetId = static_cast< uint32_t >( m_additional );
m_pSource->getAsPlayer()->unsetStateFlag( Common::PlayerStateFlag::Casting ); m_pSource->getAsPlayer()->unsetStateFlag( Common::PlayerStateFlag::Casting );
m_pSource->sendToInRangeSet( effectPacket, true ); m_pSource->sendToInRangeSet( effectPacket, true );

View file

@ -4,6 +4,7 @@
#include <Exd/ExdDataGenerated.h> #include <Exd/ExdDataGenerated.h>
#include <utility> #include <utility>
#include <Network/CommonActorControl.h> #include <Network/CommonActorControl.h>
#include <sapphire_zone/Network/PacketWrappers/EffectPacket.h>
#include "Forwards.h" #include "Forwards.h"
#include "Action/Action.h" #include "Action/Action.h"
@ -399,21 +400,20 @@ void Core::Entity::Chara::autoAttack( CharaPtr pTarget )
uint16_t damage = static_cast< uint16_t >( 10 + rand() % 12 ); uint16_t damage = static_cast< uint16_t >( 10 + rand() % 12 );
uint32_t variation = static_cast< uint32_t >( 0 + rand() % 4 ); uint32_t variation = static_cast< uint32_t >( 0 + rand() % 4 );
auto ipcEffect = makeZonePacket< Server::FFXIVIpcEffect >( getId() ); auto effectPacket = boost::make_shared< Server::EffectPacket >( getId(), pTarget->getId(), 0x336 );
ipcEffect->data().animationTargetId = pTarget->getId(); effectPacket->setRotation( Math::Util::floatToUInt16Rot( getRot() ) );
ipcEffect->data().actionAnimationId = 0x366;
ipcEffect->data().actionId = 0x366;
ipcEffect->data().numEffects = 1;
ipcEffect->data().rotation = Math::Util::floatToUInt16Rot( getRot() );
ipcEffect->data().effectTargetId = pTarget->getId();
ipcEffect->data().effects[0].value = damage;
ipcEffect->data().effects[0].effectType = ActionEffectType::Damage;
ipcEffect->data().effects[0].hitSeverity = static_cast< ActionHitSeverityType >( variation );
sendToInRangeSet( ipcEffect ); Server::EffectEntry effectEntry{ };
effectEntry.value = damage;
effectEntry.effectType = ActionEffectType::Damage;
effectEntry.hitSeverity = static_cast< ActionHitSeverityType >( variation );
effectPacket->addEffect( effectEntry );
sendToInRangeSet( effectPacket );
if( isPlayer() ) if( isPlayer() )
getAsPlayer()->queuePacket( ipcEffect ); getAsPlayer()->queuePacket( effectPacket );
pTarget->takeDamage( damage ); pTarget->takeDamage( damage );
} }
@ -440,16 +440,8 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u
// Todo: Effect packet generator. 90% of this is basically setting params and it's basically unreadable. // Todo: Effect packet generator. 90% of this is basically setting params and it's basically unreadable.
// Prepare packet. This is seemingly common for all packets in the action handler. // Prepare packet. This is seemingly common for all packets in the action handler.
auto effectPacket = boost::make_shared< Server::EffectPacket >( getId(), target.getId(), actionId );
auto effectPacket = makeZonePacket< Server::FFXIVIpcEffect >( getId() ); effectPacket->setRotation( Math::Util::floatToUInt16Rot( getRot() ) );
effectPacket->data().animationTargetId = target.getId();
effectPacket->data().actionAnimationId = actionId;
//effectPacket->data().unknown_62 = 1; // Affects displaying action name next to number in floating text
//effectPacket->data().globalEffectCounter = 1; // This seems to have an effect on the "double-cast finish" animation
effectPacket->data().actionId = actionId;
effectPacket->data().numEffects = 1;
effectPacket->data().rotation = Math::Util::floatToUInt16Rot( getRot() );
effectPacket->data().effectTargetId = target.getId();
// Todo: for each actor, calculate how much damage the calculated value should deal to them - 2-step damage calc. we only have 1-step // Todo: for each actor, calculate how much damage the calculated value should deal to them - 2-step damage calc. we only have 1-step
switch( type ) switch( type )
@ -457,10 +449,12 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u
case ActionEffectType::Damage: case ActionEffectType::Damage:
{ {
effectPacket->data().effects[0].value = static_cast< uint16_t >( param1 ); Server::EffectEntry effectEntry{};
effectPacket->data().effects[0].effectType = ActionEffectType::Damage; effectEntry.value = static_cast< uint16_t >( param1 );
effectPacket->data().effects[0].hitSeverity = ActionHitSeverityType::NormalDamage; effectEntry.effectType = ActionEffectType::Damage;
//effectPacket->data().effects[0].unknown_3 = 7; effectEntry.hitSeverity = ActionHitSeverityType::NormalDamage;
effectPacket->addEffect( effectEntry );
if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 ) if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 )
{ {
@ -484,8 +478,7 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u
for( const auto& pHitActor : actorsCollided ) for( const auto& pHitActor : actorsCollided )
{ {
effectPacket->data().animationTargetId = pHitActor->getId(); effectPacket->setTargetActor( pHitActor->getId() );
effectPacket->data().effectTargetId = pHitActor->getId();
// todo: send to range of what? ourselves? when mob script hits this is going to be lacking // todo: send to range of what? ourselves? when mob script hits this is going to be lacking
sendToInRangeSet( effectPacket, true ); sendToInRangeSet( effectPacket, true );
@ -515,9 +508,12 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u
{ {
uint32_t calculatedHeal = Math::CalcBattle::calculateHealValue( getAsPlayer(), static_cast< uint32_t >( param1 ) ); uint32_t calculatedHeal = Math::CalcBattle::calculateHealValue( getAsPlayer(), static_cast< uint32_t >( param1 ) );
effectPacket->data().effects[0].value = calculatedHeal; Server::EffectEntry effectEntry{};
effectPacket->data().effects[0].effectType = ActionEffectType::Heal; effectEntry.value = calculatedHeal;
effectPacket->data().effects[0].hitSeverity = ActionHitSeverityType::NormalHeal; effectEntry.effectType = ActionEffectType::Heal;
effectEntry.hitSeverity = ActionHitSeverityType::NormalHeal;
effectPacket->addEffect( effectEntry );
if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 ) if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 )
{ {
@ -537,8 +533,7 @@ void Core::Entity::Chara::handleScriptSkill( uint32_t type, uint16_t actionId, u
for( auto pHitActor : actorsCollided ) for( auto pHitActor : actorsCollided )
{ {
effectPacket->data().animationTargetId = target.getId(); effectPacket->setTargetActor( pHitActor->getId() );
effectPacket->data().effectTargetId = pHitActor->getId();
sendToInRangeSet( effectPacket, true ); sendToInRangeSet( effectPacket, true );
pHitActor->getAsChara()->heal( calculatedHeal ); pHitActor->getAsChara()->heal( calculatedHeal );

View file

@ -7,6 +7,7 @@
#include <Exd/ExdDataGenerated.h> #include <Exd/ExdDataGenerated.h>
#include <Network/PacketContainer.h> #include <Network/PacketContainer.h>
#include <Network/CommonActorControl.h> #include <Network/CommonActorControl.h>
#include <Network/PacketWrappers/EffectPacket.h>
#include "Session.h" #include "Session.h"
#include "Player.h" #include "Player.h"
@ -1418,43 +1419,32 @@ void Core::Entity::Player::autoAttack( CharaPtr pTarget )
if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer ) if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer )
{ {
auto effectPacket = makeZonePacket< Server::FFXIVIpcEffect >( getId() ); auto effectPacket = boost::make_shared< Server::EffectPacket >( getId(), pTarget->getId(), 8 );
effectPacket->data().animationTargetId = pTarget->getId(); effectPacket->setRotation( Math::Util::floatToUInt16Rot( getRot() ) );
effectPacket->data().actionAnimationId = 8;
// effectPacket.data().unknown_2 = variation; Server::EffectEntry entry;
effectPacket->data().numEffects = 1; entry.value = damage;
//effectPacket->data().unknown_61 = 1; entry.effectType = Common::ActionEffectType::Damage;
//effectPacket->data().unknown_62 = 1; entry.hitSeverity = Common::ActionHitSeverityType::NormalDamage;
effectPacket->data().actionId = 8;
effectPacket->data().rotation = Math::Util::floatToUInt16Rot( getRot() ); effectPacket->addEffect( entry );
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 ); sendToInRangeSet( effectPacket, true );
} }
else else
{ {
auto effectPacket = boost::make_shared< Server::EffectPacket >( getId(), pTarget->getId(), 7 );
effectPacket->setRotation( Math::Util::floatToUInt16Rot( getRot() ) );
auto effectPacket = makeZonePacket< Server::FFXIVIpcEffect >( getId() ); Server::EffectEntry entry;
effectPacket->data().animationTargetId = pTarget->getId(); entry.value = damage;
effectPacket->data().actionAnimationId = 7; entry.effectType = Common::ActionEffectType::Damage;
// effectPacket.data().unknown_2 = variation; entry.hitSeverity = Common::ActionHitSeverityType::NormalDamage;
effectPacket->data().numEffects = 1;
//effectPacket->data().unknown_61 = 1; effectPacket->addEffect( entry );
//effectPacket->data().unknown_62 = 1;
effectPacket->data().actionId = 7;
effectPacket->data().rotation = Math::Util::floatToUInt16Rot( getRot() );
effectPacket->data().effectTargetId = 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 ); sendToInRangeSet( effectPacket, true );
} }
pTarget->takeDamage( damage ); pTarget->takeDamage( damage );

View file

@ -0,0 +1,65 @@
#ifndef SAPPHIRE_EFFECTPACKET_H
#define SAPPHIRE_EFFECTPACKET_H
#include <Network/GamePacketNew.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
#include "Forwards.h"
namespace Core {
namespace Network {
namespace Packets {
namespace Server {
class EffectPacket :
public ZoneChannelPacket< FFXIVIpcEffect >
{
public:
EffectPacket( uint64_t sourceId, uint32_t targetId, uint32_t actionId ) :
ZoneChannelPacket< FFXIVIpcEffect >( sourceId, targetId )
{
m_data.actionId = actionId;
m_data.actionAnimationId = static_cast< uint16_t >( actionId );
m_data.animationTargetId = targetId;
m_data.effectTargetId = targetId;
m_data.effectDisplayType = Common::ActionEffectDisplayType::ShowActionName;
}
void addEffect( const Server::EffectEntry& effect )
{
assert( m_data.effectCount <= 8 );
std::memcpy( &m_data.effects[m_data.effectCount++], &effect, sizeof( Server::EffectEntry ) );
}
void setAnimationId( const uint16_t animationId )
{
m_data.actionAnimationId = animationId;
}
void setEffectFlags( const uint32_t effectFlags )
{
m_data.effectFlags = effectFlags;
}
void setRotation( const uint16_t rotation )
{
m_data.rotation = rotation;
}
void setTargetActor( const uint32_t targetId )
{
m_data.animationTargetId = targetId;
m_data.effectTargetId = targetId;
FFXIVPacketBase::setTargetActor( targetId );
}
};
}
}
}
}
#endif //SAPPHIRE_EFFECTPACKET_H