Enemies base
This commit is contained in:
1 parent
cb05da5e89
commit
b02e201cd0
532 files changed
+60713
-58412
No files matched your search
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e507e103e9cc4a20b37123cfbf31bcb2
|
||||
timeCreated: 1794940161
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions.AI
|
||||
{
|
||||
public abstract class EnemyDecider
|
||||
{
|
||||
public abstract UniTask<(BattleActionDecisionResult decisionResult, BattleActionData actionData)>
|
||||
DecideEnemy(CancellationToken ctx, EntityProperties entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 432a0821c3a040a5aa9b40d51842b10b
|
||||
timeCreated: 1794940574
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Code.OfficeGame.BattleMode.Actions.AI
|
||||
{
|
||||
public enum EnemyDeciderTypes
|
||||
{
|
||||
FrankAttack
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efec51a806bb4b3c873ef4fbebebfdff
|
||||
timeCreated: 1794940512
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1bba480028a459a960d731f9ae971d5
|
||||
timeCreated: 1794940179
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Code.Game.Gameplay.Player;
|
||||
using Code.Game.OfficeGame.Entities;
|
||||
using Code.OfficeGame.BattleMode.Effects;
|
||||
using Code.OfficeGame.BattleMode.Health;
|
||||
using Code.OfficeGame.BattleMode.HitBoxes;
|
||||
@@ -20,6 +21,8 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
public EntityPreviewVisuals EntityPreviewVisuals;
|
||||
|
||||
public EntityHealth EntityHealth;
|
||||
|
||||
public EntityTeam Team;
|
||||
|
||||
[DoNotSerialize]
|
||||
public List<Effect> Effects = new();
|
||||
|
||||
@@ -52,8 +52,14 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
public int FullPathHash;
|
||||
public float NormalizedTime;
|
||||
public float LayerWeight;
|
||||
|
||||
// Данные на случай, если снапшот сделан посреди CrossFade-перехода:
|
||||
public bool IsInTransition;
|
||||
public int NextFullPathHash;
|
||||
public float NextNormalizedTime;
|
||||
public float RemainingTransitionDuration; // в секундах
|
||||
}
|
||||
|
||||
|
||||
public struct ParameterSnapshot
|
||||
{
|
||||
public int NameHash;
|
||||
@@ -62,56 +68,76 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
public int IntValue;
|
||||
public bool BoolValue;
|
||||
}
|
||||
|
||||
|
||||
private LayerStateSnapshot[] _layers;
|
||||
private ParameterSnapshot[] _parameters;
|
||||
|
||||
private Vector3 _localPosition;
|
||||
private Quaternion _localRotation;
|
||||
private float _speed;
|
||||
|
||||
|
||||
public static AnimatorSnapshot GetSnapshot(Animator animator)
|
||||
{
|
||||
var snapshot = new AnimatorSnapshot();
|
||||
snapshot.CaptureFrom(animator);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
|
||||
public void CaptureFrom(Animator animator)
|
||||
{
|
||||
if (animator == null) return;
|
||||
|
||||
|
||||
Transform animTransform = animator.transform;
|
||||
_localPosition = animTransform.localPosition;
|
||||
_localRotation = animTransform.localRotation;
|
||||
_speed = animator.speed;
|
||||
|
||||
|
||||
int layerCount = animator.layerCount;
|
||||
if (_layers == null || _layers.Length != layerCount)
|
||||
_layers = new LayerStateSnapshot[layerCount];
|
||||
|
||||
|
||||
for (int i = 0; i < layerCount; i++)
|
||||
{
|
||||
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i);
|
||||
_layers[i] = new LayerStateSnapshot
|
||||
bool inTransition = animator.IsInTransition(i);
|
||||
|
||||
var layerSnap = new LayerStateSnapshot
|
||||
{
|
||||
FullPathHash = stateInfo.fullPathHash,
|
||||
NormalizedTime = stateInfo.normalizedTime,
|
||||
LayerWeight = animator.GetLayerWeight(i)
|
||||
LayerWeight = animator.GetLayerWeight(i),
|
||||
IsInTransition = inTransition
|
||||
};
|
||||
|
||||
Debug.Log($"Saved animator state {stateInfo.shortNameHash}");
|
||||
|
||||
if (inTransition)
|
||||
{
|
||||
AnimatorStateInfo nextInfo = animator.GetNextAnimatorStateInfo(i);
|
||||
AnimatorTransitionInfo transInfo = animator.GetAnimatorTransitionInfo(i);
|
||||
|
||||
layerSnap.NextFullPathHash = nextInfo.fullPathHash;
|
||||
layerSnap.NextNormalizedTime = nextInfo.normalizedTime;
|
||||
|
||||
// Вычисляем оставшееся время перехода в секундах:
|
||||
float totalTransSeconds = transInfo.durationUnit == DurationUnit.Fixed
|
||||
? transInfo.duration
|
||||
: transInfo.duration * stateInfo.length;
|
||||
|
||||
layerSnap.RemainingTransitionDuration = Mathf.Max(0f, totalTransSeconds * (1f - transInfo.normalizedTime));
|
||||
}
|
||||
|
||||
_layers[i] = layerSnap;
|
||||
}
|
||||
|
||||
|
||||
int paramCount = animator.parameterCount;
|
||||
if (_parameters == null || _parameters.Length != paramCount)
|
||||
_parameters = new ParameterSnapshot[paramCount];
|
||||
|
||||
|
||||
for (int i = 0; i < paramCount; i++)
|
||||
{
|
||||
AnimatorControllerParameter param = animator.GetParameter(i);
|
||||
int hash = param.nameHash;
|
||||
var paramSnapshot = new ParameterSnapshot { NameHash = hash, Type = param.type };
|
||||
|
||||
|
||||
switch (param.type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Float:
|
||||
@@ -128,17 +154,17 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
_parameters[i] = paramSnapshot;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RestoreTo(Animator targetAnimator)
|
||||
{
|
||||
if (targetAnimator == null || _layers == null) return;
|
||||
|
||||
|
||||
targetAnimator.Rebind();
|
||||
|
||||
|
||||
bool prevRootMotion = targetAnimator.applyRootMotion;
|
||||
targetAnimator.applyRootMotion = false;
|
||||
targetAnimator.speed = _speed;
|
||||
|
||||
|
||||
if (_parameters != null)
|
||||
{
|
||||
for (int i = 0; i < _parameters.Length; i++)
|
||||
@@ -146,7 +172,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
var p = _parameters[i];
|
||||
if (targetAnimator.IsParameterControlledByCurve(p.NameHash))
|
||||
continue;
|
||||
|
||||
|
||||
switch (p.Type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Float:
|
||||
@@ -165,21 +191,35 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int layerCount = Mathf.Min(_layers.Length, targetAnimator.layerCount);
|
||||
for (int i = 0; i < layerCount; i++)
|
||||
{
|
||||
var layer = _layers[i];
|
||||
targetAnimator.SetLayerWeight(i, layer.LayerWeight);
|
||||
|
||||
// 1. Ставим исходный стейт
|
||||
targetAnimator.Play(layer.FullPathHash, i, layer.NormalizedTime);
|
||||
targetAnimator.Update(0f);
|
||||
|
||||
// 2. Если в момент снапшота шёл переход (например, в атаку) —
|
||||
// запускаем CrossFade в целевой стейт с того места, где он остановился!
|
||||
if (layer.IsInTransition && layer.NextFullPathHash != 0)
|
||||
{
|
||||
targetAnimator.CrossFade(
|
||||
layer.NextFullPathHash,
|
||||
layer.RemainingTransitionDuration, // у CrossFadeInFixedTime offset в секундах, а у CrossFade с фиксированным временем проще через CrossFadeInFixedTime:
|
||||
i,
|
||||
layer.NextNormalizedTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
targetAnimator.Update(0f);
|
||||
|
||||
|
||||
Transform targetTransform = targetAnimator.transform;
|
||||
targetTransform.localPosition = _localPosition;
|
||||
targetTransform.localRotation = _localRotation;
|
||||
|
||||
|
||||
targetAnimator.applyRootMotion = prevRootMotion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using Code.Game.Entities;
|
||||
using Code.Game.OfficeGame.BattleMode;
|
||||
using Code.Game.OfficeGame.Entities;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
||||
@@ -347,6 +348,23 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
private async UniTask<(BattleActionDecisionResult, BattleActionData)> DecideAction(CancellationToken ctx,
|
||||
EntityProperties entity)
|
||||
|
||||
{
|
||||
if(entity.Team == EntityTeam.Good)
|
||||
{
|
||||
var (decisionResult, actionData) = await DecideForPlayer(ctx, entity);
|
||||
|
||||
if (decisionResult == null || actionData == null)
|
||||
throw new ArgumentNullException(nameof(decisionResult));
|
||||
|
||||
return (decisionResult, actionData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (null,null);
|
||||
}
|
||||
|
||||
private async UniTask<(BattleActionDecisionResult decisionResult, BattleActionData actionData)> DecideForPlayer(CancellationToken ctx, EntityProperties entity)
|
||||
{
|
||||
_battleActionDecisionPanel.SetEntityInfo(entity.battleActionTypes);
|
||||
|
||||
@@ -434,9 +452,6 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
_battleActionDatas[entityId] = entityActionDataSnapshot;
|
||||
_actionDecisionResults[entityId] = entityResultSnapshot;
|
||||
|
||||
if (decisionResult == null || actionData == null) throw new ArgumentNullException(nameof(decisionResult));
|
||||
|
||||
return (decisionResult, actionData);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Code.Game.OfficeGame.Entities
|
||||
{
|
||||
public enum EntityTeam
|
||||
{
|
||||
Good,
|
||||
Neutral,
|
||||
ChaoticEvil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70681dd0dd2049ba8235efa2fa853445
|
||||
timeCreated: 1794939650
|
||||
Reference in new issue
Block a user