diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7a26183a..9d47762e 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -707,7 +707,16 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectWeaponEnergy: + { + Protocol_ObjectWeaponEnergy decoded(data); + if( this->privData->myId == decoded.objectID ) + { + // show my energy + float energy = decoded.energy; + } + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectRespawn: { Protocol_ObjectRespawn decoded(data); diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 6abe81b6..6d060f60 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -13,6 +13,7 @@ AttatchmentMassDriver::AttatchmentMassDriver(void) this->hasObject = false; this->currentEnergy = StandardMaxEnergy; this->maxEnergy = StandardMaxEnergy; + this->energyChange = 0; this->rechargeRate = StandardrechargeRate; this->force = Standardforce; } @@ -22,6 +23,7 @@ AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) this->currentEnergy = StandardMaxEnergy; this->maxEnergy = StandardMaxEnergy; this->rechargeRate = StandardrechargeRate; + this->energyChange = 0; this->force = Standardforce; this->owner = &owner; @@ -120,6 +122,7 @@ void AttatchmentMassDriver::Update(float dt) if(currentEnergy < maxEnergy) { currentEnergy += rechargeRate * 0.5f; //rechargeRate is halfed if you are holding an object + energyChange += rechargeRate * 0.5f; } } @@ -128,12 +131,17 @@ void AttatchmentMassDriver::Update(float dt) if(currentEnergy < maxEnergy) { currentEnergy += rechargeRate; + energyChange += rechargeRate * 0.5f; } } if(currentEnergy > maxEnergy) currentEnergy = maxEnergy; - + if(energyChange > 10) + { + ((Game*)&Game::Instance())->onEnergyUpdateFnc( this->owner, currentEnergy); + energyChange = 0; + } } /******************************************************** diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index d37b7dd4..94251da1 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -63,7 +63,7 @@ namespace GameLogic Oyster::Math::Float maxEnergy; Oyster::Math::Float currentEnergy; - + Oyster::Math::Float energyChange; // variable used to limit energy update messages Oyster::Math::Float rechargeRate; struct Aim diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 87216b3b..33a92292 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -192,6 +192,10 @@ void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPo { this->onCollisionEventFnc = functionPointer; } +void Game::SetWeaponEnergySubscription(GameEvent::WeaponEnergyFunction functionPointer) +{ + this->onEnergyUpdateFnc = functionPointer; +} bool Game::Initiate() { API::Instance().Init(); diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index ff2ce998..23f85eb8 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -90,6 +90,7 @@ namespace GameLogic void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override; + void SetWeaponEnergySubscription(GameEvent::WeaponEnergyFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; @@ -112,6 +113,7 @@ namespace GameLogic GameEvent::AnimationEventFunction onActionEventFnc; GameEvent::PickupEventFunction onPickupEventFnc; GameEvent::CollisionEventFunction onCollisionEventFnc; + GameEvent::WeaponEnergyFunction onEnergyUpdateFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index d4c7fe36..db4eb0ed 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -34,6 +34,7 @@ namespace GameLogic typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID); + typedef void(*WeaponEnergyFunction)(IObjectData*object, float energy); //etc... }; @@ -192,6 +193,7 @@ namespace GameLogic virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0; + virtual void SetWeaponEnergySubscription(GameEvent::WeaponEnergyFunction functionPointer) = 0; }; } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 628fb396..397f9ecb 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -810,28 +810,35 @@ namespace GameLogic //#define protocol_Gameplay_ObjectWeaponEnergy 365 struct Protocol_ObjectWeaponEnergy :public Oyster::Network::CustomProtocolObject { + int objectID; float energy; Protocol_ObjectWeaponEnergy() { this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].value.netShort = protocol_Gameplay_ObjectWeaponEnergy; - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->objectID = -1; this->energy = 0.0f; } - Protocol_ObjectWeaponEnergy(float energy) + Protocol_ObjectWeaponEnergy(int objectID, float energy) { this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].value.netShort = protocol_Gameplay_ObjectWeaponEnergy; - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->objectID = objectID; this->energy = energy; } Protocol_ObjectWeaponEnergy(Oyster::Network::CustomNetProtocol& p) { - this->energy = p[1].value.netFloat; + this->objectID = p[1].value.netInt; + this->energy = p[2].value.netFloat; } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->energy; + this->protocol[1].value = this->objectID; + this->protocol[2].value = this->energy; return protocol; } diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 25e6dc2f..62fd617d 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -106,6 +106,7 @@ namespace DanBias static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID ); + static void EnergyUpdate ( GameLogic::IObjectData* movedObject , float energy ); //Private member variables private: Utility::DynamicMemory::DynamicArray gClients; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index f89fc9f3..7a0c7c16 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -185,6 +185,11 @@ using namespace DanBias; // send action protocol GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol()); } + void GameSession::EnergyUpdate( GameLogic::IObjectData* movedObject , float energy ) + { + // send action protocol + GameSession::gameSession->Send(Protocol_ObjectWeaponEnergy(movedObject->GetID(), energy).GetProtocol()); + } //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index fe27decc..93610480 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -116,6 +116,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart) this->gameInstance.SetActionSubscription(GameSession::ActionEvent); this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent); + this->gameInstance.SetWeaponEnergySubscription(GameSession::EnergyUpdate); this->gameInstance.SetFPS(60); this->description.clients.Clear();