2021-12-05 17:54:36 +00:00
|
|
|
#include "NjRailPostServer.h"
|
|
|
|
#include "RebuildComponent.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void NjRailPostServer::OnStartup(Entity* self) {
|
|
|
|
auto* rebuildComponent = self->GetComponent<RebuildComponent>();
|
|
|
|
if (rebuildComponent != nullptr) {
|
|
|
|
self->SetNetworkVar<bool>(NetworkNotActiveVariable, true);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void NjRailPostServer::OnRebuildNotifyState(Entity* self, eRebuildState state) {
|
|
|
|
if (state == REBUILD_COMPLETED) {
|
|
|
|
auto* relatedRail = GetRelatedRail(self);
|
|
|
|
if (relatedRail == nullptr)
|
|
|
|
return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
relatedRail->NotifyObject(self, "PostRebuilt");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (self->GetVar<bool>(NotActiveVariable))
|
|
|
|
return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
self->SetNetworkVar(NetworkNotActiveVariable, false);
|
|
|
|
} else if (state == REBUILD_RESETTING) {
|
|
|
|
auto* relatedRail = GetRelatedRail(self);
|
|
|
|
if (relatedRail == nullptr)
|
|
|
|
return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
relatedRail->NotifyObject(self, "PostDied");
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
return nullptr;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|