DarkflameServer/dScripts/WhFans.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.0 KiB
C++
Raw Permalink Normal View History

2022-04-17 04:35:22 +00:00
#include "WhFans.h"
2022-04-17 04:32:15 +00:00
#include "RenderComponent.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "PhantomPhysicsComponent.h"
2022-04-17 04:32:15 +00:00
2022-04-17 04:35:22 +00:00
void WhFans::OnStartup(Entity* self) {
2022-04-17 04:32:15 +00:00
self->SetVar<bool>(u"alive", true);
self->SetVar<bool>(u"on", false);
ToggleFX(self, false);
}
2022-04-17 04:35:22 +00:00
void WhFans::ToggleFX(Entity* self, bool hit) {
2022-04-18 13:27:37 +00:00
std::string fanGroup;
const auto& groups = self->GetGroups();
if (!groups.empty()) {
fanGroup = groups[0];
} else {
2022-04-18 01:24:19 +00:00
fanGroup = "";
2022-04-18 01:16:27 +00:00
}
2022-04-17 20:58:26 +00:00
2022-04-17 04:32:15 +00:00
std::vector<Entity*> fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup);
auto* renderComponent = self->GetComponent<RenderComponent>();
2022-04-18 13:27:37 +00:00
if (renderComponent == nullptr) return;
2022-04-17 04:32:15 +00:00
if (fanVolumes.size() == 0 || !self->GetVar<bool>(u"alive")) return;
if (self->GetVar<bool>(u"on")) {
GameMessages::SendPlayAnimation(self, u"fan-off");
renderComponent->StopEffect("fanOn");
self->SetVar<bool>(u"on", false);
for (Entity* volume : fanVolumes) {
2022-04-17 17:46:41 +00:00
auto volumePhys = volume->GetComponent<PhantomPhysicsComponent>();
2022-04-17 04:32:15 +00:00
if (!volumePhys) continue;
volumePhys->SetPhysicsEffectActive(false);
EntityManager::Instance()->SerializeEntity(volume);
}
} else if (!self->GetVar<bool>(u"on") && self->GetVar<bool>(u"alive")) {
GameMessages::SendPlayAnimation(self, u"fan-on");
self->SetVar<bool>(u"on", true);
for (Entity* volume : fanVolumes) {
2022-04-17 17:46:41 +00:00
auto volumePhys = volume->GetComponent<PhantomPhysicsComponent>();
2022-04-17 04:32:15 +00:00
if (!volumePhys) continue;
volumePhys->SetPhysicsEffectActive(true);
EntityManager::Instance()->SerializeEntity(volume);
}
}
}
2022-04-17 04:35:22 +00:00
void WhFans::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
2022-04-17 04:32:15 +00:00
int32_t param3) {
if (args.length() == 0 || !self->GetVar<bool>(u"alive")) return;
if ((args == "turnOn" && self->GetVar<bool>(u"on")) || (args == "turnOff" && !self->GetVar<bool>(u"on"))) return;
ToggleFX(self, false);
}
2022-04-17 04:35:22 +00:00
void WhFans::OnDie(Entity* self, Entity* killer) {
2022-04-17 04:32:15 +00:00
if (self->GetVar<bool>(u"on")) {
ToggleFX(self, true);
}
self->SetVar<bool>(u"alive", false);
}