diff --git a/include/Game/Systems/ScoreScreenSystem.h b/include/Game/Systems/ScoreScreenSystem.h index 384f3c8d..f2528a7f 100644 --- a/include/Game/Systems/ScoreScreenSystem.h +++ b/include/Game/Systems/ScoreScreenSystem.h @@ -31,11 +31,11 @@ private: int ID = -1; std::string Name = ""; int Team = 1; + int Kills = 0; + int Deaths = 0; EntityWrapper Player = EntityWrapper::Invalid; }; - std::unordered_map m_DeathAmount; - std::unordered_map m_KillAmount; std::vector m_DisconnectedIdentities; int m_PlayerCounter = 0; std::unordered_map m_PlayerIdentities; diff --git a/src/Game/Systems/BoostSystem.cpp b/src/Game/Systems/BoostSystem.cpp index c79576e4..c3dc1f2b 100644 --- a/src/Game/Systems/BoostSystem.cpp +++ b/src/Game/Systems/BoostSystem.cpp @@ -11,10 +11,16 @@ bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e) if (e.Victim.ID == e.Inflictor.ID) { return false; } - if (!e.Victim.Valid() && e.Victim != LocalPlayer && !e.Victim.IsChildOf(LocalPlayer)) { + + if (!e.Victim.Valid() || !LocalPlayer.Valid()) { return false; } - if (!e.Inflictor.Valid() || !e.Victim.Valid()) { + + if (e.Victim != LocalPlayer && !e.Victim.IsChildOf(LocalPlayer)) { + return false; + } + + if (!e.Inflictor.Valid()) { return false; } diff --git a/src/Game/Systems/ScoreScreenSystem.cpp b/src/Game/Systems/ScoreScreenSystem.cpp index 5c7fe569..29749a9b 100644 --- a/src/Game/Systems/ScoreScreenSystem.cpp +++ b/src/Game/Systems/ScoreScreenSystem.cpp @@ -40,7 +40,7 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& for (auto it = m_PlayerIdentities.begin(); it != m_PlayerIdentities.end(); ++it) { bool found = false; - for (auto child : children) { + for (auto& child : children) { int ID = (int)child["ScoreIdentity"]["ID"]; if (it->first == ID) { if (it->second.Team != currentTeam) { @@ -61,21 +61,11 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& } found = true; //Update Deaths for child - std::unordered_map::iterator gotDeaths = m_DeathAmount.find(ID); - if(gotDeaths != m_DeathAmount.end()) { - (int&)child["ScoreIdentity"]["Deaths"] += gotDeaths->second; - (double&)child["ScoreIdentity"]["KD"] = (double)((int)child["ScoreIdentity"]["Deaths"]/(int)child["ScoreIdentity"]["Deaths"]); - m_DeathAmount.erase(gotDeaths); - - } + (int&)child["ScoreIdentity"]["Kills"] = it->second.Kills; //Update Kills for child - std::unordered_map::iterator gotKills = m_KillAmount.find(ID); - if (gotKills != m_KillAmount.end()) { - (int&)child["ScoreIdentity"]["Kills"] += gotKills->second; - (double&)child["ScoreIdentity"]["KD"] = (double)((int)child["ScoreIdentity"]["Deaths"]/(int)child["ScoreIdentity"]["Deaths"]); - m_KillAmount.erase(gotKills); + (int&)child["ScoreIdentity"]["Deaths"] = it->second.Deaths; + //KD is not updated at the moment. - } //Update position for child glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"]; (glm::vec3&) child["Transform"]["Position"] = offset * position; @@ -118,8 +108,15 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& bool ScoreScreenSystem::OnPlayerDeath(const Events::KillDeath& e) { //When player die, add it to his score, and when possible the player who killed him. - m_DeathAmount[e.Casualty]++; - m_KillAmount[e.Killer]++; + std::unordered_map::iterator got; + got = m_PlayerIdentities.find(e.Casualty); + if(got != m_PlayerIdentities.end()) { + got->second.Deaths++; + } + got = m_PlayerIdentities.find(e.Killer); + if (got != m_PlayerIdentities.end()) { + got->second.Kills++; + } return 0; }