diff --git a/dNet/dServer.h b/dNet/dServer.h index 5add696e..a577d191 100644 --- a/dNet/dServer.h +++ b/dNet/dServer.h @@ -81,7 +81,10 @@ class dServer { const ServerType GetServerType() const { return mServerType; } - [[nodiscard]] std::chrono::time_point GetStartTime() const { return m_startTime; } + [[nodiscard]] + std::chrono::steady_clock::duration GetUptime() const { + return std::chrono::steady_clock::now() - mStartTime; + } private: bool Startup(); @@ -117,5 +120,5 @@ class dServer { SystemAddress mMasterSystemAddress; std::string mMasterIP; int mMasterPort; - std::chrono::time_point m_startTime = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point mStartTime = std::chrono::steady_clock::now(); }; diff --git a/dScripts/02_server/Map/AG/NpcAgCourseStarter.cpp b/dScripts/02_server/Map/AG/NpcAgCourseStarter.cpp index 05cc1e5d..5fb13d66 100644 --- a/dScripts/02_server/Map/AG/NpcAgCourseStarter.cpp +++ b/dScripts/02_server/Map/AG/NpcAgCourseStarter.cpp @@ -15,10 +15,13 @@ void NpcAgCourseStarter::OnUse(Entity* self, Entity* user) { auto* const scriptedActivityComponent = self->GetComponent(); if (!scriptedActivityComponent) return; + const auto selfId = self->GetObjectID(); + const auto userSysAddr = user->GetSystemAddress(); + if (scriptedActivityComponent->GetActivityPlayerData(user->GetObjectID()) != nullptr) { - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"exit", 0, 0, LWOOBJID_EMPTY, "", user->GetSystemAddress()); + GameMessages::SendNotifyClientObject(selfId, u"exit", 0, 0, LWOOBJID_EMPTY, "", userSysAddr); } else { - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"start", 0, 0, LWOOBJID_EMPTY, "", user->GetSystemAddress()); + GameMessages::SendNotifyClientObject(selfId, u"start", 0, 0, LWOOBJID_EMPTY, "", userSysAddr); } } @@ -26,36 +29,39 @@ void NpcAgCourseStarter::OnMessageBoxResponse(Entity* self, Entity* sender, int3 auto* const scriptedActivityComponent = self->GetComponent(); if (!scriptedActivityComponent) return; + const auto selfId = self->GetObjectID(); + const auto senderId = sender->GetObjectID(); + const auto senderSysAddr = sender->GetSystemAddress(); + if (identifier == u"player_dialog_cancel_course" && button == 1) { - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"stop_timer", 0, 0, LWOOBJID_EMPTY, "", sender->GetSystemAddress()); - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"cancel_timer", 0, 0, LWOOBJID_EMPTY, "", sender->GetSystemAddress()); + GameMessages::SendNotifyClientObject(selfId, u"stop_timer", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr); + GameMessages::SendNotifyClientObject(selfId, u"cancel_timer", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr); - scriptedActivityComponent->RemoveActivityPlayerData(sender->GetObjectID()); + scriptedActivityComponent->RemoveActivityPlayerData(senderId); Game::entityManager->SerializeEntity(self); } else if (identifier == u"player_dialog_start_course" && button == 1) { - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"start_timer", 0, 0, LWOOBJID_EMPTY, "", sender->GetSystemAddress()); - GameMessages::SendActivityStart(self->GetObjectID(), sender->GetSystemAddress()); + GameMessages::SendNotifyClientObject(selfId, u"start_timer", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr); + GameMessages::SendActivityStart(selfId, senderSysAddr); - auto* const data = scriptedActivityComponent->AddActivityPlayerData(sender->GetObjectID()); + auto* const data = scriptedActivityComponent->AddActivityPlayerData(selfId); if (data->values[1] != 0) return; - const auto raceStartTime = std::chrono::steady_clock::now() - Game::server->GetStartTime() - + std::chrono::seconds(4); // Offset for starting timer + const auto raceStartTime = Game::server->GetUptime() + std::chrono::seconds(4); // Offset for starting timer const auto fRaceStartTime = std::chrono::duration>(raceStartTime).count(); data->values[1] = fRaceStartTime; Game::entityManager->SerializeEntity(self); } else if (identifier == u"FootRaceCancel") { - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"stop_timer", 0, 0, LWOOBJID_EMPTY, "", sender->GetSystemAddress()); + GameMessages::SendNotifyClientObject(selfId, u"stop_timer", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr); - if (scriptedActivityComponent->GetActivityPlayerData(sender->GetObjectID()) != nullptr) { - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"exit", 0, 0, LWOOBJID_EMPTY, "", sender->GetSystemAddress()); + if (scriptedActivityComponent->GetActivityPlayerData(senderId) != nullptr) { + GameMessages::SendNotifyClientObject(selfId, u"exit", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr); } else { - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"start", 0, 0, LWOOBJID_EMPTY, "", sender->GetSystemAddress()); + GameMessages::SendNotifyClientObject(selfId, u"start", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr); } - scriptedActivityComponent->RemoveActivityPlayerData(sender->GetObjectID()); + scriptedActivityComponent->RemoveActivityPlayerData(senderId); } } @@ -63,15 +69,19 @@ void NpcAgCourseStarter::OnFireEventServerSide(Entity* self, Entity* sender, std auto* const scriptedActivityComponent = self->GetComponent(); if (!scriptedActivityComponent) return; - auto* const data = scriptedActivityComponent->GetActivityPlayerData(sender->GetObjectID()); + const auto selfId = self->GetObjectID(); + const auto senderId = sender->GetObjectID(); + const auto senderSysAddr = sender->GetSystemAddress(); + + auto* const data = scriptedActivityComponent->GetActivityPlayerData(senderId); if (!data) return; if (args == "course_cancel") { - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"cancel_timer", 0, 0, - LWOOBJID_EMPTY, "", sender->GetSystemAddress()); - scriptedActivityComponent->RemoveActivityPlayerData(sender->GetObjectID()); + GameMessages::SendNotifyClientObject(selfId, u"cancel_timer", 0, 0, + LWOOBJID_EMPTY, "", senderSysAddr); + scriptedActivityComponent->RemoveActivityPlayerData(senderId); } else if (args == "course_finish") { - const auto raceEndTime = std::chrono::steady_clock::now() - Game::server->GetStartTime(); + const auto raceEndTime = Game::server->GetUptime(); const auto fRaceEndTime = std::chrono::duration>(raceEndTime).count(); const auto raceTimeElapsed = fRaceEndTime - data->values[1]; data->values[2] = raceTimeElapsed; @@ -79,19 +89,19 @@ void NpcAgCourseStarter::OnFireEventServerSide(Entity* self, Entity* sender, std auto* const missionComponent = sender->GetComponent(); if (missionComponent != nullptr) { missionComponent->ForceProgressTaskType(1884, 1, 1, false); - missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, -raceTimeElapsed, self->GetObjectID(), + missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, -raceTimeElapsed, selfId, "performact_time"); } Game::entityManager->SerializeEntity(self); - LeaderboardManager::SaveScore(sender->GetObjectID(), scriptedActivityComponent->GetActivityID(), raceTimeElapsed); + LeaderboardManager::SaveScore(senderId, scriptedActivityComponent->GetActivityID(), raceTimeElapsed); - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"ToggleLeaderBoard", - scriptedActivityComponent->GetActivityID(), 0, sender->GetObjectID(), - "", sender->GetSystemAddress()); - GameMessages::SendNotifyClientObject(self->GetObjectID(), u"stop_timer", 1, raceTimeElapsed, LWOOBJID_EMPTY, "", - sender->GetSystemAddress()); + GameMessages::SendNotifyClientObject(selfId, u"ToggleLeaderBoard", + scriptedActivityComponent->GetActivityID(), 0, senderId, + "", senderSysAddr); + GameMessages::SendNotifyClientObject(selfId, u"stop_timer", 1, raceTimeElapsed, LWOOBJID_EMPTY, "", + senderSysAddr); - scriptedActivityComponent->RemoveActivityPlayerData(sender->GetObjectID()); + scriptedActivityComponent->RemoveActivityPlayerData(senderId); } }