Fix MovementSwitch Behavior (#927)

This commit is contained in:
David Markowitz 2022-12-28 14:03:07 -08:00 committed by GitHub
parent e41ed68447
commit 0e9c0a8917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 25 deletions

View File

@ -4,17 +4,17 @@
#include "dLogger.h" #include "dLogger.h"
void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) { void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
uint32_t movementType{};
if (!bitStream->Read(movementType)) {
if (this->m_groundAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && if (this->m_groundAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_jumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_jumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_fallingAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_fallingAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_doubleJumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_doubleJumpAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_airAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_airAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_jetpackAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) { this->m_jetpackAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY &&
this->m_movingAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
return; return;
} }
uint32_t movementType{};
if (!bitStream->Read(movementType)) {
Game::logger->Log("MovementSwitchBehavior", "Unable to read movementType from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits()); Game::logger->Log("MovementSwitchBehavior", "Unable to read movementType from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
return; return;
}; };
@ -27,33 +27,40 @@ void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream*
this->m_jumpAction->Handle(context, bitStream, branch); this->m_jumpAction->Handle(context, bitStream, branch);
break; break;
case 3: case 3:
this->m_fallingAction->Handle(context, bitStream, branch); this->m_airAction->Handle(context, bitStream, branch);
break; break;
case 4: case 4:
this->m_doubleJumpAction->Handle(context, bitStream, branch); this->m_doubleJumpAction->Handle(context, bitStream, branch);
break; break;
case 5: case 5:
this->m_airAction->Handle(context, bitStream, branch); this->m_fallingAction->Handle(context, bitStream, branch);
break; break;
case 6: case 6:
this->m_jetpackAction->Handle(context, bitStream, branch); this->m_jetpackAction->Handle(context, bitStream, branch);
break; break;
default: default:
Game::logger->Log("MovementSwitchBehavior", "Invalid movement behavior type (%i)!", movementType); this->m_groundAction->Handle(context, bitStream, branch);
break; break;
} }
} }
void MovementSwitchBehavior::Load() { Behavior* MovementSwitchBehavior::LoadMovementType(std::string movementType) {
this->m_airAction = GetAction("air_action"); float actionValue = GetFloat(movementType, -1.0f);
auto loadedBehavior = GetAction(actionValue != -1.0f ? actionValue : 0.0f);
this->m_doubleJumpAction = GetAction("double_jump_action"); if (actionValue == -1.0f && loadedBehavior->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
loadedBehavior = this->m_groundAction;
this->m_fallingAction = GetAction("falling_action"); }
return loadedBehavior;
this->m_groundAction = GetAction("ground_action"); }
this->m_jetpackAction = GetAction("jetpack_action"); void MovementSwitchBehavior::Load() {
float groundActionValue = GetFloat("ground_action", -1.0f);
this->m_jumpAction = GetAction("jump_action"); this->m_groundAction = GetAction(groundActionValue != -1.0f ? groundActionValue : 0.0f);
this->m_airAction = LoadMovementType("air_action");
this->m_doubleJumpAction = LoadMovementType("double_jump_action");
this->m_fallingAction = LoadMovementType("falling_action");
this->m_jetpackAction = LoadMovementType("jetpack_action");
this->m_jumpAction = LoadMovementType("jump_action");
this->m_movingAction = LoadMovementType("moving_action");
} }

View File

@ -3,7 +3,7 @@
class MovementSwitchBehavior final : public Behavior class MovementSwitchBehavior final : public Behavior
{ {
public: private:
/* /*
* Members * Members
*/ */
@ -19,6 +19,17 @@ public:
Behavior* m_jumpAction; Behavior* m_jumpAction;
Behavior* m_movingAction;
/**
* @brief Loads a movement type from the database into a behavior
*
* @param movementType The movement type to lookup in the database
* @param behaviorToLoad The Behavior where the result will be stored
*/
Behavior* LoadMovementType(std::string movementType);
public:
/* /*
* Inherited * Inherited
*/ */