Files
Cielonos/Assets/Scripts/MainGame/Characters/Base/Submodules/BuffSubmodule.cs
SoulliesOfficial 50ee502684 完善
2026-02-13 09:22:11 -05:00

90 lines
3.1 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Cielonos.MainGame.Buffs.Character;
namespace Cielonos.MainGame.Characters
{
public partial class BuffSubmodule : SubmoduleBase<CharacterBase>
{
public List<CharacterBuffBase> buffList;
public BuffSubmodule(CharacterBase character) : base(character)
{
buffList = new List<CharacterBuffBase>();
}
public void Update()
{
for (var i = 0; i < buffList.Count; i++)
{
buffList[i].OnBuffUpdate();
}
}
}
public partial class BuffSubmodule
{
public T GetBuff<T>() where T : CharacterBuffBase
{
return (T)buffList.Find(x => x.GetType() == typeof(T));
}
public T GetBuff<T>(string identification) where T : CharacterBuffBase
{
return (T)buffList.FindAll(x => x.GetType() == typeof(T)).Find(x => x.identification == identification);
}
public bool TryGetBuff<T>(out T buff) where T : CharacterBuffBase
{
buff = GetBuff<T>();
return buff != null;
}
public bool TryGetBuffs<T>(out List<T> buffs) where T : CharacterBuffBase
{
List<CharacterBuffBase> foundBuffs = buffList.FindAll(x => x.GetType() == typeof(T));
buffs = foundBuffs.Cast<T>().ToList();
return buffs.Count > 0;
}
public bool HasBuff<T>() where T : CharacterBuffBase
{
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 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;
}
}
}
}
}