Lil improvements

This commit is contained in:
ThomasCharester committed 2026-10-31 02:59:29 +03:00
1 parent 31850e77bc
commit d00ce7bb0e
59 files changed
+79385 -23141

No files matched your search

@@ -0,0 +1,25 @@
namespace Code.OfficeGame.BattleMode.Actions
{
public class AttackBattleActionData : BattleActionData
{
public int CurrentFrame;
public override BattleActionData GetSnapshot()
{
var snapshot = new AttackBattleActionData()
{
TotalFrames = TotalFrames,
CurrentFrame = CurrentFrame
};
return snapshot;
}
public override void RestoreSnapshot(BattleActionData snapshot)
{
if (snapshot is not AttackBattleActionData neededSnapshot) return;
TotalFrames = neededSnapshot.TotalFrames;
CurrentFrame = neededSnapshot.CurrentFrame;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 64cdf1d355ea44ea8435dd8c4e2584d4
timeCreated: 1793402627
@@ -0,0 +1,25 @@
namespace Code.OfficeGame.BattleMode.Actions
{
public class StuggerActionData : BattleActionData
{
public int CurrentFrame;
public override BattleActionData GetSnapshot()
{
var snapshot = new AttackBattleActionData()
{
TotalFrames = TotalFrames,
CurrentFrame = CurrentFrame
};
return snapshot;
}
public override void RestoreSnapshot(BattleActionData snapshot)
{
if (snapshot is not AttackBattleActionData neededSnapshot) return;
TotalFrames = neededSnapshot.TotalFrames;
CurrentFrame = neededSnapshot.CurrentFrame;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 596b5dfe5898472e9bcd44bf1050209a
timeCreated: 1793404253
@@ -1,147 +1,81 @@
// using System.Linq;
// using System.Threading;
// using Code.Infrastructure.Input;
// using Code.Infrastructure.Utils;
// using Code.OfficeGame.BattleMode.Actions.Deciders;
// using Code.OfficeGame.BattleMode.Actions.HoloCopy;
// using Code.OfficeGame.BattleMode.HitBoxes;
// using Cysharp.Threading.Tasks;
// using Reflex.Attributes;
// using UnityEngine;
// using UnityEngine.InputSystem;
//
// namespace Code.OfficeGame.BattleMode.Actions.Attacks
// {
// public class BattleActionPlayerAttackMMA : BattleAction
// {
// [SerializeField] private HoloCop holoCop;
// [SerializeField] private Animator animator;
// private EntityHitBoxes _entityHitBoxes;
// private AttackActionConfig _attackData;
// public int EntryStateHash => Animator.StringToHash("WalkBlend");
//
// private int _currentFrame;
// private IInputService _inputService;
// private CancellationTokenSource _waitForEnterTokenSource;
// private BattleActionDecisionResultCode _decisionResultCode;
//
// [Inject]
// public void Construct(MultipleConfig<BattleActionParameters> attackData, IInputService inputService)
// {
// _inputService = inputService;
//
// _entityHitBoxes = GetComponent<EntityHitBoxes>();
//
// _attackData = (AttackActionConfig) attackData.Configs.SingleOrDefault(x=>x.ActionType == ActionType);
// }
//
// public override async UniTask<BattleActionDecisionResult> DecideAction()
// {
// _currentFrame = 0;
// Finished = false;
//
// _waitForEnterTokenSource = new CancellationTokenSource();
// _decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
//
// _inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Confirm,
// ConfirmAttack);
// _inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Cancel,
// CancelAttack);
//
// holoCop.Simulate(TickHoloCopy, _waitForEnterTokenSource.Token).Forget();
//
// await UniTask.WaitUntilCanceled(_waitForEnterTokenSource.Token).SuppressCancellationThrow();
//
// _inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Confirm,
// ConfirmAttack);
// _inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Cancel,
// CancelAttack);
//
// _currentFrame = 0;
//
// return new() { ResultCode = _decisionResultCode, FrameDuration = _attackData.TotalFrames};
// }
//
// private void CancelAttack(InputAction.CallbackContext obj)
// {
// _decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
// _waitForEnterTokenSource?.Cancel();
// }
//
// private void ConfirmAttack(InputAction.CallbackContext obj)
// {
// _decisionResultCode = BattleActionDecisionResultCode.Decided;
// _waitForEnterTokenSource?.Cancel();
// }
//
// public override BattleActionType ActionType => BattleActionType.PlayerAttackMMA;
//
// public override bool Tick(float tickDelta, EntityProperties entity)
// {
// if (Finished) return;
//
// if (_currentFrame == 0)
// {
// // TODO Root Motion не должен быть использован в нормальных анимациях
// animator.applyRootMotion = true;
// animator.Play(_attackData.StateHash, 0, 0f);
// }
//
// _currentFrame++;
//
// if (_currentFrame >= _attackData.HitboxStartFrame && _currentFrame <= _attackData.HitboxEndFrame)
// {
// _entityHitBoxes.CheckHitsForCurrentFrame(OnEnemyHit, HitBoxPartType.LArm);
// }
//
// if (_currentFrame >= _attackData.TotalFrames)
// {
// CompleteOrInterruptAction();
// }
// }
//
// public override DeciderType DeciderType => DeciderType.Position;
//
// private void OnEnemyHit(Collider enemyCollider)
// {
// Debug.Log($"Попадание в {enemyCollider.name} на {_currentFrame}-м кадре! Урон: {_attackData.Damage}");
// var entityActor = enemyCollider.GetComponentInParent<EntityTimelineActor>();
// entityActor.ForceDecideAction(BattleActionType.Stugger);
// }
//
// public void CompleteOrInterruptAction()
// {
// animator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда
// animator.Update(0f);
//
// // TODO С нормальными анимациями не нужен будет рут моушен√
// animator.applyRootMotion = false;
// animator.transform.localPosition = Vector3.zero;
// animator.transform.localRotation = Quaternion.identity;
//
// Finished = true;
// }
//
// // HoloCopy
//
// private bool TickHoloCopy(HoloCop holoCop, float tickDelta)
// {
// if (_currentFrame == 0)
// {
// holoCop.Animator.applyRootMotion = true;
// holoCop.Animator.Play(_attackData.StateHash, 0, 0f);
// }
//
// _currentFrame++;
//
// if(_currentFrame >= _attackData.TotalFrames)
// {
// _currentFrame = 0;
// holoCop.Animator.applyRootMotion = false;
// return true;
// }
//
// return false;
// }
// }
// }
using System.Linq;
using Code.Infrastructure.Utils;
using Code.OfficeGame.BattleMode.Actions.Deciders;
using Code.OfficeGame.BattleMode.HitBoxes;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions.Attacks
{
public class BattleActionPlayerAttackMMA : BattleAction
{
private AttackActionConfig _attackData;
public int EntryStateHash => Animator.StringToHash("WalkBlend");
public BattleActionPlayerAttackMMA(MultipleConfig<BattleActionParameters> attackData)
{
_attackData = (AttackActionConfig)
attackData.Configs.SingleOrDefault(x=>x.ActionType == ActionType);
}
public override BattleActionType ActionType => BattleActionType.PlayerAttackMMA;
public override bool Tick(float tickDelta,
EntityProperties entity,
BattleActionDecisionResult battleActionDecisionResult,
BattleActionData battleActionData)
{
if (battleActionData is not AttackBattleActionData actionData) return true;
if (actionData.CurrentFrame == 0)
{
var entityAnimator = entity.animator;
// TODO Root Motion не должен быть использован в нормальных анимациях
entityAnimator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда
entityAnimator.Update(0f);
entityAnimator.applyRootMotion = false;
entityAnimator.transform.localPosition = Vector3.zero;
entityAnimator.transform.localRotation = Quaternion.identity;
entityAnimator.applyRootMotion = true;
entityAnimator.Play(_attackData.StateHash, 0, 0f);
}
actionData.CurrentFrame++;
if (actionData.CurrentFrame >= _attackData.HitboxStartFrame
&& actionData.CurrentFrame <= _attackData.HitboxEndFrame)
{
entity.EntityHitBoxes.CheckHitsForCurrentFrame(OnEnemyHit, HitBoxPartType.LArm);
}
if (actionData.CurrentFrame >= _attackData.TotalFrames)
{
var entityAnimator = entity.animator;
entityAnimator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда
entityAnimator.Update(0f);
// TODO С нормальными анимациями не нужен будет рут моушен√
entityAnimator.applyRootMotion = false;
entityAnimator.transform.localPosition = Vector3.zero;
entityAnimator.transform.localRotation = Quaternion.identity;
return true;
}
return false;
}
public override DeciderType DeciderType => DeciderType.Position;
public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result)
{
return new AttackBattleActionData() { TotalFrames = _attackData.TotalFrames };
}
private void OnEnemyHit(Collider enemyCollider)
{
Debug.Log($"Попадание в {enemyCollider.name}! Урон: {_attackData.Damage}");
}
}
}
@@ -1,64 +1,52 @@
// using System.Linq;
// using Code.Infrastructure.Utils;
// using Code.OfficeGame.BattleMode.HitBoxes;
// using Cysharp.Threading.Tasks;
// using Reflex.Attributes;
// using UnityEngine;
//
// namespace Code.OfficeGame.BattleMode.Actions
// {
// public class BattleActionStugger : BattleAction
// {
// private Animator _animator;
// private EntityHitBoxes _entityHitBoxes;
// private int EntryStateHash => Animator.StringToHash("WalkBlend");
// private int StuggerStateHash => Animator.StringToHash("Stugger");
//
// private BattleActionParameters _actionParameters;
//
// private int _currentFrame;
//
// [Inject]
// public void Construct(MultipleConfig<BattleActionParameters> actionData)
// {
// _animator = GetComponentInChildren<Animator>();
// _entityHitBoxes = GetComponent<EntityHitBoxes>();
// _actionParameters = actionData.Configs.SingleOrDefault(x => x.ActionType == ActionType);
// }
// public override async UniTask<BattleActionDecisionResult> DecideAction()
// {
// await UniTask.Yield();
//
// _currentFrame = 0;
// Finished = false;
//
// return new() { ResultCode = BattleActionDecisionResultCode.Decided, FrameDuration = _actionParameters.TotalFrames};
//
// }
//
// public override BattleActionType ActionType => BattleActionType.Stugger;
//
// public override bool Tick(float tickDelta, EntityProperties entity)
// {
// if (Finished) return;
//
// if (_currentFrame == 0)
// {
// _animator.Play(StuggerStateHash, 0, 0f);
// }
//
// _currentFrame++;
//
// if (_currentFrame >= _actionParameters.TotalFrames)
// {
// CompleteOrInterruptAction();
// }
// }
//
// public void CompleteOrInterruptAction()
// {
// _animator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда
// Finished = true;
// }
// }
// }
using System.Linq;
using Code.Infrastructure.Utils;
using Code.OfficeGame.BattleMode.Actions.Deciders;
using Reflex.Attributes;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions
{
public class BattleActionStugger : BattleAction
{
private int EntryStateHash => Animator.StringToHash("WalkBlend");
private int StuggerStateHash => Animator.StringToHash("Stugger");
private BattleActionParameters _actionParameters;
[Inject]
public void Construct(MultipleConfig<BattleActionParameters> actionData)
{
_actionParameters = actionData.Configs.SingleOrDefault(x => x.ActionType == ActionType);
}
public override BattleActionType ActionType => BattleActionType.Stugger;
public override DeciderType DeciderType => DeciderType.AsIs;
public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result)
{
return new StuggerActionData { TotalFrames = _actionParameters.TotalFrames};
}
public override bool Tick(float tickDelta,
EntityProperties entity,
BattleActionDecisionResult battleActionDecisionResult,
BattleActionData battleActionData)
{
if (battleActionData is not StuggerActionData stuggerActionData) return true;
if (stuggerActionData.CurrentFrame == 0)
{
entity.animator.Play(StuggerStateHash, 0, 0f);
}
stuggerActionData.CurrentFrame++;
if (stuggerActionData.CurrentFrame >= _actionParameters.TotalFrames)
{
entity.animator.Play(EntryStateHash, 0, 0f);
return true;
}
return false;
}
}
}
@@ -1,4 +1,5 @@
using Code.Game.Gameplay.Player;
using Code.OfficeGame.BattleMode.HitBoxes;
using KinematicCharacterController;
using UnityEngine;
@@ -11,5 +12,6 @@ namespace Code.OfficeGame.BattleMode.Actions
public MovementController MovementController;
public KinematicCharacterMotor KinematicCharacterMotor;
public EntityHitBoxes EntityHitBoxes;
}
}
@@ -10,6 +10,7 @@ using Code.Infrastructure.SceneLoader;
using Code.Infrastructure.UI;
using Code.Infrastructure.Utils;
using Code.OfficeGame.BattleMode.Actions;
using Code.OfficeGame.BattleMode.Actions.Attacks;
using Code.OfficeGame.BattleMode.Actions.Deciders;
using Code.OfficeGame.BattleMode.Actions.Player;
using Code.OfficeGame.BattleMode.Marker;
@@ -103,6 +104,8 @@ namespace Code.Game.OfficeGame.GameStates
builder.RegisterType(typeof(BattleActionMove), new[]{ typeof(BattleAction) }, Lifetime.Singleton, Resolution.Eager);
builder.RegisterType(typeof(BattleActionWait), new[]{ typeof(BattleAction) }, Lifetime.Singleton, Resolution.Eager);
builder.RegisterType(typeof(BattleActionNone), new[]{ typeof(BattleAction) }, Lifetime.Singleton, Resolution.Eager);
builder.RegisterType(typeof(BattleActionPlayerAttackMMA), new[]{ typeof(BattleAction) }, Lifetime.Singleton, Resolution.Eager);
builder.RegisterType(typeof(BattleActionStugger), new[]{ typeof(BattleAction) }, Lifetime.Singleton, Resolution.Eager);
builder.RegisterType(typeof(BattleActionPositionDecider), new[]{ typeof(BattleActionDecider) } , Lifetime.Singleton, Resolution.Eager);
builder.RegisterType(typeof(AsIsBattleActionDecider), new[]{ typeof(BattleActionDecider) } , Lifetime.Singleton, Resolution.Eager);
@@ -121,11 +121,11 @@ namespace Code.OfficeGame.BattleMode.Timeline
Dictionary<EntityId, BattleActionData> actionDataSnapshots = new();
Dictionary<EntityId, BattleActionDecisionResult> resultsSnapshots = new();
Dictionary<EntityId, EntitySnapshot> entitySnapshots = new();
foreach (var entity in entities)
{
var entityId = entity.GetEntityId();
if (!_actionDecisionResults.TryGetValue(entityId, out var actionDecisionResult)
|| !_battleActionDatas.TryGetValue(entityId, out var battleActionData))
continue;
@@ -137,8 +137,6 @@ namespace Code.OfficeGame.BattleMode.Timeline
try
{
Debug.Log(frameCount);
await PlayTimelineForCertainFrames(frameCount, ctx).AttachExternalCancellation(ctx);
}
finally
@@ -146,17 +144,17 @@ namespace Code.OfficeGame.BattleMode.Timeline
foreach (var entity in entities)
{
var entityId = entity.GetEntityId();
if (!resultsSnapshots.TryGetValue(entityId, out var actionDecisionResult)
|| !actionDataSnapshots.TryGetValue(entityId, out var battleActionData))
continue;
if(!_actionDecisionResults.TryAdd(entityId, actionDecisionResult))
if (!_actionDecisionResults.TryAdd(entityId, actionDecisionResult))
_actionDecisionResults[entityId]?.RestoreSnapshot(actionDecisionResult);
if(!_battleActionDatas.TryAdd(entityId, battleActionData))
if (!_battleActionDatas.TryAdd(entityId, battleActionData))
_battleActionDatas[entityId]?.RestoreSnapshot(battleActionData);
entity.RestoreSnapshot(entitySnapshots[entityId]);
}
}
@@ -252,13 +250,11 @@ namespace Code.OfficeGame.BattleMode.Timeline
BattleActionDecisionResult decisionResult = null;
BattleActionData actionData = null;
CancellationTokenSource previewCancellationToken = new();
var entityId = entity.GetEntityId();
BattleActionData entityActionDataSnapshot = null;
BattleActionDecisionResult entityResultSnapshot = null;
if (_battleActionDatas.TryGetValue(entityId, out var battleActionData))
entityActionDataSnapshot = battleActionData.GetSnapshot();
@@ -281,6 +277,8 @@ namespace Code.OfficeGame.BattleMode.Timeline
_battleActionDeciders[deciderType].MountDecider();
CancellationTokenSource previewCancellationToken = new();
while (!ctx.IsCancellationRequested)
{
Cursor.lockState = CursorLockMode.Locked;
@@ -293,13 +291,13 @@ namespace Code.OfficeGame.BattleMode.Timeline
decisionResult.ActionType = decidedActionType;
Debug.Log(decisionResult.ResultCode);
actionData = _battleActions[decidedActionType].MountAndGetFrames(entity, decisionResult);
previewCancellationToken.Cancel();
previewCancellationToken.Dispose();
if(decisionResult.ResultCode == BattleActionDecisionResultCode.Deciding)
if (decisionResult.ResultCode == BattleActionDecisionResultCode.Deciding)
{
_actionDecisionResults[entityId] = decisionResult;
_battleActionDatas[entityId] = actionData;
@@ -309,23 +307,24 @@ namespace Code.OfficeGame.BattleMode.Timeline
PreviewBattleLoopAsync(actionData.TotalFrames, _entities, previewCancellationToken.Token)
.Forget();
}
if (decisionResult.ResultCode == BattleActionDecisionResultCode.CancelDecision)
else if (decisionResult.ResultCode == BattleActionDecisionResultCode.CancelDecision)
{
decidedActionType = BattleActionType.None;
if (decisionResult.ResultCode != BattleActionDecisionResultCode.Deciding)
break;
}
else break;
}
_battleActionDeciders[deciderType].UnmountDecider();
}
if(entityResultSnapshot != null
&& !_actionDecisionResults.TryAdd(entityId, entityResultSnapshot))
if (entityResultSnapshot != null
&& !_actionDecisionResults.TryAdd(entityId, entityResultSnapshot))
_actionDecisionResults[entityId]?.RestoreSnapshot(entityResultSnapshot);
if(entityActionDataSnapshot != null
&& !_battleActionDatas.TryAdd(entityId, entityActionDataSnapshot))
if (entityActionDataSnapshot != null
&& !_battleActionDatas.TryAdd(entityId, entityActionDataSnapshot))
_battleActionDatas[entityId]?.RestoreSnapshot(entityActionDataSnapshot);
if (decisionResult == null || actionData == null) throw new ArgumentNullException(nameof(decisionResult));