From 6743ad3dcdd9563afcf5377bd18568bd85129e82 Mon Sep 17 00:00:00 2001 From: Lucca Faria Ferri Date: Mon, 30 Jan 2023 14:40:58 -0800 Subject: [PATCH] Added onRemoved fixed attribute action --- .../GSSystem/ObjectsSystem/FixedMap.cs | 25 ++++++++++++++++--- .../Implementations/HeroSkills/Necromancer.cs | 5 +++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/FixedMap.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/FixedMap.cs index b962abb..a924774 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/FixedMap.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/FixedMap.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using DiIiS_NA.Core.Logging; +using DiIiS_NA.GameServer.MessageSystem; namespace DiIiS_NA.GameServer.GSSystem.ObjectsSystem { @@ -12,24 +13,42 @@ namespace DiIiS_NA.GameServer.GSSystem.ObjectsSystem Resourceful, AttackSpeed } - + public class FixedMap { private static readonly Logger _logger = LogManager.CreateLogger(nameof(FixedMap)); private readonly Dictionary> _attributeMap = new(); + private readonly Dictionary _removedAttributeMap = new(); - public void Add(FixedAttribute name, Action action) + public void Add(FixedAttribute name, Action action, + Action removedAction = null) { + _attributeMap.Add(name, action); + if (removedAction != null) + { + _removedAttributeMap.Add(name, removedAction); + } + if (Contains(name)) { _attributeMap[name] += action; _logger.Warn($"Fixed attribute {name} already exists. Action will be added."); return; } + _attributeMap.Add(name, action); } - public void Remove(FixedAttribute name) => _attributeMap.Remove(name); + public void Remove(FixedAttribute name) + { + _attributeMap.Remove(name); + if (_removedAttributeMap.ContainsKey(name)) + { + _removedAttributeMap[name](); + _removedAttributeMap.Remove(name); + } + } + public void Clear() => _attributeMap.Clear(); public bool Contains(FixedAttribute name) => _attributeMap.ContainsKey(name); public void Apply(GameAttributeMap map) diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Implementations/HeroSkills/Necromancer.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Implementations/HeroSkills/Necromancer.cs index 43d71c9..6a27a12 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Implementations/HeroSkills/Necromancer.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Implementations/HeroSkills/Necromancer.cs @@ -2051,7 +2051,9 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations if (!skeleton.Attributes.FixedMap.Contains(FixedAttribute.AttackSpeed)) { var originalAttackSpeed = skeleton.Attributes[GameAttribute.Attacks_Per_Second]; - skeleton.Attributes.FixedMap.Add(FixedAttribute.AttackSpeed, attr => attr[GameAttribute.Attacks_Per_Second] = originalAttackSpeed * 1.25f); + skeleton.Attributes.FixedMap.Add(FixedAttribute.AttackSpeed, + attr => attr[GameAttribute.Attacks_Per_Second] = originalAttackSpeed * 1.25f, + () => skeleton.Attributes[GameAttribute.Attacks_Per_Second] = originalAttackSpeed); skeleton.Attributes.BroadcastChangedIfRevealed(); } } @@ -2067,6 +2069,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations { Target = Target }; + attack.AddWeaponDamage(greaterDamage ? 2.15f : 1.0f, damageType); attack.OnHit = hit => {