Should now work fully, not KD tho

This commit is contained in:
Tleety
2016-03-04 01:34:29 +01:00
parent 66374b7ff9
commit 00b5a1771c
3 changed files with 23 additions and 20 deletions
+2 -2
View File
@@ -31,11 +31,11 @@ private:
int ID = -1; int ID = -1;
std::string Name = ""; std::string Name = "";
int Team = 1; int Team = 1;
int Kills = 0;
int Deaths = 0;
EntityWrapper Player = EntityWrapper::Invalid; EntityWrapper Player = EntityWrapper::Invalid;
}; };
std::unordered_map<int, int> m_DeathAmount;
std::unordered_map<int, int> m_KillAmount;
std::vector<int> m_DisconnectedIdentities; std::vector<int> m_DisconnectedIdentities;
int m_PlayerCounter = 0; int m_PlayerCounter = 0;
std::unordered_map<int, PlayerData> m_PlayerIdentities; std::unordered_map<int, PlayerData> m_PlayerIdentities;
+8 -2
View File
@@ -11,10 +11,16 @@ bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e)
if (e.Victim.ID == e.Inflictor.ID) { if (e.Victim.ID == e.Inflictor.ID) {
return false; return false;
} }
if (!e.Victim.Valid() && e.Victim != LocalPlayer && !e.Victim.IsChildOf(LocalPlayer)) {
if (!e.Victim.Valid() || !LocalPlayer.Valid()) {
return false; 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; return false;
} }
+13 -16
View File
@@ -40,7 +40,7 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
for (auto it = m_PlayerIdentities.begin(); it != m_PlayerIdentities.end(); ++it) { for (auto it = m_PlayerIdentities.begin(); it != m_PlayerIdentities.end(); ++it) {
bool found = false; bool found = false;
for (auto child : children) { for (auto& child : children) {
int ID = (int)child["ScoreIdentity"]["ID"]; int ID = (int)child["ScoreIdentity"]["ID"];
if (it->first == ID) { if (it->first == ID) {
if (it->second.Team != currentTeam) { if (it->second.Team != currentTeam) {
@@ -61,21 +61,11 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
} }
found = true; found = true;
//Update Deaths for child //Update Deaths for child
std::unordered_map<int, int>::iterator gotDeaths = m_DeathAmount.find(ID); (int&)child["ScoreIdentity"]["Kills"] = it->second.Kills;
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);
}
//Update Kills for child //Update Kills for child
std::unordered_map<int, int>::iterator gotKills = m_KillAmount.find(ID); (int&)child["ScoreIdentity"]["Deaths"] = it->second.Deaths;
if (gotKills != m_KillAmount.end()) { //KD is not updated at the moment.
(int&)child["ScoreIdentity"]["Kills"] += gotKills->second;
(double&)child["ScoreIdentity"]["KD"] = (double)((int)child["ScoreIdentity"]["Deaths"]/(int)child["ScoreIdentity"]["Deaths"]);
m_KillAmount.erase(gotKills);
}
//Update position for child //Update position for child
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"]; glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
(glm::vec3&) child["Transform"]["Position"] = offset * position; (glm::vec3&) child["Transform"]["Position"] = offset * position;
@@ -118,8 +108,15 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
bool ScoreScreenSystem::OnPlayerDeath(const Events::KillDeath& e) bool ScoreScreenSystem::OnPlayerDeath(const Events::KillDeath& e)
{ {
//When player die, add it to his score, and when possible the player who killed him. //When player die, add it to his score, and when possible the player who killed him.
m_DeathAmount[e.Casualty]++; std::unordered_map<int, PlayerData>::iterator got;
m_KillAmount[e.Killer]++; 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; return 0;
} }