2024-02-25 22:59:10 +00:00
|
|
|
#include "DLUVanityTeleportingObject.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "dServer.h"
|
2022-07-05 06:00:10 +00:00
|
|
|
#include "VanityUtilities.h"
|
2023-03-20 13:10:52 +00:00
|
|
|
#include "RenderComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
void DLUVanityTeleportingObject::OnStartup(Entity* self) {
|
|
|
|
if (!self->HasVar(u"npcName") || !self->HasVar(u"teleport")) return;
|
|
|
|
m_Object = VanityUtilities::GetObject(self->GetVarAsString(u"npcName"));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
if (!m_Object) return;
|
|
|
|
if (self->HasVar(u"teleportInterval")) m_TeleportInterval = self->GetVar<float>(u"teleportInterval");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (self->GetVar<bool>(u"teleport")) {
|
2024-02-25 22:59:10 +00:00
|
|
|
self->AddTimer("setupTeleport", m_TeleportInterval);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
void DLUVanityTeleportingObject::OnTimerDone(Entity* self, std::string timerName) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (timerName == "setupTeleport") {
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(self, u"interact");
|
2021-12-05 17:54:36 +00:00
|
|
|
GameMessages::SendPlayFXEffect(self->GetObjectID(), 6478, u"teleportBeam", "teleportBeam");
|
|
|
|
GameMessages::SendPlayFXEffect(self->GetObjectID(), 6478, u"teleportRings", "teleportRings");
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
self->AddTimer("teleport", 2.0f);
|
|
|
|
self->AddTimer("stopFX", 2.0f);
|
|
|
|
} else if (timerName == "stopFX") {
|
|
|
|
GameMessages::SendStopFXEffect(self, true, "teleportBeam");
|
|
|
|
GameMessages::SendStopFXEffect(self, true, "teleportRings");
|
|
|
|
} else if (timerName == "teleport") {
|
2024-02-25 22:59:10 +00:00
|
|
|
std::vector<VanityObjectLocation>& locations = m_Object->m_Locations[Game::server->GetZoneID()];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
selectLocation:
|
2024-02-25 22:59:10 +00:00
|
|
|
VanityObjectLocation& newLocation = locations[GeneralUtils::GenerateRandomNumber<size_t>(0, locations.size() - 1)];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
// try to get not the same position, but if we get the same one twice, it's fine
|
2021-12-05 17:54:36 +00:00
|
|
|
if (self->GetPosition() == newLocation.m_Position) {
|
2024-02-25 22:59:10 +00:00
|
|
|
VanityObjectLocation& newLocation = locations[GeneralUtils::GenerateRandomNumber<size_t>(0, locations.size() - 1)];
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
self->SetPosition(newLocation.m_Position);
|
|
|
|
self->SetRotation(newLocation.m_Rotation);
|
2024-02-25 22:59:10 +00:00
|
|
|
self->SetScale(newLocation.m_Scale);
|
2021-12-05 17:54:36 +00:00
|
|
|
GameMessages::SendPlayFXEffect(self->GetObjectID(), 6478, u"teleportBeam", "teleportBeam");
|
|
|
|
GameMessages::SendPlayFXEffect(self->GetObjectID(), 6478, u"teleportRings", "teleportRings");
|
|
|
|
self->AddTimer("stopFX", 2.0f);
|
2024-02-25 22:59:10 +00:00
|
|
|
self->AddTimer("setupTeleport", m_TeleportInterval);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|