Created EPlayerSpawned that gets published when a player spawns

This commit is contained in:
2016-01-22 10:16:35 +01:00
parent 8cf83454d7
commit 1e3fc1ae2d
3 changed files with 41 additions and 5 deletions
+14 -4
View File
@@ -13,7 +13,7 @@ void PlayerSpawnSystem::Update(double dt)
return;
}
for (auto& team : m_SpawnRequests) {
for (auto& req : m_SpawnRequests) {
for (auto& cPlayerSpawn : *playerSpawns) {
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
if (!spawner.HasComponent("Spawner")) {
@@ -22,7 +22,7 @@ void PlayerSpawnSystem::Update(double dt)
// If the spawner has a team affiliation, check it
if (spawner.HasComponent("Team")) {
if ((int)spawner["Team"]["Team"] != team) {
if ((int)spawner["Team"]["Team"] != req.Team) {
continue;
}
}
@@ -30,7 +30,14 @@ void PlayerSpawnSystem::Update(double dt)
// Spawn the player!
EntityWrapper player = SpawnerSystem::Spawn(spawner);
// Set the player team affiliation
player["Team"]["Team"] = team;
player["Team"]["Team"] = req.Team;
// Publish a PlayerSpawned event
Events::PlayerSpawned e;
e.PlayerID = req.PlayerID;
e.Player = player;
e.Spawner = spawner;
m_EventBroker->Publish(e);
}
}
m_SpawnRequests.clear();
@@ -43,7 +50,10 @@ bool PlayerSpawnSystem::OnInputCommand(const Events::InputCommand& e)
}
if (e.Value != 0) {
m_SpawnRequests.push_back((int)e.Value);
SpawnRequest req;
req.PlayerID = e.PlayerID;
req.Team = (ComponentInfo::EnumType)e.Value;
m_SpawnRequests.push_back(req);
}
return true;