Added onRemoved fixed attribute action

This commit is contained in:
Lucca Faria Ferri 2023-01-30 14:40:58 -08:00
parent 29df8c3646
commit 6743ad3dcd
2 changed files with 26 additions and 4 deletions

View File

@ -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<FixedAttribute, Action<GameAttributeMap>> _attributeMap = new();
private readonly Dictionary<FixedAttribute, Action> _removedAttributeMap = new();
public void Add(FixedAttribute name, Action<GameAttributeMap> action)
public void Add(FixedAttribute name, Action<GameAttributeMap> 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)

View File

@ -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 =>
{