Skip to content

Commit

Permalink
Chore: split VE script up (#1598)
Browse files Browse the repository at this point in the history
* Testing Scripts

Testing splitting AgSpaceStuff into AgSpaceStuff and AgShipShake

* fixed inclusions

* Removed DoShake

* cleaning up

* consistent if statements

* Update dScripts/ai/AG/AgShipShake.h

Co-authored-by: David Markowitz <[email protected]>

---------

Co-authored-by: David Markowitz <[email protected]>
  • Loading branch information
Tiernan-Alderman and EmosewaMC authored May 27, 2024
1 parent 9328021 commit e966d3a
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 89 deletions.
2 changes: 2 additions & 0 deletions dScripts/CppScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "AgShipPlayerDeathTrigger.h"
#include "AgShipPlayerShockServer.h"
#include "AgSpaceStuff.h"
#include "AgShipShake.h"
#include "AgImagSmashable.h"
#include "NpcNpSpacemanBob.h"
#include "StoryBoxInteractServer.h"
Expand Down Expand Up @@ -341,6 +342,7 @@ namespace {
{ "scripts\\ai\\AG\\L_AG_SHIP_PLAYER_DEATH_TRIGGER.lua", []() { return new AgShipPlayerDeathTrigger(); } },
{"scripts\\ai\\NP\\L_NPC_NP_SPACEMAN_BOB.lua", []() { return new NpcNpSpacemanBob(); } },
{"scripts\\ai\\AG\\L_AG_SPACE_STUFF.lua", []() { return new AgSpaceStuff();} },
{"scripts\\ai\\AG\\L_AG_SHIP_SHAKE.lua", []() { return new AgShipShake();}},
{"scripts\\ai\\AG\\L_AG_SHIP_PLAYER_SHOCK_SERVER.lua", []() { return new AgShipPlayerShockServer();} },
{"scripts\\ai\\AG\\L_AG_IMAG_SMASHABLE.lua", []() { return new AgImagSmashable();} },
{"scripts\\02_server\\Map\\General\\L_STORY_BOX_INTERACT_SERVER.lua", []() { return new StoryBoxInteractServer();} },
Expand Down
81 changes: 81 additions & 0 deletions dScripts/ai/AG/AgShipShake.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "AgShipShake.h"
#include "EntityInfo.h"
#include "GeneralUtils.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "RenderComponent.h"
#include "Entity.h"

void AgShipShake::OnStartup(Entity* self) {
EntityInfo info{};

info.pos = { -418, 585, -30 };
info.lot = 33;
info.spawnerID = self->GetObjectID();

auto* ref = Game::entityManager->CreateEntity(info);

Game::entityManager->ConstructEntity(ref);

self->SetVar(u"ShakeObject", ref->GetObjectID());

self->AddTimer("ShipShakeIdle", 2.0f);
self->SetVar(u"RandomTime", 10);
}

void AgShipShake::OnTimerDone(Entity* self, std::string timerName) {
auto* shipFxObject = GetEntityInGroup(ShipFX);
auto* shipFxObject2 = GetEntityInGroup(ShipFX2);
auto* debrisObject = GetEntityInGroup(DebrisFX);
if (timerName == "ShipShakeIdle") {
auto* ref = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"ShakeObject"));

const auto randomTime = self->GetVar<int>(u"RandomTime");
auto time = GeneralUtils::GenerateRandomNumber<int>(0, randomTime + 1);

if (time < randomTime / 2) {
time += randomTime / 2;
}

self->AddTimer("ShipShakeIdle", static_cast<float>(time));

if (ref)
GameMessages::SendPlayEmbeddedEffectOnAllClientsNearObject(ref, FXName, ref->GetObjectID(), 500.0f);


if (debrisObject)
GameMessages::SendPlayFXEffect(debrisObject, -1, u"DebrisFall", "Debris", LWOOBJID_EMPTY, 1.0f, 1.0f, true);

const auto randomFx = GeneralUtils::GenerateRandomNumber<int>(0, 3);

if (shipFxObject) {
std::string effectType = "shipboom" + std::to_string(randomFx);
GameMessages::SendPlayFXEffect(shipFxObject, 559, GeneralUtils::ASCIIToUTF16(effectType), "FX", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
}

self->AddTimer("ShipShakeExplode", 5.0f);

if (shipFxObject2)
RenderComponent::PlayAnimation(shipFxObject2, u"explosion");
} else if (timerName == "ShipShakeExplode") {
if (shipFxObject)
RenderComponent::PlayAnimation(shipFxObject, u"idle");
if (shipFxObject2)
RenderComponent::PlayAnimation(shipFxObject2, u"idle");
}
}

Entity* AgShipShake::GetEntityInGroup(const std::string& group) {
auto entities = Game::entityManager->GetEntitiesInGroup(group);
Entity* en = nullptr;

for (auto entity : entities) {
if (entity) {
en = entity;
break;
}
}

return en;
}

16 changes: 16 additions & 0 deletions dScripts/ai/AG/AgShipShake.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "CppScripts.h"

class AgShipShake : public CppScripts::Script {
public:
void OnStartup(Entity* self) override;
void OnTimerDone(Entity* self, std::string timerName) override;

std::string DebrisFX = "DebrisFX";
std::string ShipFX = "ShipFX";
std::string ShipFX2 = "ShipFX2";
std::u16string FXName = u"camshake-bridge";

private:
Entity* GetEntityInGroup(const std::string& group);
};
80 changes: 0 additions & 80 deletions dScripts/ai/AG/AgSpaceStuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@

void AgSpaceStuff::OnStartup(Entity* self) {
self->AddTimer("FloaterScale", 5.0f);

EntityInfo info{};

info.pos = { -418, 585, -30 };
info.lot = 33;
info.spawnerID = self->GetObjectID();

auto* ref = Game::entityManager->CreateEntity(info);

Game::entityManager->ConstructEntity(ref);

self->SetVar(u"ShakeObject", ref->GetObjectID());

self->AddTimer("ShipShakeIdle", 2.0f);
self->SetVar(u"RandomTime", 10);
}

void AgSpaceStuff::OnTimerDone(Entity* self, std::string timerName) {
Expand All @@ -37,70 +22,5 @@ void AgSpaceStuff::OnTimerDone(Entity* self, std::string timerName) {

RenderComponent::PlayAnimation(self, u"path_0" + (GeneralUtils::to_u16string(pathType)));
self->AddTimer("FloaterScale", randTime);
} else if (timerName == "ShipShakeExplode") {
DoShake(self, true);
} else if (timerName == "ShipShakeIdle") {
DoShake(self, false);
}
}

void AgSpaceStuff::DoShake(Entity* self, bool explodeIdle) {

if (!explodeIdle) {
auto* ref = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"ShakeObject"));

const auto randomTime = self->GetVar<int>(u"RandomTime");
auto time = GeneralUtils::GenerateRandomNumber<int>(0, randomTime + 1);

if (time < randomTime / 2) {
time += randomTime / 2;
}

self->AddTimer("ShipShakeIdle", static_cast<float>(time));

if (ref)
GameMessages::SendPlayEmbeddedEffectOnAllClientsNearObject(ref, FXName, ref->GetObjectID(), 500.0f);

auto* debrisObject = GetEntityInGroup(DebrisFX);

if (debrisObject)
GameMessages::SendPlayFXEffect(debrisObject, -1, u"DebrisFall", "Debris", LWOOBJID_EMPTY, 1.0f, 1.0f, true);

const auto randomFx = GeneralUtils::GenerateRandomNumber<int>(0, 3);

auto* shipFxObject = GetEntityInGroup(ShipFX);
if (shipFxObject) {
std::string effectType = "shipboom" + std::to_string(randomFx);
GameMessages::SendPlayFXEffect(shipFxObject, 559, GeneralUtils::ASCIIToUTF16(effectType), "FX", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
}

self->AddTimer("ShipShakeExplode", 5.0f);

auto* shipFxObject2 = GetEntityInGroup(ShipFX2);
if (shipFxObject2)
RenderComponent::PlayAnimation(shipFxObject2, u"explosion");
} else {
auto* shipFxObject = GetEntityInGroup(ShipFX);
auto* shipFxObject2 = GetEntityInGroup(ShipFX2);

if (shipFxObject)
RenderComponent::PlayAnimation(shipFxObject, u"idle");

if (shipFxObject2)
RenderComponent::PlayAnimation(shipFxObject2, u"idle");
}
}

Entity* AgSpaceStuff::GetEntityInGroup(const std::string& group) {
auto entities = Game::entityManager->GetEntitiesInGroup(group);
Entity* en = nullptr;

for (auto entity : entities) {
if (entity) {
en = entity;
break;
}
}

return en;
}
9 changes: 0 additions & 9 deletions dScripts/ai/AG/AgSpaceStuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,5 @@ class AgSpaceStuff : public CppScripts::Script {
public:
void OnStartup(Entity* self);
void OnTimerDone(Entity* self, std::string timerName);
void DoShake(Entity* self, bool explodeIdle);

std::string DebrisFX = "DebrisFX";
std::string ShipFX = "ShipFX";
std::string ShipFX2 = "ShipFX2";
std::u16string FXName = u"camshake-bridge";

private:
Entity* GetEntityInGroup(const std::string& group);
};

1 change: 1 addition & 0 deletions dScripts/ai/AG/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(DSCRIPTS_SOURCES_AI_AG
"AgShipPlayerDeathTrigger.cpp"
"AgSpaceStuff.cpp"
"AgShipShake.cpp"
"AgShipPlayerShockServer.cpp"
"AgImagSmashable.cpp"
"ActSharkPlayerDeathTrigger.cpp"
Expand Down

0 comments on commit e966d3a

Please sign in to comment.