From 8798fc90068c19ed4fe5b76a98f567b87f912edf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:22:08 +0100 Subject: [PATCH 1/3] Fixed static id not matching on client/server. --- Code/Game/GameLogic/Level.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 0f0ab632..e22c11b6 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -238,7 +238,11 @@ bool Level::InitiateLevel(std::wstring levelPath) { LevelMetaData* LevelObjData = ((LevelMetaData*)obj); std::string levelName = LevelObjData->levelName; + // LevelObjData->worldSize; + + //LevelMetaData is not an object. + --this->objID; } break; case ObjectType::ObjectType_Static: From 9ec3fc6fa40ead95f7f0cacb30eecdab87ce72cf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:22:43 +0100 Subject: [PATCH 2/3] Does not render non visible models anymore. --- Code/Game/GameClient/GameClientState/C_Object.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index b168b92c..8e84da8e 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -91,7 +91,10 @@ void C_Object::Render() { if( this->model ) { - Oyster::Graphics::API::RenderModel(model); + if(this->model->Visible) + { + Oyster::Graphics::API::RenderModel(model); + } } } void C_Object::Release() From 925f05b3b05d49be201c153f88bc77c4594c129a Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:23:38 +0100 Subject: [PATCH 3/3] Health pickups is now working! --- .../GameClient/GameClientState/GameState.cpp | 18 ++++++++++++--- Code/Game/GameLogic/CollisionManager.cpp | 20 ++++++++++++----- Code/Game/GameLogic/PickupSystem/Pickup.cpp | 1 + .../GameLogic/PickupSystem/PickupHealth.cpp | 4 ++++ Code/Game/GameLogic/Player.cpp | 22 ++++++++++++------- .../Implementation/GameSession_Gameplay.cpp | 2 +- Code/Game/LevelLoader/LevelParser.cpp | 8 +++++++ 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7e8a0ee7..28c65b12 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -142,8 +142,8 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa this->privData->camera.SetPosition( p->getPos() ); Float3 offset = Float3( 0.0f ); // DEBUG position of camera so we can see the player model - offset.y = p->getScale().y * 5.0f; - offset.z = p->getScale().z * -5.0f; + //offset.y = p->getScale().y * 5.0f; + //offset.z = p->getScale().z * -5.0f; // !DEBUG this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); @@ -187,7 +187,7 @@ bool GameState::Render() { if(playerObject->second) { - //if( this->privData->myId != playerObject->second->GetId() ) + if( this->privData->myId != playerObject->second->GetId() ) { playerObject->second->Render(); } @@ -596,6 +596,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) @@ -613,6 +619,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e931f8e..187d592c 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -44,7 +44,6 @@ using namespace GameLogic; realObjB = realObjA; } - switch (realObjB->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_Generic: @@ -368,14 +367,19 @@ using namespace GameLogic; Object* a = (Object*)objA->GetCustomTag(); Object* b = (Object*)objB->GetCustomTag(); - if(!a) + if(!a) return; - if(!b) + if(!b) return; if(b->GetObjectType() == ObjectSpecialType_Player) { - ((Pickup*)a)->OnCollision((Player*)(b)); + //Only update if it is active. And if the player is alive + if(((Pickup*)a)->IsActive() && ((Player*)b)->GetState() != PLAYER_STATE_DEAD && ((Player*)b)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)a)->OnCollision((Player*)(b)); + } + return; } else if(a->GetObjectType() != ObjectSpecialType_Player) { @@ -383,6 +387,10 @@ using namespace GameLogic; //Do nothing. return; } - - ((Pickup*)b)->OnCollision((Player*)a); + + //Only update if it is active. And if the player is alive + if(((Pickup*)b)->IsActive() && ((Player*)a)->GetState() != PLAYER_STATE_DEAD && ((Player*)a)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)b)->OnCollision((Player*)a); + } } \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp index 73a319f8..a7bcaf14 100644 --- a/Code/Game/GameLogic/PickupSystem/Pickup.cpp +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -9,6 +9,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi this->active = true; this->spawnTime = spawnTime; timer.reset(); + this->GetRigidBody()->MoveToLimbo(); } Pickup::~Pickup() diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp index 56cbef1e..5473c44c 100644 --- a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp @@ -1,4 +1,5 @@ #include "PickupHealth.h" +#include "../Game.h" using namespace GameLogic; @@ -14,5 +15,8 @@ PickupHealth::~PickupHealth() void PickupHealth::OnCollision(Player *player) { timer.reset(); + ((Game*)&Game::Instance())->onDisableFnc(this); + + this->active = false; player->DamageLife(-hpValue); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ddacf25b..9a440b2d 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -345,16 +345,22 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - this->playerStats.hp -= damage; - // send hp to client - this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); - - if(this->playerStats.hp <= 0) + if(damage != 0) { - this->playerStats.hp = 0; - this->playerState = PLAYER_STATE_DIED; - } + this->playerStats.hp -= damage; + if(this->playerStats.hp > 100) + this->playerStats.hp = 100; + + // send hp to client + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); + + if(this->playerStats.hp <= 0) + { + this->playerStats.hp = 0; + this->playerState = PLAYER_STATE_DIED; + } + } } void Player::AddAffectedObject(DynamicObject &AffectedObject) diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index fd000a0c..7887e858 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -152,7 +152,7 @@ using namespace DanBias; } void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) { - GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + GameSession::gameSession->Send(Protocol_ObjectEnable(movedObject->GetID()).GetProtocol()); } void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) { diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index 680b0358..f94513b0 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -167,6 +167,14 @@ std::vector> LevelParser::Parse(std::string filen ParseObject(&buffer[counter], &header->healthValue, 4); counter += 4; + + // DEBUG + header->position[1] = 150; + header->spawnTime = 5; + header->boundingVolume.box.mass = 0; + header->typeID = ObjectType_Static; + header->healthValue = 50; + // !DEBUG objects.push_back(header); break;