mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 23:17:28 +00:00
455f9470a5
* Move EntityManager to Game namespace * move initialization to later Need to wait for dZoneManager to be initialized. * Fix bugs - Cannot delete from a RandomAccessIterator while in a range based for loop. Touchup zone manager initialize replace magic numbers with better named constants replace magic zonecontrol id with a more readable hex alternative condense stack variables move initializers closer to their use initialize entity manager with zone control change initialize timings If zone is not zero we expect to initialize the entity manager during zone manager initialization Add constexpr for zone control LOT * Add proper error handling * revert vanity changes * Update WorldServer.cpp * Update dZoneManager.cpp
74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#include "WhFans.h"
|
|
|
|
#include "RenderComponent.h"
|
|
#include "GameMessages.h"
|
|
#include "EntityManager.h"
|
|
#include "PhantomPhysicsComponent.h"
|
|
#include "RenderComponent.h"
|
|
#include "Entity.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 = Game::entityManager->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")) {
|
|
RenderComponent::PlayAnimation(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);
|
|
Game::entityManager->SerializeEntity(volume);
|
|
}
|
|
} else if (!self->GetVar<bool>(u"on") && self->GetVar<bool>(u"alive")) {
|
|
RenderComponent::PlayAnimation(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);
|
|
Game::entityManager->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);
|
|
}
|