DarkflameServer/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp
David Markowitz 455f9470a5
Move EntityManager to Game namespace (#1140)
* 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
2023-07-15 13:56:33 -07:00

75 lines
2.5 KiB
C++

#include "EnemySpiderSpawner.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "EntityInfo.h"
#include "DestroyableComponent.h"
#include "eReplicaComponentType.h"
//----------------------------------------------
//--Initiate egg hatching on call
//----------------------------------------------
void EnemySpiderSpawner::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1,
int32_t param2, int32_t param3) {
if (args == "prepEgg") {
// Highlight eggs about to hatch with Maelstrom effect
GameMessages::SendPlayFXEffect(self->GetObjectID(), 2856, u"maelstrom", "test", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
// Make indestructible
auto dest = static_cast<DestroyableComponent*>(self->GetComponent(eReplicaComponentType::DESTROYABLE));
if (dest) {
dest->SetFaction(-1);
}
Game::entityManager->SerializeEntity(self);
// Keep track of who prepped me
self->SetI64(u"SpawnOwner", sender->GetObjectID());
} else if (args == "hatchEgg") {
// Final countdown to pop
self->AddTimer("StartSpawnTime", hatchTime);
}
}
//----------------------------------------------------------------
//--Called when timers are done
//----------------------------------------------------------------
void EnemySpiderSpawner::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "StartSpawnTime") {
SpawnSpiderling(self);
} else if (timerName == "SpawnSpiderling") {
GameMessages::SendPlayFXEffect(self->GetObjectID(), 644, u"create", "egg_puff_b", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
//TODO: set the aggro radius larger
EntityInfo info{};
info.lot = 16197;
info.pos = self->GetPosition();
info.spawner = nullptr;
info.spawnerID = self->GetI64(u"SpawnOwner");
info.spawnerNodeID = 0;
Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr);
if (newEntity) {
Game::entityManager->ConstructEntity(newEntity);
newEntity->GetGroups().push_back("BabySpider");
/*
auto* movementAi = newEntity->GetComponent<MovementAIComponent>();
movementAi->SetDestination(newEntity->GetPosition());
*/
}
self->ScheduleKillAfterUpdate();
}
}
//--------------------------------------------------------------
//Called when it is finally time to release the Spiderlings
//--------------------------------------------------------------
void EnemySpiderSpawner::SpawnSpiderling(Entity* self) {
//Initiate the actual spawning
GameMessages::SendPlayFXEffect(self->GetObjectID(), 2260, u"rebuild_medium", "dropdustmedium", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
self->AddTimer("SpawnSpiderling", spawnTime);
}