Merge pull request #170 from teamfisk/ScoreBoard
I Hope To God That This Works.
This commit is contained in:
@@ -14,6 +14,7 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EComponentDeleted, &Server::OnComponentDeleted);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Server::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &Server::OnAmmoPickup);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &Server::OnPlayerDeath);
|
||||
// BindWW
|
||||
if (port == 0) {
|
||||
port = config->Get<float>("Networking.Port", 27666);
|
||||
@@ -351,7 +352,7 @@ void Server::parseTCPConnect(Packet & packet)
|
||||
LOG_INFO("Parsing connections");
|
||||
// Check if player is already connected
|
||||
// Ska vara till lagd i TCPServer receive
|
||||
PlayerID playerID = GetPlayerIDFromEndpoint();
|
||||
PlayerID playerID = getPlayerIDFromEndpoint();
|
||||
if (playerID == -1) {
|
||||
return;
|
||||
}
|
||||
@@ -363,6 +364,11 @@ void Server::parseTCPConnect(Packet & packet)
|
||||
m_ConnectedPlayers.at(playerID).TCPAddress = m_Address;
|
||||
m_ConnectedPlayers.at(playerID).TCPPort = m_Port;
|
||||
|
||||
Events::PlayerConnected e;
|
||||
e.PlayerID = playerID;
|
||||
e.PlayerName = m_ConnectedPlayers.at(playerID).Name;
|
||||
m_EventBroker->Publish(e);
|
||||
|
||||
LOG_INFO("parseTCPConnect: Spectator \"%s\" connected on IP: %s", m_ConnectedPlayers.at(playerID).Name.c_str(),
|
||||
m_ConnectedPlayers.at(playerID).TCPAddress.to_string().c_str());
|
||||
|
||||
@@ -526,10 +532,20 @@ bool Server::OnAmmoPickup(const Events::AmmoPickup & e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Server::OnPlayerDeath(const Events::PlayerDeath& e)
|
||||
{
|
||||
Events::KillDeath eKD;
|
||||
eKD.Casualty = getPlayerIDFromEntityID(e.Player.ID);
|
||||
eKD.Killer = getPlayerIDFromEntityID(e.Killer.ID);
|
||||
m_EventBroker->Publish(eKD);
|
||||
return false;
|
||||
}
|
||||
|
||||
void Server::parseClientPing()
|
||||
{
|
||||
LOG_INFO("%i: Parsing ping", m_PacketID);
|
||||
PlayerID player = GetPlayerIDFromEndpoint();
|
||||
PlayerID player = getPlayerIDFromEndpoint();
|
||||
if (player == -1) {
|
||||
return;
|
||||
}
|
||||
@@ -567,7 +583,7 @@ void Server::parseOnInputCommand(Packet& packet)
|
||||
{
|
||||
PlayerID player = -1;
|
||||
// Check which player it was who sent the message
|
||||
player = GetPlayerIDFromEndpoint();
|
||||
player = getPlayerIDFromEndpoint();
|
||||
if (player != -1) {
|
||||
while (packet.DataReadSize() < packet.Size()) {
|
||||
Events::InputCommand e;
|
||||
@@ -586,7 +602,7 @@ void Server::parseOnInputCommand(Packet& packet)
|
||||
|
||||
void Server::parsePlayerTransform(Packet& packet)
|
||||
{
|
||||
PlayerID playerID = GetPlayerIDFromEndpoint();
|
||||
PlayerID playerID = getPlayerIDFromEndpoint();
|
||||
if (playerID == -1) {
|
||||
return;
|
||||
}
|
||||
@@ -630,12 +646,16 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid()
|
||||
|| childEntity.HasComponent("CapturePoint") || childEntity.HasComponent("HealthPickup")
|
||||
|| childEntity.HasComponent("AmmoPickup");
|
||||
return childEntity.HasComponent("Player")
|
||||
|| childEntity.FirstParentWithComponent("Player").Valid()
|
||||
|| childEntity.HasComponent("CapturePoint")
|
||||
|| childEntity.HasComponent("HealthPickup")
|
||||
|| childEntity.HasComponent("AmmoPickup")
|
||||
|| childEntity.HasComponent("ScoreScreen")
|
||||
|| childEntity.FirstParentWithComponent("ScoreScreen").Valid();
|
||||
}
|
||||
|
||||
PlayerID Server::GetPlayerIDFromEndpoint()
|
||||
PlayerID Server::getPlayerIDFromEndpoint()
|
||||
{
|
||||
// check both tcp and udp connection
|
||||
for (auto& kv : m_ConnectedPlayers) {
|
||||
@@ -647,4 +667,14 @@ PlayerID Server::GetPlayerIDFromEndpoint()
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerID Server::getPlayerIDFromEntityID(EntityID entityID)
|
||||
{
|
||||
for(auto& kv : m_ConnectedPlayers) {
|
||||
if (entityID == kv.second.EntityID) {
|
||||
return kv.first;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "Game/Systems/KillFeedSystem.h"
|
||||
#include "Game/Systems/BoostSystem.h"
|
||||
#include "Game/Systems/BoostIconsHUDSystem.h"
|
||||
#include "Game/Systems/ScoreScreenSystem.h"
|
||||
#include "GUI/ButtonSystem.h"
|
||||
#include "GUI/MainMenuSystem.h"
|
||||
|
||||
@@ -155,6 +156,7 @@ Game::Game(int argc, char* argv[])
|
||||
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
|
||||
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
|
||||
m_SystemPipeline->AddSystem<BoostIconsHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<ScoreScreenSystem>(updateOrderLevel);
|
||||
// Populate Octree with collidables
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
|
||||
|
||||
@@ -14,17 +14,20 @@ void AbilityCooldownHUDSystem::Update(double dt)
|
||||
if (!abilityEntity.Valid())
|
||||
return;
|
||||
EntityWrapper cooldownTextEntity = entity.FirstChildByName("Cooldown");
|
||||
|
||||
double maxAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownMaxTimer"];
|
||||
double currentAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownTimer"];
|
||||
|
||||
currentAbilityCD = currentAbilityCD >= 0.0 ? currentAbilityCD : 0.0;
|
||||
|
||||
if(cooldownTextEntity.Valid()) {
|
||||
if(cooldownTextEntity.HasComponent("Text"))
|
||||
{
|
||||
double maxAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownMaxTimer"];
|
||||
double currentAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownTimer"];
|
||||
currentAbilityCD = currentAbilityCD >= 0.0 ? currentAbilityCD : 0.0;
|
||||
std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3);
|
||||
if(entity.HasComponent("Fill")) {
|
||||
entity["Fill"]["Percentage"] = currentAbilityCD/maxAbilityCD; //TODO: current time needs to be in the component.
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entity.HasComponent("Fill")) {
|
||||
entity["Fill"]["Percentage"] = currentAbilityCD/maxAbilityCD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ CapturePointHUDSystem::CapturePointHUDSystem(SystemParams params)
|
||||
|
||||
void CapturePointHUDSystem::Update(double dt)
|
||||
{
|
||||
bool LoadCheck = true;
|
||||
bool loadCheck = true;
|
||||
int redTeam;
|
||||
int blueTeam;
|
||||
int spectatorTeam;
|
||||
@@ -35,11 +35,11 @@ void CapturePointHUDSystem::Update(double dt)
|
||||
//Check if the HUD corresponds to the Capture Point Number
|
||||
if (HUD_ID == (int)entityCP["CapturePoint"]["CapturePointNumber"]) {
|
||||
ComponentWrapper& teamComponent = entityCP["Team"];
|
||||
if (LoadCheck) {
|
||||
if (loadCheck) {
|
||||
redTeam = (int)teamComponent["Team"].Enum("Red");
|
||||
blueTeam = (int)teamComponent["Team"].Enum("Blue");
|
||||
spectatorTeam = (int)teamComponent["Team"].Enum("Spectator");
|
||||
LoadCheck = false;
|
||||
loadCheck = false;
|
||||
}
|
||||
//Color hud with team color
|
||||
auto capturePointTeam = (int)teamComponent["Team"];
|
||||
|
||||
@@ -12,15 +12,7 @@ HealthSystem::HealthSystem(SystemParams params)
|
||||
}
|
||||
|
||||
void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cHealth, double dt)
|
||||
{
|
||||
double& health = cHealth["Health"];
|
||||
if (health <= 0.0) {
|
||||
Events::PlayerDeath ePlayerDeath;
|
||||
ePlayerDeath.Player = entity;
|
||||
m_EventBroker->Publish(ePlayerDeath);
|
||||
//Note: we will delete the entity in PlayerDeathSystem
|
||||
}
|
||||
}
|
||||
{ }
|
||||
|
||||
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
||||
{
|
||||
@@ -35,7 +27,16 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
||||
if (playerBoostDefenderEntity.Valid()) {
|
||||
e.Damage -= (double)playerBoostDefenderEntity["BoostDefender"]["StrengthOfEffect"];
|
||||
}
|
||||
health -= e.Damage;
|
||||
if (health > 0) {
|
||||
health -= e.Damage;
|
||||
if (health <= 0.0) {
|
||||
Events::PlayerDeath ePlayerDeath;
|
||||
ePlayerDeath.Player = e.Victim;
|
||||
ePlayerDeath.Killer = e.Inflictor;
|
||||
m_EventBroker->Publish(ePlayerDeath);
|
||||
//Note: we will delete the entity in PlayerDeathSystem
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
#include "Game/Systems/ScoreScreenSystem.h"
|
||||
|
||||
|
||||
ScoreScreenSystem::ScoreScreenSystem(SystemParams params)
|
||||
: System(params)
|
||||
, PureSystem("ScoreScreen")
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &ScoreScreenSystem::OnPlayerDeath);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &ScoreScreenSystem::OnPlayerSpawn);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerConnected, &ScoreScreenSystem::OnPlayerConnected);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDisconnected, &ScoreScreenSystem::OnPlayerDisconnected);
|
||||
}
|
||||
|
||||
void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& scoreScreen, double dt)
|
||||
{
|
||||
if (!IsServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!entity.HasComponent("ScoreScreen")){
|
||||
return;
|
||||
}
|
||||
|
||||
int currentTeam = 0;
|
||||
|
||||
if(entity.HasComponent("Team")) {
|
||||
currentTeam = (int)entity["Team"]["Team"];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
auto children = entity.ChildrenWithComponent("ScoreIdentity");
|
||||
|
||||
float position = 0.f;
|
||||
|
||||
for (auto it = m_PlayerIdentities.begin(); it != m_PlayerIdentities.end(); ++it) {
|
||||
bool found = false;
|
||||
for (auto& child : children) {
|
||||
int ID = (int)child["ScoreIdentity"]["ID"];
|
||||
if (it->first == ID) {
|
||||
if (it->second.Team != currentTeam) {
|
||||
m_World->DeleteEntity(child.ID);
|
||||
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1;
|
||||
break;
|
||||
}
|
||||
for (auto it2 = m_DisconnectedIdentities.begin(); it2 != m_DisconnectedIdentities.end(); ++it2) {
|
||||
if (ID == *it2) {
|
||||
m_World->DeleteEntity(child.ID);
|
||||
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1;
|
||||
it2 = m_DisconnectedIdentities.erase(it2);
|
||||
it = m_PlayerIdentities.erase(it);
|
||||
|
||||
//Remove from m_playerIdentities
|
||||
break;
|
||||
}
|
||||
}
|
||||
found = true;
|
||||
if(!child.Valid()) {
|
||||
break;
|
||||
}
|
||||
//Update Deaths for child
|
||||
(int&)child["ScoreIdentity"]["Kills"] = it->second.Kills;
|
||||
//Update Kills for child
|
||||
(int&)child["ScoreIdentity"]["Deaths"] = it->second.Deaths;
|
||||
//KD is not updated at the moment.
|
||||
if (it->second.Deaths != 0) {
|
||||
(double&)child["ScoreIdentity"]["KD"] = it->second.Kills/it->second.Deaths;
|
||||
}
|
||||
|
||||
//Update position for child
|
||||
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
|
||||
(glm::vec3&) child["Transform"]["Position"] = offset * position;
|
||||
position += 1.f;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (it == m_PlayerIdentities.end()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(found == false) {
|
||||
if(it->second.Team != currentTeam) {
|
||||
//This player is not the same team as this scoreboard should show.
|
||||
continue;
|
||||
}
|
||||
//There is no entry for this player, create one.
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/ScoreIdentity.xml");
|
||||
EntityWrapper scoreIdentity = entityFile->MergeInto(m_World);
|
||||
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
|
||||
int newPosition = (int)entity["ScoreScreen"]["TotalIdentities"];
|
||||
(glm::vec3&) scoreIdentity["Transform"]["Position"] = offset * (float)newPosition;
|
||||
auto cScoreIdentity = scoreIdentity["ScoreIdentity"];
|
||||
auto data = it->second;
|
||||
|
||||
(std::string&)cScoreIdentity["Name"] = data.Name;
|
||||
(int&)cScoreIdentity["ID"] = data.ID;
|
||||
|
||||
m_World->SetParent(scoreIdentity.ID, entity.ID);
|
||||
|
||||
(int&)entity["ScoreScreen"]["TotalIdentities"] += 1;
|
||||
|
||||
}
|
||||
}
|
||||
//Local player should have an icon, compare with LocalPlayer somthing
|
||||
}
|
||||
|
||||
bool ScoreScreenSystem::OnPlayerDeath(const Events::KillDeath& e)
|
||||
{
|
||||
//When player die, add it to his score, and when possible the player who killed him.
|
||||
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;
|
||||
}
|
||||
|
||||
bool ScoreScreenSystem::OnPlayerSpawn(const Events::PlayerSpawned& e)
|
||||
{
|
||||
//When a player spawn, add data to the list entry with the same ID.
|
||||
|
||||
std::unordered_map<int, PlayerData>::iterator got;
|
||||
|
||||
got = m_PlayerIdentities.find(e.PlayerID);
|
||||
if(got == m_PlayerIdentities.end()) {
|
||||
LOG_ERROR("Player spawned without having an entry on score screen");
|
||||
return 0;
|
||||
}
|
||||
auto& data = got->second;
|
||||
data.Player = e.Player;
|
||||
data.Team = (int)data.Player["Team"]["Team"];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ScoreScreenSystem::OnPlayerConnected(const Events::PlayerConnected& e)
|
||||
{
|
||||
//player has connected, add his data to the list of ScoreIdentities
|
||||
PlayerData data;
|
||||
data.ID = e.PlayerID;
|
||||
data.Name = e.PlayerName;
|
||||
m_PlayerIdentities.insert( {data.ID, data} );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ScoreScreenSystem::OnPlayerDisconnected(const Events::PlayerDisconnected& e)
|
||||
{
|
||||
//player has disconnected, remove him from list of ScoreIdentities
|
||||
m_DisconnectedIdentities.push_back(e.PlayerID);
|
||||
return 0;
|
||||
}
|
||||
@@ -35,9 +35,17 @@ void TextFieldReader::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
if (field.Type == "int") {
|
||||
text = boost::lexical_cast<std::string>((const int&)component[fieldName]);
|
||||
} else if (field.Type == "float") {
|
||||
text = boost::lexical_cast<std::string>((const float&)component[fieldName]);
|
||||
std::ostringstream ss;
|
||||
float f = (float)component[fieldName];
|
||||
ss << std::fixed << std::setprecision(2);
|
||||
ss << f;
|
||||
text = ss.str();
|
||||
} else if (field.Type == "double") {
|
||||
text = boost::lexical_cast<std::string>((const double&)component[fieldName]);
|
||||
std::ostringstream ss;
|
||||
double d = (double)component[fieldName];
|
||||
ss << std::fixed << std::setprecision(1);
|
||||
ss << d;
|
||||
text = ss.str();
|
||||
} else if (field.Type == "bool") {
|
||||
text = boost::lexical_cast<std::string>((const bool&)component[fieldName]);
|
||||
} else if (field.Type == "string") {
|
||||
|
||||
Reference in New Issue
Block a user