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_GENERAL_NINJAGO
"NjRailActivatorsServer.cpp"
"NjRailPostServer.cpp"
"NjIceRailActivator.cpp"
"NjhubLavaPlayerDeathTrigger.cpp"
PARENT_SCOPE)

View File

@@ -0,0 +1,25 @@
#include "NjIceRailActivator.h"
#include "EntityManager.h"
#include "GameMessages.h"
void NjIceRailActivator::OnPlayerRailArrived(Entity* self, Entity* sender, const std::u16string& pathName,
int32_t waypoint) {
const auto breakPoint = self->GetVar<int32_t>(BreakpointVariable);
if (breakPoint == waypoint) {
const auto& blockGroup = self->GetVar<std::u16string>(BlockGroupVariable);
for (auto* block : EntityManager::Instance()->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(blockGroup))) {
GameMessages::SendPlayAnimation(block, u"explode");
const auto blockID = block->GetObjectID();
self->AddCallbackTimer(1.0f, [self, blockID]() {
auto* block = EntityManager::Instance()->GetEntity(blockID);
if (block != nullptr) {
block->Kill(self);
}
});
}
}
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "NjRailActivatorsServer.h"
class NjIceRailActivator : public NjRailActivatorsServer {
void OnPlayerRailArrived(Entity* self, Entity* sender, const std::u16string& pathName, int32_t waypoint) override;
private:
std::u16string BreakpointVariable = u"BreakPoint";
std::u16string BlockGroupVariable = u"BlockGroup";
std::u16string IceBlockVariable = u"IceBlock";
};

View File

@@ -0,0 +1,16 @@
#include "NjRailActivatorsServer.h"
#include "RebuildComponent.h"
#include "Character.h"
void NjRailActivatorsServer::OnUse(Entity* self, Entity* user) {
const auto flag = self->GetVar<int32_t>(u"RailFlagNum");
auto* rebuildComponent = self->GetComponent<RebuildComponent>();
// Only allow use if this is not a quick build or the quick build is built
if (rebuildComponent == nullptr || rebuildComponent->GetState() == REBUILD_COMPLETED) {
auto* character = user->GetCharacter();
if (character != nullptr) {
character->SetPlayerFlag(flag, true);
}
}
}

View File

@@ -0,0 +1,6 @@
#pragma once
#include "NjRailPostServer.h"
class NjRailActivatorsServer : public NjRailPostServer {
void OnUse(Entity* self, Entity* user) override;
};

View File

@@ -0,0 +1,51 @@
#include "NjRailPostServer.h"
#include "RebuildComponent.h"
#include "EntityManager.h"
void NjRailPostServer::OnStartup(Entity* self) {
auto* rebuildComponent = self->GetComponent<RebuildComponent>();
if (rebuildComponent != nullptr) {
self->SetNetworkVar<bool>(NetworkNotActiveVariable, true);
}
}
void NjRailPostServer::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1,
int32_t param2) {
if (name == "PostRebuilt") {
self->SetNetworkVar<bool>(NetworkNotActiveVariable, false);
} else if (name == "PostDied") {
self->SetNetworkVar<bool>(NetworkNotActiveVariable, true);
}
}
void NjRailPostServer::OnRebuildNotifyState(Entity* self, eRebuildState state) {
if (state == REBUILD_COMPLETED) {
auto* relatedRail = GetRelatedRail(self);
if (relatedRail == nullptr)
return;
relatedRail->NotifyObject(self, "PostRebuilt");
if (self->GetVar<bool>(NotActiveVariable))
return;
self->SetNetworkVar(NetworkNotActiveVariable, false);
} else if (state == REBUILD_RESETTING) {
auto* relatedRail = GetRelatedRail(self);
if (relatedRail == nullptr)
return;
relatedRail->NotifyObject(self, "PostDied");
}
}
Entity* NjRailPostServer::GetRelatedRail(Entity* self) {
const auto& railGroup = self->GetVar<std::u16string>(RailGroupVariable);
if (!railGroup.empty()) {
for (auto* entity : EntityManager::Instance()->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(railGroup))) {
return entity;
}
}
return nullptr;
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "CppScripts.h"
class NjRailPostServer : public CppScripts::Script {
void OnStartup(Entity* self) override;
void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) override;
void OnRebuildNotifyState(Entity* self, eRebuildState state) override;
private:
Entity* GetRelatedRail(Entity* self);
const std::u16string NetworkNotActiveVariable = u"NetworkNotActive";
const std::u16string NotActiveVariable = u"NotActive";
const std::u16string RailGroupVariable = u"RailGroup";
};

View File

@@ -0,0 +1,9 @@
#include "NjhubLavaPlayerDeathTrigger.h"
#include "Entity.h"
void NjhubLavaPlayerDeathTrigger::OnCollisionPhantom(Entity* self, Entity* target) {
if (!target->IsPlayer())
return;
target->Smash(self->GetObjectID(), VIOLENT, u"drown");
}

View File

@@ -0,0 +1,6 @@
#pragma once
#include "CppScripts.h"
class NjhubLavaPlayerDeathTrigger : public CppScripts::Script {
void OnCollisionPhantom(Entity* self, Entity* target) override;
};