2021-12-05 17:54:36 +00:00
|
|
|
#include "NpcAgCourseStarter.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "ScriptedActivityComponent.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "LeaderboardManager.h"
|
2024-12-17 20:06:16 +00:00
|
|
|
#include "dServer.h"
|
2022-07-05 06:00:10 +00:00
|
|
|
#include "eMissionTaskType.h"
|
|
|
|
#include "eMissionState.h"
|
|
|
|
#include "MissionComponent.h"
|
2024-12-17 20:06:16 +00:00
|
|
|
#include <chrono>
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
void NpcAgCourseStarter::OnStartup(Entity* self) {}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void NpcAgCourseStarter::OnUse(Entity* self, Entity* user) {
|
2024-12-17 20:06:16 +00:00
|
|
|
auto* const scriptedActivityComponent = self->GetComponent<ScriptedActivityComponent>();
|
|
|
|
if (!scriptedActivityComponent) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
const auto selfId = self->GetObjectID();
|
|
|
|
const auto userId = user->GetObjectID();
|
|
|
|
const auto& userSysAddr = user->GetSystemAddress();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
if (scriptedActivityComponent->GetActivityPlayerData(userId) != nullptr) {
|
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"exit", 0, 0, LWOOBJID_EMPTY, "", userSysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
} else {
|
2024-12-17 20:06:16 +00:00
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"start", 0, 0, LWOOBJID_EMPTY, "", userSysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NpcAgCourseStarter::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) {
|
2024-12-17 20:06:16 +00:00
|
|
|
auto* const scriptedActivityComponent = self->GetComponent<ScriptedActivityComponent>();
|
|
|
|
if (!scriptedActivityComponent) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
const auto selfId = self->GetObjectID();
|
|
|
|
const auto senderId = sender->GetObjectID();
|
|
|
|
const auto& senderSysAddr = sender->GetSystemAddress();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (identifier == u"player_dialog_cancel_course" && button == 1) {
|
2024-12-17 20:06:16 +00:00
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"stop_timer", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr);
|
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"cancel_timer", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
scriptedActivityComponent->RemoveActivityPlayerData(senderId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(self);
|
2021-12-05 17:54:36 +00:00
|
|
|
} else if (identifier == u"player_dialog_start_course" && button == 1) {
|
2024-12-17 20:06:16 +00:00
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"start_timer", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr);
|
|
|
|
GameMessages::SendActivityStart(selfId, senderSysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
auto* const data = scriptedActivityComponent->AddActivityPlayerData(senderId);
|
2021-12-05 17:54:36 +00:00
|
|
|
if (data->values[1] != 0) return;
|
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
const auto raceStartTime = Game::server->GetUptime() + std::chrono::seconds(4); // Offset for starting timer
|
|
|
|
const auto fRaceStartTime = std::chrono::duration<float, std::ratio<1>>(raceStartTime).count();
|
|
|
|
data->values[1] = fRaceStartTime;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(self);
|
2021-12-05 17:54:36 +00:00
|
|
|
} else if (identifier == u"FootRaceCancel") {
|
2024-12-17 20:06:16 +00:00
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"stop_timer", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
if (scriptedActivityComponent->GetActivityPlayerData(senderId) != nullptr) {
|
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"exit", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
} else {
|
2024-12-17 20:06:16 +00:00
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"start", 0, 0, LWOOBJID_EMPTY, "", senderSysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
scriptedActivityComponent->RemoveActivityPlayerData(senderId);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-10 05:00:13 +00:00
|
|
|
void NpcAgCourseStarter::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
|
2024-12-17 20:06:16 +00:00
|
|
|
auto* const scriptedActivityComponent = self->GetComponent<ScriptedActivityComponent>();
|
|
|
|
if (!scriptedActivityComponent) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
const auto selfId = self->GetObjectID();
|
|
|
|
const auto senderId = sender->GetObjectID();
|
|
|
|
const auto& senderSysAddr = sender->GetSystemAddress();
|
|
|
|
|
|
|
|
auto* const data = scriptedActivityComponent->GetActivityPlayerData(senderId);
|
|
|
|
if (!data) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (args == "course_cancel") {
|
2024-12-17 20:06:16 +00:00
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"cancel_timer", 0, 0,
|
|
|
|
LWOOBJID_EMPTY, "", senderSysAddr);
|
|
|
|
scriptedActivityComponent->RemoveActivityPlayerData(senderId);
|
2021-12-05 17:54:36 +00:00
|
|
|
} else if (args == "course_finish") {
|
2024-12-17 20:06:16 +00:00
|
|
|
const auto raceEndTime = Game::server->GetUptime();
|
|
|
|
const auto fRaceEndTime = std::chrono::duration<float, std::ratio<1>>(raceEndTime).count();
|
|
|
|
const auto raceTimeElapsed = fRaceEndTime - data->values[1];
|
|
|
|
data->values[2] = raceTimeElapsed;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
auto* const missionComponent = sender->GetComponent<MissionComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
if (missionComponent != nullptr) {
|
|
|
|
missionComponent->ForceProgressTaskType(1884, 1, 1, false);
|
2024-12-17 20:06:16 +00:00
|
|
|
missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, -raceTimeElapsed, selfId,
|
2021-12-05 17:54:36 +00:00
|
|
|
"performact_time");
|
|
|
|
}
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(self);
|
2024-12-17 20:06:16 +00:00
|
|
|
LeaderboardManager::SaveScore(senderId, scriptedActivityComponent->GetActivityID(), raceTimeElapsed);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"ToggleLeaderBoard",
|
|
|
|
scriptedActivityComponent->GetActivityID(), 0, senderId,
|
|
|
|
"", senderSysAddr);
|
|
|
|
GameMessages::SendNotifyClientObject(selfId, u"stop_timer", 1, raceTimeElapsed, LWOOBJID_EMPTY, "",
|
|
|
|
senderSysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-12-17 20:06:16 +00:00
|
|
|
scriptedActivityComponent->RemoveActivityPlayerData(senderId);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|