2023-02-16 17:30:33 +00:00
|
|
|
#include "BehaviorMessageBase.h"
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
#include "Amf3.h"
|
2023-02-16 17:30:33 +00:00
|
|
|
#include "BehaviorStates.h"
|
|
|
|
#include "dCommonVars.h"
|
|
|
|
|
|
|
|
BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) {
|
|
|
|
behaviorId = 0;
|
|
|
|
behaviorId = GetBehaviorIdFromArgument(arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) {
|
|
|
|
const auto* key = "BehaviorID";
|
2023-05-13 22:22:00 +00:00
|
|
|
auto* behaviorIDValue = arguments->Get<std::string>(key);
|
2023-02-16 17:30:33 +00:00
|
|
|
int32_t behaviorID = -1;
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
|
|
|
|
behaviorID = std::stoul(behaviorIDValue->GetValue());
|
|
|
|
} else if (arguments->Get(key)->GetValueType() != eAmf::Undefined) {
|
2023-02-16 17:30:33 +00:00
|
|
|
throw std::invalid_argument("Unable to find behavior ID");
|
|
|
|
}
|
|
|
|
|
|
|
|
return behaviorID;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) {
|
2023-05-13 22:22:00 +00:00
|
|
|
auto* actionIndexAmf = arguments->Get<double>(keyName);
|
2023-02-16 17:30:33 +00:00
|
|
|
if (!actionIndexAmf) {
|
|
|
|
throw std::invalid_argument("Unable to find actionIndex");
|
|
|
|
}
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
return static_cast<uint32_t>(actionIndexAmf->GetValue());
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|