2024-02-27 16:07:14 +00:00
|
|
|
#include "WanderingVendor.h"
|
|
|
|
#include "MovementAIComponent.h"
|
|
|
|
#include "ProximityMonitorComponent.h"
|
2024-03-30 03:17:39 +00:00
|
|
|
#include <ranges>
|
2024-02-27 16:07:14 +00:00
|
|
|
|
|
|
|
void WanderingVendor::OnStartup(Entity* self) {
|
|
|
|
auto movementAIComponent = self->GetComponent<MovementAIComponent>();
|
|
|
|
if (!movementAIComponent) return;
|
|
|
|
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<MovementAIComponent>();
|
|
|
|
if (!movementAIComponent) return;
|
2024-03-27 02:06:22 +00:00
|
|
|
movementAIComponent->Pause();
|
2024-02-27 16:07:14 +00:00
|
|
|
self->CancelTimer("startWalking");
|
|
|
|
} else if (status == "LEAVE") {
|
|
|
|
auto* proximityMonitorComponent = self->GetComponent<ProximityMonitorComponent>();
|
|
|
|
if (!proximityMonitorComponent) self->AddComponent<ProximityMonitorComponent>();
|
|
|
|
|
|
|
|
const auto proxObjs = proximityMonitorComponent->GetProximityObjects("playermonitor");
|
2024-03-30 03:17:39 +00:00
|
|
|
bool foundPlayer = false;
|
|
|
|
for (const auto id : proxObjs | std::views::keys) {
|
|
|
|
auto* entity = Game::entityManager->GetEntity(id);
|
|
|
|
if (entity && entity->IsPlayer()) {
|
|
|
|
foundPlayer = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundPlayer) self->AddTimer("startWalking", 1.5);
|
2024-02-27 16:07:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WanderingVendor::OnTimerDone(Entity* self, std::string timerName) {
|
|
|
|
if (timerName == "startWalking") {
|
|
|
|
auto movementAIComponent = self->GetComponent<MovementAIComponent>();
|
|
|
|
if (!movementAIComponent) return;
|
2024-03-27 02:06:22 +00:00
|
|
|
movementAIComponent->Resume();
|
2024-02-27 16:07:14 +00:00
|
|
|
}
|
|
|
|
}
|