Files
.github
dAuthServer
dChatFilter
dChatServer
dCommon
dDatabase
dGame
dMasterServer
dNavigation
dNet
dPhysics
dScripts
02_server
EquipmentScripts
EquipmentTriggers
ai
ACT
AG
FV
GENERAL
GF
MINIGAME
NP
NS
NS_PP_01
WH
CMakeLists.txt
ClRing.cpp
ClRing.h
NsConcertChoiceBuild.cpp
NsConcertChoiceBuild.h
NsConcertInstrument.cpp
NsConcertInstrument.h
NsConcertQuickBuild.cpp
NsConcertQuickBuild.h
NsGetFactionMissionServer.cpp
NsGetFactionMissionServer.h
NsJohnnyMissionServer.cpp
NsJohnnyMissionServer.h
NsModularBuild.cpp
NsModularBuild.h
NsQbImaginationStatue.cpp
NsQbImaginationStatue.h
WhFans.cpp
WhFans.h
PETS
PROPERTY
RACING
SPEC
WILD
CMakeLists.txt
client
zone
ActivityManager.cpp
ActivityManager.h
BaseConsoleTeleportServer.cpp
BaseConsoleTeleportServer.h
BasePropertyServer.cpp
BasePropertyServer.h
BaseRandomServer.cpp
BaseRandomServer.h
BaseSurvivalServer.cpp
BaseSurvivalServer.h
BaseWavesGenericEnemy.cpp
BaseWavesGenericEnemy.h
BaseWavesServer.cpp
BaseWavesServer.h
CMakeLists.txt
ChooseYourDestinationNsToNt.cpp
ChooseYourDestinationNsToNt.h
CppScripts.cpp
CppScripts.h
Darkitect.cpp
Darkitect.h
NPCAddRemoveItem.cpp
NPCAddRemoveItem.h
NtFactionSpyServer.cpp
NtFactionSpyServer.h
ScriptComponent.cpp
ScriptComponent.h
ScriptedPowerupSpawner.cpp
ScriptedPowerupSpawner.h
SpawnPetBaseServer.cpp
SpawnPetBaseServer.h
dWorldServer
dZoneManager
docker
docs
migrations
resources
tests
thirdparty
vanity
.dockerignore
.editorconfig
.env.example
.git-blame-ignore-revs
.gitattributes
.gitignore
.gitmodules
CMakeLists.txt
CMakePresets.json
CMakeVariables.txt
CONTRIBUTING.md
Docker.md
Docker_Windows.md
LICENSE
README.md
SECURITY.md
build.sh
docker-compose.yml
logo.png
versions.txt
DarkflameServer/dScripts/ai/NS/WhFans.cpp
David Markowitz 8d37d9b681 Organize dScripts ()
* Organize dScripts

whitespace

Remove parent scope

Remove parent scope from initial setter

Remove debug

Remove helper programs

* Fix NtImagimeterVisibility script

Co-authored-by: aronwk-aaron <aronwk.aaron@gmail.com>
2022-11-03 12:57:54 -05:00

72 lines
2.0 KiB
C++

#include "WhFans.h"
#include "RenderComponent.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "PhantomPhysicsComponent.h"
void WhFans::OnStartup(Entity* self) {
self->SetVar<bool>(u"alive", true);
self->SetVar<bool>(u"on", false);
ToggleFX(self, false);
}
void WhFans::ToggleFX(Entity* self, bool hit) {
std::string fanGroup;
const auto& groups = self->GetGroups();
if (!groups.empty()) {
fanGroup = groups[0];
} else {
fanGroup = "";
}
std::vector<Entity*> fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup);
auto* renderComponent = self->GetComponent<RenderComponent>();
if (renderComponent == nullptr) return;
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) {
auto volumePhys = volume->GetComponent<PhantomPhysicsComponent>();
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) {
auto volumePhys = volume->GetComponent<PhantomPhysicsComponent>();
if (!volumePhys) continue;
volumePhys->SetPhysicsEffectActive(true);
EntityManager::Instance()->SerializeEntity(volume);
}
}
}
void WhFans::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
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);
}
void WhFans::OnDie(Entity* self, Entity* killer) {
if (self->GetVar<bool>(u"on")) {
ToggleFX(self, true);
}
self->SetVar<bool>(u"alive", false);
}