2021-12-05 17:54:36 +00:00
|
|
|
#include "NjRailPostServer.h"
|
2023-12-29 04:24:30 +00:00
|
|
|
#include "QuickBuildComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "EntityManager.h"
|
|
|
|
|
|
|
|
void NjRailPostServer::OnStartup(Entity* self) {
|
2023-12-29 04:24:30 +00:00
|
|
|
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
|
|
|
|
if (quickBuildComponent != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 04:24:30 +00:00
|
|
|
void NjRailPostServer::OnQuickBuildNotifyState(Entity* self, eQuickBuildState state) {
|
|
|
|
if (state == eQuickBuildState::COMPLETED) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* relatedRail = GetRelatedRail(self);
|
|
|
|
if (relatedRail == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
relatedRail->NotifyObject(self, "PostRebuilt");
|
|
|
|
|
|
|
|
if (self->GetVar<bool>(NotActiveVariable))
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->SetNetworkVar(NetworkNotActiveVariable, false);
|
2023-12-29 04:24:30 +00:00
|
|
|
} else if (state == eQuickBuildState::RESETTING) {
|
2021-12-05 17:54:36 +00:00
|
|
|
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()) {
|
2023-07-15 20:56:33 +00:00
|
|
|
for (auto* entity : Game::entityManager->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(railGroup))) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|