Files
Continentis/Assets/Scripts/MainGame/Buff/BuffBase.cs
SoulliesOfficial ac98ec3aef 更新
2026-04-17 12:01:50 -04:00

136 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using SLSUtilities.General;
using UnityEngine;
namespace Continentis.MainGame
{
public enum BuffDispelLevel
{
Basic = 0, //弱驱散
Strong = 10, //强驱散
DeathOnly = 20, //不可驱散(死亡除外)
Undispellable = 100 //不可驱散(包括死亡)
}
public enum BuffType
{
Positive,
Negative,
Neutral,
Focusing
}
public abstract partial class BuffBase<T> : IPrioritized
{
public string identification;
public BuffType buffType;
public BuffDispelLevel dispelThreshold;
public ContentSubmodule contentSubmodule;
public int Priority { get; private set; }
protected void Initialize(BuffType buffType, BuffDispelLevel dispelThreshold, int priority = 0)
{
this.buffType = buffType;
this.dispelThreshold = dispelThreshold;
this.Priority = priority + (buffType == BuffType.Focusing ? 10000 : 0);
}
protected void SetIdentification(string id)
{
this.identification = id;
}
}
public partial class BuffBase<T>
{
protected bool FindExistingSameBuffs<T1, T2>(out List<T2> existingBuffs, List<T1> buffList) where T1 : BuffBase<T> where T2 : BuffBase<T>
{
existingBuffs = new List<T2>();
//Debug.Log($"Searching for existing buff of type: {this.GetType()} in buff list of count: {buffList.Count}");
foreach (T1 buff in buffList)
{
//Debug.Log($"existing buff type: {buff.GetType().AssemblyQualifiedName}, this buff type: {this.GetType().AssemblyQualifiedName}");
if (buff.GetType() == this.GetType())
{
//Debug.Log("Found existing buff of the same type.");
existingBuffs.Add(buff as T2);
//Debug.Log(existingBuff == null);
}
else
{
//Debug.Log("Buff types do not match.");
}
}
return existingBuffs.Count > 0;
}
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<T>
{
//Buff生命周期函数
/// <summary>
/// Buff被尝试添加到宿主时调用。
/// 返回 true 表示这是一个全新的 Buff框架将执行添加流程
/// 返回 false 表示已有同类 Buff 存在,框架将执行叠加/跳过流程。
/// 子类必须实现此方法。
/// </summary>
public abstract bool OnBuffApply(out BuffBase<T> existingBuff);
/// <summary>
/// Buff首次成功添加到角色后调用。在OnBuffApply完成且返回true之后调用。
/// 如果Buff在被添加时发现已有同类Buff存在则不会调用此函数。
/// </summary>
public virtual void OnAfterFirstApply()
{
}
/// <summary>
/// Buff被驱散移除时调用在OnBuffRemove之前调用。
/// </summary>
public virtual void OnBuffDispel()
{
}
/// <summary>
/// Buff被正常移除包括驱散时调用。在Buff生命周期结束时调用。
/// UntriggerRemove不会调用此函数。但是UntriggerRemove通常情况下绝不会被调用。
/// </summary>
public virtual void OnBuffRemove()
{
}
}
public partial class BuffBase<T>
{
/// <summary>
/// 判断该Buff能否被指定驱散等级的驱散效果驱散。
/// </summary>
protected bool CanBeDispelled(BuffDispelLevel dispelLevel)
{
return dispelLevel >= dispelThreshold;
}
}
}