2021-12-05 17:54:36 +00:00
|
|
|
#include "FvBrickPuzzleServer.h"
|
|
|
|
#include "GeneralUtils.h"
|
|
|
|
#include "dZoneManager.h"
|
|
|
|
#include "Spawner.h"
|
|
|
|
#include "RebuildComponent.h"
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void FvBrickPuzzleServer::OnStartup(Entity* self) {
|
|
|
|
const auto myGroup = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner_name"));
|
|
|
|
|
|
|
|
int32_t pipeNum = 0;
|
|
|
|
if (!GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1), pipeNum)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pipeNum != 1) {
|
|
|
|
self->AddTimer("reset", 30);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void FvBrickPuzzleServer::OnDie(Entity* self, Entity* killer) {
|
|
|
|
const auto myGroup = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner_name"));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
int32_t pipeNum = 0;
|
|
|
|
if (!GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1), pipeNum)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto pipeGroup = myGroup.substr(0, 10);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto nextPipeNum = pipeNum + 1;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto samePipeSpawners = dZoneManager::Instance()->GetSpawnersByName(myGroup);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!samePipeSpawners.empty()) {
|
|
|
|
samePipeSpawners[0]->SoftReset();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
samePipeSpawners[0]->Deactivate();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (killer != nullptr && killer->IsPlayer()) {
|
|
|
|
const auto nextPipe = pipeGroup + std::to_string(nextPipeNum);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto nextPipeSpawners = dZoneManager::Instance()->GetSpawnersByName(nextPipe);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!nextPipeSpawners.empty()) {
|
|
|
|
nextPipeSpawners[0]->Activate();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const auto nextPipe = pipeGroup + "1";
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const auto firstPipeSpawners = dZoneManager::Instance()->GetSpawnersByName(nextPipe);
|
|
|
|
|
|
|
|
if (!firstPipeSpawners.empty()) {
|
|
|
|
firstPipeSpawners[0]->Activate();
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void FvBrickPuzzleServer::OnTimerDone(Entity* self, std::string timerName) {
|
|
|
|
if (timerName == "reset") {
|
2023-06-07 07:23:50 +00:00
|
|
|
auto rebuildComponent = self->GetComponent<RebuildComponent>();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
if (rebuildComponent != nullptr && rebuildComponent->GetState() == eRebuildState::OPEN) {
|
|
|
|
self->Smash(self->GetObjectID(), eKillType::SILENT);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|