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>
229 lines
7.4 KiB
C++
229 lines
7.4 KiB
C++
#include "ActivityManager.h"
|
|
#include "EntityManager.h"
|
|
#include "ScriptedActivityComponent.h"
|
|
#include "LeaderboardManager.h"
|
|
#include "GameMessages.h"
|
|
#include "ObjectMessages.h"
|
|
#include <algorithm>
|
|
#include "Logger.h"
|
|
#include "Loot.h"
|
|
#include "ShootingGalleryComponent.h"
|
|
#include "RacingControlComponent.h"
|
|
|
|
bool ActivityManager::IsPlayerInActivity(Entity* self, LWOOBJID playerID) {
|
|
const auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
return sac != nullptr && sac->IsPlayedBy(playerID);
|
|
}
|
|
|
|
void ActivityManager::UpdatePlayer(Entity* self, LWOOBJID playerID, const bool remove) {
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
if (sac == nullptr)
|
|
return;
|
|
|
|
if (remove) {
|
|
sac->PlayerRemove(playerID);
|
|
} else {
|
|
auto* player = Game::entityManager->GetEntity(playerID);
|
|
if (player != nullptr) {
|
|
sac->PlayerJoin(player);
|
|
SetActivityScore(self, playerID, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ActivityManager::SetActivityScore(Entity* self, LWOOBJID playerID, uint32_t score) {
|
|
SetActivityValue(self, playerID, 0, score);
|
|
}
|
|
|
|
void ActivityManager::SetActivityValue(Entity* self, const LWOOBJID playerID, const uint32_t valueIndex,
|
|
const float_t value) {
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
if (sac == nullptr)
|
|
return;
|
|
|
|
sac->SetActivityValue(playerID, valueIndex, value);
|
|
}
|
|
|
|
float_t ActivityManager::GetActivityValue(Entity* self, const LWOOBJID playerID, const uint32_t valueIndex) {
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
if (sac == nullptr)
|
|
return -1.0f;
|
|
|
|
return sac->GetActivityValue(playerID, valueIndex);
|
|
}
|
|
|
|
void ActivityManager::StopActivity(Entity* self, const LWOOBJID playerID, const uint32_t score,
|
|
const uint32_t value1, const uint32_t value2, bool quit) {
|
|
int32_t gameID = 0;
|
|
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
if (sac == nullptr) {
|
|
gameID = self->GetLOT();
|
|
} else {
|
|
gameID = sac->GetActivityID();
|
|
}
|
|
|
|
if (quit) {
|
|
UpdatePlayer(self, playerID, true);
|
|
} else {
|
|
auto* player = Game::entityManager->GetEntity(playerID);
|
|
if (player == nullptr)
|
|
return;
|
|
|
|
SetActivityScore(self, playerID, score);
|
|
SetActivityValue(self, playerID, 1, value1);
|
|
SetActivityValue(self, playerID, 2, value2);
|
|
|
|
Loot::GiveActivityLoot(player, self->GetObjectID(), gameID, CalculateActivityRating(self, playerID));
|
|
|
|
if (sac != nullptr) {
|
|
sac->PlayerRemove(player->GetObjectID());
|
|
}
|
|
}
|
|
}
|
|
|
|
void ActivityManager::SaveScore(Entity* self, const LWOOBJID playerID, const float primaryScore, const float secondaryScore, const float tertiaryScore) const {
|
|
auto* player = Game::entityManager->GetEntity(playerID);
|
|
if (!player) return;
|
|
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
uint32_t gameID = sac != nullptr ? sac->GetActivityID() : self->GetLOT();
|
|
// Save the new score to the leaderboard and show the leaderboard to the player
|
|
LeaderboardManager::SaveScore(playerID, gameID, primaryScore, secondaryScore, tertiaryScore);
|
|
|
|
// Makes the leaderboard show up for the player
|
|
GameMessages::NotifyClientObject(self->GetObjectID(), u"ToggleLeaderBoard", gameID, 0, playerID, "").Send(player->GetSystemAddress());
|
|
}
|
|
|
|
bool ActivityManager::TakeActivityCost(const Entity* self, const LWOOBJID playerID) {
|
|
ActivityComponent* activityComponent = self->GetComponent<ScriptedActivityComponent>();
|
|
if (activityComponent == nullptr) {
|
|
activityComponent = self->GetComponent<ShootingGalleryComponent>();
|
|
}
|
|
|
|
if (!activityComponent) return false;
|
|
|
|
auto* player = Game::entityManager->GetEntity(playerID);
|
|
if (player == nullptr)
|
|
return false;
|
|
|
|
return activityComponent->TakeCost(player);
|
|
}
|
|
|
|
uint32_t ActivityManager::CalculateActivityRating(Entity* self, const LWOOBJID playerID) {
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
if (sac == nullptr)
|
|
return 0;
|
|
|
|
return sac->GetInstance(playerID).GetParticipants().size();
|
|
}
|
|
|
|
uint32_t ActivityManager::GetActivityID(const Entity* self) {
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
return sac != nullptr ? sac->GetActivityID() : 0;
|
|
}
|
|
|
|
void ActivityManager::GetLeaderboardData(Entity* self, const LWOOBJID playerID, const uint32_t activityID, uint32_t numResults) {
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
uint32_t gameID = sac != nullptr ? sac->GetActivityID() : self->GetLOT();
|
|
// Save the new score to the leaderboard and show the leaderboard to the player
|
|
LeaderboardManager::SendLeaderboard(activityID, Leaderboard::InfoType::MyStanding, false, playerID, self->GetObjectID(), numResults);
|
|
}
|
|
|
|
void ActivityManager::ActivityTimerStart(Entity* self, const std::string& timerName, const float_t updateInterval,
|
|
const float_t stopTime) {
|
|
auto* timer = new ActivityTimer{ timerName, updateInterval, stopTime };
|
|
activeTimers.push_back(timer);
|
|
|
|
LOG_DEBUG("Starting timer '%s', %f, %f", timerName.c_str(), updateInterval, stopTime);
|
|
|
|
self->AddTimer(GetPrefixedName(timer->name), timer->updateInterval);
|
|
}
|
|
|
|
void ActivityManager::ActivityTimerStopAllTimers(Entity* self) {
|
|
for (auto* timer : activeTimers) {
|
|
self->CancelTimer(GetPrefixedName(timer->name));
|
|
delete timer;
|
|
}
|
|
|
|
activeTimers.clear();
|
|
}
|
|
|
|
float_t ActivityManager::ActivityTimerGetCurrentTime(Entity* self, const std::string& timerName) const {
|
|
auto* timer = GetTimer(timerName);
|
|
return timer != nullptr ? timer->runTime : 0.0f;
|
|
}
|
|
|
|
int32_t ActivityManager::GetGameID(Entity* self) const {
|
|
int32_t gameID = 0;
|
|
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
if (sac == nullptr) {
|
|
gameID = self->GetLOT();
|
|
} else {
|
|
gameID = sac->GetActivityID();
|
|
}
|
|
|
|
return gameID;
|
|
}
|
|
|
|
float_t ActivityManager::ActivityTimerGetRemainingTime(Entity* self, const std::string& timerName) const {
|
|
auto* timer = GetTimer(timerName);
|
|
return timer != nullptr ? std::max(timer->stopTime - timer->runTime, 0.0f) : 0.0f;
|
|
}
|
|
|
|
void ActivityManager::ActivityTimerReset(Entity* self, const std::string& timerName) {
|
|
auto* timer = GetTimer(timerName);
|
|
if (timer != nullptr) {
|
|
timer->runTime = 0.0f;
|
|
}
|
|
}
|
|
|
|
ActivityTimer* ActivityManager::GetTimer(const std::string& name) const {
|
|
for (auto* timer : activeTimers) {
|
|
if (timer->name == name)
|
|
return timer;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
void ActivityManager::ActivityTimerStop(Entity* self, const std::string& timerName) {
|
|
auto* timer = GetTimer(timerName);
|
|
if (timer != nullptr) {
|
|
self->CancelTimer(GetPrefixedName(timer->name));
|
|
|
|
activeTimers.erase(std::remove(activeTimers.begin(), activeTimers.end(), timer),
|
|
activeTimers.end());
|
|
delete timer;
|
|
}
|
|
}
|
|
|
|
std::string ActivityManager::GetPrefixedName(const std::string& name) const {
|
|
return TimerPrefix + "_" + name;
|
|
}
|
|
|
|
void ActivityManager::OnTimerDone(Entity* self, std::string timerName) {
|
|
auto nameSplit = GeneralUtils::SplitString(timerName, '_');
|
|
if (nameSplit.size() > 1 && nameSplit.at(0) == TimerPrefix) {
|
|
const auto& activityTimerName = nameSplit.at(1);
|
|
auto* timer = GetTimer(activityTimerName);
|
|
|
|
if (timer != nullptr) {
|
|
timer->runTime += timer->updateInterval;
|
|
|
|
if (timer->stopTime != -1.0f && timer->runTime >= timer->stopTime) {
|
|
activeTimers.erase(std::remove(activeTimers.begin(), activeTimers.end(), timer),
|
|
activeTimers.end());
|
|
delete timer;
|
|
LOG_DEBUG("Executing timer '%s'", activityTimerName.c_str());
|
|
OnActivityTimerDone(self, activityTimerName);
|
|
} else {
|
|
LOG_DEBUG("Updating timer '%s'", activityTimerName.c_str());
|
|
OnActivityTimerUpdate(self, timer->name, timer->stopTime - timer->runTime, timer->runTime);
|
|
self->AddTimer(GetPrefixedName(timer->name), timer->updateInterval);
|
|
}
|
|
}
|
|
}
|
|
}
|