DarkflameServer/dScripts/NtVentureCannonServer.cpp
David Markowitz 8cdb388915
Optimize scripts for faster compilation (#597)
* Implement Precompiled Headers

* First volume of optimizations

* Scripts A-B

Gonna be doing this in alphabetical order now.

* C Scripts and remove unneeded includes from base cppscripts header

Remove the MissionComponent and Loot includes from all base scripts and place their needed includes in the respective scripts.

* D scripts

* F scripts

* F scripts 2

Finish up removing extraneous includes from scripts that start with the letter F

* G scripts

Removing extraneous includes from scripts that start with the letter G

* I scripts

Removing extraneous includes from scripts that start with the letter I

* M-Z scripts

Removing extraneous includes from scripts that start with the letter M-Z

* Revert "Implement Precompiled Headers"

This reverts commit d79d8d4991.

* Revert "Revert "Implement Precompiled Headers""

This reverts commit 0597faf308.

* Add back in PCH

Add back in PCH

* Fix CMake

Whitespace

Remove duplicate file glob

Remove newline
2022-07-04 23:00:10 -07:00

135 lines
4.0 KiB
C++

#include "NtVentureCannonServer.h"
#include "GameMessages.h"
#include "EntityManager.h"
void NtVentureCannonServer::OnUse(Entity* self, Entity* user)
{
auto* player = user;
const auto playerID = player->GetObjectID();
auto enterCinematic = self->GetVar<std::u16string>(u"EnterCinematic");
if (enterCinematic.empty())
{
return;
}
self->SetNetworkVar(u"bIsInUse", true);
GameMessages::SendSetStunned(playerID, PUSH, player->GetSystemAddress(), LWOOBJID_EMPTY,
true, true, true, true, true, true, true
);
auto destPosition = self->GetPosition();
destPosition.y += 5 - 1.57f;
auto destRotation = self->GetRotation();
GameMessages::SendTeleport(playerID, destPosition, destRotation, player->GetSystemAddress(), true);
GameMessages::SendPlayAnimation(player, u"scale-down", 4.0f);
const auto enterCinematicUname = enterCinematic;
GameMessages::SendPlayCinematic(player->GetObjectID(), enterCinematicUname, player->GetSystemAddress());
GameMessages::SendPlayNDAudioEmitter(player, player->GetSystemAddress(), "{e8bf79ce-7453-4a7d-b872-fee65e97ff15}");
self->AddCallbackTimer(3, [this, self]() {
self->SetNetworkVar(u"bIsInUse", false);
});
self->AddCallbackTimer(1.5f, [this, self, playerID]() {
auto* player = EntityManager::Instance()->GetEntity(playerID);
if (player == nullptr)
{
return;
}
EnterCannonEnded(self, player);
});
}
void NtVentureCannonServer::EnterCannonEnded(Entity* self, Entity* player)
{
const auto playerID = player->GetObjectID();
const auto& cannonEffectGroup = EntityManager::Instance()->GetEntitiesInGroup("cannonEffect");
if (!cannonEffectGroup.empty())
{
auto* cannonEffect = cannonEffectGroup[0];
GameMessages::SendPlayFXEffect(cannonEffect, 6036, u"create", "cannon_blast", LWOOBJID_EMPTY, 1, 1, true);
GameMessages::SendPlayEmbeddedEffectOnAllClientsNearObject(cannonEffect, u"camshake-bridge", cannonEffect->GetObjectID(), 100);
}
FirePlayer(self, player);
auto exitCinematic = self->GetVar<std::u16string>(u"ExitCinematic");
if (exitCinematic.empty())
{
UnlockCannonPlayer(self, player);
return;
}
const auto exitCinematicUname = exitCinematic;
GameMessages::SendPlayCinematic(player->GetObjectID(), exitCinematicUname, player->GetSystemAddress(),
true, true, true, false, 0, false, 0, false, false
);
self->AddCallbackTimer(1.5f, [this, self, playerID]() {
auto* player = EntityManager::Instance()->GetEntity(playerID);
if (player == nullptr)
{
return;
}
ExitCannonEnded(self, player);
});
}
void NtVentureCannonServer::ExitCannonEnded(Entity* self, Entity* player)
{
UnlockCannonPlayer(self, player);
}
void NtVentureCannonServer::UnlockCannonPlayer(Entity* self, Entity* player)
{
GameMessages::SendSetStunned(player->GetObjectID(), POP, player->GetSystemAddress(), LWOOBJID_EMPTY,
true, true, true, true, true, true, true
);
self->SetNetworkVar(u"bIsInUse", false);
GameMessages::SendTerminateInteraction(player->GetObjectID(), FROM_INTERACTION, self->GetObjectID());
}
void NtVentureCannonServer::FirePlayer(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));
if (!groupObjs.empty())
{
destination = groupObjs[0];
}
}
const auto destPosition = destination->GetPosition();
const auto destRotation = destination->GetRotation();
GameMessages::SendTeleport(player->GetObjectID(), destPosition, destRotation, player->GetSystemAddress(), true);
GameMessages::SendPlayAnimation(player, u"venture-cannon-out", 4.0f);
}