169 lines
5.4 KiB
C#
169 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Cielonos.MainGame.Inventory;
|
|
using Opsive.BehaviorDesigner.Runtime;
|
|
using Sirenix.OdinInspector;
|
|
using SLSUtilities.FunctionalAnimation;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
namespace Cielonos.MainGame.Characters
|
|
{
|
|
public partial class Automata : CharacterBase
|
|
{
|
|
public Player player => MainGameManager.Player;
|
|
|
|
[TitleGroup("Data & Presets")]
|
|
public List<FuncAnimData> fullBodyFuncAnims = new List<FuncAnimData>();
|
|
public AttackData attackData;
|
|
[HideInInspector]
|
|
private List<string> registeredFunctionNames = new List<string>();
|
|
|
|
[TitleGroup("Submodules")]
|
|
public ActionRecordSubmodule actionRecordSm;
|
|
|
|
[TitleGroup("Subcontrollers")]
|
|
public BehaviorTree behaviorTree;
|
|
public NavMeshAgent navMeshAgent;
|
|
|
|
|
|
private IDisposable getHitRecovery;
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
RegisterFullBodyFuncAnims();
|
|
//RegisterFunctionsToAnimSc(LightAttack0);
|
|
}
|
|
|
|
protected override void InitializeSubmodules()
|
|
{
|
|
base.InitializeSubmodules();
|
|
actionRecordSm = new ActionRecordSubmodule(this);
|
|
}
|
|
}
|
|
|
|
public partial class Automata
|
|
{
|
|
public override bool GetHit(BreakthroughType breakthroughType, out float recoveryTime,
|
|
DisruptionType disruptionType = DisruptionType.NormalExternal, Vector3 direction = default)
|
|
{
|
|
if (base.GetHit(breakthroughType, out recoveryTime, disruptionType, direction))
|
|
{
|
|
navMeshAgent.isStopped = true;
|
|
statusSm.AddStatus(StatusType.Stun);
|
|
getHitRecovery?.Dispose();
|
|
getHitRecovery = Observable.Timer(TimeSpan.FromSeconds(recoveryTime)).Subscribe(_ =>
|
|
{
|
|
navMeshAgent.isStopped = false;
|
|
statusSm.RemoveStatus(StatusType.Stun);
|
|
}).AddTo(this);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public partial class Automata
|
|
{
|
|
public override void Die()
|
|
{
|
|
if (BattleManager.EnemySm.activeEnemiesList.Contains(this))
|
|
{
|
|
BattleManager.EnemySm.activeEnemiesList.Remove(this);
|
|
}
|
|
|
|
if (fullBodyFuncAnims.Any(funcAnimData => funcAnimData.animInfo.animationName == "Death"))
|
|
{
|
|
statusSm.isDead = true;
|
|
animationSc.fullBodyFuncAnimSm.Play("Death");
|
|
behaviorTree.StopBehavior();
|
|
navMeshAgent.isStopped = true;
|
|
collisionSc.DisableAllColliders();
|
|
}
|
|
|
|
//base.Die();
|
|
}
|
|
}
|
|
|
|
public partial class Automata
|
|
{
|
|
public Vector3 PredictPlayerPosition(float timeAhead)
|
|
{
|
|
Vector3 currentPosition = player.flexibleCenterPoint.position;
|
|
Vector3 currentVelocity = player.landMovementSc.horizontalMovement / player.selfTimeSm.DeltaTime;
|
|
return currentPosition + currentVelocity * timeAhead;
|
|
}
|
|
}
|
|
|
|
public partial class Automata
|
|
{
|
|
public void RegisterFullBodyFuncAnims()
|
|
{
|
|
foreach (FuncAnimData funcAnim in fullBodyFuncAnims)
|
|
{
|
|
animationSc.fullBodyFuncAnimSm.Add(funcAnim);
|
|
}
|
|
}
|
|
|
|
protected virtual void RegisterFunctionsToAnimSc(params Action[] functions)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected virtual void RegisterFunctionsToAnimSc(params Action<RuntimeFuncAnim>[] functions)
|
|
{
|
|
foreach (Action<RuntimeFuncAnim> function in functions)
|
|
{
|
|
string functionName = function.Method.Name;
|
|
if (!animationSc.registeredFunctions.TryAdd(functionName, function))
|
|
{
|
|
Debug.LogWarning($"Function {functionName} is already registered.");
|
|
}
|
|
else
|
|
{
|
|
registeredFunctionNames.Add(functionName);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void RemoveAllRegisteredFunctions()
|
|
{
|
|
foreach (string functionName in registeredFunctionNames)
|
|
{
|
|
if (!animationSc.registeredFunctions.Remove(functionName))
|
|
{
|
|
Debug.LogWarning($"Function {functionName} is not found.");
|
|
}
|
|
}
|
|
|
|
registeredFunctionNames.Clear();
|
|
}
|
|
|
|
protected virtual void RemoveFunctionsFromAnimSc(params Action[] functions)
|
|
{
|
|
foreach (Action function in functions)
|
|
{
|
|
string functionName = function.Method.Name;
|
|
if (!animationSc.registeredFunctions.Remove(functionName))
|
|
{
|
|
Debug.LogWarning($"Function {functionName} is not found.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |