Killfeed should work now.
This commit is contained in:
@@ -165,6 +165,9 @@ void Client::parseMessageType(Packet& packet)
|
||||
case MessageType::RemoveWorld:
|
||||
parseRemoveWorld(packet);
|
||||
break;
|
||||
case MessageType::KD:
|
||||
parseKDEvent(packet);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -349,6 +352,22 @@ void Client::parseRemoveWorld(Packet & packet)
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
void Client::parseKDEvent(Packet & packet)
|
||||
{
|
||||
Events::KillDeath e;
|
||||
e.Casualty = packet.ReadPrimitive<int>();
|
||||
e.CasualtyClass = packet.ReadPrimitive<int>();
|
||||
e.CasualtyName = packet.ReadString();
|
||||
e.CasualtyTeam = packet.ReadPrimitive<int>();
|
||||
|
||||
e.Killer = packet.ReadPrimitive<int>();
|
||||
e.KillerClass = packet.ReadPrimitive<int>();
|
||||
e.KillerName = packet.ReadString();
|
||||
e.KillerTeam = packet.ReadPrimitive<int>();
|
||||
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID)
|
||||
{
|
||||
for (auto field : componentInfo.FieldsInOrder) {
|
||||
|
||||
@@ -560,9 +560,48 @@ bool Server::OnAmmoPickup(const Events::AmmoPickup & e)
|
||||
bool Server::OnPlayerDeath(const Events::PlayerDeath& e)
|
||||
{
|
||||
Events::KillDeath eKD;
|
||||
auto entity = e;
|
||||
eKD.Casualty = getPlayerIDFromEntityID(e.Player.ID);
|
||||
eKD.Killer = getPlayerIDFromEntityID(e.Killer.ID);
|
||||
|
||||
eKD.CasualtyName = m_ConnectedPlayers.at(getPlayerIDFromEntityID(e.Player.ID)).Name;
|
||||
eKD.KillerName = m_ConnectedPlayers.at(getPlayerIDFromEntityID(e.Killer.ID)).Name;
|
||||
|
||||
if(entity.Player.HasComponent("Team")) {
|
||||
eKD.CasualtyTeam = (const int&)entity.Player["Team"]["Team"];
|
||||
}
|
||||
if (entity.Killer.HasComponent("Team")) {
|
||||
eKD.KillerTeam = (const int&)entity.Killer["Team"]["Team"];
|
||||
}
|
||||
|
||||
if(entity.Player.HasComponent("DashAbility")) {
|
||||
eKD.CasualtyClass = 1;
|
||||
} else if (entity.Player.HasComponent("ShieldAbility")) {
|
||||
eKD.CasualtyClass = 2;
|
||||
} else if (entity.Player.HasComponent("SprintAbility")) {
|
||||
eKD.CasualtyClass = 3;
|
||||
}
|
||||
if (entity.Killer.HasComponent("DashAbility")) {
|
||||
eKD.KillerClass = 1;
|
||||
} else if (entity.Killer.HasComponent("ShieldAbility")) {
|
||||
eKD.KillerClass = 2;
|
||||
} else if (entity.Killer.HasComponent("SprintAbility")) {
|
||||
eKD.KillerClass = 3;
|
||||
}
|
||||
|
||||
m_EventBroker->Publish(eKD);
|
||||
|
||||
Packet kdPacket(MessageType::KD);
|
||||
kdPacket.WritePrimitive(eKD.Casualty);
|
||||
kdPacket.WritePrimitive(eKD.CasualtyClass);
|
||||
kdPacket.WriteString(eKD.CasualtyName);
|
||||
kdPacket.WritePrimitive(eKD.CasualtyTeam);
|
||||
|
||||
kdPacket.WritePrimitive(eKD.Killer);
|
||||
kdPacket.WritePrimitive(eKD.KillerClass);
|
||||
kdPacket.WriteString(eKD.KillerName);
|
||||
kdPacket.WritePrimitive(eKD.KillerTeam);
|
||||
reliableBroadcast(kdPacket);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ void KillFeedSystem::Update(double dt)
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto it = m_DeathQueue.begin(); it != m_DeathQueue.end(); it++) {
|
||||
(*it).TimeToLive -= dt;
|
||||
}
|
||||
|
||||
for (auto& killFeedComponent : *killFeeds) {
|
||||
EntityWrapper entity = EntityWrapper(m_World, killFeedComponent.EntityID);
|
||||
|
||||
@@ -16,10 +20,7 @@ void KillFeedSystem::Update(double dt)
|
||||
(Field<std::string>)child["Text"]["Content"] = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int feedIndex = 1;
|
||||
for (auto it = m_DeathQueue.begin(); it != m_DeathQueue.end(); ) {
|
||||
bool remove = false;
|
||||
@@ -27,14 +28,19 @@ void KillFeedSystem::Update(double dt)
|
||||
EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(feedIndex));
|
||||
|
||||
if (child.HasComponent("Text")) {
|
||||
(Field<std::string>)child["Text"]["Content"] = (*it).Content;
|
||||
(Field<glm::vec4>)child["Text"]["Color"] = (*it).Color;
|
||||
|
||||
(*it).TimeToLive -= dt;
|
||||
std::string str = "";
|
||||
//Add killer to the start of string.
|
||||
str = (*it).KillerColor + "\\" + std::to_string((*it).KillerClass) + "\\CFFFFFF" + " " + (*it).KillerName + " ";
|
||||
//Add Weapon to middle of string.
|
||||
str += "\\" + std::to_string((*it).KillerClass+3) + " ";
|
||||
//Add victim to the end of string
|
||||
str += (*it).VictimColor + "\\" + std::to_string((*it).VictimClass) + "\\CFFFFFF" + " " + (*it).VictimName;
|
||||
|
||||
(Field<std::string>)child["Text"]["Content"] = str;
|
||||
|
||||
if ((*it).TimeToLive <= 0.f) {
|
||||
(Field<std::string>)child["Text"]["Content"] = "";
|
||||
(Field<glm::vec4>)child["Text"]["Color"] = (*it).Color;
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
@@ -52,29 +58,30 @@ void KillFeedSystem::Update(double dt)
|
||||
}
|
||||
}
|
||||
|
||||
bool KillFeedSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
bool KillFeedSystem::OnPlayerKillDeath(Events::KillDeath& e)
|
||||
{
|
||||
KillFeedInfo kfInfo;
|
||||
KillFeedInfo info;
|
||||
|
||||
if (e.Player.HasComponent("Team")) {
|
||||
int red = e.Player["Team"].Enum("Team", "Red");
|
||||
int blue = e.Player["Team"].Enum("Team", "Blue");
|
||||
|
||||
if ((int)e.Player["Team"]["Team"] == red) {
|
||||
kfInfo.Content = "Blue Player killed Red Player";
|
||||
kfInfo.Color = glm::vec4(0.f, 0.2f, 1.f, 0.8f);
|
||||
m_DeathQueue.push_back(kfInfo);
|
||||
} else if ((int)e.Player["Team"]["Team"] == blue) {
|
||||
kfInfo.Content = "Red Player killed blue Player";
|
||||
kfInfo.Color = glm::vec4(1.f, 0.f, 0.f, 0.8f);
|
||||
m_DeathQueue.push_back(kfInfo);
|
||||
}
|
||||
info.KillerName = e.KillerName;
|
||||
info.KillerID = e.Killer;
|
||||
info.KillerClass = e.KillerClass;
|
||||
info.KillerTeam = e.KillerTeam;
|
||||
if(info.KillerTeam == 2){
|
||||
info.KillerColor = m_BlueColor;
|
||||
} else if (info.KillerTeam == 3) {
|
||||
info.KillerColor = m_RedColor;
|
||||
}
|
||||
|
||||
|
||||
if(m_DeathQueue.size() > 3) {
|
||||
m_DeathQueue.pop_front();
|
||||
info.VictimName = e.CasualtyName;
|
||||
info.VictimID = e.Casualty;
|
||||
info.VictimClass = e.CasualtyClass;
|
||||
info.VictimTeam = e.CasualtyTeam;
|
||||
if (info.VictimTeam == 2) {
|
||||
info.VictimColor = m_BlueColor;
|
||||
} else if (info.VictimTeam == 3) {
|
||||
info.VictimColor = m_RedColor;
|
||||
}
|
||||
|
||||
return true;
|
||||
m_DeathQueue.push_back(info);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user