using System; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Continentis.MainGame { public enum BuffDispelLevel { Basic = 0, //弱驱散 Strong = 10, //强驱散 Immune = 20, //不可驱散(死亡除外) Undispellable = 100 //不可驱散(包括死亡) } public enum BuffType { Positive, Negative, Neutral } public abstract partial class BuffBase { public string name; public string description; public BuffType buffType; public BuffDispelLevel dispelThreshold; protected virtual void Initialize(string name, string description, BuffType buffType, BuffDispelLevel dispelThreshold) { this.name = name; this.description = description; this.buffType = buffType; this.dispelThreshold = dispelThreshold; } } public partial class BuffBase { protected bool FindExistingBuff(out T2 existingBuff, List buffList) where T1 : BuffBase where T2 : BuffBase { existingBuff = null; foreach (T1 buff in buffList.Where(buff => buff.GetType() == typeof(T2))) { existingBuff = buff as T2; return true; } return false; } public abstract void Apply(T attached); public abstract void Remove(); public abstract void UntriggerRemove(); public virtual void Dispel(BuffDispelLevel dispelLevel) { if (CanBeDispelled(dispelLevel)) { OnBuffDispel(); Remove(); } } } public partial class BuffBase { //Buff生命周期函数 /// /// Buff被尝试添加到角色时调用。 /// public virtual bool OnBuffApply(out BuffBase existingBuff) { throw new System.NotImplementedException(); //需要在子类中实现 } /// /// Buff首次成功添加到角色后调用。在OnBuffApply完成,且返回true之后调用。 /// 如果Buff在被添加时,发现已有同类Buff存在,则不会调用此函数。 /// public virtual void OnAfterFirstApply() { } /// /// Buff被驱散(移除)时调用,在OnBuffRemove之前调用。 /// public virtual void OnBuffDispel() { } /// /// Buff被正常移除时调用。在Buff生命周期结束时调用。 /// UntriggerRemove不会调用此函数。但是此函数通常情况下绝不会被调用。 /// public virtual void OnBuffRemove() { } } public partial class BuffBase { /// /// 判断该Buff能否被指定驱散等级的驱散效果驱散。 /// protected bool CanBeDispelled(BuffDispelLevel dispelLevel) { return dispelLevel >= dispelThreshold; } } }