DarkflameServer/dScripts/ai/PROPERTY/AgPropguards.cpp
David Markowitz 455f9470a5
Move EntityManager to Game namespace (#1140)
* Move EntityManager to Game namespace

* move initialization to later

Need to wait for dZoneManager to be initialized.

* Fix bugs

- Cannot delete from a RandomAccessIterator while in a range based for loop.

Touchup zone manager initialize

replace magic numbers with better named constants
replace magic zonecontrol id with a more readable hex alternative
condense stack variables
move initializers closer to their use
initialize entity manager with zone control

change initialize timings

If zone is not zero we expect to initialize the entity manager during zone manager initialization

Add constexpr for zone control LOT

* Add proper error handling

* revert vanity changes

* Update WorldServer.cpp

* Update dZoneManager.cpp
2023-07-15 13:56:33 -07:00

58 lines
1.6 KiB
C++

#include "AgPropguards.h"
#include "Character.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "dZoneManager.h"
#include "eMissionState.h"
void AgPropguards::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, eMissionState missionState) {
auto* character = target->GetCharacter();
if (character == nullptr)
return;
const auto flag = GetFlagForMission(missionID);
if (flag == 0)
return;
if ((missionState == eMissionState::AVAILABLE || missionState == eMissionState::ACTIVE)
&& !character->GetPlayerFlag(flag)) {
// If the player just started the mission, play a cinematic highlighting the target
GameMessages::SendPlayCinematic(target->GetObjectID(), u"MissionCam", target->GetSystemAddress());
} else if (missionState == eMissionState::COMPLETE_READY_TO_COMPLETE) {
// Makes the guard disappear once the mission has been completed
const auto zoneControlID = Game::entityManager->GetZoneControlEntity()->GetObjectID();
GameMessages::SendNotifyClientObject(zoneControlID, u"GuardChat", 0, 0, self->GetObjectID(),
"", UNASSIGNED_SYSTEM_ADDRESS);
self->AddCallbackTimer(5.0f, [self]() {
auto spawnerName = self->GetVar<std::string>(u"spawner_name");
if (spawnerName.empty())
spawnerName = "Guard";
auto spawners = dZoneManager::Instance()->GetSpawnersByName(spawnerName);
for (auto* spawner : spawners) {
spawner->Deactivate();
}
self->Smash();
});
}
}
int32_t AgPropguards::GetFlagForMission(uint32_t missionID) {
switch (missionID) {
case 872:
return 97;
case 873:
return 98;
case 874:
return 99;
case 1293:
return 118;
case 1322:
return 122;
default:
return 0;
}
}