FiE-Game/Assets/Scripts/Fie/Ponies/Fie.Ponies.Applejack/FieStateMachineApplejackFireRope.cs

209 lines
6 KiB
C#
Raw Normal View History

2018-11-20 20:10:49 +01:00
using Fie.Manager;
using Fie.Object;
using GameDataEditor;
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.Ponies.Applejack
{
public class FieStateMachineApplejackFireRope : FieStateMachineGameCharacterBase
{
private enum FireState
{
ROPE_READY,
ROPE_FIRE,
ROPE_WAITING,
ROPE_PULL,
ROPE_END
}
public float pullDuration = 0.75f;
private const float STAGGER = 100f;
private const float HATE = 5f;
private const float PUNCH_DELAY = 0.5f;
private const float GROUND_FORCE_TIME = 1.5f;
private const float GROUND_FORCE = 15f;
private const float AIR_ROPE_FLYING_FORCE = 4f;
private const float AIR_ROPE_PAST_TIME = 0.3f;
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 updateState<T>(ref T gameCharacter)
{
if (gameCharacter is FieApplejack)
{
_timeCount += Time.deltaTime;
FieApplejack applejack = gameCharacter as FieApplejack;
FireState fireState = _fireState;
switch (fireState)
{
case FireState.ROPE_READY:
{
bool isFlyingAction = false;
int animationId = (applejack.groundState != 0) ? 32 : 31;
if (applejack.groundState == FieObjectGroundState.Flying)
{
isFlyingAction = true;
}
applejack.resetMoveForce();
applejack.setGravityRate(0.2f);
autoFlipToEnemy(applejack);
TrackEntry trackEntry = applejack.animationManager.SetAnimation(animationId, isLoop: false, isForceSet: true);
applejack.emotionController.SetEmoteAnimation(41, isForceSet: true);
applejack.SetDialog(30, FieMasterData<GDEWordScriptsListData>.I.GetMasterData(GDEItemKeys.WordScriptsList_P_HONESTY_ABILITY_ROPE_1), FieMasterData<GDEWordScriptsListData>.I.GetMasterData(GDEItemKeys.WordScriptsList_P_HONESTY_ABILITY_ROPE_2));
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
{
Vector3 directionalVec = (applejack.flipState != 0) ? Vector3.right : Vector3.left;
FieEmitObjectApplejackRope fieEmitObjectApplejackRope = FieManagerBehaviour<FieEmittableObjectManager>.I.EmitObject<FieEmitObjectApplejackRope>(applejack.mouthTransform, directionalVec, applejack.detector.getLockonEnemyTransform(), applejack);
if (!(fieEmitObjectApplejackRope == null))
{
GDESkillTreeData skill = applejack.GetSkill(FieConstValues.FieSkill.HONESTY_ROPE_LV3_1);
if (skill != null)
{
applejack.damageSystem.AddDefenceMagni(1005, 1f, skill.Value1);
}
GDESkillTreeData skill2 = applejack.GetSkill(FieConstValues.FieSkill.HONESTY_ROPE_LV4_SYNERGY_ROPING);
if (skill2 != null)
{
applejack.abilitiesContainer.IncreaseOrReduceCooldownAll(0f - skill2.Value1);
}
fieEmitObjectApplejackRope.setPullPosition(applejack.transform.position);
fieEmitObjectApplejackRope.emitObjectHitEvent += delegate(FieEmittableObjectBase emitObject, FieGameCharacter hitCharacter)
{
if (isFlyingAction)
{
(applejack.getStateMachine().setState(typeof(FieStateMachineApplejackRopeActionAir), isForceSet: false) as FieStateMachineGameCharacterBase)?.addTargetGameCharacter(hitCharacter);
_isEnd = true;
}
else
{
FieStateMachineGameCharacterBase fieStateMachineGameCharacterBase = applejack.getStateMachine().setState(typeof(FieStateMachineApplejackRopeAction), isForceSet: false) as FieStateMachineGameCharacterBase;
if (fieStateMachineGameCharacterBase != null)
{
FieDamage fieDamage = new FieDamage(100f, 5f);
FieStatusEffectsPullEntity item = new FieStatusEffectsPullEntity
{
pullPosition = applejack.transform.position,
pullDuration = pullDuration
};
fieDamage.statusEffects.Add(item);
hitCharacter.AddDamage(applejack, fieDamage);
fieStateMachineGameCharacterBase.addTargetGameCharacter(hitCharacter);
}
_isEnd = true;
}
};
}
}
2023-07-24 21:52:50 +02:00
else if (trackIndex.Data.Name == "takeOff")
2018-11-20 20:10:49 +01:00
{
Vector3 up = Vector3.up;
up.Normalize();
up *= 4f;
applejack.setMoveForce(up, 0.3f);
}
2023-07-24 21:52:50 +02:00
else if (trackIndex.Data.Name == "finished")
2018-11-20 20:10:49 +01:00
{
_nextState = typeof(FieStateMachineApplejackFlying);
_isEnd = true;
}
};
trackEntry.Complete += delegate
{
_isEnd = true;
};
2023-07-24 21:52:50 +02:00
_endTime = trackEntry.animationEnd;
2018-11-20 20:10:49 +01:00
}
else
{
applejack.setGravityRate(1f);
applejack.isEnableGravity = true;
_endTime = 0f;
}
_fireState = FireState.ROPE_FIRE;
break;
}
}
if (_timeCount > _endTime)
{
_isEnd = true;
}
}
}
public override void initialize(FieGameCharacter gameCharacter)
{
FieApplejack fieApplejack = gameCharacter as FieApplejack;
if (!(fieApplejack == null))
{
fieApplejack.isEnableHeadTracking = false;
}
}
public override void terminate(FieGameCharacter gameCharacter)
{
FieApplejack fieApplejack = gameCharacter as FieApplejack;
if (!(fieApplejack == null))
{
fieApplejack.setGravityRate(1f);
fieApplejack.isEnableGravity = true;
fieApplejack.isEnableHeadTracking = true;
}
}
public override bool isEnd()
{
return _isEnd;
}
public override Type getNextState()
{
return _nextState;
}
public override List<Type> getAllowedStateList()
{
List<Type> list = new List<Type>();
list.Add(typeof(FieStateMachineApplejackRopeActionAir));
list.Add(typeof(FieStateMachineApplejackRopeAction));
return list;
}
public override float getDelay()
{
return 0.5f;
}
public override bool isFinished()
{
return _isFinished;
}
}
}