You fix some, you brake some
This commit is contained in:
1 parent
d810ea00b6
commit
1a75cf8461
778 files changed
+203405
-86541
No files matched your search
@@ -89,6 +89,16 @@ namespace Code.OfficeGame.BattleMode.Actions.Attacks
|
||||
return new AttackBattleActionData() { TotalFrames = _attackData.TotalFrames };
|
||||
}
|
||||
|
||||
public override void Finish(EntityProperties entity, BattleActionData actionData, BattleActionDecisionResult result)
|
||||
{
|
||||
var entityAnimator = entity.animator;
|
||||
|
||||
entity.SyncRootMotionToMotor();
|
||||
|
||||
entityAnimator.Play(EntryStateHash, 0, 0f);
|
||||
entityAnimator.Update(0f);
|
||||
}
|
||||
|
||||
private void OnEnemyHit(Collider enemyCollider)
|
||||
{
|
||||
var originEntityId = enemyCollider.GetComponentInParent<EntityProperties>().GetEntityId();
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
public abstract BattleActionType ActionType { get; }
|
||||
public abstract DeciderType DeciderType { get; }
|
||||
public abstract BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result);
|
||||
public abstract void Finish(EntityProperties entity, BattleActionData actionData, BattleActionDecisionResult result);
|
||||
|
||||
protected BattleTimeline battleTimeline;
|
||||
public void SetBattleTimeline(BattleTimeline battleTimeline) => this.battleTimeline = battleTimeline;
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
data.Corners = new[] { startPos, validTarget };
|
||||
data.CurrentCornerIndex = 1;
|
||||
data.TotalFrames = CalculatePathFrames(data.Corners, entity.MovementController);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -95,6 +96,17 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
return data;
|
||||
}
|
||||
|
||||
public override void Finish(EntityProperties entity, BattleActionData actionData, BattleActionDecisionResult result)
|
||||
{
|
||||
entity.KinematicCharacterMotor.BaseVelocity = Vector3.zero;
|
||||
|
||||
entity.MovementController.Freeze = true;
|
||||
entity.MovementController.InternalVelocityAdd = Vector3.zero;
|
||||
entity.MovementController.MoveInputVector = Vector3.zero;
|
||||
|
||||
Debug.Log($"{entity.GetEntityId()} is frozen");
|
||||
}
|
||||
|
||||
public override void Tick(
|
||||
float tickDelta,
|
||||
EntityProperties entity,
|
||||
@@ -110,6 +122,8 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
var movementController = entity.MovementController;
|
||||
|
||||
movementController.Freeze = false;
|
||||
|
||||
if (movementActionData.IsRotateOnly)
|
||||
{
|
||||
movementActionData.CurrentFrame++;
|
||||
@@ -131,7 +145,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
entity.KinematicCharacterMotor.SetRotation(positionDecisionResult.Rotation);
|
||||
battleActionData.Finished = true;
|
||||
Debug.Log("Rotated");
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -142,7 +155,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
entity.KinematicCharacterMotor.SetRotation(positionDecisionResult.Rotation);
|
||||
StopMovementAndFinish(movementController);
|
||||
battleActionData.Finished = true;
|
||||
Debug.Log($"Corners {movementActionData.Corners == null} || Wrong index {movementActionData.CurrentCornerIndex >= movementActionData.Corners?.Length}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,7 +184,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
StopMovementAndFinish(movementController);
|
||||
|
||||
battleActionData.Finished = true;
|
||||
Debug.Log("Last corner");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -214,7 +225,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
entity.KinematicCharacterMotor.SetRotation(positionDecisionResult.Rotation);
|
||||
StopMovementAndFinish(movementController);
|
||||
Debug.Log("Very Last corner");
|
||||
battleActionData.Finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,5 +16,10 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
return new NoneBattleActionData();
|
||||
}
|
||||
|
||||
public override void Finish(EntityProperties entity, BattleActionData actionData, BattleActionDecisionResult result)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using Code.Game.Entities;
|
||||
using Code.Infrastructure.Utils;
|
||||
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
||||
using Code.OfficeGame.BattleMode.Timeline;
|
||||
@@ -22,7 +23,12 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
public override DeciderType DeciderType => DeciderType.AsIs;
|
||||
public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result)
|
||||
{
|
||||
return new StuggerActionData { TotalFrames = _actionParameters.TotalFrames};
|
||||
return new StuggerActionData { TotalFrames = _actionParameters.TotalFrames, Finished = false};
|
||||
}
|
||||
|
||||
public override void Finish(EntityProperties entity, BattleActionData actionData, BattleActionDecisionResult result)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Tick(float tickDelta,
|
||||
@@ -32,6 +38,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
if (battleActionData is not StuggerActionData stuggerActionData)
|
||||
{
|
||||
Debug.Log("WrongData");
|
||||
battleActionData.Finished = true;
|
||||
return;
|
||||
}
|
||||
@@ -39,7 +46,9 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
if (stuggerActionData.CurrentFrame == 0)
|
||||
{
|
||||
var transitionTime = stuggerActionData.TransitionFrames * BattleTimeline.TickDelta;
|
||||
entity.animator.ResetAnimatorPosition();
|
||||
|
||||
entity.SyncRootMotionToMotor();
|
||||
|
||||
entity.animator.CrossFadeInFixedTime(StuggerStateHash, transitionTime);
|
||||
}
|
||||
|
||||
@@ -47,6 +56,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
if (stuggerActionData.CurrentFrame >= _actionParameters.TotalFrames)
|
||||
{
|
||||
Debug.Log("Frame last");
|
||||
battleActionData.Finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,5 +55,10 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
return actionData;
|
||||
}
|
||||
|
||||
public override void Finish(EntityProperties entity, BattleActionData actionData, BattleActionDecisionResult result)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
entity.animator.enabled = false;
|
||||
entity.MovementController.enabled = false;
|
||||
entity.MovementController.Freeze = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -167,7 +167,7 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
{
|
||||
container.Resolve<EntityAnimator>().Animator.enabled = enabled;
|
||||
container.Resolve<PlayerControlsProvider>().enabled = enabled;
|
||||
container.Resolve<MovementController>().enabled = enabled;
|
||||
container.Resolve<MovementController>().Freeze = !enabled;
|
||||
}
|
||||
|
||||
private void ToggleBattleMode(InputAction.CallbackContext obj)
|
||||
@@ -198,7 +198,7 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
entity.animator.enabled = true;
|
||||
entity.MovementController.enabled = true;
|
||||
entity.MovementController.Freeze = false;
|
||||
}
|
||||
|
||||
Context.ParticleLoader.ReleaseParticles(ParticlePartition.HitParticles);
|
||||
|
||||
@@ -26,15 +26,12 @@ namespace Code.OfficeGame.BattleMode
|
||||
await UniTask.Yield();
|
||||
|
||||
_onContainerBuildDisposable.Dispose();
|
||||
|
||||
Debug.Log("Containment");
|
||||
|
||||
_sceneContainerManager = container.Resolve<ISceneContainerManager>();
|
||||
_sceneContainerManager.ScenesContainers.Add(SceneId.Battle, container);
|
||||
}
|
||||
|
||||
public void OnDestroy(){
|
||||
Debug.Log("Disposement");
|
||||
_sceneContainerManager.ScenesContainers.Remove(SceneId.Battle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,26 +43,26 @@ namespace Code.OfficeGame.BattleMode.Snapshots
|
||||
|| !actionDataSnapshots.TryGetValue(entityId, out var battleActionData))
|
||||
continue;
|
||||
|
||||
bool actionChanged = false;
|
||||
|
||||
if (!actionDecisionResults.TryAdd(entityId, actionDecisionResult))
|
||||
{
|
||||
actionChanged = actionDecisionResult.ActionType
|
||||
!= actionDecisionResults[entityId].ActionType;
|
||||
|
||||
if (actionChanged)
|
||||
// bool actionChanged = false;
|
||||
//
|
||||
// if (!actionDecisionResults.TryAdd(entityId, actionDecisionResult))
|
||||
// {
|
||||
// actionChanged = actionDecisionResult.ActionType
|
||||
// != actionDecisionResults[entityId].ActionType;
|
||||
//
|
||||
// // if (actionChanged)
|
||||
actionDecisionResults[entityId] = actionDecisionResult.GetSnapshot();
|
||||
else
|
||||
actionDecisionResults[entityId]?.RestoreSnapshot(actionDecisionResult);
|
||||
}
|
||||
|
||||
if (!battleActionDatas.TryAdd(entityId, battleActionData))
|
||||
{
|
||||
if (actionChanged)
|
||||
// else
|
||||
// actionDecisionResults[entityId]?.RestoreSnapshot(actionDecisionResult);
|
||||
// }
|
||||
//
|
||||
// if (!battleActionDatas.TryAdd(entityId, battleActionData))
|
||||
// {
|
||||
// if (actionChanged)
|
||||
battleActionDatas[entityId] = battleActionData.GetSnapshot();
|
||||
else
|
||||
battleActionDatas[entityId]?.RestoreSnapshot(battleActionData);
|
||||
}
|
||||
// else
|
||||
// battleActionDatas[entityId]?.RestoreSnapshot(battleActionData);
|
||||
// }
|
||||
|
||||
entity.RestoreSnapshot(entitySnapshots[entityId]);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,24 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
var readyEntities = SimulateSingleFrame(_entities);
|
||||
|
||||
if (readyEntities.Length > 0) return readyEntities;
|
||||
if (readyEntities.Length > 0)
|
||||
{
|
||||
foreach (var entityId in readyEntities)
|
||||
{
|
||||
Debug.Log($"Entity {entityId} is real ready");
|
||||
|
||||
_battleActions[_actionDecisionResults[entityId].ActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
_battleActionDatas[entityId],
|
||||
_actionDecisionResults[entityId]);
|
||||
|
||||
_battleActionDatas.Remove(entityId);
|
||||
_actionDecisionResults.Remove(entityId);
|
||||
}
|
||||
|
||||
return readyEntities;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +174,42 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
_preview.Release(1);
|
||||
}
|
||||
}
|
||||
private async UniTask PreviewBattleLoopAsync(EntityId entityId,
|
||||
Dictionary<EntityId, EntityProperties> entities,
|
||||
CancellationToken ctx)
|
||||
{
|
||||
_snapshotUtility.GetSnapshots(
|
||||
entities,
|
||||
_actionDecisionResults,
|
||||
_battleActionDatas);
|
||||
|
||||
try
|
||||
{
|
||||
while (!ctx.IsCancellationRequested)
|
||||
{
|
||||
_snapshotUtility.RestoreFromSnapshots(
|
||||
entities,
|
||||
_actionDecisionResults,
|
||||
_battleActionDatas);
|
||||
|
||||
await PlayTimelineUntilThatSpecific(entityId, ctx).AttachExternalCancellation(ctx);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_snapshotUtility.RestoreFromSnapshots(
|
||||
entities,
|
||||
_actionDecisionResults,
|
||||
_battleActionDatas);
|
||||
|
||||
foreach (var (_, entity) in entities)
|
||||
{
|
||||
entity.EntityPreviewVisuals.HidePreviewState();
|
||||
}
|
||||
|
||||
_preview.Release(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask PlayTimelineForCertainFrames(int frameCount, CancellationToken ctx)
|
||||
{
|
||||
@@ -182,22 +235,58 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
foreach (var entityId in readyEntities)
|
||||
{
|
||||
Debug.Log($"Entity {entityId} is ready");
|
||||
var battleActionType = _actionDecisionResults[entityId].ActionType;
|
||||
Debug.Log($"Entity {entityId} is preview ready {battleActionType}");
|
||||
|
||||
_battleActions[battleActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
_battleActionDatas[entityId],
|
||||
_actionDecisionResults[entityId]);
|
||||
|
||||
_battleActionDatas.Remove(entityId);
|
||||
_actionDecisionResults.Remove(entityId);
|
||||
|
||||
// _battleActionDatas[entityId] = new WaitBattleActionData {
|
||||
// TotalFrames = frameCount,
|
||||
// WaitFrames = frameCount
|
||||
// };
|
||||
// _actionDecisionResults[entityId] = new FrameBattleActionDeciderResult
|
||||
// {
|
||||
// ActionType = BattleActionType.Wait,
|
||||
// FrameCount = frameCount,
|
||||
// ResultCode = BattleActionDecisionResultCode.Decided
|
||||
// };
|
||||
}
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private async UniTask PlayTimelineUntilThatSpecific(EntityId specificEntityId, CancellationToken ctx)
|
||||
{
|
||||
float accumulator = 0f;
|
||||
|
||||
while (!ctx.IsCancellationRequested)
|
||||
{
|
||||
bool isCanceled = await UniTask.Yield(PlayerLoopTiming.Update, ctx).SuppressCancellationThrow();
|
||||
if (isCanceled) break;
|
||||
|
||||
accumulator += Mathf.Min(Time.unscaledDeltaTime, 0.1f);
|
||||
|
||||
while (accumulator >= TickDelta && !ctx.IsCancellationRequested)
|
||||
{
|
||||
// Debug.Log($"Simulating {counter}/{frameCount}");
|
||||
accumulator -= TickDelta;
|
||||
|
||||
var readyEntities = SimulateSingleFrame(_entities);
|
||||
|
||||
if (readyEntities.Length > 0)
|
||||
{
|
||||
foreach (var entityId in readyEntities)
|
||||
{
|
||||
var battleActionType = _actionDecisionResults[entityId].ActionType;
|
||||
Debug.Log($"Entity {entityId} is preview ready {battleActionType}");
|
||||
|
||||
_battleActions[_actionDecisionResults[entityId].ActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
_battleActionDatas[entityId],
|
||||
_actionDecisionResults[entityId]);
|
||||
|
||||
_battleActionDatas.Remove(entityId);
|
||||
_actionDecisionResults.Remove(entityId);
|
||||
}
|
||||
if(readyEntities.Contains(specificEntityId)) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -321,7 +410,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
await _preview.WaitAsync(previewCancellationToken.Token);
|
||||
|
||||
PreviewBattleLoopAsync(actionData.TotalFrames, _entities, previewCancellationToken.Token)
|
||||
PreviewBattleLoopAsync(entityId, _entities, previewCancellationToken.Token)
|
||||
.Forget();
|
||||
}
|
||||
else if (decisionResult.ResultCode == BattleActionDecisionResultCode.CancelDecision)
|
||||
@@ -337,6 +426,9 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
_battleActionDeciders[deciderType].UnmountDecider();
|
||||
}
|
||||
|
||||
_battleActionDatas[entityId] = entityActionDataSnapshot;
|
||||
_actionDecisionResults[entityId] = entityResultSnapshot;
|
||||
|
||||
if (decisionResult == null || actionData == null) throw new ArgumentNullException(nameof(decisionResult));
|
||||
|
||||
return (decisionResult, actionData);
|
||||
@@ -347,6 +439,14 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
BattleActionData forcedBattleActionData,
|
||||
BattleActionDecisionResult forcedBattleActionDataResult)
|
||||
{
|
||||
if(_battleActionDatas.TryGetValue(entityId, out var battleActionData)
|
||||
&& _actionDecisionResults.TryGetValue(entityId, out var actionDecisionResult))
|
||||
_battleActions[_actionDecisionResults[entityId].ActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
battleActionData,
|
||||
actionDecisionResult);
|
||||
|
||||
_battleActionDatas[entityId] = forcedBattleActionData;
|
||||
_actionDecisionResults[entityId] = forcedBattleActionDataResult;
|
||||
|
||||
|
||||
Reference in new issue
Block a user