using System.Collections.Generic; using System.Linq; using Cielonos.MainGame.Buffs.Character; namespace Cielonos.MainGame.Characters { public partial class BuffSubmodule : SubmoduleBase { public List buffList; public BuffSubmodule(CharacterBase character) : base(character) { buffList = new List(); } public void Update() { for (var i = 0; i < buffList.Count; i++) { buffList[i].OnBuffUpdate(); } } } public partial class BuffSubmodule { public T GetBuff() where T : CharacterBuffBase { return (T)buffList.Find(x => x.GetType() == typeof(T)); } public T GetBuff(string identification) where T : CharacterBuffBase { return (T)buffList.FindAll(x => x.GetType() == typeof(T)).Find(x => x.identification == identification); } public bool TryGetBuff(out T buff) where T : CharacterBuffBase { buff = GetBuff(); return buff != null; } public bool TryGetBuffs(out List buffs) where T : CharacterBuffBase { List foundBuffs = buffList.FindAll(x => x.GetType() == typeof(T)); buffs = foundBuffs.Cast().ToList(); return buffs.Count > 0; } public bool HasBuff() where T : CharacterBuffBase { return buffList.Exists(x => x.GetType() == typeof(T)); } /*public List Dispel(BuffDispelLevel dispelLevel, CharacterBase dispelSource) { List dispelledBuffs = buffList .Where(buff => buff.dispelThreshold <= dispelLevel && buff.buffType == (owner.IsAlly(dispelSource) ? BuffType.Negative : BuffType.Positive)) .ToList(); dispelledBuffs.For(buff => buff.Remove()); return dispelledBuffs; }*/ } public partial class BuffSubmodule { public void ApplyAttributeChange(string attributeName, ref float numericChange, ref float percentageAccumulationChange, ref float percentageMultiplicationChange) { foreach (CharacterBuffBase buff in buffList.Where(buff => buff.attributeSubmodule != null)) { if (buff.attributeSubmodule.numericChange.TryGetValue(attributeName, out float nChange)) { numericChange += nChange; } if (buff.attributeSubmodule.percentageChangeOfAccumulation.TryGetValue(attributeName, out float paChange)) { percentageAccumulationChange += paChange; } if (buff.attributeSubmodule.percentageChangeOfMultiplication.TryGetValue(attributeName, out float pmChange)) { percentageMultiplicationChange *= pmChange; } } } } }