mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-06 07:18:42 +00:00
Implement skill contributor tracking to fix multiple items with same skill issue
Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
@@ -1172,8 +1172,14 @@ void InventoryComponent::AddItemSkills(const LOT lot) {
|
||||
|
||||
if (slot == BehaviorSlot::Invalid) return;
|
||||
|
||||
const auto index = m_Skills.find(slot);
|
||||
const auto skill = FindSkill(lot);
|
||||
if (skill == 0) return; // No skill to add
|
||||
|
||||
// Add this item to the contributors for this slot
|
||||
m_SkillContributors[slot].insert(lot);
|
||||
|
||||
// Set the skill for this slot (this will overwrite if there's already a skill,
|
||||
// but that's fine since multiple items might provide the same skill)
|
||||
SetSkill(slot, skill);
|
||||
}
|
||||
|
||||
@@ -1202,19 +1208,33 @@ void InventoryComponent::RemoveItemSkills(const LOT lot) {
|
||||
const auto slot = FindBehaviorSlot(info.equipLocation, static_cast<eItemType>(info.itemType));
|
||||
if (slot == BehaviorSlot::Invalid) return;
|
||||
|
||||
const auto index = m_Skills.find(slot);
|
||||
if (index == m_Skills.end()) return;
|
||||
// Find the contributors for this slot
|
||||
auto contributorsIter = m_SkillContributors.find(slot);
|
||||
if (contributorsIter == m_SkillContributors.end()) return;
|
||||
|
||||
const auto old = index->second;
|
||||
// Remove this item from the contributors
|
||||
contributorsIter->second.erase(lot);
|
||||
|
||||
GameMessages::SendRemoveSkill(m_Parent, old);
|
||||
|
||||
m_Skills.erase(slot);
|
||||
|
||||
if (slot == BehaviorSlot::Primary) {
|
||||
m_Skills.insert_or_assign(BehaviorSlot::Primary, 1);
|
||||
GameMessages::SendAddSkill(m_Parent, 1, BehaviorSlot::Primary);
|
||||
// Only remove the skill if there are no more contributors
|
||||
if (contributorsIter->second.empty()) {
|
||||
// No more items contributing to this slot, remove the skill
|
||||
const auto skillIter = m_Skills.find(slot);
|
||||
if (skillIter != m_Skills.end()) {
|
||||
const auto oldSkill = skillIter->second;
|
||||
GameMessages::SendRemoveSkill(m_Parent, oldSkill);
|
||||
m_Skills.erase(slot);
|
||||
}
|
||||
|
||||
// Clean up the empty contributors set
|
||||
m_SkillContributors.erase(contributorsIter);
|
||||
|
||||
// Restore default skill for Primary slot if needed
|
||||
if (slot == BehaviorSlot::Primary) {
|
||||
m_Skills.insert_or_assign(BehaviorSlot::Primary, 1);
|
||||
GameMessages::SendAddSkill(m_Parent, 1, BehaviorSlot::Primary);
|
||||
}
|
||||
}
|
||||
// If there are still contributors, keep the skill active
|
||||
}
|
||||
|
||||
void InventoryComponent::TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target) {
|
||||
|
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <set>
|
||||
|
||||
|
||||
#include "BehaviorSlot.h"
|
||||
@@ -426,6 +427,12 @@ private:
|
||||
*/
|
||||
std::map<BehaviorSlot, uint32_t> m_Skills;
|
||||
|
||||
/**
|
||||
* Tracks which items (by LOT) contribute skills to each behavior slot
|
||||
* Used to properly manage skills when multiple items provide the same skill to the same slot
|
||||
*/
|
||||
std::map<BehaviorSlot, std::set<LOT>> m_SkillContributors;
|
||||
|
||||
/**
|
||||
* The pets this entity has, mapped by object ID and pet info
|
||||
*/
|
||||
|
Reference in New Issue
Block a user