Added collision and weapon events and send them to client
This commit is contained in:
parent
8438b7dfbb
commit
13d6a062fc
|
@ -750,6 +750,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
|
|||
case GameLogic::PlayerAction::PlayerAction_Idle:
|
||||
player->playAnimation(L"idle", true);
|
||||
break;
|
||||
|
||||
case GameLogic::WeaponAction::WeaponAction_PrimaryShoot:
|
||||
break;
|
||||
case GameLogic::WeaponAction::WeaponAction_SecondaryShoot:
|
||||
break;
|
||||
case GameLogic::WeaponAction::WeaponAction_Reload:
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -757,6 +766,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
|
|||
}
|
||||
}
|
||||
return GameClientState::event_processed;
|
||||
case protocol_Gameplay_ObjectCollision:
|
||||
{
|
||||
Protocol_ObjectCollision decoded(data);
|
||||
C_Object *object;
|
||||
object = (this->privData->players)[decoded.objectID];
|
||||
if( !object)
|
||||
{
|
||||
// if it is not a player
|
||||
object = (*this->privData->dynamicObjects)[decoded.objectID];
|
||||
}
|
||||
if( object )
|
||||
{
|
||||
switch (decoded.collisionID)
|
||||
{
|
||||
case GameLogic::CollisionEvent::CollisionEvent_BasicCollision:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return GameClientState::event_processed;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "AttatchmentMassDriver.h"
|
||||
#include "PhysicsAPI.h"
|
||||
#include "GameLogicStates.h"
|
||||
|
||||
#include "Game.h"
|
||||
using namespace GameLogic;
|
||||
|
||||
|
||||
|
@ -48,6 +48,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
|
|||
{
|
||||
currentEnergy -= 90.0f;
|
||||
ForcePush(usage,dt);
|
||||
// add CD
|
||||
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -55,7 +57,9 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
|
|||
if(currentEnergy >= 1.0f)
|
||||
{
|
||||
currentEnergy -= 1.0f;
|
||||
ForcePull(usage,dt);
|
||||
ForcePull(usage,dt);
|
||||
// add CD
|
||||
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -64,6 +68,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
|
|||
{
|
||||
currentEnergy -= 90.0f;
|
||||
ForceZip(usage,dt);
|
||||
// add CD
|
||||
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@ using namespace GameLogic;
|
|||
//player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
|
||||
break;
|
||||
}
|
||||
|
||||
// send collision event message
|
||||
((Game*)&Game::Instance())->onCollisionEventFnc(player, CollisionEvent::CollisionEvent_BasicCollision);
|
||||
//return Physics::ICustomBody::SubscriptMessage_none;
|
||||
}
|
||||
|
||||
|
|
|
@ -188,6 +188,10 @@ void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer)
|
|||
{
|
||||
this->onPickupEventFnc = functionPointer;
|
||||
}
|
||||
void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer)
|
||||
{
|
||||
this->onCollisionEventFnc = functionPointer;
|
||||
}
|
||||
bool Game::Initiate()
|
||||
{
|
||||
API::Instance().Init();
|
||||
|
|
|
@ -87,6 +87,7 @@ namespace GameLogic
|
|||
void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override;
|
||||
void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override;
|
||||
void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override;
|
||||
void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override;
|
||||
bool Initiate() override;
|
||||
|
||||
float GetFrameTime() const;
|
||||
|
@ -108,6 +109,7 @@ namespace GameLogic
|
|||
GameEvent::ObjectDeadFunction onDeadFnc;
|
||||
GameEvent::AnimationEventFunction onActionEventFnc;
|
||||
GameEvent::PickupEventFunction onPickupEventFnc;
|
||||
GameEvent::CollisionEventFunction onCollisionEventFnc;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace GameLogic
|
|||
typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer
|
||||
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);
|
||||
//etc...
|
||||
};
|
||||
|
||||
|
@ -188,7 +189,7 @@ namespace GameLogic
|
|||
virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0;
|
||||
virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0;
|
||||
virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0;
|
||||
|
||||
virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ using namespace Oyster::Math;
|
|||
|
||||
Level::Level(void)
|
||||
{
|
||||
srand (time(NULL));
|
||||
objID = 100;
|
||||
}
|
||||
Level::~Level(void)
|
||||
|
@ -405,6 +406,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID)
|
|||
}
|
||||
void Level::AddPlayerToGame(Player *player)
|
||||
{
|
||||
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
|
||||
{
|
||||
if (!this->playerObjects[i])
|
||||
{
|
||||
this->playerObjects[i] = player;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if no free space, allocate a new spot
|
||||
this->playerObjects.Push(player);
|
||||
}
|
||||
void Level::RemovePlayerFromGame(Player *player)
|
||||
|
@ -413,7 +423,7 @@ void Level::RemovePlayerFromGame(Player *player)
|
|||
{
|
||||
if ((Player*)this->playerObjects[i] == player)
|
||||
{
|
||||
//this->playerObjects[i].
|
||||
this->playerObjects[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -426,7 +436,8 @@ void Level::RespawnPlayer(Player *player)
|
|||
{
|
||||
//this->teamManager.RespawnPlayerRandom(player);
|
||||
|
||||
Float3 spawnPoint = spawnPoints[0];
|
||||
int i = rand() % spawnPoints.Size();
|
||||
Float3 spawnPoint = spawnPoints[i];
|
||||
player->Respawn(spawnPoint);
|
||||
}
|
||||
void Level::Update(float deltaTime)
|
||||
|
@ -434,19 +445,22 @@ void Level::Update(float deltaTime)
|
|||
// update lvl-things
|
||||
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
|
||||
{
|
||||
if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
|
||||
if(this->playerObjects[i])
|
||||
{
|
||||
// true when timer reaches 0
|
||||
if(this->playerObjects[i]->deathTimerTick(deltaTime))
|
||||
RespawnPlayer(this->playerObjects[i]);
|
||||
}
|
||||
else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED)
|
||||
{
|
||||
this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
|
||||
// HACK to avoid crasch. affected by tag is NULL
|
||||
Player* killer = this->playerObjects[i]->getAffectingPlayer();
|
||||
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID
|
||||
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID
|
||||
if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
|
||||
{
|
||||
// true when timer reaches 0
|
||||
if(this->playerObjects[i]->deathTimerTick(deltaTime))
|
||||
RespawnPlayer(this->playerObjects[i]);
|
||||
}
|
||||
else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED)
|
||||
{
|
||||
this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
|
||||
// HACK to avoid crasch. affected by tag is NULL
|
||||
Player* killer = this->playerObjects[i]->getAffectingPlayer();
|
||||
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID
|
||||
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -969,7 +969,7 @@ namespace GameLogic
|
|||
Oyster::Network::CustomNetProtocol protocol;
|
||||
};
|
||||
}
|
||||
//#define protocol_Gameplay_ObjectAction 369
|
||||
//#define protocol_Gameplay_ObjectAction 369
|
||||
struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject
|
||||
{
|
||||
short objectID;
|
||||
|
@ -1010,4 +1010,46 @@ namespace GameLogic
|
|||
private:
|
||||
Oyster::Network::CustomNetProtocol protocol;
|
||||
};
|
||||
//#define protocol_Gameplay_ObjectCollision 370
|
||||
struct Protocol_ObjectCollision :public Oyster::Network::CustomProtocolObject
|
||||
{
|
||||
short objectID;
|
||||
int collisionID;
|
||||
// TODO: maybe position, impact, and velocity
|
||||
|
||||
Protocol_ObjectCollision()
|
||||
{
|
||||
this->protocol[0].value = protocol_Gameplay_ObjectCollision;
|
||||
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
|
||||
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
|
||||
|
||||
this->objectID = -1;
|
||||
this->collisionID = -1;
|
||||
}
|
||||
Protocol_ObjectCollision(Oyster::Network::CustomNetProtocol& p)
|
||||
{
|
||||
this->objectID = p[1].value.netShort;
|
||||
this->collisionID = p[2].value.netInt;
|
||||
}
|
||||
Protocol_ObjectCollision( int id, int collisionID)
|
||||
{
|
||||
this->protocol[0].value = protocol_Gameplay_ObjectCollision;
|
||||
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
|
||||
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
|
||||
|
||||
this->objectID = id;
|
||||
this->collisionID = collisionID;
|
||||
}
|
||||
Oyster::Network::CustomNetProtocol GetProtocol() override
|
||||
{
|
||||
this->protocol[1].value = objectID;
|
||||
this->protocol[2].value = collisionID;
|
||||
return protocol;
|
||||
}
|
||||
|
||||
private:
|
||||
Oyster::Network::CustomNetProtocol protocol;
|
||||
};
|
||||
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H
|
|
@ -72,6 +72,7 @@
|
|||
#define protocol_Gameplay_ObjectDie 367
|
||||
#define protocol_Gameplay_ObjectDisconnectPlayer 368
|
||||
#define protocol_Gameplay_ObjectAction 369
|
||||
#define protocol_Gameplay_ObjectCollision 370
|
||||
#define protocol_GameplayMAX 399
|
||||
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ namespace DanBias
|
|||
static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds );
|
||||
static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID );
|
||||
static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID );
|
||||
static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID );
|
||||
//Private member variables
|
||||
private:
|
||||
Utility::DynamicMemory::DynamicArray<gClient> gClients;
|
||||
|
|
|
@ -176,6 +176,11 @@ using namespace DanBias;
|
|||
// send action protocol
|
||||
GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol());
|
||||
}
|
||||
void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID )
|
||||
{
|
||||
// send action protocol
|
||||
GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol());
|
||||
}
|
||||
//*****************************************************//
|
||||
//****************** Protocol methods *****************//
|
||||
//******************************************************************************************************************//
|
||||
|
|
|
@ -114,6 +114,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart)
|
|||
this->gameInstance.SetDeadSubscription(GameSession::ObjectDead);
|
||||
this->gameInstance.SetActionSubscription(GameSession::ActionEvent);
|
||||
this->gameInstance.SetPickupSubscription(GameSession::PickupEvent);
|
||||
this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent);
|
||||
this->gameInstance.SetFPS(60);
|
||||
|
||||
this->description.clients.Clear();
|
||||
|
|
|
@ -95,16 +95,26 @@ namespace GameLogic
|
|||
|
||||
enum PlayerAction
|
||||
{
|
||||
PlayerAction_Jump,
|
||||
PlayerAction_Walk,
|
||||
PlayerAction_Idle,
|
||||
PlayerAction_Jump = 0,
|
||||
PlayerAction_Walk = 1,
|
||||
PlayerAction_Idle = 2,
|
||||
};
|
||||
// continue ID counting from playerAction
|
||||
enum WeaponAction
|
||||
{
|
||||
WeaponAtcion_PrimaryShoot,
|
||||
WeaponAction_SecondaryShoot
|
||||
WeaponAction_PrimaryShoot = 3,
|
||||
WeaponAction_SecondaryShoot = 4,
|
||||
WeaponAction_UtilityActivate = 5,
|
||||
WeaponAction_Reload = 6,
|
||||
WeaponAction_EnergyDepleted = 7,
|
||||
|
||||
};
|
||||
|
||||
// TODO: add more collision Events
|
||||
enum CollisionEvent
|
||||
{
|
||||
CollisionEvent_BasicCollision,
|
||||
};
|
||||
enum PickupType
|
||||
{
|
||||
PickupType_Health,
|
||||
|
|
Loading…
Reference in New Issue