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) {
|
2024-02-10 11:05:25 +00:00
|
|
|
this->behaviorId = GetBehaviorIdFromArgument(arguments);
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* const arguments) {
|
|
|
|
const char* const key = "BehaviorID";
|
|
|
|
const auto* const behaviorIDValue = arguments->Get<std::string>(key);
|
2023-02-16 17:30:33 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
|
2024-02-10 11:05:25 +00:00
|
|
|
this->behaviorId =
|
|
|
|
GeneralUtils::TryParse<int32_t>(behaviorIDValue->GetValue()).value_or(this->behaviorId);
|
2024-01-03 13:34:38 +00:00
|
|
|
} else if (arguments->Get(key) && arguments->Get(key)->GetValueType() != eAmf::Undefined) {
|
2023-02-16 17:30:33 +00:00
|
|
|
throw std::invalid_argument("Unable to find behavior ID");
|
|
|
|
}
|
|
|
|
|
2024-02-10 11:05:25 +00:00
|
|
|
return this->behaviorId;
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 19:44:40 +00:00
|
|
|
int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName) const {
|
|
|
|
const auto* const actionIndexAmf = arguments->Get<double>(keyName);
|
|
|
|
if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex");
|
2023-02-16 17:30:33 +00:00
|
|
|
|
2024-01-03 13:34:38 +00:00
|
|
|
return static_cast<int32_t>(actionIndexAmf->GetValue());
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|