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;
std::string Name = "";
int Team = 1;
int Kills = 0;
int Deaths = 0;
EntityWrapper Player = EntityWrapper::Invalid;
};
std::unordered_map<int, int> m_DeathAmount;
std::unordered_map<int, int> m_KillAmount;
std::vector<int> m_DisconnectedIdentities;
int m_PlayerCounter = 0;
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) {
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;
}
+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) {
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<int, int>::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<int, int>::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<int, PlayerData>::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;
}