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.
 
 
 
 
 
 

56 lines
1.8 KiB

using BigFloatNumerics;
using System;
using UnityEngine;
[Serializable]
public class EnemyAttack : State<Character>
{
StatData attackStat;
BigFloat attack => attackStat != null ? attackStat.Value : 0;
StatData attackSpeedPerSec;
float attackSpeed => attackSpeedPerSec != null ? attackSpeedPerSec.Value : 1f;
float backupAnimationSpeed;
public IBattleEntity Target { get; set; }
protected override void OnInitialize()
{
Owner.Excutor.Data.TryGetStat(StatID.Attack, out attackStat);
Owner.Excutor.Data.TryGetStat(StatID.AttackSpeedPerSec, out attackSpeedPerSec);
Debug.Assert(Owner.Excutor.SkeletonAnimation.TryGetAnimation("attack", out Spine.Animation _), "attack animation not exist");
}
public override void Enter()
{
backupAnimationSpeed = Owner.Excutor.SkeletonAnimation.timeScale;
Owner.Excutor.SkeletonAnimation.timeScale = attackSpeed;
Owner.Excutor.SkeletonAnimation.AnimationState.SetAnimation(0, "attack", false);
Owner.Excutor.SkeletonAnimation.AnimationState.Event += OnAttackEvent;
Owner.Excutor.ChangeLookDirection((Target as Entity).transform);
}
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()
{
Owner.Excutor.SkeletonAnimation.AnimationState.Event -= OnAttackEvent;
Owner.Excutor.SkeletonAnimation.timeScale = backupAnimationSpeed;
}
private void OnAttackEvent(Spine.TrackEntry trackEntry, Spine.Event e)
{
if (e.Data.Name != "attack" || Target is null || !Target.IsBattleAvail()) return;
BattleMgr.Instance.SendDamage(Target, attack, 0, 0);
}
}