mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-05 14:58:27 +00:00
feat: add saving behaviors to the inventory (#1822)
* change behavior id to LWOOBJID Convert behavior ID to LWOOBJID length missed header fix sqlite field names sqlite brother * feat: add saving behaviors to the inventory consolidate copied code consolidate copied code Update ModelComponent.cpp remove ability to save loot behaviors
This commit is contained in:
@@ -66,15 +66,18 @@ public:
|
||||
*
|
||||
* @tparam Msg The message type to pass
|
||||
* @param args the arguments of the message to be deserialized
|
||||
*
|
||||
* @return returns true if a new behaviorID is needed.
|
||||
*/
|
||||
template<typename Msg>
|
||||
void HandleControlBehaviorsMsg(const AMFArrayValue& args) {
|
||||
bool HandleControlBehaviorsMsg(const AMFArrayValue& args) {
|
||||
static_assert(std::is_base_of_v<BehaviorMessageBase, Msg>, "Msg must be a BehaviorMessageBase");
|
||||
Msg msg{ args };
|
||||
for (auto&& behavior : m_Behaviors) {
|
||||
if (behavior.GetBehaviorId() == msg.GetBehaviorId()) {
|
||||
behavior.CheckModifyState(msg);
|
||||
behavior.HandleMsg(msg);
|
||||
return;
|
||||
return msg.GetNeedsNewBehaviorID();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,19 +85,21 @@ public:
|
||||
if (m_Behaviors.size() > 5) m_Behaviors.resize(5);
|
||||
|
||||
// Do not allow more than 5 to be added. The client UI will break if you do!
|
||||
if (m_Behaviors.size() == 5) return;
|
||||
if (m_Behaviors.size() == 5) return false;
|
||||
|
||||
auto newBehavior = m_Behaviors.insert(m_Behaviors.begin(), PropertyBehavior());
|
||||
// Generally if we are inserting a new behavior, it is because the client is creating a new behavior.
|
||||
// However if we are testing behaviors the behavior will not exist on the initial pass, so we set the ID here to that of the msg.
|
||||
// This will either set the ID to -1 (no change in the current default) or set the ID to the ID of the behavior we are testing.
|
||||
newBehavior->SetBehaviorId(msg.GetBehaviorId());
|
||||
newBehavior->CheckModifyState(msg);
|
||||
newBehavior->HandleMsg(msg);
|
||||
return msg.GetNeedsNewBehaviorID();
|
||||
};
|
||||
|
||||
void AddBehavior(AddMessage& msg);
|
||||
|
||||
void MoveToInventory(MoveToInventoryMessage& msg);
|
||||
void RemoveBehavior(MoveToInventoryMessage& msg, const bool keepItem);
|
||||
|
||||
// Updates the pending behavior ID to the new ID.
|
||||
void UpdatePendingBehaviorId(const LWOOBJID newId, const LWOOBJID oldId);
|
||||
@@ -141,6 +146,13 @@ public:
|
||||
|
||||
void OnChatMessageReceived(const std::string& sMessage);
|
||||
private:
|
||||
|
||||
// Loads a behavior from the database.
|
||||
void LoadBehavior(const LWOOBJID behaviorID, const size_t index, const bool isIndexed);
|
||||
|
||||
// Writes a behavior to a string so it can be saved.
|
||||
std::string SaveBehavior(const PropertyBehavior& behavior) const;
|
||||
|
||||
// Number of Actions that are awaiting an UnSmash to finish.
|
||||
uint32_t m_NumActiveUnSmash{};
|
||||
|
||||
|
Reference in New Issue
Block a user