FiE-Game/Assets/Scripts/Fie/Enemies/HoovesRaces/ChangelingAlpha/FieStateMachineChangelingAlphaChargeFinish.cs

154 lines
3.7 KiB
C#
Raw Normal View History

2018-11-20 20:10:49 +01:00
using Fie.Manager;
using Fie.Object;
using Spine;
using System;
using System.Collections.Generic;
using UnityEngine;
2023-07-24 21:52:50 +02:00
using Event = Spine.Event;
2018-11-20 20:10:49 +01:00
namespace Fie.Enemies.HoovesRaces.ChangelingAlpha
{
public class FieStateMachineChangelingAlphaChargeFinish : FieStateMachineGameCharacterBase
{
private enum FireState
{
KICK_START,
KICKING
}
private const float KICK_DELAY = 0.2f;
private const float KICK_HORMING_DISTANCE = 1f;
private const float KICK_HORMING_DEFAULT_RATE = 1f;
private const float GROUND_FORCE_TIME = 1.5f;
private const float GROUND_FORCE = 15f;
private Type _nextState = typeof(FieStateMachineCommonIdle);
private FireState _fireState;
private bool _isEnd;
private float _endTime = 3.40282347E+38f;
private float _timeCount;
private bool _isSetEndAnim;
private bool _isFinished;
public override void initialize(FieGameCharacter gameCharacter)
{
FieChangelingAlpha fieChangelingAlpha = gameCharacter as FieChangelingAlpha;
if (!(fieChangelingAlpha == null))
{
autoFlipToEnemy(fieChangelingAlpha);
fieChangelingAlpha.isEnableAutoFlip = false;
}
}
public override void terminate(FieGameCharacter gameCharacter)
{
FieChangelingAlpha fieChangelingAlpha = gameCharacter as FieChangelingAlpha;
if (!(fieChangelingAlpha == null))
{
fieChangelingAlpha.isEnableAutoFlip = false;
}
}
public override void updateState<T>(ref T gameCharacter)
{
if (gameCharacter is FieChangelingAlpha)
{
_timeCount += Time.deltaTime;
FieChangelingAlpha changelingAlpha = gameCharacter as FieChangelingAlpha;
switch (_fireState)
{
case FireState.KICK_START:
if (changelingAlpha.groundState == FieObjectGroundState.Grounding)
{
TrackEntry trackEntry = changelingAlpha.animationManager.SetAnimation(14, isLoop: false, isForceSet: true);
if (trackEntry != null)
{
2023-07-24 21:52:50 +02:00
trackEntry.Event += delegate(TrackEntry state, Event trackIndex)
2018-11-20 20:10:49 +01:00
{
2023-07-24 21:52:50 +02:00
if (trackIndex.Data.Name == "fire")
2018-11-20 20:10:49 +01:00
{
FieManagerBehaviour<FieEmittableObjectManager>.I.EmitObject<FieEmitObjectChangelingAlphaChargeFinish>(changelingAlpha.centerTransform, changelingAlpha.flipDirectionVector, null, changelingAlpha);
}
2023-07-24 21:52:50 +02:00
if (trackIndex.Data.Name == "move")
2018-11-20 20:10:49 +01:00
{
Vector3 a = changelingAlpha.flipDirectionVector;
Transform lockonEnemyTransform = changelingAlpha.detector.getLockonEnemyTransform();
float num = 1f;
if (lockonEnemyTransform != null)
{
Vector3 vector = lockonEnemyTransform.position - changelingAlpha.transform.position;
vector.Normalize();
a = vector;
a.y = 0f;
}
2023-07-24 21:52:50 +02:00
Vector3 vector2 = a * (trackIndex.Float * num);
2018-11-20 20:10:49 +01:00
changelingAlpha.resetMoveForce();
changelingAlpha.setMoveForce(vector2, 0f, useRound: false);
2023-07-24 21:52:50 +02:00
if (trackIndex.Float > 0f)
2018-11-20 20:10:49 +01:00
{
changelingAlpha.setFlipByVector(vector2);
}
}
2023-07-24 21:52:50 +02:00
if (trackIndex.Data.Name == "finished")
2018-11-20 20:10:49 +01:00
{
_isEnd = true;
}
};
2023-07-24 21:52:50 +02:00
_endTime = trackEntry.animationEnd;
2018-11-20 20:10:49 +01:00
}
else
{
_endTime = 0f;
}
_fireState = FireState.KICKING;
}
else
{
_isEnd = true;
}
break;
}
if (_timeCount > _endTime)
{
_isEnd = true;
}
}
}
public override bool isEnd()
{
return _isEnd;
}
public override Type getNextState()
{
return _nextState;
}
public override List<Type> getAllowedStateList()
{
return new List<Type>();
}
public override float getDelay()
{
return 0.2f;
}
public override bool isFinished()
{
return _isFinished;
}
}
}