Files
DarkflameServer/dScripts/02_server/Map/GF/MastTeleport.cpp
Aaron Kimbrell a956e615f8 fix(scripts): the mast swing reads its lead-in as the game names it
The Gnarled Forest masts give the cinematic lead-in as LeadIn, an integer
(LeadIn=1:1). The mast script read LeanIn as a float, so the swing cinematic
always played with no lead-in. It now reads LeadIn and takes the integer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 07:08:36 -06:00

126 lines
4.3 KiB
C++

#include "MastTeleport.h"
#include "EntityManager.h"
#include "GameMessages.h"
#include "EffectsMessages.h"
#include "CombatMessages.h"
#include "MovementMessages.h"
#include "Preconditions.h"
#include "eEndBehavior.h"
#include "DestroyableComponent.h"
#include "eStateChangeType.h"
#ifdef _WIN32
#define _USE_MATH_DEFINES
#include <math.h>
#endif
#include "RenderComponent.h"
void MastTeleport::OnStartup(Entity* self) {
self->SetNetworkVar<std::string>(u"hookPreconditions", "154;44", UNASSIGNED_SYSTEM_ADDRESS);
}
void MastTeleport::OnQuickBuildComplete(Entity* self, Entity* target) {
if (Preconditions::Check(target, 154) && Preconditions::Check(target, 44)) {
self->SetVar<LWOOBJID>(u"userID", target->GetObjectID());
GameMessages::SetStunned stun;
stun.target = target->GetObjectID();
stun.StateChangeType = eStateChangeType::PUSH;
stun.bCantAttack = true;
stun.bCantEquip = true;
stun.bCantInteract = true;
stun.bCantJump = true;
stun.bCantMove = true;
stun.bCantTurn = true;
stun.bCantUseItem = true;
stun.Send(target->GetSystemAddress());
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
if (destroyableComponent) destroyableComponent->SetStatusImmunity(eStateChangeType::PUSH, true, true, true, true, true, false, false, true, true);
self->AddTimer("Start", 3);
}
}
void MastTeleport::OnTimerDone(Entity* self, std::string timerName) {
const auto playerId = self->GetVar<LWOOBJID>(u"userID");
auto* player = Game::entityManager->GetEntity(playerId);
if (player == nullptr) return;
if (timerName == "Start") {
auto position = self->GetPosition();
auto rotation = self->GetRotation();
GameMessages::Teleport(playerId, position, rotation, true).SendToClient(player->GetSystemAddress());
GameMessages::Teleport(playerId, position, rotation, true).SendToClient(player->GetSystemAddress());
const auto cinematic = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"Cinematic"));
// The mast's config holds the lead-in as an integer (LeadIn=1:1)
const auto leadIn = self->GetVarAs<float>(u"LeadIn");
if (!cinematic.empty()) {
GameMessages::PlayCinematic playCinematic;
playCinematic.target = playerId;
playCinematic.pathName = GeneralUtils::ASCIIToUTF16(cinematic);
playCinematic.allowGhostUpdates = true;
playCinematic.bCloseMultiInteract = true;
playCinematic.bSendServerNotify = false;
playCinematic.bUseControlledObjectForAudioListener = false;
playCinematic.endBehavior = eEndBehavior::RETURN;
playCinematic.hidePlayerDuringCine = false;
playCinematic.leadIn = leadIn;
playCinematic.Send(player->GetSystemAddress());
}
GameMessages::PlayFXEffect(playerId, 6039, u"hook", "hook").Send(UNASSIGNED_SYSTEM_ADDRESS);
float animationTime = 6.25f;
animationTime = RenderComponent::PlayAnimation(player, "crow-swing-no-equip", 4.0f);
RenderComponent::PlayAnimation(self, u"swing");
self->AddTimer("PlayerAnimDone", animationTime);
} else if (timerName == "PlayerAnimDone") {
GameMessages::StopFXEffect(player->GetObjectID(), true, "hook").Send(UNASSIGNED_SYSTEM_ADDRESS);
auto forward = QuatUtils::Forward(self->GetRotation());
const auto degrees = -25.0f;
const auto rads = degrees * (static_cast<float>(M_PI) / 180.0f);
const Vector3 newPlayerRot = { 0, rads, 0 };
auto position = self->GetPosition();
position.x += (forward.x * 20.5f);
position.y += 12;
position.z += (forward.z * 20.5f);
GameMessages::OrientToAngle orientToAngle;
orientToAngle.target = playerId;
orientToAngle.bRelativeToCurrent = true;
orientToAngle.fAngle = rads;
orientToAngle.Send(player->GetSystemAddress());
GameMessages::Teleport(playerId, position, QuatUtils::IDENTITY).SendToClient(player->GetSystemAddress());
GameMessages::SetStunned stun;
stun.target = playerId;
stun.StateChangeType = eStateChangeType::POP;
stun.bCantAttack = true;
stun.bCantEquip = true;
stun.bCantInteract = true;
stun.bCantJump = true;
stun.bCantMove = true;
stun.bCantTurn = true;
stun.bCantUseItem = true;
stun.Send(player->GetSystemAddress());
auto* destroyableComponent = player->GetComponent<DestroyableComponent>();
if (destroyableComponent) destroyableComponent->SetStatusImmunity(eStateChangeType::POP, true, true, true, true, true, false, false, true, true);
Game::entityManager->SerializeEntity(player);
}
}