Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2167b6f7b1 | |||
| 714665f0a3 | |||
| 8466a282b7 |
@@ -10,8 +10,9 @@ namespace Events
|
||||
struct PlayerDeath : Event
|
||||
{
|
||||
//KilledBy,KilledByWhat is optional for now. It might be used later in the playerlog-system
|
||||
EntityWrapper Player;
|
||||
std::string KilledByWhat;
|
||||
EntityWrapper Player = EntityWrapper::Invalid;
|
||||
EntityWrapper Killer = EntityWrapper::Invalid;
|
||||
std::string KilledByWhat = "";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef Events_KillDeath_h__
|
||||
#define Events_KillDeath_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
typedef unsigned int PlayerID;
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct KillDeath : public Event
|
||||
{
|
||||
PlayerID Casualty = -1;
|
||||
PlayerID Killer = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "Core/EEntityDeleted.h"
|
||||
#include "Core/EComponentDeleted.h"
|
||||
#include "Core/EAmmoPickup.h"
|
||||
#include "Core/EPlayerDeath.h"
|
||||
#include "Network/EKillDeath.h"
|
||||
|
||||
class Server : public Network
|
||||
{
|
||||
@@ -77,7 +79,8 @@ private:
|
||||
void parseOnPlayerDamage(Packet& packet);
|
||||
void identifyPacketLoss();
|
||||
void kick(PlayerID player);
|
||||
PlayerID GetPlayerIDFromEndpoint();
|
||||
PlayerID getPlayerIDFromEndpoint();
|
||||
PlayerID getPlayerIDFromEntityID(EntityID entityID);
|
||||
void parsePlayerTransform(Packet& packet);
|
||||
void parseOnInputCommand(Packet& packet);
|
||||
void parseClientPing();
|
||||
@@ -103,6 +106,8 @@ private:
|
||||
bool OnPlayerDamage(const Events::PlayerDamage& e);
|
||||
EventRelay<Server, Events::AmmoPickup> m_EAmmoPickup;
|
||||
bool OnAmmoPickup(const Events::AmmoPickup& e);
|
||||
EventRelay<Server, Events::PlayerDeath> m_EPlayerDeath;
|
||||
bool OnPlayerDeath(const Events::PlayerDeath& e);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -526,10 +527,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 +578,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 +597,7 @@ void Server::parseOnInputCommand(Packet& packet)
|
||||
|
||||
void Server::parsePlayerTransform(Packet& packet)
|
||||
{
|
||||
PlayerID playerID = GetPlayerIDFromEndpoint();
|
||||
PlayerID playerID = getPlayerIDFromEndpoint();
|
||||
if (playerID == -1) {
|
||||
return;
|
||||
}
|
||||
@@ -635,7 +646,7 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
|
||||
|| childEntity.HasComponent("AmmoPickup");
|
||||
}
|
||||
|
||||
PlayerID Server::GetPlayerIDFromEndpoint()
|
||||
PlayerID Server::getPlayerIDFromEndpoint()
|
||||
{
|
||||
// check both tcp and udp connection
|
||||
for (auto& kv : m_ConnectedPlayers) {
|
||||
@@ -647,4 +658,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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user