DarkflameServer/dScripts/02_server/Map/AM/AmDropshipComputer.cpp
jadebenn 0c1ee0513d
refactor: Change TryParse implementation (#1442)
* Changed how the TryParse function works (and also did some general cleanup along the way)

* Update noexcept attributes (verified these are correct)

* Add fp overload for MacOS functionality

* resolving some feedback

* Split out unrelated changes to CleanupRoundup branch

* Update in response to feedback

* the consequences of emo's member variable renaming request

* Revert "the consequences of emo's member variable renaming request"

This reverts commit bf318caeda.

* Fully revert renaming attempt

* Revert "the consequences of emo's member variable renaming request"

This reverts commit bf318caeda.

Fully revert renaming attempt

* Created ClientVersion.h and moved the client version defaults to it

* Fix partial parsing and MacOS floating point errors

* attempting fix to MacOS compiler error

* syntax pass (should be the last commit unless the CI fails)

* ah, wait, forgot to uncomment the preprocessor statements for MacOS. THIS should be the last commit pending CI

* Okay, one last thing I noticed: We were including C headers here. Now they're C++ headers. Pinky swear this is it!

* typo and I am OCD. please let this be the last

* hash is usally but not always noexcept, so the specifier should go

* Address MOST of the feedback

* address the claim codes issue
2024-02-10 05:05:25 -06:00

79 lines
2.3 KiB
C++

#include "AmDropshipComputer.h"
#include "MissionComponent.h"
#include "QuickBuildComponent.h"
#include "InventoryComponent.h"
#include "dZoneManager.h"
#include "eMissionState.h"
void AmDropshipComputer::OnStartup(Entity* self) {
self->AddTimer("reset", 45.0f);
}
void AmDropshipComputer::OnUse(Entity* self, Entity* user) {
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
if (quickBuildComponent == nullptr || quickBuildComponent->GetState() != eQuickBuildState::COMPLETED) {
return;
}
auto* missionComponent = user->GetComponent<MissionComponent>();
auto* inventoryComponent = user->GetComponent<InventoryComponent>();
if (missionComponent == nullptr || inventoryComponent == nullptr) {
return;
}
if (inventoryComponent->GetLotCount(m_NexusTalonDataCard) != 0 || missionComponent->GetMission(979)->GetMissionState() == eMissionState::COMPLETE) {
return;
}
inventoryComponent->AddItem(m_NexusTalonDataCard, 1, eLootSourceType::NONE);
}
void AmDropshipComputer::OnDie(Entity* self, Entity* killer) {
const auto myGroup = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner_name"));
const auto pipeNum = GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1));
if (!pipeNum) return;
const auto pipeGroup = myGroup.substr(0, 10);
const auto nextPipeNum = pipeNum.value() + 1;
const auto samePipeSpawners = Game::zoneManager->GetSpawnersByName(myGroup);
if (!samePipeSpawners.empty()) {
samePipeSpawners[0]->SoftReset();
samePipeSpawners[0]->Deactivate();
}
if (killer != nullptr && killer->IsPlayer()) {
const auto nextPipe = pipeGroup + std::to_string(nextPipeNum);
const auto nextPipeSpawners = Game::zoneManager->GetSpawnersByName(nextPipe);
if (!nextPipeSpawners.empty()) {
nextPipeSpawners[0]->Activate();
}
} else {
const auto nextPipe = pipeGroup + "1";
const auto firstPipeSpawners = Game::zoneManager->GetSpawnersByName(nextPipe);
if (!firstPipeSpawners.empty()) {
firstPipeSpawners[0]->Activate();
}
}
}
void AmDropshipComputer::OnTimerDone(Entity* self, std::string timerName) {
const auto* const quickBuildComponent = self->GetComponent<QuickBuildComponent>();
if (!quickBuildComponent) return;
if (timerName == "reset" && quickBuildComponent->GetState() == eQuickBuildState::OPEN) {
self->Smash(self->GetObjectID(), eKillType::SILENT);
}
}