From 482ff82656cbc959e179eb265700e755a6969861 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 14 Apr 2026 01:04:26 -0700 Subject: [PATCH] fix: adding custom behaviors (#1969) --- dGame/dComponents/ModelComponent.cpp | 8 ++++++-- dGame/dComponents/ModelComponent.h | 2 ++ dGame/dPropertyBehaviors/ControlBehaviors.cpp | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/dGame/dComponents/ModelComponent.cpp b/dGame/dComponents/ModelComponent.cpp index 4559ca72..35fc2532 100644 --- a/dGame/dComponents/ModelComponent.cpp +++ b/dGame/dComponents/ModelComponent.cpp @@ -189,8 +189,7 @@ void ModelComponent::AddBehavior(AddMessage& msg) { // Check if this behavior is able to be found via lot (if so, its a loot behavior). insertedBehavior.SetIsLoot(inventoryComponent->FindItemByLot(msg.GetBehaviorId(), eInventoryType::BEHAVIORS)); } - auto* const missionComponent = playerEntity->GetComponent(); - if (missionComponent) missionComponent->Progress(eMissionTaskType::ADD_BEHAVIOR, 0); + ProgressAddBehaviorMission(*playerEntity); } auto* const simplePhysComponent = m_Parent->GetComponent(); @@ -200,6 +199,11 @@ void ModelComponent::AddBehavior(AddMessage& msg) { } } +void ModelComponent::ProgressAddBehaviorMission(Entity& playerEntity) { + auto* const missionComponent = playerEntity.GetComponent(); + if (missionComponent) missionComponent->Progress(eMissionTaskType::ADD_BEHAVIOR, 0); +} + std::string ModelComponent::SaveBehavior(const PropertyBehavior& behavior) const { tinyxml2::XMLDocument doc; auto* root = doc.NewElement("Behavior"); diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index 97b165cb..240ddc71 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -98,6 +98,8 @@ public: return msg.GetNeedsNewBehaviorID(); }; + void ProgressAddBehaviorMission(Entity& playerEntity); + void AddBehavior(AddMessage& msg); void RemoveBehavior(MoveToInventoryMessage& msg, const bool keepItem); diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.cpp b/dGame/dPropertyBehaviors/ControlBehaviors.cpp index 70a32981..0b180979 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviors.cpp @@ -164,7 +164,12 @@ void ControlBehaviors::ProcessCommand(Entity* const modelEntity, const AMFArrayV LOG("Unknown behavior command (%s)", command.data()); } - if (needsNewBehaviorID) RequestUpdatedID(context); + // If we need a new behaviorID, request it and progress the mission for adding a behavior. + // "add" takes care of this in the ModelComponent directly so we do not need to do it here for that command. + if (needsNewBehaviorID) { + RequestUpdatedID(context); + context.modelComponent->ProgressAddBehaviorMission(*context.modelOwner); + } } ControlBehaviors::ControlBehaviors() {