diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index f08450fcf..0bb06e807 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -323,6 +323,7 @@ // WBL scripts #include "WblGenericZone.h" #include "WblStarflies.h" +#include "WblFrogBridge.h" // Alpha Scripts #include "TriggerGas.h" @@ -690,6 +691,7 @@ namespace { //WBL {"scripts\\zone\\LUPs\\WBL_generic_zone.lua", []() {return new WblGenericZone();}}, {"scripts\\zone\\LUPs\\Portabello Intro\\WBL_Starflies.lua", []() {return new WblStarflies();}}, + {"scripts\\zone\\LUPs\\Portabello Intro\\WBL_Frog_Bridge.lua", []() {return new WblFrogBridge();}}, {"scripts\\zone\\LUPs\\Moonbase Intro\\MOONBASE-INTRO_INTRO_CINEMATIC.lua", []() {return new WblGenericZone();}}, //Alpha diff --git a/dScripts/zone/LUPs/CMakeLists.txt b/dScripts/zone/LUPs/CMakeLists.txt index 642d43880..ce4dc5f68 100644 --- a/dScripts/zone/LUPs/CMakeLists.txt +++ b/dScripts/zone/LUPs/CMakeLists.txt @@ -1,6 +1,7 @@ set(DSCRIPTS_SOURCES_ZONE_LUPS "WblGenericZone.cpp" "WblStarflies.cpp" + "WblFrogBridge.cpp" ) add_subdirectory(RobotCity_Intro) diff --git a/dScripts/zone/LUPs/WblFrogBridge.cpp b/dScripts/zone/LUPs/WblFrogBridge.cpp new file mode 100644 index 000000000..1e9942265 --- /dev/null +++ b/dScripts/zone/LUPs/WblFrogBridge.cpp @@ -0,0 +1,63 @@ +#include "WblFrogBridge.h" + +#include "Entity.h" +#include "EntityManager.h" +#include "eMissionState.h" +#include "MissionComponent.h" +#include "MovingPlatformComponent.h" +#include "ProximityMonitorComponent.h" + +namespace { + constexpr uint32_t BRIDGE_MISSION = 946; +} + +void WblFrogBridge::OnStartup(Entity* self) { + self->SetProximityRadius(25.0f, "frog"); + self->SetVar(u"TongueOut", false); +} + +void WblFrogBridge::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) { + if (name == "frog" && status == "ENTER") StickOutTongue(self); +} + +// Piece 1-4: the first object of group FrogBridge01..04 +void WblFrogBridge::MovePiece(const int piece, const uint32_t waypoint) { + const auto pieces = Game::entityManager->GetEntitiesInGroup("FrogBridge0" + std::to_string(piece)); + if (pieces.empty()) return; + if (auto* movingPlatform = pieces.front()->GetComponent()) movingPlatform->GotoWaypoint(waypoint, true); +} + +void WblFrogBridge::StickOutTongue(Entity* self) { + if (self->GetVar(u"TongueOut")) return; + auto* proximity = self->GetComponent(); + if (!proximity) return; + for (const auto id : proximity->GetProximityObjects("frog")) { + auto* player = Game::entityManager->GetEntity(id); + auto* missions = player ? player->GetComponent() : nullptr; + if (!missions || missions->GetMissionState(BRIDGE_MISSION) < eMissionState::COMPLETE) continue; + for (int piece = 1; piece <= 4; piece++) MovePiece(piece, 1); + self->SetVar(u"TongueOut", true); + self->AddTimer("tongueWait", 10.0f); + return; + } +} + +void WblFrogBridge::OnTimerDone(Entity* self, std::string timerName) { + // Back one piece a second, from the tip, then 7 seconds before the frog looks for players again + if (timerName == "tongueWait") { + self->AddTimer("back4", 1.0f); + MovePiece(4, 0); + } else if (timerName == "back4") { + self->AddTimer("back3", 1.0f); + MovePiece(3, 0); + } else if (timerName == "back3") { + self->AddTimer("back2", 1.0f); + MovePiece(2, 0); + } else if (timerName == "back2") { + self->AddTimer("tongueIn", 7.0f); + MovePiece(1, 0); + } else if (timerName == "tongueIn") { + self->SetVar(u"TongueOut", false); + StickOutTongue(self); + } +} diff --git a/dScripts/zone/LUPs/WblFrogBridge.h b/dScripts/zone/LUPs/WblFrogBridge.h new file mode 100644 index 000000000..2cba13eed --- /dev/null +++ b/dScripts/zone/LUPs/WblFrogBridge.h @@ -0,0 +1,14 @@ +#pragma once +#include "CppScripts.h" + +// WBL_Frog_Bridge (Portabello): the frog puts its tongue out as a bridge (the four FrogBridge pieces move to their +// second waypoint) when a player who finished mission 946 comes near, then pulls it back piece by piece +class WblFrogBridge : public CppScripts::Script { +public: + void OnStartup(Entity* self) override; + void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) override; + void OnTimerDone(Entity* self, std::string timerName) override; +private: + static void StickOutTongue(Entity* self); + static void MovePiece(int piece, uint32_t waypoint); +};