DarkflameServer/dScripts/FvHorsemenTrigger.cpp

54 lines
1.5 KiB
C++
Raw Normal View History

#include "FvHorsemenTrigger.h"
#include "EntityManager.h"
#include "MissionComponent.h"
2022-07-28 13:39:57 +00:00
void FvHorsemenTrigger::OnStartup(Entity* self) {
self->SetProximityRadius(40, "horsemenTrigger");
2022-07-28 13:39:57 +00:00
self->SetVar<std::vector<LWOOBJID>>(u"players", {});
}
2022-07-28 13:39:57 +00:00
void FvHorsemenTrigger::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
if (name != "horsemenTrigger" || !entering->IsPlayer()) {
return;
}
2022-07-28 13:39:57 +00:00
auto players = self->GetVar<std::vector<LWOOBJID>>(u"players");
2022-07-28 13:39:57 +00:00
const auto& iter = std::find(players.begin(), players.end(), entering->GetObjectID());
2022-07-28 13:39:57 +00:00
if (status == "ENTER" && iter == players.end()) {
players.push_back(entering->GetObjectID());
} else if (status == "LEAVE" && iter != players.end()) {
players.erase(iter);
}
2022-07-28 13:39:57 +00:00
self->SetVar<std::vector<LWOOBJID>>(u"players", players);
}
void
2022-07-28 13:39:57 +00:00
FvHorsemenTrigger::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) {
auto players = self->GetVar<std::vector<LWOOBJID>>(u"players");
2022-07-28 13:39:57 +00:00
if (args == "HorsemenDeath") {
for (const auto& playerId : self->GetVar<std::vector<LWOOBJID>>(u"players")) {
auto* player = EntityManager::Instance()->GetEntity(playerId);
2022-07-28 13:39:57 +00:00
if (player == nullptr) {
continue;
}
2022-07-28 13:39:57 +00:00
auto* missionComponent = player->GetComponent<MissionComponent>();
2022-07-28 13:39:57 +00:00
if (missionComponent == nullptr) {
continue;
}
2022-07-28 13:39:57 +00:00
for (const auto missionId : m_Missions) {
missionComponent->ForceProgressTaskType(missionId, 1, 1);
}
}
}
}