using System.Collections.Generic; using System.Linq; using Continentis.MainGame.Card; using SLSFramework.General; using UnityEngine; namespace Continentis.MainGame.Character { public partial class CombatBuffSubmodule : SubmoduleBase { public List buffList; public CombatBuffSubmodule(CharacterBase character) : base(character) { buffList = new List(); } } public partial class CombatBuffSubmodule { public T GetBuff() where T : CharacterCombatBuffBase { return (T)buffList.Find(x => x.GetType() == typeof(T)); } public T GetBuff(string identification) where T : CharacterCombatBuffBase { return (T)buffList.FindAll(x => x.GetType() == typeof(T)).Find(x => x.identification == identification); } public bool TryGetBuff(out T buff) where T : CharacterCombatBuffBase { buff = GetBuff(); return buff != null; } public bool TryGetBuffs(out List buffs) where T : CharacterCombatBuffBase { List foundBuffs = buffList.FindAll(x => x.GetType() == typeof(T)); buffs = foundBuffs.Cast().ToList(); return buffs.Count > 0; } public bool HasBuff() where T : CharacterCombatBuffBase { 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 CombatBuffSubmodule { public void RoundStart() { buffList.For(buff => buff.roundCountSubmodule?.Update()); buffList.For(buff => buff.eventSubmodule?.onRoundStart?.Invoke()); } public void RoundEnd() { buffList.For(buff => buff.eventSubmodule?.onRoundEnd?.Invoke()); } public void ActionStart() { if (owner.actionCountThisRound == 0) { buffList.For(buff => buff.roundFirstActionCountSubmodule?.Update()); } buffList.For(buff => buff.actionCountSubmodule?.Update()); buffList.For(buff => buff.eventSubmodule?.onActionStart?.Invoke()); } public void ActionEnd() { buffList.For(buff => buff.eventSubmodule?.onActionEnd?.Invoke()); } } public partial class CombatBuffSubmodule { public void GetCoreAttributeChange(string attributeName, out float numericChange, out float percentageChangeOfAccumulation, out float percentChangeOfMultiplication) { numericChange = buffList.Where(buff => buff.coreAttributeSubmodule != null) .SelectMany(buff => buff.coreAttributeSubmodule.numericChange) .Where(change => change.Key == attributeName) .Sum(change => change.Value); percentageChangeOfAccumulation = buffList.Where(buff => buff.coreAttributeSubmodule != null) .SelectMany(buff => buff.coreAttributeSubmodule.percentageChangeOfAccumulation) .Where(change => change.Key == attributeName) .Sum(change => change.Value); percentChangeOfMultiplication = buffList.Where(buff => buff.coreAttributeSubmodule != null) .SelectMany(buff => buff.coreAttributeSubmodule.percentageChangeOfMultiplication) .Where(change => change.Key == attributeName) .Aggregate, float>(1, (current, change) => current * change.Value); } public void GetGeneralAttributeChange(string attributeName, out float numericChange, out float percentageChangeOfAccumulation, out float percentChangeOfMultiplication) { numericChange = buffList.Where(buff => buff.generalAttributeSubmodule != null) .SelectMany(buff => buff.generalAttributeSubmodule.numericChange) .Where(change => change.Key == attributeName) .Sum(change => change.Value); percentageChangeOfAccumulation = buffList.Where(buff => buff.generalAttributeSubmodule != null) .SelectMany(buff => buff.generalAttributeSubmodule.percentageChangeOfAccumulation) .Where(change => change.Key == attributeName) .Sum(change => change.Value); percentChangeOfMultiplication = buffList.Where(buff => buff.generalAttributeSubmodule != null) .SelectMany(buff => buff.generalAttributeSubmodule.percentageChangeOfMultiplication) .Where(change => change.Key == attributeName) .Aggregate, float>(1, (current, change) => current * change.Value); } } }