Decision WORKS YAY
This commit is contained in:
1 parent
739d1f0374
commit
ccc4c04234
177 files changed
+208565
-120026
No files matched your search
@@ -6,6 +6,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public bool Finished { get; protected set; }
|
||||
public abstract void Tick(float tickDelta);
|
||||
public abstract UniTask<bool> DecideAction();
|
||||
public abstract UniTask<BattleActionDecisionResultCode> DecideAction();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public enum BattleActionDecisionResultCode
|
||||
{
|
||||
Decided,
|
||||
Deciding,
|
||||
CancelDecision
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6aa25f1eaf09411a875619aca0a36a3e
|
||||
timeCreated: 1792758849
|
||||
@@ -4,7 +4,6 @@ using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Input;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using KinematicCharacterController;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -127,18 +126,20 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
}
|
||||
|
||||
private CancellationTokenSource _waitForEnterTokenSource;
|
||||
private bool _positionChosen;
|
||||
private BattleActionDecisionResultCode _decisionResultCode;
|
||||
|
||||
public override async UniTask<bool> DecideAction()
|
||||
public override async UniTask<BattleActionDecisionResultCode> DecideAction()
|
||||
{
|
||||
_waitForEnterTokenSource = new CancellationTokenSource();
|
||||
_positionChosen = false;
|
||||
_decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
|
||||
_targetPosition = _playerMovementController.transform.position;
|
||||
|
||||
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Select,
|
||||
SelectPosition);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Confirm,
|
||||
ConfirmPosition);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Cancel,
|
||||
CancelPosition);
|
||||
|
||||
await UniTask.WaitUntilCanceled(_waitForEnterTokenSource.Token).SuppressCancellationThrow();
|
||||
|
||||
@@ -146,12 +147,21 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
SelectPosition);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Confirm,
|
||||
ConfirmPosition);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Cancel,
|
||||
CancelPosition);
|
||||
|
||||
_waitForEnterTokenSource.Dispose();
|
||||
_waitForEnterTokenSource = null;
|
||||
|
||||
Finished = !_positionChosen;
|
||||
return _positionChosen;
|
||||
Finished = _decisionResultCode != BattleActionDecisionResultCode.Decided;
|
||||
|
||||
return _decisionResultCode;
|
||||
}
|
||||
|
||||
private void CancelPosition(InputAction.CallbackContext obj)
|
||||
{
|
||||
_decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
|
||||
_waitForEnterTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
private void ConfirmPosition(InputAction.CallbackContext input)
|
||||
@@ -164,9 +174,10 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
_corners = _path.corners;
|
||||
_currentCornerIndex = _corners.Length > 1 ? 1 : 0;
|
||||
_positionChosen = true;
|
||||
_decisionResultCode = BattleActionDecisionResultCode.Decided;
|
||||
}
|
||||
|
||||
else _decisionResultCode = BattleActionDecisionResultCode.Deciding;
|
||||
|
||||
_waitForEnterTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public enum BattleActionType
|
||||
{
|
||||
None,
|
||||
Wait,
|
||||
Move
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
if (_waitFrames <= 0) Finished = true;
|
||||
}
|
||||
|
||||
public override async UniTask<bool> DecideAction()
|
||||
public override async UniTask<BattleActionDecisionResultCode> DecideAction()
|
||||
{
|
||||
Finished = false;
|
||||
|
||||
_waitFrames = 120;
|
||||
|
||||
return true;
|
||||
return BattleActionDecisionResultCode.Decided;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,10 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
public BattleAction CurrentAction { get; protected set;}
|
||||
public bool Finished => CurrentAction == null || CurrentAction.Finished;
|
||||
|
||||
public abstract UniTask DecideAction(CancellationToken ct);
|
||||
public abstract UniTask DecideAction(CancellationToken ctx);
|
||||
|
||||
public Animator animator;
|
||||
|
||||
protected Dictionary<BattleActionType, BattleAction> BattleActions = new();
|
||||
protected readonly Dictionary<BattleActionType, BattleAction> BattleActions = new();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Threading;
|
||||
using Code.Game.Gameplay.Player;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Input;
|
||||
using Code.OfficeGame.BattleMode.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
@@ -10,6 +11,8 @@ namespace Code.OfficeGame.BattleMode.Actions.Player
|
||||
{
|
||||
public class PlayerTimelineActor : EntityTimelineActor
|
||||
{
|
||||
[Inject] private BattleActionDecisionPanel _battleActionDecisionPanel;
|
||||
|
||||
[Inject]
|
||||
private void Construct(
|
||||
CameraStateMachine cameraStateMachine,
|
||||
@@ -17,20 +20,41 @@ namespace Code.OfficeGame.BattleMode.Actions.Player
|
||||
PlayerMovementController playerMovementController)
|
||||
{
|
||||
BattleActions.Add(BattleActionType.Wait, new BattleActionWait());
|
||||
BattleActions.Add(BattleActionType.Move, new BattleActionMove(cameraStateMachine, inputService, playerMovementController));
|
||||
BattleActions.Add(BattleActionType.Move,
|
||||
new BattleActionMove(cameraStateMachine, inputService, playerMovementController));
|
||||
}
|
||||
|
||||
public override async UniTask DecideAction(CancellationToken ct)
|
||||
public override async UniTask DecideAction(CancellationToken ctx)
|
||||
{
|
||||
bool succeded = false;
|
||||
BattleActionDecisionResultCode decision = BattleActionDecisionResultCode.Deciding;
|
||||
|
||||
var decidedAction = BattleActionType.Move; // T
|
||||
_battleActionDecisionPanel.SetEntityInfo(BattleActions);
|
||||
|
||||
while (!succeded || ct.IsCancellationRequested)
|
||||
BattleActionType decidedAction = BattleActionType.None;
|
||||
|
||||
while (decidedAction == BattleActionType.None || ctx.IsCancellationRequested)
|
||||
{
|
||||
Debug.Log("player decided to move");
|
||||
Cursor.lockState = CursorLockMode.Confined;
|
||||
|
||||
await _battleActionDecisionPanel.Open(ctx);
|
||||
|
||||
succeded = await BattleActions[decidedAction].DecideAction();
|
||||
decidedAction = await _battleActionDecisionPanel.GetDecision(ctx);
|
||||
|
||||
while (decidedAction != BattleActionType.None
|
||||
&& decision == BattleActionDecisionResultCode.Deciding
|
||||
&& !ctx.IsCancellationRequested)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
|
||||
await _battleActionDecisionPanel.Close(ctx);
|
||||
|
||||
// Панель UI здесь
|
||||
|
||||
decision = await BattleActions[decidedAction].DecideAction();
|
||||
|
||||
if (decision == BattleActionDecisionResultCode.CancelDecision)
|
||||
decidedAction = BattleActionType.None;
|
||||
}
|
||||
}
|
||||
|
||||
CurrentAction = BattleActions[decidedAction];
|
||||
|
||||
Reference in new issue
Block a user