Skip to content

GameCore.BuffSystem ​

Buff 双端 ​

命名空间 GameCore.BuffSystem

csharp
public class Buff : AttachedObject, IActorScopeOwner, IActorScopeContext, IActorScopePersist, IActorScope, IAttachedObject<Buff, GameDataBuff>, IAttachedObject<GameDataBuff>, IAttachedObject, ISyncIdOwner, IDisposable, IGameObject<GameDataBuff>, IGameObject, IPropertyOwner<PropertyAttachedObject>, IPropertyOwner, IChannelUser, IDisplayInfo, IExecutionContext, IPropertyOwner<PropertyBuff>, IResponseOwner, IThinker

挂载在单位上的 Buff(增益/减益),管理持续时间、层数、周期效果和属性修改。 由 BuffManager 管理生命周期和堆叠规则。

构造函数 ​

Buff 仅客户端 ​

csharp
public Buff(Unit owner, IGameLink<GameDataBuff> link, uint? stack = null, TimeSpan? durationOverride = null)

Client-side constructor for replicating Buff objects from server.

  • owner — The unit that owns this buff
  • link — The GameDataBuff link
  • stack — The stack count
  • durationOverride — Override duration if any

Buff 仅服务端 ​

csharp
public Buff(Unit owner, IGameLink<GameDataBuff> link, EffectBuffAdd effect, uint? stack = null, TimeSpan? durationOverride = null)

属性 ​

csharp
public IGameLink<GameDataBuff> Link { get; }

Cache 双端 ​

csharp
public GameDataBuff Cache { get; }

Stack 双端 ​

csharp
public uint Stack { get; }

StackInternal 双端 ​

csharp
protected override uint StackInternal { get; }

Manager 双端 ​

csharp
public BuffManager Manager { get; }

Duration 双端 ​

csharp
public TimeSpan? Duration { get; }

RemainingTime 双端 ​

csharp
public TimeSpan? RemainingTime { get; }

InstanceComparison 双端 ​

csharp
public Comparison<Buff>? InstanceComparison { get; }

SyncIdType 双端 ​

csharp
public override SyncIdType SyncIdType { get; }

IsLinkEnabled 双端 ​

csharp
public override bool IsLinkEnabled { get; }

MergeAction 双端 ​

csharp
public Func<Buff, bool>? MergeAction { get; }

DisableOnDeath 双端 ​

csharp
public bool DisableOnDeath { get; }

RemoveOnDeath 双端 ​

csharp
public bool RemoveOnDeath { get; }

DisplayCache 双端 ​

csharp
public override IDisplayInfoData DisplayCache { get; }

StackMax 仅服务端 ​

csharp
public uint? StackMax { get; }

StackParam 仅服务端 ​

csharp
public Effect StackParam { get; }

方法 ​

ReplicateFromKeyValue 仅客户端 ​

csharp
public override bool ReplicateFromKeyValue(System.Enum propertyEnum, ReadOnlySpan<byte> value, bool isHostReplicating = false)

DisposeManaged 双端 ​

csharp
protected override void DisposeManaged()

ToString 双端 ​

csharp
public override string? ToString()

HasState 仅客户端 ​

csharp
public override bool HasState(AttachedObjectState state)

GetProperty 双端 ​

csharp
public TValue? GetProperty<TValue>(PropertyBuff property)

Think 双端 ​

csharp
public void Think(int delta)

AddStack 仅服务端 ​

csharp
public uint AddStack(int stack)

SetStack 仅服务端 ​

csharp
public uint SetStack(uint stack)

SetRemainingTime 仅服务端 ​

csharp
public bool SetRemainingTime(TimeSpan? newRemainingTime)

Pause 仅服务端 ​

csharp
public void Pause(bool on)

SetProperty 仅服务端 ​

csharp
public void SetProperty<TValue>(PropertyBuff property, TValue value)

AddProperty 仅服务端 ​

csharp
public void AddProperty(PropertyBuff property, double value)

Disable 仅服务端 ​

csharp
public void Disable()

事件 ​

OnPropertyChanged 双端 ​

csharp
public event Action<PropertyBuff>? OnPropertyChanged

当 Buff 属性发生变化时触发(服务端:SetProperty/AddProperty,客户端:属性复制)。 适用场景:UI 层监听特定 Buff 实例的属性变化(如持续时间、层数)。 直接订阅到对象上,无需过滤,生命周期跟随 Buff 实例。 替代方案: EventBuffPropertyChange — Trigger 事件,适合游戏逻辑中跨单位全局监听所有 Buff 属性变化 OnAttachedObjectStateChanged — 仅关注 Disabled/Deactivated/Hidden 状态切换时使用

GameDataBuff 双端 ​

命名空间 GameCore.BuffSystem.Data

csharp
public class GameDataBuff : GameDataCategory<GameDataBuff>, IAttachedData<GameDataBuff>, IAttachedData, IGameData<GameDataBuff>, IGameData, IUnitModificationData, IResponseOwnerData, IGameDataActorScopeOwner, IGameData<IGameDataActorScopeOwner>, IDisplayInfoData, IEventSender, IGameDataActorScope, IGameDataCategory<GameDataBuff>

Buff 的数据配置,定义持续时间、堆叠上限、周期效果、属性修改、状态变更等。

构造函数 ​

GameDataBuff 双端 ​

csharp
public GameDataBuff(GameLink<GameDataBuff, GameDataBuff> link)

GameDataBuff 双端 ​

csharp
public GameDataBuff(IGameLink<GameDataBuff> link)

属性 ​

DisplayName 双端 ​

csharp
public LocalizedString? DisplayName { get; set; }

Description 双端 ​

csharp
public LocalizedString? Description { get; set; }

Icon 双端 ​

csharp
public Icon? Icon { get; set; }

SyncType 双端 ​

csharp
public SyncType SyncType { get; set; }

Polarity 双端 ​

csharp
public BuffPolarity Polarity { get; set; }

StackStart 双端 ​

csharp
public uint StackStart { get; set; }

InstanceMax 双端 ​

csharp
public uint? InstanceMax { get; set; }

StackMax 双端 ​

csharp
public FuncUIntEffect? StackMax { get; set; }

InitialEffect 双端 ​

csharp
public IGameLink<GameDataEffect>? InitialEffect { get; set; }

PeriodicEffect 双端 ​

csharp
public IGameLink<GameDataEffect>? PeriodicEffect { get; set; }

ExpireEffect 双端 ​

csharp
public IGameLink<GameDataEffect>? ExpireEffect { get; set; }

RefreshEffect 双端 ​

csharp
public IGameLink<GameDataEffect>? RefreshEffect { get; set; }

FinalEffect 双端 ​

csharp
public IGameLink<GameDataEffect>? FinalEffect { get; set; }

Period 双端 ​

csharp
public FuncTimeEffect? Period { get; set; }

Duration 双端 ​

csharp
public FuncTimeEffect? Duration { get; set; }

DurationSyncMode 双端 ​

csharp
public BuffDurationSyncMode DurationSyncMode { get; set; }

控制运行时 Duration 和 RemainingTime 的同步范围,默认仅同步给所挂单位的所属玩家。

Categories 双端 ​

csharp
public List<BuffCategory> Categories { get; set; }

BuffFlags 双端 ​

csharp
public BuffFlags BuffFlags { get; set; }

Modifications 双端 ​

csharp
public List<UnitPropertyModification> Modifications { get; set; }

AddStates 双端 ​

csharp
public List<UnitState> AddStates { get; set; }

RemoveStates 双端 ​

csharp
public List<UnitState> RemoveStates { get; set; }

ImmuneStates 双端 ​

csharp
public List<UnitState> ImmuneStates { get; set; }

Responses 双端 ​

csharp
public List<IGameLink<GameDataResponse>?>? Responses { get; set; }

EnableValidator 双端 ​

csharp
public ValidatorEffect? EnableValidator { get; set; }

PersistValidator 双端 ​

csharp
public ValidatorEffect? PersistValidator { get; set; }

BuffsEnable 双端 ​

csharp
public List<IGameLink<GameDataBuff>> BuffsEnable { get; set; }

Is dropdown only if the list does not allow null values

BuffsDisable 双端 ​

csharp
public List<IGameLink<GameDataBuff>> BuffsDisable { get; set; }

BuffCategoriesEnable 双端 ​

csharp
public List<BuffCategory> BuffCategoriesEnable { get; set; }

BuffCategoriesDisable 双端 ​

csharp
public List<BuffCategory> BuffCategoriesDisable { get; set; }

AbilitiesEnable 双端 ​

csharp
public List<IGameLink<GameDataAbility>> AbilitiesEnable { get; set; }

AbilitiesDisable 双端 ​

csharp
public List<IGameLink<GameDataAbility>> AbilitiesDisable { get; set; }

AbilityCategoriesEnable 双端 ​

csharp
public List<AbilityCategory> AbilityCategoriesEnable { get; set; }

AbilityCategoriesDisable 双端 ​

csharp
public List<AbilityCategory> AbilityCategoriesDisable { get; set; }

ActorArray 双端 ​

csharp
public List<IGameLink<GameDataActor>?>? ActorArray { get; set; }

UISettings 双端 ​

csharp
public BuffUISettings UISettings { get; set; }

AggregatorWeakReference 双端 ​

csharp
public WeakReference<EventAggregator> AggregatorWeakReference { get; }

DebugDrawSettings 双端 ​

csharp
public DebugDrawSettings? DebugDrawSettings { get; set; }

BuffDurationSyncMode 双端 ​

命名空间 GameCore.BuffSystem.Data.Enum

csharp
public enum BuffDurationSyncMode

控制 Buff 的总持续时间和剩余时间向哪些玩家同步。

枚举值 ​

  • None — 不同步计时信息,服务端照常计时。
  • Owner — 仅同步给 Buff 所挂单位的所属玩家,且不超出 Buff 本体的同步范围。
  • Inherit — 计时信息继承 Buff 本体的同步方式。

BuffPolarity 双端 ​

命名空间 GameCore.BuffSystem.Data.Enum

csharp
public enum BuffPolarity

枚举值 ​

  • Neutral
  • Positive
  • Negative

UIDurationFormat 双端 ​

命名空间 GameCore.BuffSystem.Data.Enum

csharp
public enum UIDurationFormat

枚举值 ​

  • None
  • Numeric
  • CircularProgress

BuffFlags 双端 ​

命名空间 GameCore.BuffSystem.Data.Struct

csharp
public class BuffFlags

定义 Buff 效果的行为标志,控制 Buff 的各种特性和生命周期管理

备注

BuffFlags 类用于配置 Buff 效果的特殊行为,包括叠加规则、持续性设置、 死亡时的处理和引导效果等。这些标志影响 Buff 在游戏中的应用和管理方式。

构造函数 ​

BuffFlags 双端 ​

csharp
public BuffFlags()

属性 ​

SingleInstancePerCaster 双端 ​

csharp
public bool SingleInstancePerCaster { get; set; }

获取或设置是否每个施法者只能对同一目标施加一个相同类型(数编Id一致)的 Buff 实例

备注

当设置为 true 时,如果同一个施法者尝试对已有相同 Buff 的目标再次施加该 Buff, 新的 Buff 会替换旧的实例,并重置 Buff 的持续时间。如果 Buff 未达到最大叠加次数,则会将新旧实例的叠加次数相加。

Permanent 双端 ​

csharp
public bool Permanent { get; set; }

获取或设置 Buff 是否为永久效果。永久效果并不是指持续时间无限,而是指不会因为变身、死亡等条件而消失。

备注

当设置为 true 时,Buff 不会因为变身、死亡等条件而消失。

DisableWhenDead 双端 ​

csharp
public bool DisableWhenDead { get; set; }

获取或设置当单位死亡时是否禁用此 Buff

备注

默认值为 true,意味着大多数 Buff 在单位死亡时会被禁用或移除。 设置为 false 可以让某些特殊效果在死亡后继续存在,例如灵魂形态或复活效果。 需要配合 Permanent 一起使用,否则 Buff 在死后必定消失。

Channeling 双端 ​

csharp
public bool Channeling { get; set; }

获取或设置 Buff 是否为引导效果

备注

当设置为 true 时,表示此 Buff 需要施法者持续引导,如果施法者的引导被打断, 该 Buff 也会被移除。这通常用于需要集中精神维持的法术效果。

BuffUISettings 双端 ​

命名空间 GameCore.BuffSystem.Data.Struct

csharp
public class BuffUISettings

构造函数 ​

BuffUISettings 双端 ​

csharp
public BuffUISettings()

属性 ​

ShowStackCount 双端 ​

csharp
public bool ShowStackCount { get; set; }

Whether to display the stack count (Only for stackable buffs).

DurationFormat 双端 ​

csharp
public UIDurationFormat DurationFormat { get; set; }

How the remaining duration is rendered (e.g. numeric text, circular progress, none).

CombineInstances 双端 ​

csharp
public bool CombineInstances { get; set; }

Whether multiple simultaneous instances of the same buff are combined into a single UI entry (with stacks).

BlinkThreshold 双端 ​

csharp
public TimeSpan? BlinkThreshold { get; set; }

Gets or sets the time threshold that determines when a fading blink effect is triggered.

备注

If the value is null, the fading blink effect is disabled. The default value is 2 seconds. If the total duration of the buff is less than this threshold, the fading blink effect will not be applied.

BuffCategory 双端 ​

命名空间 GameCore.BuffSystem.Enum

csharp
public readonly struct BuffCategory : IGameClass, IExtendableEnum<BuffCategory>, IExtendableEnum, IExtendedEnum, ISyncIdOwner

方法 ​

ToString 双端 ​

csharp
public override string? ToString()

operator == 双端 ​

csharp
public static bool operator ==(BuffCategory left, BuffCategory right)

operator != 双端 ​

csharp
public static bool operator !=(BuffCategory left, BuffCategory right)

Equals 双端 ​

csharp
public override bool Equals(object? obj)

GetHashCode 双端 ​

csharp
public override int GetHashCode()

OnRegisterGameClass 双端 ​

csharp
public static void OnRegisterGameClass()

字段 ​

InnerValue 双端 ​

csharp
public readonly System.Enum InnerValue

CanBeDisabled 双端 ​

csharp
public static readonly BuffCategory CanBeDisabled

CanBeDispelled 双端 ​

csharp
public static readonly BuffCategory CanBeDispelled

EPropertyBuff 双端 ​

命名空间 GameCore.BuffSystem.Enum

csharp
public enum EPropertyBuff

枚举值 ​

  • Duration
  • Stack

PropertyBuff 双端 ​

命名空间 GameCore.BuffSystem.Enum

csharp
public readonly struct PropertyBuff : IGameClass, IExtendableEnum<PropertyBuff>, IExtendableEnum, IExtendedEnum, ISyncIdOwner

方法 ​

ToString 双端 ​

csharp
public override string? ToString()

operator == 双端 ​

csharp
public static bool operator ==(PropertyBuff left, PropertyBuff right)

operator != 双端 ​

csharp
public static bool operator !=(PropertyBuff left, PropertyBuff right)

Equals 双端 ​

csharp
public override bool Equals(object? obj)

GetHashCode 双端 ​

csharp
public override int GetHashCode()

OnRegisterGameClass 双端 ​

csharp
public static void OnRegisterGameClass()

字段 ​

InnerValue 双端 ​

csharp
public readonly System.Enum InnerValue

Duration 双端 ​

csharp
public static readonly PropertyBuff Duration

Stack 双端 ​

csharp
public static readonly PropertyBuff Stack

BuffManager 双端 ​

命名空间 GameCore.BuffSystem.Manager

csharp
public class BuffManager : ObjectManager<Buff, GameDataBuff>, IContextTypeService<Entity, BuffManager>

管理单位上所有 Buff 的添加、移除、堆叠和查询。 通过 entity.GetComponent&lt;BuffManager&gt;() 获取。

构造函数 ​

BuffManager 双端 ​

csharp
public BuffManager(Entity host)

属性 ​

ObjectType 双端 ​

csharp
public override AttachedType ObjectType { get; }

方法 ​

CreateInstance 双端 ​

csharp
public static BuffManager CreateInstance(Entity content)

HasBuff 双端 ​

csharp
public bool HasBuff(IGameLink<GameDataBuff> buffLink)

检查是否有指定的Buff

  • buffLink — Buff数编Link

返回: 如果存在指定Buff则返回true

HasAnyBuff 双端 ​

csharp
public bool HasAnyBuff(params IGameLink<GameDataBuff>[] buffLinks)

检查是否有任意一个指定的Buff

  • buffLinks — Buff数编Link数组

返回: 如果存在任意一个指定Buff则返回true

HasAllBuffs 双端 ​

csharp
public bool HasAllBuffs(params IGameLink<GameDataBuff>[] buffLinks)

检查是否有所有指定的Buff

  • buffLinks — Buff数编Link数组

返回: 如果存在所有指定Buff则返回true

RemoveByPredicate 双端 ​

csharp
public int RemoveByPredicate(Func<Buff, bool> predicate)

按条件移除Buff

  • predicate — 移除条件

返回: 移除的Buff数量

DispelBuffs 双端 ​

csharp
public int DispelBuffs(BuffPolarity polarity, bool onlyDispellable = true)

驱散指定极性的Buff

  • polarity — 要驱散的Buff极性
  • onlyDispellable — 是否只驱散可驱散的Buff

返回: 驱散的Buff数量

DispelPositiveBuffs 双端 ​

csharp
public int DispelPositiveBuffs(bool onlyDispellable = true)

驱散有益Buff

  • onlyDispellable — 是否只驱散可驱散的Buff

返回: 驱散的Buff数量

DispelNegativeBuffs 双端 ​

csharp
public int DispelNegativeBuffs(bool onlyDispellable = true)

驱散有害Buff

  • onlyDispellable — 是否只驱散可驱散的Buff

返回: 驱散的Buff数量

ClearAllDispellableBuffs 双端 ​

csharp
public int ClearAllDispellableBuffs()

清除所有可驱散的Buff

返回: 清除的Buff数量

HasState 双端 ​

csharp
public bool HasState(UnitState state)

检查单位是否有指定状态(通过Buff添加的)

  • state — 要检查的状态

返回: 如果单位具有该状态则返回true

GetCurrentStates 双端 ​

csharp
public IEnumerable<UnitState> GetCurrentStates()

获取单位当前所有状态(通过Buff添加的)

返回: 当前所有状态的集合

GetBuffsByPolarity 双端 ​

csharp
public IEnumerable<Buff> GetBuffsByPolarity(BuffPolarity polarity)

获取指定极性的所有Buff

  • polarity — Buff极性

返回: 指定极性的Buff集合

GetPositiveBuffs 双端 ​

csharp
public IEnumerable<Buff> GetPositiveBuffs()

获取所有有益Buff

返回: 有益Buff集合

GetNegativeBuffs 双端 ​

csharp
public IEnumerable<Buff> GetNegativeBuffs()

获取所有有害Buff

返回: 有害Buff集合

GetDispellableBuffs 双端 ​

csharp
public IEnumerable<Buff> GetDispellableBuffs()

获取所有可驱散的Buff

返回: 可驱散的Buff集合

CountBuffs 双端 ​

csharp
public int CountBuffs(Func<Buff, bool> predicate)

统计指定类型的Buff数量

  • predicate — 统计条件

返回: 满足条件的Buff数量

CountBuffsByPolarity 双端 ​

csharp
public int CountBuffsByPolarity(BuffPolarity polarity)

统计指定极性的Buff数量

  • polarity — Buff极性

返回: 指定极性的Buff数量

CountPositiveBuffs 双端 ​

csharp
public int CountPositiveBuffs()

统计有益Buff数量

返回: 有益Buff数量

CountNegativeBuffs 双端 ​

csharp
public int CountNegativeBuffs()

统计有害Buff数量

返回: 有害Buff数量

BuffManagerExtension 双端 ​

命名空间 GameCore.BuffSystem.Manager

csharp
public static class BuffManagerExtension

方法 ​

GetComponent 双端 ​

csharp
public static BuffManager? GetComponent<TComponent>(this Entity entity) where TComponent : BuffManager

GetOrCreateComponent 双端 ​

csharp
public static BuffManager GetOrCreateComponent<TComponent>(this Entity entity) where TComponent : BuffManager