mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-23 14:03:34 +00:00
d138b7b878
* Make case consistent * How modular can you go? Holy modular * Add comments * Initialize values
34 lines
1.0 KiB
C++
34 lines
1.0 KiB
C++
#include "BehaviorMessageBase.h"
|
|
|
|
#include "AMFFormat.h"
|
|
#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";
|
|
auto* behaviorIDValue = arguments->FindValue<AMFStringValue>(key);
|
|
int32_t behaviorID = -1;
|
|
|
|
if (behaviorIDValue) {
|
|
behaviorID = std::stoul(behaviorIDValue->GetStringValue());
|
|
} else if (!arguments->FindValue<AMFUndefinedValue>(key)) {
|
|
throw std::invalid_argument("Unable to find behavior ID");
|
|
}
|
|
|
|
return behaviorID;
|
|
}
|
|
|
|
uint32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) {
|
|
auto* actionIndexAmf = arguments->FindValue<AMFDoubleValue>(keyName);
|
|
if (!actionIndexAmf) {
|
|
throw std::invalid_argument("Unable to find actionIndex");
|
|
}
|
|
|
|
return static_cast<uint32_t>(actionIndexAmf->GetDoubleValue());
|
|
}
|