mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
Every game message still written or read by hand is now a NetGameMsg with Serialize and Deserialize, in per-domain files: - MovementMessages: teleport, platforms (resync and its request), orient to angle, node rotation lock, gravity scale, jetpack mode, control scheme, respawn checkpoint, rails (set/start, ready, cancel, arrived), mount inventory ID, dismount complete, possession ack, ghost reference override and position, camera cycling (eCameraTargetCyclingMode moves here). - ZoneMessages: player loaded (the old PLAYER_LOADED case), ready for updates, player ready, restore to post load stats, server done loading, invalid zone transfer list, zone summary display/dismissed, level processing complete, object world state, and the localized announcement WorldMigration wrote by hand. - PlayerMessages: chat mode, GM level, LEGO score, currency, reputation, GM invis, pickup currency, zone and player statistics, chat commands, bug reports, verify ack. - ObjectMessages: fire event client/server side, notify client (zone) object, notify object, script network vars, failed preconditions, terminate interaction, set name, request use, request server object info. - QuickBuildMessages: notify state, enable, cancel. - ActivityMessages gains match response/update/request, leaderboard request and data, shooting gallery score/rotation/fire, activity state change. - MissionMessages gains MissionDialogueCancelled (a no-op, as before). The wire structs left in GameMessages.h move to their domains (tooltip and emote to Effects, loot and item use to Inventory, model build to Building, behavior sound to Property, skill sets to Skill) and gain the missing direction. The dismount logic moves to PossessorComponent::OnDismountComplete. Every inbound message is registered in the GameMessageHandler map; the switch is gone, and GameMessages.cpp only holds the GameMsg/NetGameMsg base code. Call sites build the structs (NotifyClientObject, TerminateInteraction, Teleport, PlatformResync, FireEventClientSide, NotifyObject and NotifyClientZoneObject get convenience constructors like PlayFXEffect). Dead senders are dropped: SendSetShootingGalleryParams (no callers, field order was a guess), SendTeamPickupItem (the struct already existed), SendRequestActivitySummaryLeaderboardData (the struct covers it). Verified with RemainingMessagesTests: every old Send* function is frozen verbatim in Legacy/RemainingMessagesLegacy.h and compared byte for byte (same bits, destination and broadcast flag) over grids of inputs; every old Handle* read sequence is frozen as a Read* oracle and compared with the struct's Deserialize; round trips, truncation and a golden packet. PlayerLoaded (0x00dc36f0), SetGMLevel (0x00dd6230), MissionDialogueCancelled (0x00d9cc10) and LocalizedAnnouncementServerToSingleClient (0x00f23c50) were checked against the client. Behaviour notes: an inbound message that fails to deserialize is dropped, so ParseChatMessage over MAX_MESSAGE_LENGTH is dropped instead of truncated, and PLAYER_LOADED / READY_FOR_UPDATES / MISSION_DIALOGUE_CANCELLED now read their (unused) client fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
225 lines
6.2 KiB
C++
225 lines
6.2 KiB
C++
#include "CavePrisonCage.h"
|
|
#include "EntityManager.h"
|
|
#include "QuickBuildComponent.h"
|
|
#include "GameMessages.h"
|
|
#include "ObjectMessages.h"
|
|
#include "Character.h"
|
|
#include "dZoneManager.h"
|
|
#include "RenderComponent.h"
|
|
|
|
void CavePrisonCage::OnStartup(Entity* self) {
|
|
const auto& myNum = self->GetVar<std::u16string>(u"myNumber");
|
|
|
|
if (myNum.empty()) {
|
|
return;
|
|
}
|
|
|
|
const auto spawners = Game::zoneManager->GetSpawnersByName("PrisonCounterweight_0" + GeneralUtils::UTF16ToWTF8(myNum));
|
|
if (spawners.empty()) return;
|
|
|
|
auto* spawner = spawners[0];
|
|
|
|
self->SetVar<Spawner*>(u"CWSpawner", spawner);
|
|
|
|
Setup(self, spawner);
|
|
}
|
|
|
|
void CavePrisonCage::Setup(Entity* self, Spawner* spawner) {
|
|
if (!spawner) return;
|
|
SpawnCounterweight(self, spawner);
|
|
|
|
NiPoint3 mypos = self->GetPosition();
|
|
NiQuaternion myrot = self->GetRotation();
|
|
|
|
mypos.y += 1.5;
|
|
mypos.z -= 0.5;
|
|
|
|
EntityInfo info{};
|
|
info.lot = m_Villagers[self->GetVarAs<int32_t>(u"myNumber") - 1];
|
|
info.pos = mypos;
|
|
info.rot = myrot;
|
|
info.spawnerID = self->GetObjectID();
|
|
|
|
// Spawn the villager inside the jail
|
|
auto* entity = Game::entityManager->CreateEntity(info);
|
|
|
|
// Save the villeger ID
|
|
self->SetVar<LWOOBJID>(u"villager", entity->GetObjectID());
|
|
|
|
// Construct the entity
|
|
Game::entityManager->ConstructEntity(entity);
|
|
}
|
|
|
|
void CavePrisonCage::OnQuickBuildNotifyState(Entity* self, eQuickBuildState state) {
|
|
if (state != eQuickBuildState::RESETTING) {
|
|
return;
|
|
}
|
|
|
|
auto* spawner = self->GetVar<Spawner*>(u"CWSpawner");
|
|
|
|
if (spawner == nullptr) {
|
|
return;
|
|
}
|
|
|
|
spawner->Reset();
|
|
|
|
SpawnCounterweight(self, spawner);
|
|
}
|
|
|
|
void CavePrisonCage::SpawnCounterweight(Entity* self, Spawner* spawner) {
|
|
if (!spawner) return;
|
|
|
|
spawner->Reset();
|
|
|
|
auto* counterweight = spawner->Spawn();
|
|
|
|
self->SetVar<LWOOBJID>(u"Counterweight", counterweight->GetObjectID());
|
|
|
|
auto* quickBuildComponent = counterweight->GetComponent<QuickBuildComponent>();
|
|
|
|
if (quickBuildComponent != nullptr) {
|
|
quickBuildComponent->AddQuickBuildStateCallback([this, self](eQuickBuildState state) {
|
|
OnQuickBuildNotifyState(self, state);
|
|
});
|
|
|
|
quickBuildComponent->AddQuickBuildCompleteCallback([this, self](Entity* user) {
|
|
// The counterweight is a simple mover, which is not implemented, so we'll just set it's position
|
|
auto* counterweight = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
|
|
|
|
if (counterweight == nullptr) {
|
|
return;
|
|
}
|
|
|
|
// Move the counterweight down 2 units
|
|
counterweight->SetPosition(counterweight->GetPosition() + NiPoint3(0, -2, 0));
|
|
|
|
// Serialize the counterweight
|
|
Game::entityManager->SerializeEntity(counterweight);
|
|
|
|
// notifyPlatformAtLastWaypoint
|
|
|
|
// Save the userID as Builder
|
|
self->SetVar<LWOOBJID>(u"Builder", user->GetObjectID());
|
|
|
|
// Get the button and make sure it still exists
|
|
auto* button = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
|
|
|
|
if (button == nullptr) {
|
|
return;
|
|
}
|
|
|
|
// Play the 'down' animation on the button
|
|
RenderComponent::PlayAnimation(button, u"down");
|
|
|
|
// Setup a timer named 'buttonGoingDown' to be triggered in 5 seconds
|
|
self->AddTimer("buttonGoingDown", 5.0f);
|
|
});
|
|
}
|
|
|
|
if (self->GetVar<LWOOBJID>(u"Button")) {
|
|
return;
|
|
}
|
|
|
|
GetButton(self);
|
|
}
|
|
|
|
void CavePrisonCage::GetButton(Entity* self) {
|
|
const auto buttons = Game::entityManager->GetEntitiesInGroup("PrisonButton_0" + std::to_string(self->GetVarAs<int32_t>(u"myNumber")));
|
|
|
|
if (buttons.size() == 0) {
|
|
// Try again in 0.5 seconds
|
|
self->AddCallbackTimer(0.5, [this, self]() {
|
|
GetButton(self);
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
auto* button = buttons[0];
|
|
|
|
self->SetVar<LWOOBJID>(u"Button", button->GetObjectID());
|
|
}
|
|
|
|
void CavePrisonCage::OnTimerDone(Entity* self, std::string timerName) {
|
|
// the anim of the button down is over
|
|
if (timerName == "buttonGoingDown") {
|
|
// Play the 'up' animation
|
|
RenderComponent::PlayAnimation(self, u"up");
|
|
|
|
// Setup a timer named 'CageOpen' to be triggered in 1 second
|
|
self->AddTimer("CageOpen", 1.0f);
|
|
} else if (timerName == "CageOpen") {
|
|
// play the idle open anim
|
|
RenderComponent::PlayAnimation(self, u"idle-up");
|
|
|
|
// Get the villeger
|
|
auto* villager = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
|
|
|
|
if (villager == nullptr) {
|
|
return;
|
|
}
|
|
|
|
GameMessages::NotifyClientObject(villager->GetObjectID(), u"TimeToChat", 0, 0, LWOOBJID_EMPTY, "").Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
// Get the builder and make sure it still exists
|
|
auto* builder = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Builder"));
|
|
|
|
if (builder == nullptr) {
|
|
return;
|
|
}
|
|
|
|
const auto flagNum = 2020 + self->GetVarAs<int32_t>(u"myNumber");
|
|
|
|
// Set the flag on the builder character
|
|
auto* const character = builder->GetCharacter();
|
|
if (character) character->SetPlayerFlag(flagNum, true);
|
|
|
|
// Setup a timer named 'VillagerEscape' to be triggered in 5 seconds
|
|
self->AddTimer("VillagerEscape", 5.0f);
|
|
} else if (timerName == "VillagerEscape") {
|
|
// Get the villeger and make sure it still exists
|
|
auto* villager = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
|
|
|
|
if (villager == nullptr) {
|
|
return;
|
|
}
|
|
|
|
// Kill the villager
|
|
villager->Kill();
|
|
|
|
// Setup a timer named 'SmashCounterweight' to be triggered in 2 seconds
|
|
self->AddTimer("SmashCounterweight", 2.0f);
|
|
} else if (timerName == "SmashCounterweight") {
|
|
// Get the counterweight and make sure it still exists
|
|
auto* counterweight = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
|
|
|
|
if (counterweight == nullptr) {
|
|
return;
|
|
}
|
|
|
|
// Smash the counterweight
|
|
counterweight->Smash();
|
|
|
|
// Get the button and make sure it still exists
|
|
auto* button = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
|
|
|
|
if (button == nullptr) {
|
|
return;
|
|
}
|
|
|
|
// Play the 'up' animation on the button
|
|
RenderComponent::PlayAnimation(button, u"up");
|
|
|
|
// Setup a timer named 'CageClosed' to be triggered in 1 second
|
|
self->AddTimer("CageClosed", 1.0f);
|
|
} else if (timerName == "CageClosed") {
|
|
// play the idle closed anim
|
|
RenderComponent::PlayAnimation(self, u"idle");
|
|
|
|
// Setup a timer named 'ResetPrison' to be triggered in 10 seconds
|
|
self->AddTimer("ResetPrison", 10.0f);
|
|
} else if (timerName == "ResetPrison") {
|
|
Setup(self, self->GetVar<Spawner*>(u"CWSpawner"));
|
|
}
|
|
}
|