2021-12-05 17:54:36 +00:00
|
|
|
#include "NjRailPostServer.h"
|
2023-06-09 22:12:57 +00:00
|
|
|
#include "QuickBuildComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "EntityManager.h"
|
2023-06-16 08:01:13 +00:00
|
|
|
#include "Entity.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void NjRailPostServer::OnStartup(Entity* self) {
|
2023-06-09 22:12:57 +00:00
|
|
|
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
|
|
|
|
if (quickBuildComponent != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
self->SetNetworkVar<bool>(NetworkNotActiveVariable, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-16 08:01:13 +00:00
|
|
|
void NjRailPostServer::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1,
|
2021-12-05 17:54:36 +00:00
|
|
|
int32_t param2) {
|
2023-06-16 08:01:13 +00:00
|
|
|
if (name == u"PostRebuilt") {
|
2021-12-05 17:54:36 +00:00
|
|
|
self->SetNetworkVar<bool>(NetworkNotActiveVariable, false);
|
2023-06-16 08:01:13 +00:00
|
|
|
} else if (name == u"PostDied") {
|
2021-12-05 17:54:36 +00:00
|
|
|
self->SetNetworkVar<bool>(NetworkNotActiveVariable, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NjRailPostServer::OnRebuildNotifyState(Entity* self, eRebuildState state) {
|
2023-05-02 22:39:21 +00:00
|
|
|
if (state == eRebuildState::COMPLETED) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* relatedRail = GetRelatedRail(self);
|
|
|
|
if (relatedRail == nullptr)
|
|
|
|
return;
|
|
|
|
|
2023-06-16 08:01:13 +00:00
|
|
|
relatedRail->NotifyObject(self, u"PostRebuilt");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (self->GetVar<bool>(NotActiveVariable))
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->SetNetworkVar(NetworkNotActiveVariable, false);
|
2023-05-02 22:39:21 +00:00
|
|
|
} else if (state == eRebuildState::RESETTING) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* relatedRail = GetRelatedRail(self);
|
|
|
|
if (relatedRail == nullptr)
|
|
|
|
return;
|
|
|
|
|
2023-06-16 08:01:13 +00:00
|
|
|
relatedRail->NotifyObject(self, u"PostDied");
|
2021-12-05 17:54:36 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|