2023-02-16 17:30:33 +00:00
|
|
|
#include "Action.h"
|
2024-01-03 13:34:38 +00:00
|
|
|
#include "Amf3.h"
|
2023-02-16 17:30:33 +00:00
|
|
|
|
|
|
|
Action::Action() {
|
|
|
|
type = "";
|
|
|
|
valueParameterName = "";
|
|
|
|
valueParameterString = "";
|
|
|
|
valueParameterDouble = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Action::Action(AMFArrayValue* arguments) {
|
|
|
|
type = "";
|
|
|
|
valueParameterName = "";
|
|
|
|
valueParameterString = "";
|
|
|
|
valueParameterDouble = 0.0;
|
2024-01-03 13:34:38 +00:00
|
|
|
for (auto& [paramName, paramValue] : arguments->GetAssociative()) {
|
|
|
|
if (paramName == "Type") {
|
|
|
|
if (paramValue->GetValueType() != eAmf::String) continue;
|
|
|
|
type = static_cast<AMFStringValue*>(paramValue)->GetValue();
|
2023-02-16 17:30:33 +00:00
|
|
|
} else {
|
2024-01-03 13:34:38 +00:00
|
|
|
valueParameterName = paramName;
|
2023-02-16 17:30:33 +00:00
|
|
|
// Message is the only known string parameter
|
|
|
|
if (valueParameterName == "Message") {
|
2024-01-03 13:34:38 +00:00
|
|
|
if (paramValue->GetValueType() != eAmf::String) continue;
|
|
|
|
valueParameterString = static_cast<AMFStringValue*>(paramValue)->GetValue();
|
2023-02-16 17:30:33 +00:00
|
|
|
} else {
|
2024-01-03 13:34:38 +00:00
|
|
|
if (paramValue->GetValueType() != eAmf::Double) continue;
|
|
|
|
valueParameterDouble = static_cast<AMFDoubleValue*>(paramValue)->GetValue();
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-03 13:34:38 +00:00
|
|
|
|
|
|
|
void Action::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
|
|
|
|
auto* actionArgs = args.PushArray();
|
|
|
|
actionArgs->Insert("Type", type);
|
|
|
|
|
|
|
|
auto valueParameterName = GetValueParameterName();
|
|
|
|
if (valueParameterName.empty()) return;
|
|
|
|
|
|
|
|
if (valueParameterName == "Message") {
|
|
|
|
actionArgs->Insert(valueParameterName, valueParameterString);
|
|
|
|
} else {
|
|
|
|
actionArgs->Insert(valueParameterName, valueParameterDouble);
|
|
|
|
}
|
|
|
|
}
|