From f7009b499b644724cb7369fd73dd16475c23993d Mon Sep 17 00:00:00 2001 From: Nordegraf <57260460+Nordegraf@users.noreply.github.com> Date: Sat, 5 Feb 2022 13:19:25 +0100 Subject: [PATCH] added tracking of Pet Excavator achievement (#213) * added tracking of the Pet Excavator achievement * make Pet Extractor Progress Zone specific * added tracking of Pet Excavator Achievement using player flags --- dScripts/PetDigServer.cpp | 31 ++++++++++++++++++++++++------- dScripts/PetDigServer.h | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/dScripts/PetDigServer.cpp b/dScripts/PetDigServer.cpp index 41dce8f2..a78c0881 100644 --- a/dScripts/PetDigServer.cpp +++ b/dScripts/PetDigServer.cpp @@ -39,7 +39,7 @@ const std::map PetDigServer::digInfoMap { {12192, DigInfo { 12192, -1, -1, true, false, false, false }}, }; -void PetDigServer::OnStartup(Entity* self) +void PetDigServer::OnStartup(Entity* self) { treasures.push_back(self->GetObjectID()); const auto digInfoIterator = digInfoMap.find(self->GetLOT()); @@ -64,7 +64,7 @@ void PetDigServer::OnStartup(Entity* self) } } -void PetDigServer::OnDie(Entity* self, Entity* killer) +void PetDigServer::OnDie(Entity* self, Entity* killer) { const auto iterator = std::find(treasures.begin(), treasures.end(), self->GetObjectID()); if (iterator != treasures.end()) @@ -91,7 +91,7 @@ void PetDigServer::OnDie(Entity* self, Entity* killer) PetDigServer::HandleBouncerDig(self, owner); } - PetDigServer::ProgressCanYouDigIt(owner); + PetDigServer::ProgressPetDigMissions(owner, self); self->SetNetworkVar(u"treasure_dug", true); // TODO: Reset other pets @@ -157,19 +157,36 @@ void PetDigServer::HandleBouncerDig(const Entity *self, const Entity *owner) { } /** - * Progresses the Can You Dig It mission if the player has never completed it yet + * Progresses the Can You Dig It mission and the Pet Excavator Achievement if the player has never completed it yet * \param owner the owner that just made a pet dig something up */ -void PetDigServer::ProgressCanYouDigIt(const Entity* owner) { +void PetDigServer::ProgressPetDigMissions(const Entity* owner, const Entity* chest) { auto* missionComponent = owner->GetComponent(); if (missionComponent != nullptr) { + // Can You Dig It progress const auto digMissionState = missionComponent->GetMissionState(843); if (digMissionState == MissionState::MISSION_STATE_ACTIVE) { missionComponent->ForceProgress(843, 1216, 1); } + + // Pet Excavator progress + const auto excavatorMissionState = missionComponent->GetMissionState(505); + if (excavatorMissionState == MissionState::MISSION_STATE_ACTIVE) + { + if (chest->HasVar(u"PetDig")) { + int32_t playerFlag = 1260 + chest->GetVarAs(u"PetDig"); + Character* player = owner->GetCharacter(); + + // check if player flag is set + if (!player->GetPlayerFlag(playerFlag)) { + missionComponent->ForceProgress(505, 767, 1); + player->SetPlayerFlag(playerFlag, 1); + } + } + } } } @@ -203,7 +220,7 @@ void PetDigServer::SpawnPet(Entity* self, const Entity* owner, const DigInfo dig EntityManager::Instance()->ConstructEntity(spawnedPet); } -Entity* PetDigServer::GetClosestTresure(NiPoint3 position) +Entity* PetDigServer::GetClosestTresure(NiPoint3 position) { float closestDistance = 0; Entity* closest = nullptr; @@ -215,7 +232,7 @@ Entity* PetDigServer::GetClosestTresure(NiPoint3 position) if (tresure == nullptr) continue; float distance = Vector3::DistanceSquared(tresure->GetPosition(), position); - + if (closest == nullptr || distance < closestDistance) { closestDistance = distance; diff --git a/dScripts/PetDigServer.h b/dScripts/PetDigServer.h index 22a96a46..968ca50d 100644 --- a/dScripts/PetDigServer.h +++ b/dScripts/PetDigServer.h @@ -20,7 +20,7 @@ public: static Entity* GetClosestTresure(NiPoint3 position); private: - static void ProgressCanYouDigIt(const Entity* owner); + static void ProgressPetDigMissions(const Entity* owner, const Entity* chest); static void SpawnPet(Entity* self, const Entity* owner, DigInfo digInfo); static void HandleXBuildDig(const Entity* self, Entity* owner, Entity* pet); static void HandleBouncerDig(const Entity* self, const Entity* owner);