From 9954e20eaccd426bb25b9b6749549d85f6464041 Mon Sep 17 00:00:00 2001 From: wincent Date: Mon, 30 Oct 2023 19:02:54 +0100 Subject: [PATCH] More scene metadata * Added the ability to specify a change to play * Added the ability to specify if a scene can play multiple times to the same player --- dGame/dCinema/Play.cpp | 2 -- dGame/dCinema/Recorder.cpp | 6 ++++-- dGame/dCinema/Scene.cpp | 22 ++++++++++++++++++++++ dGame/dCinema/Scene.h | 4 ++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/dGame/dCinema/Play.cpp b/dGame/dCinema/Play.cpp index ec539bb0..b810745c 100644 --- a/dGame/dCinema/Play.cpp +++ b/dGame/dCinema/Play.cpp @@ -29,8 +29,6 @@ void Cinema::Play::SetupCheckForAudience() { void Cinema::Play::CheckForAudience() { auto* player = Game::entityManager->GetEntity(this->player); - LOG("Checking for audience"); - if (player == nullptr) { CleanUp(); diff --git a/dGame/dCinema/Recorder.cpp b/dGame/dCinema/Recorder.cpp index a467a7bb..2345f244 100644 --- a/dGame/dCinema/Recorder.cpp +++ b/dGame/dCinema/Recorder.cpp @@ -59,6 +59,8 @@ void Recorder::ActingDispatch(Entity* actor, size_t index, Play* variables) { // Check if the record is a fork auto* forkRecord = dynamic_cast(record); + float delay = record->m_Delay; + if (forkRecord) { if (variables == nullptr) { // Skip the fork @@ -217,7 +219,7 @@ void Recorder::ActingDispatch(Entity* actor, size_t index, Play* variables) { auto* visibilityRecord = dynamic_cast(record); if (visibilityRecord) { - if (visibilityRecord->visible) { + if (!visibilityRecord->visible) { ServerPreconditions::AddExcludeFor(actor->GetObjectID(), variables->player); } else { ServerPreconditions::RemoveExcludeFor(actor->GetObjectID(), variables->player); @@ -262,7 +264,7 @@ void Recorder::ActingDispatch(Entity* actor, size_t index, Play* variables) { return; } - actor->AddCallbackTimer(record->m_Delay, [this, actor, index, variables]() { + actor->AddCallbackTimer(delay, [this, actor, index, variables]() { ActingDispatch(actor, index + 1, variables); }); diff --git a/dGame/dCinema/Scene.cpp b/dGame/dCinema/Scene.cpp index 37d1c5fd..51546f4c 100644 --- a/dGame/dCinema/Scene.cpp +++ b/dGame/dCinema/Scene.cpp @@ -56,6 +56,8 @@ void Cinema::Scene::Conclude(Entity* player) { // Remove the player from the audience m_Audience.erase(player->GetObjectID()); m_HasBeenOutside.erase(player->GetObjectID()); + + m_VisitedPlayers.emplace(player->GetObjectID()); } bool Cinema::Scene::IsPlayerInBounds(Entity* player) const { @@ -118,6 +120,14 @@ void Cinema::Scene::AutoLoadScenesForZone(LWOMAPID zone) { auto& scene = LoadFromFile(file); + if (scene.m_ChanceToPlay != 1.0f) { + const auto chance = GeneralUtils::GenerateRandomNumber(0.0f, 1.0f); + + if (chance > scene.m_ChanceToPlay) { + continue; + } + } + scene.Rehearse(); } } @@ -148,6 +158,10 @@ void Cinema::Scene::CheckForShowings() { continue; } + if (!m_Repeatable && m_VisitedPlayers.find(player->GetObjectID()) != m_VisitedPlayers.end()) { + continue; + } + CheckTicket(player); } @@ -307,6 +321,14 @@ Scene& Cinema::Scene::LoadFromFile(std::string file) { scene.m_ShowingDistance = scene.m_Bounds * 2.0f; } + if (root->Attribute("chanceToPlay")) { + scene.m_ChanceToPlay = root->FloatAttribute("chanceToPlay"); + } + + if (root->Attribute("repeatable")) { + scene.m_Repeatable = root->BoolAttribute("repeatable"); + } + // Load accept and complete mission if (root->Attribute("acceptMission")) { scene.m_AcceptMission = root->IntAttribute("acceptMission"); diff --git a/dGame/dCinema/Scene.h b/dGame/dCinema/Scene.h index b32b3124..32bb0f57 100644 --- a/dGame/dCinema/Scene.h +++ b/dGame/dCinema/Scene.h @@ -101,6 +101,8 @@ private: NiPoint3 m_Center; float m_Bounds = 0.0f; float m_ShowingDistance = 0.0f; + float m_ChanceToPlay = 1.0f; + bool m_Repeatable = true; std::vector> m_Preconditions; @@ -110,6 +112,8 @@ private: std::unordered_set m_Audience; std::unordered_set m_HasBeenOutside; + std::unordered_set m_VisitedPlayers; + static std::unordered_map m_Scenes; };