From b6fd18baed34dc3f098448d9fba4ea95ceaddf16 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 25 Jan 2016 11:56:40 +0100 Subject: [PATCH] Hacked in serverside effects --- include/Engine/Input/EInputCommand.h | 2 ++ resources/Schema/Entities/Player.xml | 19 +++---------------- src/Engine/Core/EntityWrapper.cpp | 4 ++++ src/Engine/Network/Server.cpp | 1 + src/Game/Systems/WeaponSystem.cpp | 15 +++++++++------ 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/Engine/Input/EInputCommand.h b/include/Engine/Input/EInputCommand.h index 1e150786..d4608b55 100644 --- a/include/Engine/Input/EInputCommand.h +++ b/include/Engine/Input/EInputCommand.h @@ -2,6 +2,7 @@ #define Events_InputCommand_h__ #include "Core/EventBroker.h" +#include "Core/EntityWrapper.h" namespace Events { @@ -10,6 +11,7 @@ struct InputCommand : Event { /** Numerical ID of the player. */ int PlayerID; + EntityWrapper Player; /** The command that was sent. */ std::string Command; /** The value of the command. */ diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 71490508..0e13dc94 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -20,7 +20,7 @@ - + @@ -120,20 +120,7 @@ - - - - - Models/CylinderBullet.mesh - - - - - - - - - + @@ -157,7 +144,7 @@ Hold Pos - + 1 diff --git a/src/Engine/Core/EntityWrapper.cpp b/src/Engine/Core/EntityWrapper.cpp index 70d98aec..ad423573 100644 --- a/src/Engine/Core/EntityWrapper.cpp +++ b/src/Engine/Core/EntityWrapper.cpp @@ -99,6 +99,10 @@ EntityWrapper::operator bool() EntityWrapper EntityWrapper::firstChildByNameRecursive(const std::string& name, EntityID parent) { + if (!this->World->ValidEntity(parent)) { + return EntityWrapper::Invalid; + } + auto itPair = this->World->GetChildren(parent); if (itPair.first == itPair.second) { return EntityWrapper::Invalid; diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index a29f4f02..629984a8 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -269,6 +269,7 @@ void Server::parseOnInputCommand(Packet& packet) Events::InputCommand e; e.Command = packet.ReadString(); e.PlayerID = player; // Set correct player id + e.Player = EntityWrapper(m_World, m_ConnectedPlayers.at(player).EntityID); e.Value = packet.ReadPrimitive(); m_EventBroker->Publish(e); //LOG_INFO("Server::parseOnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID); diff --git a/src/Game/Systems/WeaponSystem.cpp b/src/Game/Systems/WeaponSystem.cpp index 9e813867..f78e092f 100644 --- a/src/Game/Systems/WeaponSystem.cpp +++ b/src/Game/Systems/WeaponSystem.cpp @@ -25,14 +25,13 @@ bool WeaponSystem::OnPlayerSpawned(const Events::PlayerSpawned& e) bool WeaponSystem::OnInputCommand(const Events::InputCommand& e) { - // Only shoot if the player is alive - if (!m_LocalPlayer.Valid()) { - return false; - } - if (e.Command == "PrimaryFire" && e.Value > 0) { Events::Shoot eShoot; - eShoot.Player = m_LocalPlayer; + if (e.PlayerID == -1) { + eShoot.Player = m_LocalPlayer; + } else { + eShoot.Player = e.Player; + } m_EventBroker->Publish(eShoot); } @@ -41,6 +40,10 @@ bool WeaponSystem::OnInputCommand(const Events::InputCommand& e) bool WeaponSystem::OnShoot(Events::Shoot& eShoot) { + if (!eShoot.Player.Valid()) { + return false; + } + // TODO: Weapon firing effects here auto rayRed = ResourceManager::Load("Schema/Entities/RayRed.xml");