Files
DarkflameServer/dScripts/02_server/Map/NT/NtParadoxTeleServer.cpp
Aaron Kimbrell f7f5d304d0 refactor: death, stun, buff and knockback game messages as structs
Converts the combat messages to NetGameMsgs in CombatMessages.{h,cpp}:
Die, Resurrect, SetResurrectRestoreValues, SetPlayerAllowedRespawn
(SendToClient, as before), Knockback, SetStunned, SetStunImmunity,
SetStatusImmunity, AddBuff, RemoveBuff, AddRunSpeedModifier,
RemoveRunSpeedModifier and DeactivateBubbleBuffFromServer, and the
received RequestDie, RequestSmashPlayer, RequestResurrect, Resurrect,
ActivateBubbleBuff and DeactivateBubbleBuff. Smash and UnSmash move
here from GameMessages.h (Smash's ghostCapacity is ghostOpacity, the
client's name) and gain a Deserialize.

The callers (DestroyableComponent, BuffComponent,
ControllablePhysicsComponent, QuickBuildComponent, RacingControl,
RailActivator and the scripts) build the structs. SendResurrect's
respawn timer moves to DestroyableComponent::Resurrect. The received
messages are registered in GameMessageHandler's map and their switch
cases are deleted, along with the unused HandleRequestDie overload and
the Send* functions nothing called (SendSmash, SendUnSmash, the run
speed modifiers, SendActivateBubbleBuffFromServer). Handler logic is
unchanged.

No wire change and no change in recipients. Verified byte for byte
against a frozen verbatim copy of the old functions over an input grid
(every optional field, bool patterns, empty and long strings), received
messages compared with the old handlers' read sequences and truncated
payloads rejected, hand computed golden bytes, round trips, and a
deliberate width mutation made the tests fail.

Known difference from the client, not changed here: DLU writes
SetStatusImmunity's nine flags in its own order; the client reads them
alphabetically (GameMessage::SetStatusImmunity::Serialize @ 00d8f140).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:53 -05:00

140 lines
4.0 KiB
C++

#include "NtParadoxTeleServer.h"
#include "GameMessages.h"
#include "EffectsMessages.h"
#include "CombatMessages.h"
#include "EntityManager.h"
#include "MissionComponent.h"
#include "eMissionTaskType.h"
#include "RenderComponent.h"
#include "eStateChangeType.h"
void NtParadoxTeleServer::OnStartup(Entity* self) {
self->SetProximityRadius(5, "teleport");
}
void NtParadoxTeleServer::OnPlayerLoaded(Entity* self, Entity* player) {
}
void NtParadoxTeleServer::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
if (status != "ENTER" || !entering->IsPlayer() || name != "teleport") return;
auto* player = entering;
const auto playerID = player->GetObjectID();
const auto iter = m_TeleportingPlayerTable.find(playerID);
if (iter == m_TeleportingPlayerTable.end()) m_TeleportingPlayerTable[playerID] = false;
const auto bPlayerBeingTeleported = m_TeleportingPlayerTable[playerID];
if (player->IsPlayer() && !bPlayerBeingTeleported) {
GameMessages::SetStunned stun;
stun.target = playerID;
stun.StateChangeType = eStateChangeType::PUSH;
stun.bCantAttack = true;
stun.bCantEquip = true;
stun.bCantInteract = true;
stun.bCantJump = true;
stun.bCantMove = true;
stun.bCantTurn = true;
stun.bCantUseItem = true;
stun.Send(player->GetSystemAddress());
auto animTime = RenderComponent::PlayAnimation(player, u"teledeath", 4.0f);
if (animTime == 0.0f) animTime = 2.0f;
self->AddCallbackTimer(animTime, [this, self, playerID]() {
auto* player = Game::entityManager->GetEntity(playerID);
if (player == nullptr) {
return;
}
TeleportPlayer(self, player);
});
}
auto* missionComponent = player->GetComponent<MissionComponent>();
if (missionComponent != nullptr) {
missionComponent->Progress(eMissionTaskType::SCRIPT, self->GetLOT());
}
}
void NtParadoxTeleServer::TeleportPlayer(Entity* self, Entity* player) {
auto destinationGroup = self->GetVar<std::u16string>(u"teleGroup");
auto* destination = self;
if (!destinationGroup.empty()) {
const auto& groupObjs = Game::entityManager->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(destinationGroup));
if (!groupObjs.empty()) {
destination = groupObjs[0];
}
}
const auto destPosition = destination->GetPosition();
const auto destRotation = destination->GetRotation();
auto teleCinematic = self->GetVar<std::u16string>(u"Cinematic");
if (!teleCinematic.empty()) {
const auto teleCinematicUname = teleCinematic;
GameMessages::PlayCinematic cinematic;
cinematic.target = player->GetObjectID();
cinematic.pathName = teleCinematicUname;
cinematic.Send(player->GetSystemAddress());
}
GameMessages::SendTeleport(player->GetObjectID(), destPosition, destRotation, player->GetSystemAddress(), true);
RenderComponent::PlayAnimation(player, u"paradox-teleport-in", 4.0f);
const auto animTime = 2;
const auto playerID = player->GetObjectID();
self->AddCallbackTimer(animTime, [this, self, playerID]() {
auto* player = Game::entityManager->GetEntity(playerID);
if (player == nullptr) {
return;
}
UnlockPlayer(self, player);
});
const auto useSound = self->GetVar<std::string>(u"sound1");
if (!useSound.empty()) {
GameMessages::PlayNDAudioEmitter(player->GetObjectID(), useSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
}
void NtParadoxTeleServer::UnlockPlayer(Entity* self, Entity* player) {
const auto playerID = player->GetObjectID();
m_TeleportingPlayerTable[playerID] = false;
GameMessages::SetStunned stun;
stun.target = playerID;
stun.StateChangeType = eStateChangeType::POP;
stun.bCantAttack = true;
stun.bCantEquip = true;
stun.bCantInteract = true;
stun.bCantJump = true;
stun.bCantMove = true;
stun.bCantTurn = true;
stun.bCantUseItem = true;
stun.Send(player->GetSystemAddress());
auto teleCinematic = self->GetVar<std::u16string>(u"Cinematic");
if (!teleCinematic.empty()) {
const auto teleCinematicUname = teleCinematic;
GameMessages::EndCinematic endCinematic;
endCinematic.target = player->GetObjectID();
endCinematic.pathName = teleCinematicUname;
endCinematic.Send(player->GetSystemAddress());
}
}