mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
Converts PlayAnimation, PlayNDAudioEmitter, PlayEmbeddedEffectOnAllClientsNearObject,
PlayFXEffect, StopFXEffect, BroadcastTextToChatbox, Play2DAmbientSound,
Stop2DAmbientSound, UIMessageServerToSingleClient, UIMessageServerToAllClients,
StartCelebrationEffect, DisplayMessageBox, DisplayChatBubble, ChangeIdleFlags,
SetNameBillboardState, ShowBillboardInteractIcon, PlayCinematic, EndCinematic,
SlashCommandTextFeedback, PlayEmote and SetEmoteLockState (21 old Send
functions, 23 with overloads) and the received MessageBoxRespond,
ChoiceBoxRespond, CinematicUpdate and PlayEmote to NetGameMsgs in
EffectsMessages.{h,cpp}. The high traffic messages get a constructor for their
required fields. UI messages own their AMF arguments. Every caller is switched,
the received messages are registered in GameMessageHandler's map, and the old
functions and switch cases are deleted. Handlers are copied verbatim.
No wire change and no change in recipients: functions that always broadcast
whatever address they were given are sent with Send(UNASSIGNED_SYSTEM_ADDRESS),
functions that only did SEND_PACKET use SendToClient. Quirks are kept and
documented on the structs (PlayAnimation's UTF-8 sized name, the always written
null terminator in BroadcastTextToChatbox, StartCelebrationEffect always
writing celebrationID, SetNameBillboardState having no payload).
Verified byte for byte against a frozen verbatim copy of the old functions over
an input grid, to one client and broadcast; received messages compared with the
old handlers' read sequences and every truncated payload rejected; hand
computed golden bytes; round trips; a deliberate width mutation made the tests
fail. The byte-equality helper gains a Broadcast mode for functions that
ignored their address.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
144 lines
5.5 KiB
C++
144 lines
5.5 KiB
C++
#include <algorithm>
|
|
#include "RailActivatorComponent.h"
|
|
#include "CDClientManager.h"
|
|
#include "CDRailActivatorComponent.h"
|
|
#include "Entity.h"
|
|
#include "GameMessages.h"
|
|
#include "EffectsMessages.h"
|
|
#include "QuickBuildComponent.h"
|
|
#include "Game.h"
|
|
#include "Logger.h"
|
|
#include "RenderComponent.h"
|
|
#include "EntityManager.h"
|
|
#include "eStateChangeType.h"
|
|
|
|
RailActivatorComponent::RailActivatorComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
|
|
const auto tableData = CDClientManager::GetTable<CDRailActivatorComponentTable>()->GetEntryByID(componentID);
|
|
|
|
m_Path = parent->GetVar<std::u16string>(u"rail_path");
|
|
m_PathDirection = parent->GetVar<bool>(u"rail_path_direction");
|
|
m_PathStart = parent->GetVar<uint32_t>(u"rail_path_start");
|
|
|
|
m_StartSound = tableData.startSound;
|
|
m_loopSound = tableData.loopSound;
|
|
m_StopSound = tableData.stopSound;
|
|
|
|
m_StartAnimation = tableData.startAnimation;
|
|
m_LoopAnimation = tableData.loopAnimation;
|
|
m_StopAnimation = tableData.stopAnimation;
|
|
|
|
m_StartEffect = tableData.startEffectID;
|
|
m_LoopEffect = tableData.loopEffectID;
|
|
m_StopEffect = tableData.stopEffectID;
|
|
|
|
m_DamageImmune = parent->GetVar<bool>(u"rail_activator_damage_immune");
|
|
m_NoAggro = parent->GetVar<bool>(u"rail_no_aggro");
|
|
m_NotifyArrived = parent->GetVar<bool>(u"rail_notify_activator_arrived");
|
|
m_ShowNameBillboard = parent->GetVar<bool>(u"rail_show_name_billboard");
|
|
m_UseDB = parent->GetVar<bool>(u"rail_use_db");
|
|
m_CameraLocked = tableData.cameraLocked;
|
|
m_CollisionEnabled = tableData.playerCollision;
|
|
}
|
|
|
|
RailActivatorComponent::~RailActivatorComponent() = default;
|
|
|
|
void RailActivatorComponent::OnUse(Entity* originator) {
|
|
auto* quickBuildComponent = m_Parent->GetComponent<QuickBuildComponent>();
|
|
if (quickBuildComponent != nullptr && quickBuildComponent->GetState() != eQuickBuildState::COMPLETED)
|
|
return;
|
|
|
|
if (quickBuildComponent != nullptr) {
|
|
// Don't want it to be destroyed while a player is using it
|
|
quickBuildComponent->SetResetTime(quickBuildComponent->GetResetTime() + 10.0f);
|
|
}
|
|
|
|
m_EntitiesOnRail.push_back(originator->GetObjectID());
|
|
|
|
// Start the initial effects
|
|
if (!m_StartEffect.second.empty()) {
|
|
GameMessages::PlayFXEffect(originator->GetObjectID(), m_StartEffect.first, m_StartEffect.second, std::to_string(m_StartEffect.first)).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
}
|
|
|
|
float animationLength = 0.5f;
|
|
if (!m_StartAnimation.empty()) {
|
|
animationLength = RenderComponent::PlayAnimation(originator, m_StartAnimation);
|
|
}
|
|
|
|
const auto originatorID = originator->GetObjectID();
|
|
|
|
m_Parent->AddCallbackTimer(animationLength, [originatorID, this]() {
|
|
auto* originator = Game::entityManager->GetEntity(originatorID);
|
|
|
|
if (originator == nullptr) {
|
|
return;
|
|
}
|
|
|
|
GameMessages::SendStartRailMovement(originator->GetObjectID(), m_Path, m_StartSound,
|
|
m_loopSound, m_StopSound, originator->GetSystemAddress(),
|
|
m_PathStart, m_PathDirection, m_DamageImmune, m_NoAggro, m_NotifyArrived,
|
|
m_ShowNameBillboard, m_CameraLocked, m_CollisionEnabled, m_UseDB, m_ComponentID,
|
|
m_Parent->GetObjectID());
|
|
});
|
|
}
|
|
|
|
void RailActivatorComponent::OnRailMovementReady(Entity* originator) const {
|
|
// Stun the originator
|
|
GameMessages::SendSetStunned(originator->GetObjectID(), eStateChangeType::PUSH, originator->GetSystemAddress(), LWOOBJID_EMPTY,
|
|
true, true, true, true, true, true, true
|
|
);
|
|
|
|
if (std::find(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(), originator->GetObjectID()) != m_EntitiesOnRail.end()) {
|
|
// Stop the initial effects
|
|
if (!m_StartEffect.second.empty()) {
|
|
GameMessages::StopFXEffect(originator->GetObjectID(), false, std::to_string(m_StartEffect.first)).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
}
|
|
|
|
// Start the looping effects
|
|
if (!m_LoopEffect.second.empty()) {
|
|
GameMessages::PlayFXEffect(originator->GetObjectID(), m_LoopEffect.first, m_LoopEffect.second, std::to_string(m_LoopEffect.first)).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
}
|
|
|
|
if (!m_LoopAnimation.empty()) {
|
|
RenderComponent::PlayAnimation(originator, m_LoopAnimation);
|
|
}
|
|
|
|
GameMessages::SendSetRailMovement(originator->GetObjectID(), m_PathDirection, m_Path, m_PathStart,
|
|
originator->GetSystemAddress(), m_ComponentID,
|
|
m_Parent->GetObjectID());
|
|
}
|
|
}
|
|
|
|
void RailActivatorComponent::OnCancelRailMovement(Entity* originator) {
|
|
// Remove the stun from the originator
|
|
GameMessages::SendSetStunned(originator->GetObjectID(), eStateChangeType::POP, originator->GetSystemAddress(), LWOOBJID_EMPTY,
|
|
true, true, true, true, true, true, true
|
|
);
|
|
|
|
auto* quickBuildComponent = m_Parent->GetComponent<QuickBuildComponent>();
|
|
|
|
if (quickBuildComponent != nullptr) {
|
|
// Set back reset time
|
|
quickBuildComponent->SetResetTime(quickBuildComponent->GetResetTime() - 10.0f);
|
|
}
|
|
|
|
if (std::find(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(), originator->GetObjectID()) != m_EntitiesOnRail.end()) {
|
|
// Stop the looping effects
|
|
if (!m_LoopEffect.second.empty()) {
|
|
GameMessages::StopFXEffect(originator->GetObjectID(), false, std::to_string(m_LoopEffect.first)).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
}
|
|
|
|
// Start the end effects
|
|
if (!m_StopEffect.second.empty()) {
|
|
GameMessages::PlayFXEffect(originator->GetObjectID(), m_StopEffect.first, m_StopEffect.second, std::to_string(m_StopEffect.first)).Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
}
|
|
|
|
if (!m_StopAnimation.empty()) {
|
|
RenderComponent::PlayAnimation(originator, m_StopAnimation);
|
|
}
|
|
|
|
// Remove the player after they've signalled they're done railing
|
|
m_EntitiesOnRail.erase(std::remove(m_EntitiesOnRail.begin(), m_EntitiesOnRail.end(),
|
|
originator->GetObjectID()), m_EntitiesOnRail.end());
|
|
}
|
|
}
|