mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 10:44:08 +00:00
change behavior id to LWOOBJID
Convert behavior ID to LWOOBJID length missed header fix sqlite field names sqlite brother
This commit is contained in:
@@ -67,7 +67,7 @@ void ModelComponent::LoadBehaviors() {
|
||||
for (const auto& behavior : behaviors) {
|
||||
if (behavior.empty()) continue;
|
||||
|
||||
const auto behaviorId = GeneralUtils::TryParse<int32_t>(behavior);
|
||||
const auto behaviorId = GeneralUtils::TryParse<LWOOBJID>(behavior);
|
||||
if (!behaviorId.has_value() || behaviorId.value() == 0) continue;
|
||||
|
||||
LOG_DEBUG("Loading behavior %d", behaviorId.value());
|
||||
@@ -78,7 +78,7 @@ void ModelComponent::LoadBehaviors() {
|
||||
|
||||
tinyxml2::XMLDocument behaviorXml;
|
||||
auto res = behaviorXml.Parse(behaviorStr.c_str(), behaviorStr.size());
|
||||
LOG_DEBUG("Behavior %i %d: %s", res, behaviorId.value(), behaviorStr.c_str());
|
||||
LOG_DEBUG("Behavior %llu %d: %s", res, behaviorId.value(), behaviorStr.c_str());
|
||||
|
||||
const auto* const behaviorRoot = behaviorXml.FirstChildElement("Behavior");
|
||||
if (!behaviorRoot) {
|
||||
@@ -116,8 +116,11 @@ void ModelComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialU
|
||||
if (bIsInitialUpdate) outBitStream.Write0(); // We are not writing model editing info
|
||||
}
|
||||
|
||||
void ModelComponent::UpdatePendingBehaviorId(const int32_t newId) {
|
||||
for (auto& behavior : m_Behaviors) if (behavior.GetBehaviorId() == -1) behavior.SetBehaviorId(newId);
|
||||
void ModelComponent::UpdatePendingBehaviorId(const LWOOBJID newId, const LWOOBJID oldId) {
|
||||
for (auto& behavior : m_Behaviors) {
|
||||
if (behavior.GetBehaviorId() != oldId) continue;
|
||||
behavior.SetBehaviorId(newId);
|
||||
}
|
||||
}
|
||||
|
||||
void ModelComponent::SendBehaviorListToClient(AMFArrayValue& args) const {
|
||||
@@ -134,7 +137,7 @@ void ModelComponent::VerifyBehaviors() {
|
||||
for (auto& behavior : m_Behaviors) behavior.VerifyLastEditedState();
|
||||
}
|
||||
|
||||
void ModelComponent::SendBehaviorBlocksToClient(int32_t behaviorToSend, AMFArrayValue& args) const {
|
||||
void ModelComponent::SendBehaviorBlocksToClient(const LWOOBJID behaviorToSend, AMFArrayValue& args) const {
|
||||
args.Insert("BehaviorID", std::to_string(behaviorToSend));
|
||||
args.Insert("objectID", std::to_string(m_Parent->GetObjectID()));
|
||||
for (auto& behavior : m_Behaviors) if (behavior.GetBehaviorId() == behaviorToSend) behavior.SendBehaviorBlocksToClient(args);
|
||||
@@ -165,8 +168,8 @@ void ModelComponent::MoveToInventory(MoveToInventoryMessage& msg) {
|
||||
}
|
||||
}
|
||||
|
||||
std::array<std::pair<int32_t, std::string>, 5> ModelComponent::GetBehaviorsForSave() const {
|
||||
std::array<std::pair<int32_t, std::string>, 5> toReturn{};
|
||||
std::array<std::pair<LWOOBJID, std::string>, 5> ModelComponent::GetBehaviorsForSave() const {
|
||||
std::array<std::pair<LWOOBJID, std::string>, 5> toReturn{};
|
||||
for (auto i = 0; i < m_Behaviors.size(); i++) {
|
||||
const auto& behavior = m_Behaviors.at(i);
|
||||
if (behavior.GetBehaviorId() == -1) continue;
|
||||
|
@@ -97,7 +97,7 @@ public:
|
||||
void MoveToInventory(MoveToInventoryMessage& msg);
|
||||
|
||||
// Updates the pending behavior ID to the new ID.
|
||||
void UpdatePendingBehaviorId(const int32_t newId);
|
||||
void UpdatePendingBehaviorId(const LWOOBJID newId, const LWOOBJID oldId);
|
||||
|
||||
// Sends the behavior list to the client.
|
||||
|
||||
@@ -112,11 +112,11 @@ public:
|
||||
*/
|
||||
void SendBehaviorListToClient(AMFArrayValue& args) const;
|
||||
|
||||
void SendBehaviorBlocksToClient(int32_t behaviorToSend, AMFArrayValue& args) const;
|
||||
void SendBehaviorBlocksToClient(const LWOOBJID behaviorToSend, AMFArrayValue& args) const;
|
||||
|
||||
void VerifyBehaviors();
|
||||
|
||||
std::array<std::pair<int32_t, std::string>, 5> GetBehaviorsForSave() const;
|
||||
std::array<std::pair<LWOOBJID, std::string>, 5> GetBehaviorsForSave() const;
|
||||
|
||||
const std::vector<PropertyBehavior>& GetBehaviors() const { return m_Behaviors; };
|
||||
|
||||
|
@@ -10,5 +10,5 @@ AddActionMessage::AddActionMessage(const AMFArrayValue& arguments)
|
||||
|
||||
m_Action = Action{ *actionValue };
|
||||
|
||||
LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f m_BehaviorId %i", m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_Action.GetType().data(), m_Action.GetValueParameterName().data(), m_Action.GetValueParameterString().data(), m_Action.GetValueParameterDouble(), m_BehaviorId);
|
||||
LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f m_BehaviorId %llu", m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_Action.GetType().data(), m_Action.GetValueParameterName().data(), m_Action.GetValueParameterString().data(), m_Action.GetValueParameterDouble(), m_BehaviorId);
|
||||
}
|
||||
|
@@ -5,5 +5,5 @@ AddMessage::AddMessage(const AMFArrayValue& arguments) : BehaviorMessageBase{ ar
|
||||
if (!behaviorIndexValue) return;
|
||||
|
||||
m_BehaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());
|
||||
LOG_DEBUG("behaviorId %i index %i", m_BehaviorId, m_BehaviorIndex);
|
||||
LOG_DEBUG("behaviorId %llu index %i", m_BehaviorId, m_BehaviorIndex);
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ AddStripMessage::AddStripMessage(const AMFArrayValue& arguments)
|
||||
|
||||
m_ActionsToAdd.emplace_back(*actionValue);
|
||||
|
||||
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().data(), m_ActionsToAdd.back().GetValueParameterName().data(), m_ActionsToAdd.back().GetValueParameterString().data(), m_ActionsToAdd.back().GetValueParameterDouble());
|
||||
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %llu t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().data(), m_ActionsToAdd.back().GetValueParameterName().data(), m_ActionsToAdd.back().GetValueParameterString().data(), m_ActionsToAdd.back().GetValueParameterDouble());
|
||||
}
|
||||
LOG_DEBUG("number of actions %i", m_ActionsToAdd.size());
|
||||
}
|
||||
|
@@ -4,14 +4,14 @@
|
||||
#include "BehaviorStates.h"
|
||||
#include "dCommonVars.h"
|
||||
|
||||
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue& arguments) {
|
||||
LWOOBJID BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue& arguments) {
|
||||
static constexpr std::string_view key = "BehaviorID";
|
||||
const auto* const behaviorIDValue = arguments.Get<std::string>(key);
|
||||
int32_t behaviorId = DefaultBehaviorId;
|
||||
LWOOBJID behaviorId = DefaultBehaviorId;
|
||||
|
||||
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
|
||||
behaviorId =
|
||||
GeneralUtils::TryParse<int32_t>(behaviorIDValue->GetValue()).value_or(behaviorId);
|
||||
GeneralUtils::TryParse<LWOOBJID>(behaviorIDValue->GetValue()).value_or(behaviorId);
|
||||
} else if (arguments.Get(key) && arguments.Get(key)->GetValueType() != eAmf::Undefined) {
|
||||
throw std::invalid_argument("Unable to find behavior ID");
|
||||
}
|
||||
|
@@ -11,19 +11,19 @@ enum class BehaviorState : uint32_t;
|
||||
|
||||
/**
|
||||
* @brief The behaviorID target of this ControlBehaviors message
|
||||
*
|
||||
*
|
||||
*/
|
||||
class BehaviorMessageBase {
|
||||
public:
|
||||
static constexpr int32_t DefaultBehaviorId{ -1 };
|
||||
static constexpr LWOOBJID DefaultBehaviorId{ -1 };
|
||||
BehaviorMessageBase(const AMFArrayValue& arguments) : m_BehaviorId{ GetBehaviorIdFromArgument(arguments) } {}
|
||||
[[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; }
|
||||
[[nodiscard]] LWOOBJID GetBehaviorId() const noexcept { return m_BehaviorId; }
|
||||
[[nodiscard]] bool IsDefaultBehaviorId() const noexcept { return m_BehaviorId == DefaultBehaviorId; }
|
||||
|
||||
protected:
|
||||
[[nodiscard]] int32_t GetBehaviorIdFromArgument(const AMFArrayValue& arguments);
|
||||
[[nodiscard]] LWOOBJID GetBehaviorIdFromArgument(const AMFArrayValue& arguments);
|
||||
[[nodiscard]] int32_t GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string_view keyName = "actionIndex") const;
|
||||
int32_t m_BehaviorId{ DefaultBehaviorId };
|
||||
LWOOBJID m_BehaviorId{ DefaultBehaviorId };
|
||||
};
|
||||
|
||||
#endif //!__BEHAVIORMESSAGEBASE__H__
|
||||
|
@@ -6,6 +6,6 @@ MergeStripsMessage::MergeStripsMessage(const AMFArrayValue& arguments)
|
||||
, m_SourceActionContext{ arguments, "srcStateID", "srcStripID" }
|
||||
, m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" } {
|
||||
|
||||
LOG_DEBUG("srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_DstActionIndex, m_BehaviorId);
|
||||
LOG_DEBUG("srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %llu", m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_DstActionIndex, m_BehaviorId);
|
||||
}
|
||||
|
||||
|
@@ -7,5 +7,5 @@ MigrateActionsMessage::MigrateActionsMessage(const AMFArrayValue& arguments)
|
||||
, m_SourceActionContext{ arguments, "srcStateID", "srcStripID" }
|
||||
, m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" } {
|
||||
|
||||
LOG_DEBUG("srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %i", m_SrcActionIndex, m_DstActionIndex, m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_BehaviorId);
|
||||
LOG_DEBUG("srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %llu", m_SrcActionIndex, m_DstActionIndex, m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_BehaviorId);
|
||||
}
|
||||
|
@@ -5,5 +5,5 @@ MoveToInventoryMessage::MoveToInventoryMessage(const AMFArrayValue& arguments) :
|
||||
if (!behaviorIndexValue) return;
|
||||
|
||||
m_BehaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());
|
||||
LOG_DEBUG("behaviorId %i behaviorIndex %i", m_BehaviorId, m_BehaviorIndex);
|
||||
LOG_DEBUG("behaviorId %llu behaviorIndex %i", m_BehaviorId, m_BehaviorIndex);
|
||||
}
|
||||
|
@@ -6,5 +6,5 @@ RearrangeStripMessage::RearrangeStripMessage(const AMFArrayValue& arguments)
|
||||
, m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") }
|
||||
, m_ActionContext{ arguments } {
|
||||
|
||||
LOG_DEBUG("srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", m_SrcActionIndex, m_DstActionIndex, m_ActionContext.GetStripId(), m_BehaviorId, m_ActionContext.GetStateId());
|
||||
LOG_DEBUG("srcactionIndex %i dstactionIndex %i stripId %i behaviorId %llu stateId %i", m_SrcActionIndex, m_DstActionIndex, m_ActionContext.GetStripId(), m_BehaviorId, m_ActionContext.GetStateId());
|
||||
}
|
||||
|
@@ -5,5 +5,5 @@ RemoveActionsMessage::RemoveActionsMessage(const AMFArrayValue& arguments)
|
||||
, m_ActionIndex{ GetActionIndexFromArgument(arguments) }
|
||||
, m_ActionContext{ arguments } {
|
||||
|
||||
LOG_DEBUG("behaviorId %i actionIndex %i stripId %i stateId %i", m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId());
|
||||
LOG_DEBUG("behaviorId %llu actionIndex %i stripId %i stateId %i", m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId());
|
||||
}
|
||||
|
@@ -4,5 +4,5 @@ RemoveStripMessage::RemoveStripMessage(const AMFArrayValue& arguments)
|
||||
: BehaviorMessageBase{ arguments }
|
||||
, m_ActionContext{ arguments } {
|
||||
|
||||
LOG_DEBUG("stripId %i stateId %i behaviorId %i", m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId);
|
||||
LOG_DEBUG("stripId %i stateId %i behaviorId %llu", m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId);
|
||||
}
|
||||
|
@@ -5,5 +5,5 @@ RenameMessage::RenameMessage(const AMFArrayValue& arguments) : BehaviorMessageBa
|
||||
if (!nameAmf) return;
|
||||
|
||||
m_Name = nameAmf->GetValue();
|
||||
LOG_DEBUG("behaviorId %i n %s", m_BehaviorId, m_Name.c_str());
|
||||
LOG_DEBUG("behaviorId %llu n %s", m_BehaviorId, m_Name.c_str());
|
||||
}
|
||||
|
@@ -7,5 +7,5 @@ SplitStripMessage::SplitStripMessage(const AMFArrayValue& arguments)
|
||||
, m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" }
|
||||
, m_DestinationPosition{ arguments, "dstStripUI" } {
|
||||
|
||||
LOG_DEBUG("behaviorId %i xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", m_BehaviorId, m_DestinationPosition.GetX(), m_DestinationPosition.GetY(), m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_SrcActionIndex);
|
||||
LOG_DEBUG("behaviorId %llu xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", m_BehaviorId, m_DestinationPosition.GetX(), m_DestinationPosition.GetY(), m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_SrcActionIndex);
|
||||
}
|
||||
|
@@ -12,5 +12,5 @@ UpdateActionMessage::UpdateActionMessage(const AMFArrayValue& arguments)
|
||||
|
||||
m_Action = Action{ *actionValue };
|
||||
|
||||
LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", m_Action.GetType().data(), m_Action.GetValueParameterName().data(), m_Action.GetValueParameterString().data(), m_Action.GetValueParameterDouble(), m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId());
|
||||
LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %llu actionIndex %i stripId %i stateId %i", m_Action.GetType().data(), m_Action.GetValueParameterName().data(), m_Action.GetValueParameterString().data(), m_Action.GetValueParameterDouble(), m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId());
|
||||
}
|
||||
|
@@ -5,5 +5,5 @@ UpdateStripUiMessage::UpdateStripUiMessage(const AMFArrayValue& arguments)
|
||||
, m_Position{ arguments }
|
||||
, m_ActionContext{ arguments } {
|
||||
|
||||
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId);
|
||||
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %llu", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId);
|
||||
}
|
||||
|
@@ -30,22 +30,27 @@
|
||||
#include "SplitStripMessage.h"
|
||||
#include "UpdateActionMessage.h"
|
||||
#include "UpdateStripUiMessage.h"
|
||||
#include "eObjectBits.h"
|
||||
|
||||
void ControlBehaviors::RequestUpdatedID(ControlBehaviorContext& context) {
|
||||
BehaviorMessageBase msgBase{ context.arguments };
|
||||
const auto oldBehaviorID = msgBase.GetBehaviorId();
|
||||
ObjectIDManager::RequestPersistentID(
|
||||
[context](uint32_t persistentId) {
|
||||
[context, oldBehaviorID](uint32_t persistentId) {
|
||||
if (!context) {
|
||||
LOG("Model to update behavior ID for is null. Cannot update ID.");
|
||||
return;
|
||||
}
|
||||
LWOOBJID persistentIdBig = persistentId;
|
||||
GeneralUtils::SetBit(persistentIdBig, eObjectBits::CHARACTER);
|
||||
// This updates the behavior ID of the behavior should this be a new behavior
|
||||
AMFArrayValue args;
|
||||
|
||||
args.Insert("behaviorID", std::to_string(persistentId));
|
||||
args.Insert("behaviorID", std::to_string(persistentIdBig));
|
||||
args.Insert("objectID", std::to_string(context.modelComponent->GetParent()->GetObjectID()));
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(context.modelOwner, context.modelOwner->GetSystemAddress(), "UpdateBehaviorID", args);
|
||||
context.modelComponent->UpdatePendingBehaviorId(persistentId);
|
||||
context.modelComponent->UpdatePendingBehaviorId(persistentIdBig, oldBehaviorID);
|
||||
|
||||
ControlBehaviors::Instance().SendBehaviorListToClient(context);
|
||||
});
|
||||
|
@@ -27,8 +27,8 @@ public:
|
||||
void SendBehaviorListToClient(AMFArrayValue& args) const;
|
||||
void SendBehaviorBlocksToClient(AMFArrayValue& args) const;
|
||||
|
||||
[[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; }
|
||||
void SetBehaviorId(int32_t id) noexcept { m_BehaviorId = id; }
|
||||
[[nodiscard]] LWOOBJID GetBehaviorId() const noexcept { return m_BehaviorId; }
|
||||
void SetBehaviorId(LWOOBJID id) noexcept { m_BehaviorId = id; }
|
||||
|
||||
void Serialize(tinyxml2::XMLElement& behavior) const;
|
||||
void Deserialize(const tinyxml2::XMLElement& behavior);
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
|
||||
// The behavior id for this behavior. This is expected to be fully unique, however an id of -1 means this behavior was just created
|
||||
// and needs to be assigned an id.
|
||||
int32_t m_BehaviorId = -1;
|
||||
LWOOBJID m_BehaviorId = -1;
|
||||
};
|
||||
|
||||
#endif //!__PROPERTYBEHAVIOR__H__
|
||||
|
Reference in New Issue
Block a user