mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
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:
6
dScripts/02_server/Map/General/Ninjago/CMakeLists.txt
Normal file
6
dScripts/02_server/Map/General/Ninjago/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
set(DSCRIPTS_SOURCES_02_SERVER_MAP_GENERAL_NINJAGO
|
||||
"NjRailActivatorsServer.cpp"
|
||||
"NjRailPostServer.cpp"
|
||||
"NjIceRailActivator.cpp"
|
||||
"NjhubLavaPlayerDeathTrigger.cpp"
|
||||
PARENT_SCOPE)
|
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
10
dScripts/02_server/Map/General/Ninjago/NjIceRailActivator.h
Normal file
10
dScripts/02_server/Map/General/Ninjago/NjIceRailActivator.h
Normal 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";
|
||||
};
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "NjRailPostServer.h"
|
||||
|
||||
class NjRailActivatorsServer : public NjRailPostServer {
|
||||
void OnUse(Entity* self, Entity* user) override;
|
||||
};
|
51
dScripts/02_server/Map/General/Ninjago/NjRailPostServer.cpp
Normal file
51
dScripts/02_server/Map/General/Ninjago/NjRailPostServer.cpp
Normal 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;
|
||||
}
|
13
dScripts/02_server/Map/General/Ninjago/NjRailPostServer.h
Normal file
13
dScripts/02_server/Map/General/Ninjago/NjRailPostServer.h
Normal 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";
|
||||
};
|
@@ -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");
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class NjhubLavaPlayerDeathTrigger : public CppScripts::Script {
|
||||
void OnCollisionPhantom(Entity* self, Entity* target) override;
|
||||
};
|
Reference in New Issue
Block a user