DarkflameServer/dGame/dBehaviors/MovementSwitchBehavior.cpp

65 lines
2.3 KiB
C++
Raw Normal View History

2022-08-06 03:01:59 +00:00
#include "MovementSwitchBehavior.h"
#include "BehaviorBranchContext.h"
#include "Game.h"
#include "dLogger.h"
2022-07-28 13:39:57 +00:00
void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
if (this->m_groundAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_jumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_fallingAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_doubleJumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_airAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
2022-07-28 13:39:57 +00:00
this->m_jetpackAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
return;
}
uint32_t movementType{};
if (!bitStream->Read(movementType)) {
Game::logger->Log("MovementSwitchBehavior", "Unable to read movementType from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
return;
};
2022-12-21 10:00:46 +00:00
Game::logger->LogDebug("MovementSwitchBehavior", "Movement type %i", movementType);
2022-07-28 13:39:57 +00:00
switch (movementType) {
case 1:
2022-12-21 10:00:46 +00:00
case 3:
this->m_groundAction->Handle(context, bitStream, branch);
break;
case 2:
this->m_jumpAction->Handle(context, bitStream, branch);
break;
case 4:
this->m_doubleJumpAction->Handle(context, bitStream, branch);
break;
case 5:
2022-12-21 10:00:46 +00:00
this->m_fallingAction->Handle(context, bitStream, branch);
break;
case 6:
this->m_jetpackAction->Handle(context, bitStream, branch);
break;
default:
2022-12-21 10:00:46 +00:00
this->m_groundAction->Handle(context, bitStream, branch);
}
}
2022-07-28 13:39:57 +00:00
void MovementSwitchBehavior::Load() {
2022-12-21 10:00:46 +00:00
this->m_groundAction = GetAction("ground_action");
this->m_airAction = GetAction("air_action");
2022-12-21 10:00:46 +00:00
if (!this->m_airAction) this->m_airAction = this->m_groundAction;
this->m_doubleJumpAction = GetAction("double_jump_action");
2022-12-21 10:00:46 +00:00
if (!this->m_doubleJumpAction) this->m_airAction = this->m_groundAction;
this->m_fallingAction = GetAction("falling_action");
2022-12-21 10:00:46 +00:00
if (!this->m_fallingAction) this->m_airAction = this->m_groundAction;
this->m_jetpackAction = GetAction("jetpack_action");
2022-12-21 10:00:46 +00:00
if (!this->m_jetpackAction) this->m_airAction = this->m_groundAction;
this->m_jumpAction = GetAction("jump_action");
2022-12-21 10:00:46 +00:00
if (!this->m_jumpAction) this->m_airAction = this->m_groundAction;
this->m_movingAction = GetAction("moving_action");
if (!this->m_movingAction) this->m_airAction = this->m_groundAction;
}