#include "AgFans.h" #include "EntityManager.h" #include "GameMessages.h" #include "PhantomPhysicsComponent.h" #include "RenderComponent.h" #include "eReplicaComponentType.h" void AgFans::OnStartup(Entity* self) { self->SetVar(u"alive", true); self->SetVar(u"on", false); ToggleFX(self, false); auto* renderComponent = static_cast(self->GetComponent(eReplicaComponentType::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 fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup); auto* renderComponent = static_cast(self->GetComponent(eReplicaComponentType::RENDER)); if (renderComponent == nullptr) { return; } if (fanVolumes.size() == 0 || !self->GetVar(u"alive")) return; if (self->GetVar(u"on")) { GameMessages::SendPlayAnimation(self, u"fan-off"); renderComponent->StopEffect("fanOn"); self->SetVar(u"on", false); for (Entity* volume : fanVolumes) { PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(eReplicaComponentType::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"); } } } else if (!self->GetVar(u"on") && self->GetVar(u"alive")) { GameMessages::SendPlayAnimation(self, u"fan-on"); renderComponent->PlayEffect(495, u"fanOn", "fanOn"); self->SetVar(u"on", true); for (Entity* volume : fanVolumes) { PhantomPhysicsComponent* volumePhys = static_cast(volume->GetComponent(eReplicaComponentType::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"); } } } } void AgFans::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) { if (args.length() == 0 || !self->GetVar(u"alive")) return; if ((args == "turnOn" && self->GetVar(u"on")) || (args == "turnOff" && !self->GetVar(u"on"))) return; ToggleFX(self, false); } void AgFans::OnDie(Entity* self, Entity* killer) { if (self->GetVar(u"on")) { ToggleFX(self, true); } self->SetVar(u"alive", false); }