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.
104 lines
2.9 KiB
104 lines
2.9 KiB
using System;
|
|
using Skill_V2;
|
|
using BigFloatNumerics;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class EnemyCastSkill : State<Character>
|
|
{
|
|
struct SkillInfo
|
|
{
|
|
public int number;
|
|
public Skill skill;
|
|
public int castCount;
|
|
|
|
public static bool Compare(SkillInfo a, SkillInfo b)
|
|
{
|
|
if (a.castCount != b.castCount)
|
|
return a.castCount.CompareTo(b.castCount) <= 0;
|
|
else
|
|
return a.skill.ElapsedCoolTimeRate.CompareTo(b.skill.ElapsedCoolTimeRate) >= 0;
|
|
}
|
|
}
|
|
|
|
StatData attackStat;
|
|
BigFloat attack => attackStat != null ? attackStat.Value : 0;
|
|
|
|
List<SkillInfo> skillInfos;
|
|
SimpleHeap<SkillInfo> sortSkillInfoHeap;
|
|
|
|
SkillInfo curSkillInfo;
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
Owner.Excutor.Data.TryGetStat(StatID.Attack, out attackStat);
|
|
|
|
skillInfos = new List<SkillInfo>();
|
|
sortSkillInfoHeap = new SimpleHeap<SkillInfo>(SkillInfo.Compare);
|
|
|
|
int i = 0;
|
|
foreach (var skill in Owner.Excutor.Skills)
|
|
{
|
|
var skillInfo = new SkillInfo { number = i, skill = skill, castCount = 0 };
|
|
|
|
skillInfos.Add(skillInfo);
|
|
sortSkillInfoHeap.Push(skillInfo);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
public bool TryGetCurrentTopSkill(out Skill skill)
|
|
{
|
|
skill = null;
|
|
|
|
if (sortSkillInfoHeap.TryGetRootValue(out SkillInfo root))
|
|
skill = root.skill;
|
|
|
|
return skill != null;
|
|
}
|
|
|
|
public override void Enter()
|
|
{
|
|
if(!sortSkillInfoHeap.TryGetRootValue(out curSkillInfo))
|
|
{
|
|
Owner.ChangeState<EnemyIdle>();
|
|
return;
|
|
}
|
|
|
|
#if false // TODO: this code need in future
|
|
string animName = FormatString.StringFormat("skill_{0}", curAvailSkillNumber);
|
|
#else
|
|
string animName = "skill";
|
|
#endif
|
|
Debug.Assert(Owner.Excutor.SkeletonAnimation.TryGetAnimation(animName, out Spine.Animation _), $"{animName} animation not exist");
|
|
Owner.Excutor.SkeletonAnimation.AnimationState.SetAnimation(0, animName, false);
|
|
Owner.Excutor.SkeletonAnimation.AnimationState.Event += OnSkillEvent;
|
|
}
|
|
|
|
public override void Excute()
|
|
{
|
|
var trackEntry = Owner.Excutor.SkeletonAnimation.AnimationState.GetCurrent(0);
|
|
if (trackEntry is null || trackEntry.IsComplete)
|
|
Owner.ChangeState<EnemyIdle>();
|
|
}
|
|
|
|
public override void Exit()
|
|
{
|
|
if (curSkillInfo.skill is null) return;
|
|
|
|
Owner.Excutor.SkeletonAnimation.AnimationState.Event -= OnSkillEvent;
|
|
curSkillInfo.skill.StartCoolTime();
|
|
|
|
sortSkillInfoHeap.Pop();
|
|
sortSkillInfoHeap.Push(curSkillInfo);
|
|
}
|
|
|
|
private void OnSkillEvent(Spine.TrackEntry trackEntry, Spine.Event e)
|
|
{
|
|
if (e.Data.Name == "cast")
|
|
{
|
|
curSkillInfo.skill.Cast(Owner.Excutor, attack);
|
|
}
|
|
}
|
|
}
|