A "Respawn" componet which automatically triggers a Spawner component when the last respawned entity of that spawner is destroyed

This commit is contained in:
2016-03-09 23:48:41 +01:00
parent 123fbf5633
commit 4b6d4e581f
8 changed files with 81 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
#include "Core/RespawnSystem.h"
RespawnSystem::RespawnSystem(SystemParams params)
: System(params)
, PureSystem("Respawn")
{
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &RespawnSystem::OnEntityDeleted);
}
void RespawnSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cRespawn, double dt)
{
if (!entity.HasComponent("Spawner")) {
return;
}
EntityWrapper& lastRespawnedEntity = m_LastRespawnedEntity[entity];
if (!lastRespawnedEntity.Valid()) {
double& _respawnCountdown = cRespawn["_RespawnCountdown"];
_respawnCountdown -= dt;
if (_respawnCountdown <= 0) {
lastRespawnedEntity = SpawnerSystem::Spawn(entity, entity);
_respawnCountdown = cRespawn["Delay"];
}
}
}
bool RespawnSystem::OnEntityDeleted(const Events::EntityDeleted& e)
{
m_LastRespawnedEntity.erase(e.DeletedEntity);
return true;
}