2021-12-05 17:54:36 +00:00
|
|
|
#include "AgFans.h"
|
|
|
|
|
2022-07-05 06:00:10 +00:00
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "PhantomPhysicsComponent.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "RenderComponent.h"
|
|
|
|
|
|
|
|
void AgFans::OnStartup(Entity* self) {
|
|
|
|
self->SetVar<bool>(u"alive", true);
|
|
|
|
self->SetVar<bool>(u"on", false);
|
|
|
|
|
|
|
|
ToggleFX(self, false);
|
|
|
|
|
|
|
|
auto* renderComponent = static_cast<RenderComponent*>(self->GetComponent(COMPONENT_TYPE_RENDER));
|
|
|
|
|
|
|
|
if (renderComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderComponent->PlayEffect(495, u"fanOn", "fanOn");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AgFans::ToggleFX(Entity* self, bool hit) {
|
|
|
|
std::string fanGroup = self->GetGroups()[0];
|
|
|
|
std::vector<Entity*> fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup);
|
|
|
|
|
|
|
|
auto* renderComponent = static_cast<RenderComponent*>(self->GetComponent(COMPONENT_TYPE_RENDER));
|
|
|
|
|
|
|
|
if (renderComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +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);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
for (Entity* volume : fanVolumes) {
|
|
|
|
PhantomPhysicsComponent* volumePhys = static_cast<PhantomPhysicsComponent*>(volume->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS));
|
|
|
|
if (!volumePhys) continue;
|
|
|
|
volumePhys->SetPhysicsEffectActive(false);
|
|
|
|
EntityManager::Instance()->SerializeEntity(volume);
|
|
|
|
if (!hit) {
|
|
|
|
Entity* fxObj = EntityManager::Instance()->GetEntitiesInGroup(fanGroup + "fx")[0];
|
|
|
|
GameMessages::SendPlayAnimation(fxObj, u"trigger");
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
} else if (!self->GetVar<bool>(u"on") && self->GetVar<bool>(u"alive")) {
|
2021-12-05 17:54:36 +00:00
|
|
|
GameMessages::SendPlayAnimation(self, u"fan-on");
|
|
|
|
|
|
|
|
renderComponent->PlayEffect(495, u"fanOn", "fanOn");
|
|
|
|
self->SetVar<bool>(u"on", true);
|
|
|
|
|
|
|
|
for (Entity* volume : fanVolumes) {
|
|
|
|
PhantomPhysicsComponent* volumePhys = static_cast<PhantomPhysicsComponent*>(volume->GetComponent(COMPONENT_TYPE_PHANTOM_PHYSICS));
|
|
|
|
if (!volumePhys) continue;
|
|
|
|
volumePhys->SetPhysicsEffectActive(true);
|
|
|
|
EntityManager::Instance()->SerializeEntity(volume);
|
|
|
|
if (!hit) {
|
|
|
|
Entity* fxObj = EntityManager::Instance()->GetEntitiesInGroup(fanGroup + "fx")[0];
|
|
|
|
GameMessages::SendPlayAnimation(fxObj, u"idle");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void AgFans::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
|
|
|
|
int32_t param3) {
|
2021-12-05 17:54:36 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AgFans::OnDie(Entity* self, Entity* killer) {
|
|
|
|
if (self->GetVar<bool>(u"on")) {
|
|
|
|
ToggleFX(self, true);
|
|
|
|
}
|
|
|
|
self->SetVar<bool>(u"alive", false);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|