2024-02-27 16:07:14 +00:00
|
|
|
#include "WanderingVendor.h"
|
|
|
|
#include "MovementAIComponent.h"
|
|
|
|
#include "ProximityMonitorComponent.h"
|
2024-03-30 13:17:56 +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 13:17:56 +00:00
|
|
|
bool foundPlayer = false;
|
2024-04-05 05:52:26 +00:00
|
|
|
for (const auto id : proxObjs) {
|
2024-03-30 13:17:56 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|