DarkflameServer/dScripts/MastTeleport.cpp

89 lines
2.8 KiB
C++
Raw Permalink Normal View History

#include "MastTeleport.h"
#include "EntityManager.h"
#include "GameMessages.h"
#include "Preconditions.h"
#ifdef _WIN32
#define _USE_MATH_DEFINES
#include <math.h>
#endif
2022-07-28 13:39:57 +00:00
void MastTeleport::OnStartup(Entity* self) {
self->SetNetworkVar<std::string>(u"hookPreconditions", "154;44", UNASSIGNED_SYSTEM_ADDRESS);
}
2022-07-28 13:39:57 +00:00
void MastTeleport::OnRebuildComplete(Entity* self, Entity* target) {
if (Preconditions::Check(target, 154) && Preconditions::Check(target, 44)) {
self->SetVar<LWOOBJID>(u"userID", target->GetObjectID());
2022-07-28 13:39:57 +00:00
GameMessages::SendSetStunned(target->GetObjectID(), PUSH, target->GetSystemAddress(),
LWOOBJID_EMPTY, true, true, true, true, true, true, true
);
2022-07-28 13:39:57 +00:00
self->AddTimer("Start", 3);
}
}
2022-07-28 13:39:57 +00:00
void MastTeleport::OnTimerDone(Entity* self, std::string timerName) {
const auto playerId = self->GetVar<LWOOBJID>(u"userID");
2022-07-28 13:39:57 +00:00
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
if (timerName == "Start") {
auto position = self->GetPosition();
auto rotation = self->GetRotation();
2022-07-28 13:39:57 +00:00
GameMessages::SendTeleport(playerId, position, rotation, player->GetSystemAddress(), true);
2022-07-28 13:39:57 +00:00
// Hacky fix for odd rotations
if (self->GetVar<std::u16string>(u"MastName") != u"Jail") {
GameMessages::SendOrientToAngle(playerId, true, (M_PI / 180) * 140.0f, player->GetSystemAddress());
} else {
GameMessages::SendOrientToAngle(playerId, true, (M_PI / 180) * 100.0f, player->GetSystemAddress());
}
2022-07-28 13:39:57 +00:00
const auto cinematic = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"Cinematic"));
const auto leanIn = self->GetVar<float>(u"LeanIn");
2022-07-28 13:39:57 +00:00
if (!cinematic.empty()) {
GameMessages::SendPlayCinematic(playerId, GeneralUtils::ASCIIToUTF16(cinematic), player->GetSystemAddress(),
true, true, false, false, 0, false, leanIn
);
}
2022-07-28 13:39:57 +00:00
GameMessages::SendPlayFXEffect(playerId, 6039, u"hook", "hook", LWOOBJID_EMPTY, 1, 1, true);
2022-07-28 13:39:57 +00:00
GameMessages::SendPlayAnimation(player, u"crow-swing-no-equip");
2022-07-28 13:39:57 +00:00
GameMessages::SendPlayAnimation(self, u"swing");
2022-07-28 13:39:57 +00:00
self->AddTimer("PlayerAnimDone", 6.25f);
} else if (timerName == "PlayerAnimDone") {
GameMessages::SendStopFXEffect(player, true, "hook");
2022-07-28 13:39:57 +00:00
auto forward = self->GetRotation().GetForwardVector();
2022-07-28 13:39:57 +00:00
const auto degrees = -25.0f;
2022-07-28 13:39:57 +00:00
const auto rads = degrees * (static_cast<float>(M_PI) / 180.0f);
2022-09-04 10:47:53 +00:00
const NiPoint3 newPlayerRot = { 0, rads, 0 };
2022-07-28 13:39:57 +00:00
auto position = self->GetPosition();
2022-07-28 13:39:57 +00:00
position.x += (forward.x * 20.5f);
position.y += 12;
position.z += (forward.z * 20.5f);
GameMessages::SendOrientToAngle(playerId, true, rads, player->GetSystemAddress());
GameMessages::SendTeleport(playerId, position, NiQuaternion::IDENTITY, player->GetSystemAddress());
GameMessages::SendSetStunned(playerId, POP, player->GetSystemAddress(),
LWOOBJID_EMPTY, true, true, true, true, true, true, true
);
}
}