2021-12-05 17:54:36 +00:00
|
|
|
#include "MovementSwitchBehavior.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void MovementSwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) {
|
2022-12-16 21:23:02 +00:00
|
|
|
uint32_t movementType{};
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(movementType)) {
|
2024-03-26 11:35:35 +00:00
|
|
|
if (this->m_groundAction->m_templateId == BehaviorTemplate::EMPTY &&
|
|
|
|
this->m_jumpAction->m_templateId == BehaviorTemplate::EMPTY &&
|
|
|
|
this->m_fallingAction->m_templateId == BehaviorTemplate::EMPTY &&
|
|
|
|
this->m_doubleJumpAction->m_templateId == BehaviorTemplate::EMPTY &&
|
|
|
|
this->m_airAction->m_templateId == BehaviorTemplate::EMPTY &&
|
|
|
|
this->m_jetpackAction->m_templateId == BehaviorTemplate::EMPTY &&
|
|
|
|
this->m_movingAction->m_templateId == BehaviorTemplate::EMPTY) {
|
2022-12-28 22:03:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-02-27 07:25:44 +00:00
|
|
|
LOG("Unable to read movementType from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
switch (movementType) {
|
|
|
|
case 1:
|
|
|
|
this->m_groundAction->Handle(context, bitStream, branch);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this->m_jumpAction->Handle(context, bitStream, branch);
|
|
|
|
break;
|
|
|
|
case 3:
|
2022-12-28 22:03:07 +00:00
|
|
|
this->m_airAction->Handle(context, bitStream, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
this->m_doubleJumpAction->Handle(context, bitStream, branch);
|
|
|
|
break;
|
|
|
|
case 5:
|
2022-12-28 22:03:07 +00:00
|
|
|
this->m_fallingAction->Handle(context, bitStream, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
this->m_jetpackAction->Handle(context, bitStream, branch);
|
|
|
|
break;
|
|
|
|
default:
|
2022-12-28 22:03:07 +00:00
|
|
|
this->m_groundAction->Handle(context, bitStream, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-28 22:03:07 +00:00
|
|
|
Behavior* MovementSwitchBehavior::LoadMovementType(std::string movementType) {
|
|
|
|
float actionValue = GetFloat(movementType, -1.0f);
|
|
|
|
auto loadedBehavior = GetAction(actionValue != -1.0f ? actionValue : 0.0f);
|
2024-03-26 11:35:35 +00:00
|
|
|
if (actionValue == -1.0f && loadedBehavior->m_templateId == BehaviorTemplate::EMPTY) {
|
2022-12-28 22:03:07 +00:00
|
|
|
loadedBehavior = this->m_groundAction;
|
|
|
|
}
|
|
|
|
return loadedBehavior;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-28 22:03:07 +00:00
|
|
|
void MovementSwitchBehavior::Load() {
|
|
|
|
float groundActionValue = GetFloat("ground_action", -1.0f);
|
|
|
|
this->m_groundAction = GetAction(groundActionValue != -1.0f ? groundActionValue : 0.0f);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-28 22:03:07 +00:00
|
|
|
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");
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|