DarkflameServer/dScripts/02_server/Map/FV/ImgBrickConsoleQB.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

243 lines
6.9 KiB
C++
Raw Permalink Normal View History

#include "ImgBrickConsoleQB.h"
#include "QuickBuildComponent.h"
#include "dZoneManager.h"
#include "EntityManager.h"
#include "GameMessages.h"
#include "MissionComponent.h"
#include "eMissionState.h"
#include "InventoryComponent.h"
#include "eTerminateType.h"
int32_t ImgBrickConsoleQB::ResetBricks = 30;
int32_t ImgBrickConsoleQB::ResetConsole = 60;
int32_t ImgBrickConsoleQB::ResetInteract = 45;
void ImgBrickConsoleQB::OnStartup(Entity* self) {
self->SetNetworkVar(u"used", false);
self->AddTimer("reset", ResetBricks);
}
void ImgBrickConsoleQB::OnUse(Entity* self, Entity* user) {
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
2022-07-28 13:39:57 +00:00
if (quickBuildComponent->GetState() == eQuickBuildState::COMPLETED) {
if (!self->GetNetworkVar<bool>(u"used")) {
const auto consoles = Game::entityManager->GetEntitiesInGroup("Console");
2022-07-28 13:39:57 +00:00
auto bothBuilt = false;
2022-07-28 13:39:57 +00:00
for (auto* console : consoles) {
auto* consoleQuickBuildComponent = console->GetComponent<QuickBuildComponent>();
2022-07-28 13:39:57 +00:00
if (consoleQuickBuildComponent->GetState() != eQuickBuildState::COMPLETED) {
continue;
}
2022-07-28 13:39:57 +00:00
console->CancelAllTimers();
2022-07-28 13:39:57 +00:00
if (console->GetNetworkVar<bool>(u"used")) {
bothBuilt = true;
2022-07-28 13:39:57 +00:00
}
}
2022-07-28 13:39:57 +00:00
if (bothBuilt) {
SmashCanister(self);
} else {
SpawnBrick(self);
}
2022-07-28 13:39:57 +00:00
self->AddTimer("Die", ResetInteract);
2022-07-28 13:39:57 +00:00
auto onFX = 0;
2022-07-28 13:39:57 +00:00
const auto location = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"console"));
2022-07-28 13:39:57 +00:00
if (location == "Left") {
onFX = 2776;
} else {
onFX = 2779;
}
2022-07-28 13:39:57 +00:00
const auto& facility = Game::entityManager->GetEntitiesInGroup("FacilityPipes");
2022-07-28 13:39:57 +00:00
if (!facility.empty()) {
GameMessages::SendStopFXEffect(facility[0], true, location + "PipeEnergy");
GameMessages::SendPlayFXEffect(facility[0]->GetObjectID(), onFX, u"create", location + "PipeOn");
2022-07-28 13:39:57 +00:00
}
}
2022-07-28 13:39:57 +00:00
auto* player = user;
2022-07-28 13:39:57 +00:00
auto* missionComponent = player->GetComponent<MissionComponent>();
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
2022-07-28 13:39:57 +00:00
if (missionComponent != nullptr && inventoryComponent != nullptr) {
if (missionComponent->GetMissionState(1302) == eMissionState::ACTIVE) {
inventoryComponent->RemoveItem(13074, 1);
2022-07-28 13:39:57 +00:00
missionComponent->ForceProgressTaskType(1302, 1, 1);
}
2022-07-28 13:39:57 +00:00
if (missionComponent->GetMissionState(1926) == eMissionState::ACTIVE) {
inventoryComponent->RemoveItem(14472, 1);
2022-07-28 13:39:57 +00:00
missionComponent->ForceProgressTaskType(1926, 1, 1);
2022-07-28 13:39:57 +00:00
}
}
2022-07-28 13:39:57 +00:00
self->SetNetworkVar(u"used", true);
2022-07-28 13:39:57 +00:00
GameMessages::SendTerminateInteraction(player->GetObjectID(), eTerminateType::FROM_INTERACTION, self->GetObjectID());
}
}
void ImgBrickConsoleQB::SpawnBrick(Entity* self) {
const auto netDevil = Game::zoneManager->GetSpawnersByName("MaelstromBug");
if (!netDevil.empty()) {
netDevil[0]->Reset();
netDevil[0]->Deactivate();
}
2022-07-28 13:39:57 +00:00
const auto brick = Game::zoneManager->GetSpawnersByName("Imagination");
if (!brick.empty()) {
brick[0]->Activate();
}
}
void ImgBrickConsoleQB::SmashCanister(Entity* self) {
const auto brick = Game::entityManager->GetEntitiesInGroup("Imagination");
if (!brick.empty()) {
GameMessages::SendPlayFXEffect(brick[0]->GetObjectID(), 122, u"create", "bluebrick");
GameMessages::SendPlayFXEffect(brick[0]->GetObjectID(), 1034, u"cast", "imaginationexplosion");
}
2022-07-28 13:39:57 +00:00
const auto canisters = Game::entityManager->GetEntitiesInGroup("Canister");
for (auto* canister : canisters) {
canister->Smash(canister->GetObjectID(), eKillType::VIOLENT);
}
2022-07-28 13:39:57 +00:00
const auto canister = Game::zoneManager->GetSpawnersByName("BrickCanister");
if (!canister.empty()) {
canister[0]->Reset();
canister[0]->Deactivate();
}
}
void ImgBrickConsoleQB::OnQuickBuildComplete(Entity* self, Entity* target) {
auto energyFX = 0;
const auto location = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"console"));
if (location == "Left") {
energyFX = 2775;
} else {
energyFX = 2778;
}
const auto& facility = Game::entityManager->GetEntitiesInGroup("FacilityPipes");
if (!facility.empty()) {
GameMessages::SendStopFXEffect(facility[0], true, location + "PipeOff");
GameMessages::SendPlayFXEffect(facility[0]->GetObjectID(), energyFX, u"create", location + "PipeEnergy");
}
const auto consoles = Game::entityManager->GetEntitiesInGroup("Console");
for (auto* console : consoles) {
auto* consoleQuickBuildComponent = console->GetComponent<QuickBuildComponent>();
if (consoleQuickBuildComponent->GetState() != eQuickBuildState::COMPLETED) {
continue;
}
console->CancelAllTimers();
}
self->AddTimer("Die", ResetConsole);
}
void ImgBrickConsoleQB::OnDie(Entity* self, Entity* killer) {
if (self->GetVar<bool>(u"Died")) {
return;
}
2022-07-28 13:39:57 +00:00
self->CancelAllTimers();
2022-07-28 13:39:57 +00:00
self->SetVar(u"Died", true);
2022-07-28 13:39:57 +00:00
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
2022-07-28 13:39:57 +00:00
if (quickBuildComponent->GetState() == eQuickBuildState::COMPLETED) {
auto offFX = 0;
2022-07-28 13:39:57 +00:00
const auto location = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"console"));
2022-07-28 13:39:57 +00:00
if (location == "Left") {
offFX = 2774;
} else {
offFX = 2777;
}
2022-07-28 13:39:57 +00:00
const auto& facility = Game::entityManager->GetEntitiesInGroup("FacilityPipes");
2022-07-28 13:39:57 +00:00
if (!facility.empty()) {
GameMessages::SendStopFXEffect(facility[0], true, location + "PipeEnergy");
GameMessages::SendStopFXEffect(facility[0], true, location + "PipeOn");
GameMessages::SendPlayFXEffect(facility[0]->GetObjectID(), offFX, u"create", location + "PipeOff");
GameMessages::SendPlayFXEffect(facility[0]->GetObjectID(), 2750, u"create", location + "imagination_canister");
2022-07-28 13:39:57 +00:00
}
}
2022-07-28 13:39:57 +00:00
const auto myGroup = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner_name"));
2022-07-28 13:39:57 +00:00
const auto pipeGroup = myGroup.substr(0, 10);
2022-07-28 13:39:57 +00:00
const auto firstPipe = pipeGroup + "1";
2022-07-28 13:39:57 +00:00
const auto samePipeSpawner = Game::zoneManager->GetSpawnersByName(myGroup);
if (!samePipeSpawner.empty()) {
samePipeSpawner[0]->Reset();
samePipeSpawner[0]->Deactivate();
}
2022-07-28 13:39:57 +00:00
const auto firstPipeSpawner = Game::zoneManager->GetSpawnersByName(firstPipe);
if (!firstPipeSpawner.empty()) {
firstPipeSpawner[0]->Activate();
}
2022-07-28 13:39:57 +00:00
const auto netdevil = Game::zoneManager->GetSpawnersByName("Imagination");
if (!netdevil.empty()) {
netdevil[0]->Reset();
netdevil[0]->Deactivate();
}
2022-07-28 13:39:57 +00:00
const auto brick = Game::zoneManager->GetSpawnersByName("MaelstromBug");
if (!brick.empty()) {
brick[0]->Activate();
}
2022-07-28 13:39:57 +00:00
const auto canister = Game::zoneManager->GetSpawnersByName("BrickCanister");
if (!canister.empty()) {
canister[0]->Activate();
}
2022-07-28 13:39:57 +00:00
self->SetNetworkVar(u"used", false);
}
void ImgBrickConsoleQB::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "reset") {
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
2022-07-28 13:39:57 +00:00
if (quickBuildComponent->GetState() == eQuickBuildState::OPEN) {
self->Smash(self->GetObjectID(), eKillType::SILENT);
}
} else if (timerName == "Die") {
const auto consoles = Game::entityManager->GetEntitiesInGroup("Console");
2022-07-28 13:39:57 +00:00
for (auto* console : consoles) {
console->Smash(console->GetObjectID(), eKillType::VIOLENT);
}
}
}