Files
DarkflameServer/dScripts/02_server/Map/FV/ImgBrickConsoleQB.cpp
Aaron Kimbrell dae1925d1a refactor: effects, audio, animation and UI text game messages as structs
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>
2026-09-28 22:30:51 -05:00

244 lines
7.3 KiB
C++

#include "ImgBrickConsoleQB.h"
#include "QuickBuildComponent.h"
#include "dZoneManager.h"
#include "EntityManager.h"
#include "GameMessages.h"
#include "EffectsMessages.h"
#include "MissionComponent.h"
#include "eMissionState.h"
#include "InventoryComponent.h"
#include "eTerminateType.h"
int32_t ImgBrickConsoleQB::ResetBricks = 30;
int32_t ImgBrickConsoleQB::ResetConsole = 60;
int32_t ImgBrickConsoleQB::ResetInteract = 45;
void ImgBrickConsoleQB::OnStartup(Entity* self) {
self->SetNetworkVar(u"used", false);
self->AddTimer("reset", ResetBricks);
}
void ImgBrickConsoleQB::OnUse(Entity* self, Entity* user) {
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
if (quickBuildComponent->GetState() == eQuickBuildState::COMPLETED) {
if (!self->GetNetworkVar<bool>(u"used")) {
const auto consoles = Game::entityManager->GetEntitiesInGroup("Console");
auto bothBuilt = false;
for (auto* console : consoles) {
auto* consoleQuickBuildComponent = console->GetComponent<QuickBuildComponent>();
if (consoleQuickBuildComponent->GetState() != eQuickBuildState::COMPLETED) {
continue;
}
console->CancelAllTimers();
if (console->GetNetworkVar<bool>(u"used")) {
bothBuilt = true;
}
}
if (bothBuilt) {
SmashCanister(self);
} else {
SpawnBrick(self);
}
self->AddTimer("Die", ResetInteract);
auto onFX = 0;
const auto location = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"console"));
if (location == "Left") {
onFX = 2776;
} else {
onFX = 2779;
}
const auto& facility = Game::entityManager->GetEntitiesInGroup("FacilityPipes");
if (!facility.empty()) {
GameMessages::StopFXEffect(facility[0]->GetObjectID(), true, location + "PipeEnergy").Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::PlayFXEffect(facility[0]->GetObjectID(), onFX, u"create", location + "PipeOn").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
}
auto* player = user;
auto* missionComponent = player->GetComponent<MissionComponent>();
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
if (missionComponent != nullptr && inventoryComponent != nullptr) {
if (missionComponent->GetMissionState(1302) == eMissionState::ACTIVE) {
inventoryComponent->RemoveItem(13074, 1, eInventoryType::ALL);
missionComponent->ForceProgressTaskType(1302, 1, 1);
}
if (missionComponent->GetMissionState(1926) == eMissionState::ACTIVE) {
inventoryComponent->RemoveItem(14472, 1, eInventoryType::ALL);
missionComponent->ForceProgressTaskType(1926, 1, 1);
}
}
self->SetNetworkVar(u"used", true);
GameMessages::SendTerminateInteraction(player->GetObjectID(), eTerminateType::FROM_INTERACTION, self->GetObjectID());
}
}
void ImgBrickConsoleQB::SpawnBrick(Entity* self) {
const auto netDevil = Game::zoneManager->GetSpawnersByName("MaelstromBug");
if (!netDevil.empty()) {
netDevil[0]->Reset();
netDevil[0]->Deactivate();
}
const auto brick = Game::zoneManager->GetSpawnersByName("Imagination");
if (!brick.empty()) {
brick[0]->Activate();
}
}
void ImgBrickConsoleQB::SmashCanister(Entity* self) {
const auto brick = Game::entityManager->GetEntitiesInGroup("Imagination");
if (!brick.empty()) {
GameMessages::PlayFXEffect(brick[0]->GetObjectID(), 122, u"create", "bluebrick").Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::PlayFXEffect(brick[0]->GetObjectID(), 1034, u"cast", "imaginationexplosion").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
const auto canisters = Game::entityManager->GetEntitiesInGroup("Canister");
for (auto* canister : canisters) {
canister->Smash(canister->GetObjectID(), eKillType::VIOLENT);
}
const auto canister = Game::zoneManager->GetSpawnersByName("BrickCanister");
if (!canister.empty()) {
canister[0]->Reset();
canister[0]->Deactivate();
}
}
void ImgBrickConsoleQB::OnQuickBuildComplete(Entity* self, Entity* target) {
auto energyFX = 0;
const auto location = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"console"));
if (location == "Left") {
energyFX = 2775;
} else {
energyFX = 2778;
}
const auto& facility = Game::entityManager->GetEntitiesInGroup("FacilityPipes");
if (!facility.empty()) {
GameMessages::StopFXEffect(facility[0]->GetObjectID(), true, location + "PipeOff").Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::PlayFXEffect(facility[0]->GetObjectID(), energyFX, u"create", location + "PipeEnergy").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
const auto consoles = Game::entityManager->GetEntitiesInGroup("Console");
for (auto* console : consoles) {
auto* consoleQuickBuildComponent = console->GetComponent<QuickBuildComponent>();
if (consoleQuickBuildComponent->GetState() != eQuickBuildState::COMPLETED) {
continue;
}
console->CancelAllTimers();
}
self->AddTimer("Die", ResetConsole);
}
void ImgBrickConsoleQB::OnDie(Entity* self, Entity* killer) {
if (self->GetVar<bool>(u"Died")) {
return;
}
self->CancelAllTimers();
self->SetVar(u"Died", true);
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
if (quickBuildComponent->GetState() == eQuickBuildState::COMPLETED) {
auto offFX = 0;
const auto location = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"console"));
if (location == "Left") {
offFX = 2774;
} else {
offFX = 2777;
}
const auto& facility = Game::entityManager->GetEntitiesInGroup("FacilityPipes");
if (!facility.empty()) {
GameMessages::StopFXEffect(facility[0]->GetObjectID(), true, location + "PipeEnergy").Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::StopFXEffect(facility[0]->GetObjectID(), true, location + "PipeOn").Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::PlayFXEffect(facility[0]->GetObjectID(), offFX, u"create", location + "PipeOff").Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::PlayFXEffect(facility[0]->GetObjectID(), 2750, u"create", location + "imagination_canister").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
}
const auto myGroup = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner_name"));
const auto pipeGroup = myGroup.substr(0, 10);
const auto firstPipe = pipeGroup + "1";
const auto samePipeSpawner = Game::zoneManager->GetSpawnersByName(myGroup);
if (!samePipeSpawner.empty()) {
samePipeSpawner[0]->Reset();
samePipeSpawner[0]->Deactivate();
}
const auto firstPipeSpawner = Game::zoneManager->GetSpawnersByName(firstPipe);
if (!firstPipeSpawner.empty()) {
firstPipeSpawner[0]->Activate();
}
const auto netdevil = Game::zoneManager->GetSpawnersByName("Imagination");
if (!netdevil.empty()) {
netdevil[0]->Reset();
netdevil[0]->Deactivate();
}
const auto brick = Game::zoneManager->GetSpawnersByName("MaelstromBug");
if (!brick.empty()) {
brick[0]->Activate();
}
const auto canister = Game::zoneManager->GetSpawnersByName("BrickCanister");
if (!canister.empty()) {
canister[0]->Activate();
}
self->SetNetworkVar(u"used", false);
}
void ImgBrickConsoleQB::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "reset") {
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
if (quickBuildComponent->GetState() == eQuickBuildState::OPEN) {
self->Smash(self->GetObjectID(), eKillType::SILENT);
}
} else if (timerName == "Die") {
const auto consoles = Game::entityManager->GetEntitiesInGroup("Console");
for (auto* console : consoles) {
console->Smash(console->GetObjectID(), eKillType::VIOLENT);
}
}
}