DarkflameServer/dScripts/ai/FV/TriggerGas.cpp
David Markowitz 891648288a Organize Entity header
Probably the third or fourth pass of this darn header...  Just keep making it better every time
Rename some functions to make more sense to a reader
Use different method for Observing/subscribing to component events
Get rid of abomination of overloading GetParentUser
2023-06-16 01:56:02 -07:00

50 lines
1.6 KiB
C++

#include "TriggerGas.h"
#include "InventoryComponent.h"
#include "SkillComponent.h"
#include "Entity.h"
#include "dLogger.h"
void TriggerGas::OnStartup(Entity* self) {
self->AddTimer(this->m_TimerName, this->m_Time);
}
void TriggerGas::OnCollisionPhantom(Entity* self, Entity* target) {
if (!target->IsPlayer()) return;
auto players = self->GetVar<std::vector<Entity*>>(u"players");
players.push_back(target);
self->SetVar(u"players", players);
}
void TriggerGas::OnOffCollisionPhantom(Entity* self, Entity* target) {
auto players = self->GetVar<std::vector<Entity*>>(u"players");
if (!target->IsPlayer() || players.empty()) return;
auto position = std::find(players.begin(), players.end(), target);
if (position != players.end()) players.erase(position);
self->SetVar(u"players", players);
}
void TriggerGas::OnTimerDone(Entity* self, std::string timerName) {
if (timerName != this->m_TimerName) return;
auto players = self->GetVar<std::vector<Entity*>>(u"players");
for (auto player : players) {
if (player->IsDead() || !player){
auto position = std::find(players.begin(), players.end(), player);
if (position != players.end()) players.erase(position);
continue;
}
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
if (inventoryComponent) {
if (!inventoryComponent->IsEquipped(this->m_MaelstromHelmet)) {
auto* skillComponent = self->GetComponent<SkillComponent>();
if (skillComponent) {
skillComponent->CastSkill(this->m_FogDamageSkill, player->GetObjectID());
}
}
}
}
self->SetVar(u"players", players);
self->AddTimer(this->m_TimerName, this->m_Time);
}