diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f8981ee..1c951f9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,6 +279,7 @@ set(INCLUDED_DIRECTORIES "dScripts/client/ai/PR" "dScripts/zone/AG" "dScripts/zone/LUPs" + "dScripts/zone/LUPs/RobotCity_Intro" "dScripts/zone/PROPERTY" "dScripts/zone/PROPERTY/FV" "dScripts/zone/PROPERTY/GF" diff --git a/dGame/dComponents/ProximityMonitorComponent.cpp b/dGame/dComponents/ProximityMonitorComponent.cpp index acc93fde..b43e80b6 100644 --- a/dGame/dComponents/ProximityMonitorComponent.cpp +++ b/dGame/dComponents/ProximityMonitorComponent.cpp @@ -61,17 +61,17 @@ bool ProximityMonitorComponent::IsInProximity(const std::string& name, LWOOBJID } void ProximityMonitorComponent::Update(float deltaTime) { - for (const auto& prox : m_ProximitiesData) { - if (!prox.second) continue; - + for (const auto& [name, dpentity] : m_ProximitiesData) { + if (!dpentity) continue; + dpentity->SetPosition(m_Parent->GetPosition()); //Process enter events - for (auto* en : prox.second->GetNewObjects()) { - m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "ENTER"); + for (auto* en : dpentity->GetNewObjects()) { + m_Parent->OnCollisionProximity(en->GetObjectID(), name, "ENTER"); } //Process exit events - for (auto* en : prox.second->GetRemovedObjects()) { - m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "LEAVE"); + for (auto* en : dpentity->GetRemovedObjects()) { + m_Parent->OnCollisionProximity(en->GetObjectID(), name, "LEAVE"); } } } diff --git a/dScripts/02_server/Map/AM/CMakeLists.txt b/dScripts/02_server/Map/AM/CMakeLists.txt index d3d13b73..b02c40c5 100644 --- a/dScripts/02_server/Map/AM/CMakeLists.txt +++ b/dScripts/02_server/Map/AM/CMakeLists.txt @@ -1,4 +1,4 @@ -set(DSCRIPTS_SOURCES_02_SERVER_MAP_AM +set(DSCRIPTS_SOURCES_02_SERVER_MAP_AM "AmConsoleTeleportServer.cpp" "RandomSpawnerFin.cpp" "RandomSpawnerPit.cpp" @@ -16,4 +16,5 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_AM "AmSkullkinTower.cpp" "AmBlueX.cpp" "AmTeapotServer.cpp" + "WanderingVendor.cpp" PARENT_SCOPE) diff --git a/dScripts/02_server/Map/AM/WanderingVendor.cpp b/dScripts/02_server/Map/AM/WanderingVendor.cpp new file mode 100644 index 00000000..996eeec5 --- /dev/null +++ b/dScripts/02_server/Map/AM/WanderingVendor.cpp @@ -0,0 +1,35 @@ +#include "WanderingVendor.h" +#include "MovementAIComponent.h" +#include "ProximityMonitorComponent.h" + +void WanderingVendor::OnStartup(Entity* self) { + auto movementAIComponent = self->GetComponent(); + if (!movementAIComponent) return; + movementAIComponent->Resume(); + self->SetProximityRadius(10, "playermonitor"); +} + +void WanderingVendor::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) { + if (status == "ENTER" && entering->IsPlayer()) { + auto movementAIComponent = self->GetComponent(); + if (!movementAIComponent) return; + movementAIComponent->Pause(); + self->CancelTimer("startWalking"); + } else if (status == "LEAVE") { + auto* proximityMonitorComponent = self->GetComponent(); + if (!proximityMonitorComponent) { + Game::logger->LogDebug("MovementAIComponent::HandleWaypointCommandRemoveNPC", "Proximity monitor component not found!"); + return; + } + const auto proxObjs = proximityMonitorComponent->GetProximityObjects("playermonitor"); + if (proxObjs.empty()) self->AddTimer("startWalking", 1.5); + } +} + +void WanderingVendor::OnTimerDone(Entity* self, std::string timerName) { + if (timerName == "startWalking") { + auto movementAIComponent = self->GetComponent(); + if (!movementAIComponent) return; + movementAIComponent->Resume(); + } +} diff --git a/dScripts/02_server/Map/AM/WanderingVendor.h b/dScripts/02_server/Map/AM/WanderingVendor.h new file mode 100644 index 00000000..e5d98073 --- /dev/null +++ b/dScripts/02_server/Map/AM/WanderingVendor.h @@ -0,0 +1,10 @@ +#pragma once +#include "CppScripts.h" + +class WanderingVendor : 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; +}; + diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index 20619548..11f1b2cd 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -235,6 +235,7 @@ #include "AmDarklingDragon.h" #include "AmBlueX.h" #include "AmTeapotServer.h" +#include "WanderingVendor.h" // NJ Scripts #include "NjGarmadonCelebration.h" @@ -762,6 +763,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr script = new AmBlueX(); else if (scriptName == "scripts\\02_server\\Map\\AM\\L_TEAPOT_SERVER.lua") script = new AmTeapotServer(); + else if (scriptName == "scripts\\02_server\\Map\\AM\\L_WANDERING_VENDOR.lua") + script = new WanderingVendor(); // Ninjago else if (scriptName == "scripts\\02_server\\Map\\njhub\\L_GARMADON_CELEBRATION_SERVER.lua") diff --git a/dScripts/WblRobotCitizen.cpp b/dScripts/WblRobotCitizen.cpp deleted file mode 100644 index b6f58e05..00000000 --- a/dScripts/WblRobotCitizen.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "WblRobotCitizen.h" -#include "GameMessages.h" - -void WblRobotCitizen::OnStartup(Entity* self) { - // TODO: make it move via controllable physics -} - -void WblRobotCitizen::OnUse(Entity* self, Entity* user) { - auto movingPlatformComponent = self->GetComponent(); - if (movingPlatformComponent) movingPlatformComponent->StopPathing(); - auto face = NiQuaternion::LookAt(self->GetPosition(), user->GetPosition()); - self->SetRotation(face); - GameMessages::SendPlayAnimation(self, u"wave"); - self->AddTimer("animation time", m_AnimationTime); -} - -void WblRobotCitizen::OnTimerDone(Entity* self, std::string timerName) { - // TODO: make it move via controllable physics -} diff --git a/dScripts/ai/WILD/CMakeLists.txt b/dScripts/ai/WILD/CMakeLists.txt index 446ce0d4..53cfbad7 100644 --- a/dScripts/ai/WILD/CMakeLists.txt +++ b/dScripts/ai/WILD/CMakeLists.txt @@ -1,5 +1,6 @@ set(DSCRIPTS_SOURCES_AI_WILD "AllCrateChicken.cpp" + "LupGenericInteract.cpp" "WildAmbients.cpp" "WildAmbientCrab.cpp" "WildAndScared.cpp" diff --git a/dScripts/LupGenericInteract.cpp b/dScripts/ai/WILD/LupGenericInteract.cpp similarity index 89% rename from dScripts/LupGenericInteract.cpp rename to dScripts/ai/WILD/LupGenericInteract.cpp index e9afd337..95eb7a96 100644 --- a/dScripts/LupGenericInteract.cpp +++ b/dScripts/ai/WILD/LupGenericInteract.cpp @@ -1,6 +1,5 @@ #include "LupGenericInteract.h" #include "GameMessages.h" -#include "dLogger.h" void LupGenericInteract::OnUse(Entity* self, Entity* user) { GameMessages::SendPlayAnimation(self, u"interact"); diff --git a/dScripts/LupGenericInteract.h b/dScripts/ai/WILD/LupGenericInteract.h similarity index 100% rename from dScripts/LupGenericInteract.h rename to dScripts/ai/WILD/LupGenericInteract.h diff --git a/dScripts/zone/LUPs/CMakeLists.txt b/dScripts/zone/LUPs/CMakeLists.txt index b3b55ad6..14c3c76a 100644 --- a/dScripts/zone/LUPs/CMakeLists.txt +++ b/dScripts/zone/LUPs/CMakeLists.txt @@ -1,3 +1,12 @@ -set(DSCRIPTS_SOURCES_ZONE_LUPS + +set(DSCRIPTS_SOURCES_ZONE_LUPS "WblGenericZone.cpp" - PARENT_SCOPE) +) + +add_subdirectory(RobotCity_Intro) + +foreach(file ${DSCRIPTS_SOURCES_ZONE_LUPS_ROBOTCITYINTRO}) + set(DSCRIPTS_SOURCES_ZONE_LUPS ${DSCRIPTS_SOURCES_ZONE_LUPS} "RobotCity_Intro/${file}") +endforeach() + +set(DSCRIPTS_SOURCES_ZONE_LUPS ${DSCRIPTS_SOURCES_ZONE_LUPS} PARENT_SCOPE) diff --git a/dScripts/zone/LUPs/RobotCity_Intro/CMakeLists.txt b/dScripts/zone/LUPs/RobotCity_Intro/CMakeLists.txt new file mode 100644 index 00000000..fae8793b --- /dev/null +++ b/dScripts/zone/LUPs/RobotCity_Intro/CMakeLists.txt @@ -0,0 +1,3 @@ +set(DSCRIPTS_SOURCES_ZONE_LUPS_ROBOTCITYINTRO + "WblRobotCitizen.cpp" + PARENT_SCOPE) diff --git a/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp new file mode 100644 index 00000000..51d64759 --- /dev/null +++ b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp @@ -0,0 +1,25 @@ +#include "WblRobotCitizen.h" +#include "MovementAIComponent.h" +#include "RenderComponent.h" + +void WblRobotCitizen::OnStartup(Entity* self) { + auto movementAIComponent = self->GetComponent(); + if (!movementAIComponent) return; + movementAIComponent->Resume(); +} + +void WblRobotCitizen::OnUse(Entity* self, Entity* user) { + auto movementAIComponent = self->GetComponent(); + if (!movementAIComponent) return; + movementAIComponent->Pause(); + auto face = NiQuaternion::LookAt(self->GetPosition(), user->GetPosition()); + self->SetRotation(face); + auto timer = RenderComponent::PlayAnimation(self, "wave"); + self->AddTimer("animation time", timer); +} + +void WblRobotCitizen::OnTimerDone(Entity* self, std::string timerName) { + auto movementAIComponent = self->GetComponent(); + if (!movementAIComponent) return; + movementAIComponent->Resume(); +} diff --git a/dScripts/WblRobotCitizen.h b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.h similarity index 85% rename from dScripts/WblRobotCitizen.h rename to dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.h index 394c7add..b80a697b 100644 --- a/dScripts/WblRobotCitizen.h +++ b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.h @@ -6,7 +6,5 @@ public: void OnStartup(Entity* self) override; void OnUse(Entity* self, Entity* user) override; void OnTimerDone(Entity* self, std::string timerName) override; -private: - const float m_AnimationTime = 2.5; };