Files
Cielonos/Assets/Scripts/MainGame/Characters/Automata/AI/Actions/ApplyBuff.cs
SoulliesOfficial f26f9fd374 爆更
2026-03-20 12:07:44 -04:00

66 lines
2.3 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 Cielonos.MainGame.Buffs.Character;
using Opsive.BehaviorDesigner.Runtime.Tasks;
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using Opsive.Shared.Utility;
using UnityEngine;
namespace Cielonos.MainGame.Characters.AI
{
[Description("向指定目标(或自身)施加一个 Buff。使用 [SerializeReference] Buff ")]
[NodeIcon("Assets/Sprites/Icon/Play.png")]
[Category("Cielonos/Buffs")]
public class ApplyBuff : AutomataActionBase
{
[Tooltip("施加 Buff 的目标对象列表。如果留空,则默认施加给 AI 自身。")]
public List<SharedVariable<GameObject>> targetList;
[Tooltip("选择要施加的 Buff 类型并配置其参数。")]
[SerializeReference]
public ICharacterBuffFactory buffFactory;
public override TaskStatus OnUpdate()
{
if (buffFactory == null)
{
Debug.LogWarning("[ApplyBuff] 未配置 Buff 工厂,请在检查器中选择一个 Buff 类型。");
return TaskStatus.Failure;
}
if (targetList != null && targetList.Count > 0)
{
foreach (var sharedTarget in targetList)
{
if (sharedTarget == null || sharedTarget.Value == null) continue;
var character = sharedTarget.Value.GetComponent<CharacterBase>();
if (character != null)
{
buffFactory.Create().Apply(character, self);
}
else
{
Debug.LogWarning($"[ApplyBuff] 目标 {sharedTarget.Value.name} 上未找到 CharacterBase 组件,已跳过。");
}
}
}
else
{
// 留空则默认施加给自身
buffFactory.Create().Apply(self, self);
}
return TaskStatus.Success;
}
public override void Reset()
{
base.Reset();
targetList = null;
buffFactory = null;
}
}
}