Files
Cielonos/Assets/Scripts/MainGame/Characters/Automata/Automata.cs

232 lines
7.5 KiB
C#
Raw Normal View History

2025-11-25 08:19:33 -05:00
using System;
using System.Collections.Generic;
2025-12-08 05:27:53 -05:00
using System.Linq;
2026-03-20 12:07:44 -04:00
using System.Reflection;
using System.Text;
using Cielonos.MainGame.Characters.Inventory;
2026-05-10 11:47:55 -04:00
using DG.Tweening;
2025-11-25 08:19:33 -05:00
using Opsive.BehaviorDesigner.Runtime;
using Sirenix.OdinInspector;
using SLSUtilities.FunctionalAnimation;
2026-05-10 11:47:55 -04:00
using SLSUtilities.General;
2025-11-25 08:19:33 -05:00
using UniRx;
using UnityEngine;
using UnityEngine.AI;
2026-05-10 11:47:55 -04:00
using Ease = DG.Tweening.Ease;
2025-11-25 08:19:33 -05:00
namespace Cielonos.MainGame.Characters
{
public partial class Automata : CharacterBase
{
2025-12-08 05:27:53 -05:00
public Player player => MainGameManager.Player;
2025-11-25 08:19:33 -05:00
[TitleGroup("Data & Presets")]
2026-03-20 12:07:44 -04:00
public FuncAnimDataCollection fullBodyFuncAnims;
public FuncAnimDataCollection upperBodyFuncAnims;
2025-11-25 08:19:33 -05:00
public AttackData attackData;
2026-03-20 12:07:44 -04:00
2025-11-25 08:19:33 -05:00
[HideInInspector]
private List<string> registeredFunctionNames = new List<string>();
2025-12-08 05:27:53 -05:00
[TitleGroup("Submodules")]
public ActionRecordSubmodule actionRecordSm;
2026-03-20 12:07:44 -04:00
[TitleGroup("Subcontrollers")]
public BehaviorSubcontroller behaviorSc;
2025-11-25 08:19:33 -05:00
2026-02-13 09:22:11 -05:00
private float getHitTimer;
2025-11-25 08:19:33 -05:00
protected override void Start()
{
base.Start();
2026-03-20 12:07:44 -04:00
RegisterFuncAnims();
RegisterFunctionsToAnimSc();
2025-11-25 08:19:33 -05:00
}
2025-12-08 05:27:53 -05:00
protected override void InitializeSubmodules()
{
base.InitializeSubmodules();
actionRecordSm = new ActionRecordSubmodule(this);
}
2026-02-13 09:22:11 -05:00
protected override void Update()
{
base.Update();
UpdateGetHit();
}
2025-11-25 08:19:33 -05:00
}
2026-05-10 11:47:55 -04:00
2025-11-25 08:19:33 -05:00
public partial class Automata
{
2025-12-17 04:19:38 -05:00
public override bool GetHit(BreakthroughType breakthroughType, out float recoveryTime,
2026-05-10 11:47:55 -04:00
DisruptionType disruptionType = DisruptionType.NormalExternal,
2026-03-20 12:07:44 -04:00
Vector3 direction = default, string funcAnimName = "")
2025-11-25 08:19:33 -05:00
{
2026-03-20 12:07:44 -04:00
if (string.IsNullOrEmpty(funcAnimName))
{
funcAnimName = GetHitFuncAnimName(breakthroughType, direction);
}
2026-05-10 11:47:55 -04:00
2026-03-20 12:07:44 -04:00
if (base.GetHit(breakthroughType, out recoveryTime, disruptionType, direction, funcAnimName))
2025-11-25 08:19:33 -05:00
{
2026-02-13 09:22:11 -05:00
if (getHitTimer <= 0)
{
2026-05-10 11:47:55 -04:00
if (behaviorSc.navMeshAgent.enabled)
{
behaviorSc.navMeshAgent.isStopped = true;
}
2026-02-13 09:22:11 -05:00
getHitTimer = recoveryTime;
}
else
2025-11-25 08:19:33 -05:00
{
2026-02-13 09:22:11 -05:00
getHitTimer = Mathf.Max(getHitTimer, recoveryTime);
}
2026-05-10 11:47:55 -04:00
2026-03-20 12:07:44 -04:00
return true;
2025-11-25 08:19:33 -05:00
}
2026-05-10 11:47:55 -04:00
2025-11-25 08:19:33 -05:00
return false;
}
2026-02-13 09:22:11 -05:00
2026-05-10 11:47:55 -04:00
2026-03-20 12:07:44 -04:00
2026-02-13 09:22:11 -05:00
protected virtual void UpdateGetHit()
{
2026-03-20 12:07:44 -04:00
getHitTimer -= selfTimeSm.DeltaTime;
2026-02-13 09:22:11 -05:00
if (getHitTimer <= 0)
{
2026-05-10 11:47:55 -04:00
if (behaviorSc.navMeshAgent.enabled)
{
behaviorSc.navMeshAgent.isStopped = false;
}
2026-03-20 12:07:44 -04:00
//statusSm.RemoveStatus(StatusType.Stun);
2026-02-13 09:22:11 -05:00
}
}
2025-11-25 08:19:33 -05:00
}
public partial class Automata
{
2025-12-08 05:27:53 -05:00
public override void Die()
{
2026-05-10 11:47:55 -04:00
eventSm.onDeath.Invoke();
BattleManager.EnemySm.RemoveEnemy(this);
float deathProcessTime = 0f;
var deathFuncAnim = fullBodyFuncAnims.animDataList.Find(data => data.animInfo.animationName == "Death");
if (deathFuncAnim is not null)
2025-12-08 05:27:53 -05:00
{
animationSc.fullBodyFuncAnimSm.Play("Death");
2026-05-10 11:47:55 -04:00
behaviorSc.mainBehaviorTree.StopBehavior();
behaviorSc.navMeshAgent.isStopped = true;
2025-12-08 05:27:53 -05:00
collisionSc.DisableAllColliders();
2026-05-10 11:47:55 -04:00
deathProcessTime = deathFuncAnim.animationClip.length;
2025-12-08 05:27:53 -05:00
}
2026-01-03 18:19:39 -05:00
statusSm.isDead = true;
2026-05-10 11:47:55 -04:00
if (deathProcessTime > 0)
{
Observable.Timer(TimeSpan.FromSeconds(deathProcessTime)).Subscribe(_ =>
{
Sequence fade = DOTween.Sequence();
foreach (Material mat in renderSc.baseRenderMaterials)
{
fade.Join(mat.DOFloat(1, "_FadeAmount", 1f).SetEase(Ease.InQuint));
//fade.Join(mat.DOColor(Color.clear, "_FadeBurnColor", 1f).SetEase(Ease.Linear));
}
fade.OnComplete(() => base.Die());
fade.Play();
}).AddTo(gameObject);
}
else
{
base.Die();
}
2025-12-08 05:27:53 -05:00
}
2025-11-25 08:19:33 -05:00
}
2025-12-08 05:27:53 -05:00
public partial class Automata
{
public Vector3 PredictPlayerPosition(float timeAhead)
{
2026-02-13 09:22:11 -05:00
Vector3 currentPosition = player.centerPoint.position;
2025-12-08 05:27:53 -05:00
Vector3 currentVelocity = player.landMovementSc.horizontalMovement / player.selfTimeSm.DeltaTime;
return currentPosition + currentVelocity * timeAhead;
}
}
2025-11-25 08:19:33 -05:00
public partial class Automata
{
2026-03-20 12:07:44 -04:00
public void RegisterFuncAnims()
2025-11-25 08:19:33 -05:00
{
2026-03-20 12:07:44 -04:00
if (fullBodyFuncAnims == null) return;
foreach (FuncAnimData funcAnim in fullBodyFuncAnims.animDataList)
2025-11-25 08:19:33 -05:00
{
animationSc.fullBodyFuncAnimSm.Add(funcAnim);
}
2026-03-20 12:07:44 -04:00
/*foreach (FuncAnimData funcAnim in upperBodyFuncAnims.animDataList)
{
animationSc.upperBodyFuncAnimSm.Add(funcAnim);
}*/
2025-11-25 08:19:33 -05:00
}
2026-03-20 12:07:44 -04:00
2025-11-25 08:19:33 -05:00
protected virtual void RegisterFunctionsToAnimSc(params Action[] functions)
{
2026-03-20 12:07:44 -04:00
if (fullBodyFuncAnims == null) return;
RegisterFunctionsToAnimSc();
2025-11-25 08:19:33 -05:00
foreach (Action function in functions)
{
string functionName = function.Method.Name;
if (!animationSc.registeredFunctions.TryAdd(functionName, anim => function()))
{
Debug.LogWarning($"Function {functionName} is already registered.");
}
else
{
registeredFunctionNames.Add(functionName);
}
}
}
2026-03-20 12:07:44 -04:00
protected virtual void RegisterFunctionsToAnimSc()
2025-11-25 08:19:33 -05:00
{
2026-03-20 12:07:44 -04:00
if (fullBodyFuncAnims == null) return;
foreach (CustomFunction function in fullBodyFuncAnims.preloadFunctions)
2025-11-25 08:19:33 -05:00
{
2026-03-20 12:07:44 -04:00
string functionName = function.functionName;
string FAPF_functionName = new StringBuilder(functionName).Insert(0, "FAPF_").ToString();
MethodInfo method = GetType().GetMethod(FAPF_functionName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method == null)
2025-11-25 08:19:33 -05:00
{
2026-03-20 12:07:44 -04:00
Debug.LogWarning($"Function {functionName} not found in {this.GetType().Name}. Skipping registration.");
continue;
2025-11-25 08:19:33 -05:00
}
2026-03-20 12:07:44 -04:00
Action<RuntimeFuncAnim> action = Delegate.CreateDelegate(typeof(Action<RuntimeFuncAnim>), this, method) as Action<RuntimeFuncAnim>;
registeredFunctionNames.Add(functionName);
animationSc.registeredFunctions.TryAdd(functionName, action);
2025-11-25 08:19:33 -05:00
}
}
2026-03-20 12:07:44 -04:00
2025-11-25 08:19:33 -05:00
protected void RemoveAllRegisteredFunctions()
{
foreach (string functionName in registeredFunctionNames)
{
if (!animationSc.registeredFunctions.Remove(functionName))
{
Debug.LogWarning($"Function {functionName} is not found.");
}
}
registeredFunctionNames.Clear();
}
}
}