Files
Continentis/Assets/Scripts/MainGame/Character/CharacterSubmodules/CombatBuffSubmodule.cs
2025-11-01 06:13:58 -04:00

131 lines
5.3 KiB
C#

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<CharacterBase>
{
public List<CharacterCombatBuffBase> buffList;
public CombatBuffSubmodule(CharacterBase character) : base(character)
{
buffList = new List<CharacterCombatBuffBase>();
}
}
public partial class CombatBuffSubmodule
{
public T GetBuff<T>() where T : CharacterCombatBuffBase
{
return (T)buffList.Find(x => x.GetType() == typeof(T));
}
public T GetBuff<T>(string identification) where T : CharacterCombatBuffBase
{
return (T)buffList.FindAll(x => x.GetType() == typeof(T)).Find(x => x.identification == identification);
}
public bool TryGetBuff<T>(out T buff) where T : CharacterCombatBuffBase
{
buff = GetBuff<T>();
return buff != null;
}
public bool TryGetBuffs<T>(out List<T> buffs) where T : CharacterCombatBuffBase
{
List<CharacterCombatBuffBase> foundBuffs = buffList.FindAll(x => x.GetType() == typeof(T));
buffs = foundBuffs.Cast<T>().ToList();
return buffs.Count > 0;
}
public bool HasBuff<T>() where T : CharacterCombatBuffBase
{
return buffList.Exists(x => x.GetType() == typeof(T));
}
public List<CharacterCombatBuffBase> Dispel(BuffDispelLevel dispelLevel, CharacterBase dispelSource)
{
List<CharacterCombatBuffBase> 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<KeyValuePair<string, float>, 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<KeyValuePair<string, float>, float>(1, (current, change) => current * change.Value);
}
}
}