CapturePointSystem updated, all tests are green

This commit is contained in:
verysecrethero
2016-01-19 17:19:58 +01:00
parent f197993beb
commit b45de542da
9 changed files with 121 additions and 58 deletions
+14 -6
View File
@@ -18,7 +18,7 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
if (!hasTeamComponent) {
world->AttachComponent(capturePoint.EntityID, "Team");
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
teamComponent["Team"] = 0;
teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator");
}
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
int firstTeamPlayersStandingInside = 0;
@@ -49,7 +49,7 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
}
}
//check team - spectatorNumber = "no team"
int teamNumber = world->GetComponent(playerID, "Player")["Team"];
int teamNumber = world->GetComponent(playerID, "Team")["Team"];
if (teamNumber == redTeam) {
firstTeamPlayersStandingInside++;
} else if (teamNumber == blueTeam) {
@@ -69,11 +69,19 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
no capturepoint taken yet for at least one of the teams <->
at the start of the match the system is unaware of what capturePoint is the first one for each team*/
if (m_Team1NextPossibleCapturePoint == m_NotACapturePoint && (int)teamComponent["Team"] == redTeam) {
m_Team1NextPossibleCapturePoint = capturePoint["CapturePointNumber"];
m_Team1HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team1NextPossibleCapturePoint
if (m_Team1HomeCapturePoint == 0) {
m_Team1NextPossibleCapturePoint = 1;
} else {
m_Team1NextPossibleCapturePoint = (int)capturePoint["CapturePointNumber"] - 1;
}
} else if (m_Team2NextPossibleCapturePoint == m_NotACapturePoint && (int)teamComponent["Team"] == blueTeam) {
m_Team2NextPossibleCapturePoint = capturePoint["CapturePointNumber"];
m_Team2HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team2NextPossibleCapturePoint
if (m_Team2HomeCapturePoint == 0) {
m_Team2NextPossibleCapturePoint = 1;
} else {
m_Team2NextPossibleCapturePoint = (int)capturePoint["CapturePointNumber"] - 1;
}
}
//at least one capturepoint has been taken over
//do nothing, its being handled inside the next code:
@@ -86,12 +94,12 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
&& m_Team1NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"])
{
timerDeltaChange = firstTeamPlayersStandingInside*dt;
currentTeam = blueTeam;
currentTeam = redTeam;
} else if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0
&& m_Team2NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"])
{
timerDeltaChange = -secondTeamPlayersStandingInside*dt;
currentTeam = redTeam;
currentTeam = blueTeam;
}
if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside == 0) {
+3 -4
View File
@@ -12,7 +12,6 @@ HealthSystem::HealthSystem(EventBroker* eventBroker)
void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
//if entityID of health is 9 then the players ID is also 9 (player,health are connected to the same entity)
ComponentWrapper player = world->GetComponent(component.EntityID, "Player");
double maxHealth = (double)component["MaxHealth"];
//process the DeltaHealthVector and change the entitys health accordingly
@@ -20,7 +19,7 @@ void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, Componen
{
auto deltaHP = m_DeltaHealthVector[i - 1];
//if we have a healthchange for the current player and health is greater than 0, then apply it
if (std::get<0>(deltaHP) == player.EntityID && (double)component["Health"] > 0.0f) {
if (std::get<0>(deltaHP) == component.EntityID && (double)component["Health"] > 0.0f) {
//get the deltaHP value from the tuple and make sure you dont get more than maxHealth
double newHealth = std::min((double)component["Health"] + (double)std::get<1>(deltaHP), maxHealth);
component["Health"] = newHealth;
@@ -30,12 +29,12 @@ void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, Componen
component["Health"] = 0.0;
//publish death event
Events::PlayerDeath e;
e.PlayerID = player.EntityID;
e.PlayerID = component.EntityID;
m_EventBroker->Publish(e);
//clear the remaining hpDeltas for the dead player
for (size_t j = m_DeltaHealthVector.size(); j > 0; j--)
{
if (std::get<0>(m_DeltaHealthVector[j - 1]) == player.EntityID)
if (std::get<0>(m_DeltaHealthVector[j - 1]) == component.EntityID)
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + j - 1);
}
//break the loop if the player is dead