fix: Removes side effect of setting skill mod when changing Owner (#1101)

## Breaking Change!
Setting `mod.Owner` will no longer update a skill mod.
**Please stick to the API and use `mobile.AddSkillMod(mod)` for all situations, including equipping.**


## Fixes
- [X] Fixes memory leak in factions.
- [X] Changes `List<SkillMod>` to `HashSet<SkillMod>`.
- [X] Eliminates skill mods adding/removing twice.
This commit is contained in:
Kamron Batman 2022-06-30 12:07:08 -07:00 • committed by GitHub
parent 414ef8d8d6
commit cb474712f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 80 additions and 109 deletions

View file

@ -1320,7 +1320,7 @@ namespace Server.Factions
var context = new SkillLossContext();
m_SkillLoss[mob] = context;
var mods = context.m_Mods = new List<SkillMod>();
var mods = context.m_Mods = new HashSet<SkillMod>();
for (var i = 0; i < mob.Skills.Length; ++i)
{
@ -1352,11 +1352,12 @@ namespace Server.Factions
var mods = context.m_Mods;
for (var i = 0; i < mods.Count; ++i)
foreach (var mod in mods)
{
mob.RemoveSkillMod(mods[i]);
mod.Remove();
}
context.m_Mods = null;
context._timerToken.Cancel();
return true;
@ -1376,7 +1377,7 @@ namespace Server.Factions
private class SkillLossContext
{
public List<SkillMod> m_Mods;
public HashSet<SkillMod> m_Mods;
public TimerExecutionToken _timerToken;
}
}

View file

@ -955,7 +955,7 @@ namespace Server
public sealed class AosSkillBonuses : BaseAttributes
{
private List<SkillMod> m_Mods;
private HashSet<SkillMod> m_Mods;
public AosSkillBonuses(Item owner) : base(owner)
{
@ -1068,7 +1068,7 @@ namespace Server
continue;
}
m_Mods ??= new List<SkillMod>();
m_Mods ??= new HashSet<SkillMod>();
SkillMod sk = new DefaultSkillMod(skill, true, bonus);
sk.ObeyCap = true;
@ -1084,10 +1084,10 @@ namespace Server
return;
}
for (var i = 0; i < m_Mods.Count; ++i)
foreach (var mod in m_Mods)
{
var m = m_Mods[i].Owner;
m_Mods[i].Remove();
var m = mod.Owner;
mod.Remove();
if (Core.ML)
{