DarkflameServer/dScripts/NtParadoxTeleServer.cpp

114 lines
3.4 KiB
C++
Raw Normal View History

#include "NtParadoxTeleServer.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "MissionComponent.h"
2022-07-28 13:39:57 +00:00
void NtParadoxTeleServer::OnStartup(Entity* self) {
self->SetProximityRadius(5, "teleport");
}
2022-07-28 13:39:57 +00:00
void NtParadoxTeleServer::OnPlayerLoaded(Entity* self, Entity* player) {
}
2022-07-28 13:39:57 +00:00
void NtParadoxTeleServer::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
if (status != "ENTER" || !entering->IsPlayer() || name != "teleport") return;
2022-07-28 13:39:57 +00:00
auto* player = entering;
const auto playerID = player->GetObjectID();
2022-07-28 13:39:57 +00:00
const auto iter = m_TeleportingPlayerTable.find(playerID);
if (iter == m_TeleportingPlayerTable.end()) m_TeleportingPlayerTable[playerID] = false;
const auto bPlayerBeingTeleported = m_TeleportingPlayerTable[playerID];
2022-07-28 13:39:57 +00:00
if (player->IsPlayer() && !bPlayerBeingTeleported) {
GameMessages::SendSetStunned(playerID, PUSH, player->GetSystemAddress(), LWOOBJID_EMPTY,
true, true, true, true, true, true, true
);
2022-07-28 13:39:57 +00:00
GameMessages::SendPlayAnimation(player, u"teledeath", 4.0f);
2022-07-28 13:39:57 +00:00
const auto animTime = 2;
2022-07-28 13:39:57 +00:00
self->AddCallbackTimer(animTime, [this, self, playerID]() {
auto* player = EntityManager::Instance()->GetEntity(playerID);
2022-07-28 13:39:57 +00:00
if (player == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
TeleportPlayer(self, player);
});
}
2022-07-28 13:39:57 +00:00
auto* missionComponent = player->GetComponent<MissionComponent>();
2022-07-28 13:39:57 +00:00
if (missionComponent != nullptr) {
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_SCRIPT, self->GetLOT());
}
}
2022-07-28 13:39:57 +00:00
void NtParadoxTeleServer::TeleportPlayer(Entity* self, Entity* player) {
auto destinationGroup = self->GetVar<std::u16string>(u"teleGroup");
auto* destination = self;
if (!destinationGroup.empty()) {
const auto& groupObjs = EntityManager::Instance()->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(destinationGroup));
2022-07-28 13:39:57 +00:00
if (!groupObjs.empty()) {
destination = groupObjs[0];
}
}
2022-07-28 13:39:57 +00:00
const auto destPosition = destination->GetPosition();
const auto destRotation = destination->GetRotation();
2022-07-28 13:39:57 +00:00
auto teleCinematic = self->GetVar<std::u16string>(u"Cinematic");
2022-07-28 13:39:57 +00:00
if (!teleCinematic.empty()) {
const auto teleCinematicUname = teleCinematic;
GameMessages::SendPlayCinematic(player->GetObjectID(), teleCinematicUname, player->GetSystemAddress());
}
2022-07-28 13:39:57 +00:00
GameMessages::SendTeleport(player->GetObjectID(), destPosition, destRotation, player->GetSystemAddress(), true);
2022-07-28 13:39:57 +00:00
GameMessages::SendPlayAnimation(player, u"paradox-teleport-in", 4.0f);
2022-07-28 13:39:57 +00:00
const auto animTime = 2;
2022-07-28 13:39:57 +00:00
const auto playerID = player->GetObjectID();
2022-07-28 13:39:57 +00:00
self->AddCallbackTimer(animTime, [this, self, playerID]() {
auto* player = EntityManager::Instance()->GetEntity(playerID);
2022-07-28 13:39:57 +00:00
if (player == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
UnlockPlayer(self, player);
});
2022-07-28 13:39:57 +00:00
const auto useSound = self->GetVar<std::string>(u"sound1");
2022-07-28 13:39:57 +00:00
if (!useSound.empty()) {
GameMessages::SendPlayNDAudioEmitter(player, player->GetSystemAddress(), useSound);
}
}
2022-07-28 13:39:57 +00:00
void NtParadoxTeleServer::UnlockPlayer(Entity* self, Entity* player) {
const auto playerID = player->GetObjectID();
2022-07-28 13:39:57 +00:00
m_TeleportingPlayerTable[playerID] = false;
2022-07-28 13:39:57 +00:00
GameMessages::SendSetStunned(playerID, POP, player->GetSystemAddress(), LWOOBJID_EMPTY,
true, true, true, true, true, true, true
);
2022-07-28 13:39:57 +00:00
auto teleCinematic = self->GetVar<std::u16string>(u"Cinematic");
2022-07-28 13:39:57 +00:00
if (!teleCinematic.empty()) {
const auto teleCinematicUname = teleCinematic;
GameMessages::SendEndCinematic(player->GetObjectID(), teleCinematicUname, player->GetSystemAddress());
}
}