DarkflameServer/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp
David Markowitz d8a5fd49a4
chore: Small movementAiComponent cleanup (#1145)
* rename and cleanup file

* more

* fix broken function

* Further naming fixes

t

Revert "Further naming fixes"

This reverts commit 057189982ba56788d48f9265d815e6c562ba6328.

* next step

* undo all testing changes

* minor tweaks
2023-08-03 21:38:04 -05:00

69 lines
2.4 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");
}
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);
}