Organize dScripts (#814)

* Organize dScripts

whitespace

Remove parent scope

Remove parent scope from initial setter

Remove debug

Remove helper programs

* Fix NtImagimeterVisibility script

Co-authored-by: aronwk-aaron <aronwk.aaron@gmail.com>
This commit is contained in:
David Markowitz
2022-11-03 10:57:54 -07:00
committed by GitHub
parent b974eed8f5
commit 8d37d9b681
567 changed files with 886 additions and 252 deletions

View File

@@ -0,0 +1,6 @@
set(DSCRIPTS_SOURCES_02_SERVER_MAP_GF
"GfTikiTorch.cpp"
"GfCaptainsCannon.cpp"
"MastTeleport.cpp"
"SpawnLionServer.cpp"
PARENT_SCOPE)

View File

@@ -0,0 +1,83 @@
#include "GfCaptainsCannon.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "MissionComponent.h"
void GfCaptainsCannon::OnUse(Entity* self, Entity* user) {
if (self->GetVar<bool>(u"bIsInUse")) {
return;
}
self->SetVar<LWOOBJID>(u"userID", user->GetObjectID());
self->SetVar<bool>(u"bIsInUse", true);
self->SetNetworkVar<bool>(u"bIsInUse", true);
GameMessages::SendSetStunned(user->GetObjectID(), PUSH, user->GetSystemAddress(),
LWOOBJID_EMPTY, true, true, true, true, true, true, true, true
);
auto position = self->GetPosition();
auto forward = self->GetRotation().GetForwardVector();
position.x += forward.x * -3;
position.z += forward.z * -3;
auto rotation = self->GetRotation();
GameMessages::SendTeleport(user->GetObjectID(), position, rotation, user->GetSystemAddress());
GameMessages::SendPlayAnimation(user, u"cannon-strike-no-equip");
GameMessages::SendPlayFXEffect(user->GetObjectID(), 6039, u"hook", "hook", LWOOBJID_EMPTY, 1, 1, true);
self->AddTimer("FireCannon", 1.667f);
}
void GfCaptainsCannon::OnTimerDone(Entity* self, std::string timerName) {
const auto playerId = self->GetVar<LWOOBJID>(u"userID");
auto* player = EntityManager::Instance()->GetEntity(playerId);
if (player == nullptr) {
self->SetVar<bool>(u"bIsInUse", false);
self->SetNetworkVar<bool>(u"bIsInUse", false);
return;
}
if (timerName == "FireCannon") {
float cinematicTime = 6.3f;
GameMessages::SendPlayCinematic(playerId, u"Cannon_Cam", player->GetSystemAddress());
self->AddTimer("cinematicTimer", cinematicTime);
const auto sharkObjects = EntityManager::Instance()->GetEntitiesInGroup("SharkCannon");
for (auto* shark : sharkObjects) {
if (shark->GetLOT() != m_SharkItemID) continue;
GameMessages::SendPlayAnimation(shark, u"cannon");
}
GameMessages::SendPlay2DAmbientSound(player, "{7457d85c-4537-4317-ac9d-2f549219ea87}");
} else if (timerName == "cinematicTimer") {
GameMessages::SendSetStunned(playerId, POP, player->GetSystemAddress(),
LWOOBJID_EMPTY, true, true, true, true, true, true, true, true
);
self->SetVar<bool>(u"bIsInUse", false);
self->SetNetworkVar<bool>(u"bIsInUse", false);
GameMessages::SendStopFXEffect(player, true, "hook");
auto* missionComponent = player->GetComponent<MissionComponent>();
if (missionComponent != nullptr) {
missionComponent->ForceProgress(601, 910, 1);
}
GameMessages::SendTerminateInteraction(playerId, FROM_INTERACTION, self->GetObjectID());
}
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "CppScripts.h"
class GfCaptainsCannon : public CppScripts::Script
{
public:
void OnUse(Entity* self, Entity* user) override;
void OnTimerDone(Entity* self, std::string timerName) override;
private:
int32_t m_SharkItemID = 7343;
};

View File

@@ -0,0 +1,75 @@
#include "GfTikiTorch.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "MissionComponent.h"
#include "RenderComponent.h"
void GfTikiTorch::OnStartup(Entity* self) {
LightTorch(self);
}
void GfTikiTorch::OnUse(Entity* self, Entity* killer) {
if (self->GetBoolean(u"isInUse")) {
self->SetBoolean(u"isInUse", false);
return;
}
GameMessages::SendPlayAnimation(self, u"interact");
self->SetI64(u"userID", killer->GetObjectID());
for (int i = 0; i < m_numspawn; i++) {
GameMessages::SendDropClientLoot(killer, self->GetObjectID(), 935, 0, self->GetPosition());
}
self->AddTimer("InteractionCooldown", 4);
}
void GfTikiTorch::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "Relight") {
LightTorch(self);
} else if (timerName == "InteractionCooldown") {
Entity* player = EntityManager::Instance()->GetEntity(self->GetI64(u"userID"));
if (player != nullptr && player->GetCharacter()) {
GameMessages::SendTerminateInteraction(player->GetObjectID(), FROM_INTERACTION, self->GetObjectID());
}
self->SetBoolean(u"isInUse", false);
self->SetI64(u"userID", 0);
}
}
void GfTikiTorch::LightTorch(Entity* self) {
auto* renderComponent = static_cast<RenderComponent*>(self->GetComponent(COMPONENT_TYPE_RENDER));
if (renderComponent == nullptr)
return;
self->SetBoolean(u"isInUse", false);
renderComponent->PlayEffect(611, u"fire", "tikitorch");
self->SetBoolean(u"isBurning", true);
}
void GfTikiTorch::OnSkillEventFired(Entity* self, Entity* caster, const std::string& message) {
if (self->GetBoolean(u"isBurning") && message == "waterspray") {
GameMessages::SendPlayAnimation(self, u"water");
auto* renderComponent = self->GetComponent<RenderComponent>();
if (renderComponent != nullptr) {
renderComponent->StopEffect("tikitorch");
renderComponent->PlayEffect(611, u"water", "water");
renderComponent->PlayEffect(611, u"steam", "steam");
}
auto* casterMissionComponent = caster->GetComponent<MissionComponent>();
if (casterMissionComponent != nullptr) {
for (const auto missionID : m_missions) {
casterMissionComponent->ForceProgressTaskType(missionID, static_cast<uint32_t>(MissionTaskType::MISSION_TASK_TYPE_SCRIPT), 1);
}
}
self->AddTimer("Relight", 7.0f);
self->SetBoolean(u"isBurning", false);
}
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "CppScripts.h"
class GfTikiTorch : public CppScripts::Script
{
public:
void OnStartup(Entity* self) override;
void OnUse(Entity* self, Entity* killer) override;
void OnTimerDone(Entity* self, std::string timerName) override;
void OnSkillEventFired(Entity* self, Entity* caster, const std::string& message) override;
private:
void LightTorch(Entity* self);
LOT m_imaginationlot = 935;
int32_t m_numspawn = 3;
std::vector<int> m_missions = { 472, 1429, 1527, 1564, 1601 };
};

View File

@@ -0,0 +1,88 @@
#include "MastTeleport.h"
#include "EntityManager.h"
#include "GameMessages.h"
#include "Preconditions.h"
#ifdef _WIN32
#define _USE_MATH_DEFINES
#include <math.h>
#endif
void MastTeleport::OnStartup(Entity* self) {
self->SetNetworkVar<std::string>(u"hookPreconditions", "154;44", UNASSIGNED_SYSTEM_ADDRESS);
}
void MastTeleport::OnRebuildComplete(Entity* self, Entity* target) {
if (Preconditions::Check(target, 154) && Preconditions::Check(target, 44)) {
self->SetVar<LWOOBJID>(u"userID", target->GetObjectID());
GameMessages::SendSetStunned(target->GetObjectID(), PUSH, target->GetSystemAddress(),
LWOOBJID_EMPTY, true, true, true, true, true, true, true
);
self->AddTimer("Start", 3);
}
}
void MastTeleport::OnTimerDone(Entity* self, std::string timerName) {
const auto playerId = self->GetVar<LWOOBJID>(u"userID");
auto* player = EntityManager::Instance()->GetEntity(playerId);
if (player == nullptr) return;
if (timerName == "Start") {
auto position = self->GetPosition();
auto rotation = self->GetRotation();
GameMessages::SendTeleport(playerId, position, rotation, player->GetSystemAddress(), true);
// 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());
}
const auto cinematic = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"Cinematic"));
const auto leanIn = self->GetVar<float>(u"LeanIn");
if (!cinematic.empty()) {
GameMessages::SendPlayCinematic(playerId, GeneralUtils::ASCIIToUTF16(cinematic), player->GetSystemAddress(),
true, true, false, false, 0, false, leanIn
);
}
GameMessages::SendPlayFXEffect(playerId, 6039, u"hook", "hook", LWOOBJID_EMPTY, 1, 1, true);
GameMessages::SendPlayAnimation(player, u"crow-swing-no-equip");
GameMessages::SendPlayAnimation(self, u"swing");
self->AddTimer("PlayerAnimDone", 6.25f);
} else if (timerName == "PlayerAnimDone") {
GameMessages::SendStopFXEffect(player, true, "hook");
auto forward = self->GetRotation().GetForwardVector();
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::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
);
}
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "CppScripts.h"
class MastTeleport : public CppScripts::Script {
public:
void OnStartup(Entity* self) override;
void OnRebuildComplete(Entity* self, Entity* target) override;
void OnTimerDone(Entity* self, std::string timerName) override;
};

View File

@@ -0,0 +1,10 @@
#include "SpawnLionServer.h"
#include "Entity.h"
void SpawnLionServer::SetVariables(Entity* self) {
self->SetVar<LOT>(u"petLOT", 3520);
self->SetVar<std::string>(u"petType", "lion");
self->SetVar<uint32_t>(u"maxPets", 5);
self->SetVar<std::u16string>(u"spawnAnim", u"spawn-lion");
self->SetVar<std::u16string>(u"spawnCinematic", u"Lion_spawn");
}

View File

@@ -0,0 +1,6 @@
#pragma once
#include "SpawnPetBaseServer.h"
class SpawnLionServer : public SpawnPetBaseServer {
void SetVariables(Entity* self) override;
};