You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.1 KiB
98 lines
3.1 KiB
using BehaviorDesigner.Runtime;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using GAS.Runtime;
|
|
using UnityEngine;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
/// <summary>
|
|
/// 释放明确的技能
|
|
/// </summary>
|
|
[TaskDescription("释放明确的技能")]
|
|
public class TryCastAbilityExplicitAction : Action
|
|
{
|
|
[BehaviorDesigner.Runtime.Tasks.Tooltip("能力id")]
|
|
[SerializeField] private int gaCid;
|
|
[BehaviorDesigner.Runtime.Tasks.Tooltip("是否优先使用已经授予的技能")]
|
|
[SerializeField] private bool useHasGrantGa = true;
|
|
[BehaviorDesigner.Runtime.Tasks.Tooltip("释放完是否移除技能,默认false")]
|
|
[SerializeField] private bool dropAbilityWhenEnd = false;
|
|
private bool m_HasAttach = false;
|
|
private CombatEntity m_OwnerEnt;
|
|
private int m_GaSeq;
|
|
private bool m_HasActiveGa;
|
|
|
|
// 重置
|
|
public override void OnAwake()
|
|
{
|
|
m_OwnerEnt = null;
|
|
m_GaSeq = -1;
|
|
m_HasAttach = false;
|
|
m_HasActiveGa = false;
|
|
}
|
|
public override void OnStart()
|
|
{
|
|
if (m_HasAttach == false)
|
|
{
|
|
m_OwnerEnt = Owner.GetEntity<CombatEntity>();
|
|
if (useHasGrantGa)
|
|
{
|
|
m_GaSeq = m_OwnerEnt.abilitySystem.AbilityContainer.GetUniqueAbilitySpecByGaid(gaCid);
|
|
}
|
|
|
|
// 如果没有授予技能,尝试授予技能
|
|
if (m_GaSeq <= 0)
|
|
{
|
|
var ctx = AbilitySrv.AttachActiveAbility(m_OwnerEnt, gaCid);
|
|
if (ctx != null)
|
|
{
|
|
m_GaSeq = ctx.gaSeq;
|
|
ctx.dropAbilityWhenEnd = dropAbilityWhenEnd;
|
|
if (dropAbilityWhenEnd)
|
|
ctx.abilitySpec.RegisterUnGrantAbility(OnUnGrantAbility);
|
|
}
|
|
}
|
|
|
|
if (m_GaSeq > 0)
|
|
{
|
|
m_HasAttach = true;
|
|
}
|
|
}
|
|
|
|
// 尝试激活技能
|
|
m_HasActiveGa = m_OwnerEnt.abilitySystem.TryActivateAbility_WithSeq(m_GaSeq);
|
|
}
|
|
|
|
private void OnUnGrantAbility(AbilitySpec abilitySpec)
|
|
{
|
|
if (m_HasAttach)
|
|
{
|
|
m_HasAttach = false;
|
|
}
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (m_HasActiveGa == false)
|
|
{
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
var abilitySpecs = m_OwnerEnt.abilitySystem.AbilityContainer.AbilitySpecs();
|
|
if (abilitySpecs.TryGetValue(m_GaSeq, out var abilitySpec))
|
|
{
|
|
var ret = abilitySpec.CanActivate();
|
|
if (ret == AbilityActivateResult.FailHasActivated)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
|
|
}
|
|
}
|