Skip to content

Commit f35a791

Browse files
committed
Align tutorial competition with timeout flow
1 parent 2fc30f7 commit f35a791

2 files changed

Lines changed: 64 additions & 15 deletions

File tree

Assets/Scripts/Game/Logic/CompetitionHandler.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ public class CompetitionHandler
5252
/// </summary>
5353
public void End() => IsActive = false;
5454

55+
/// <summary>
56+
/// タイムアウト判定の基準時刻を現在時刻へ更新
57+
/// </summary>
58+
public void ResetTimeout()
59+
{
60+
if (!IsActive) return;
61+
_lastActionTime = Time.time;
62+
}
63+
5564
/// <summary>
5665
/// プレイヤーが1枚上乗せ(任意の感情)
5766
/// </summary>

Assets/Scripts/Game/Logic/TutorialBattlePresenter.cs

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ public class TutorialCompetitionPhaseRunner : CompetitionPhaseRunner
301301
private readonly BattleUIPresenter _uiPresenter;
302302
private readonly int _requiredRaises;
303303
private readonly EmotionType _forcedEmotion;
304+
private const int EnemyRaiseDelayMinMilliseconds = 700;
305+
private const int EnemyRaiseDelayMaxMilliseconds = 1300;
304306

305307
public TutorialCompetitionPhaseRunner(
306308
Player player,
@@ -321,6 +323,10 @@ public override async UniTask<CompetitionHandler> RunAsync(CardModel card, int p
321323
{
322324
var handler = new CompetitionHandler();
323325
handler.Start(card, playerTotal, enemyTotal);
326+
var pendingEnemyRaiseCount = 0;
327+
var nextEnemyRaiseTime = 0f;
328+
329+
using var disposables = new CompositeDisposable();
324330
_uiPresenter.SetBattleInstruction(instruction);
325331
_uiPresenter.ShowCompetition(handler.PlayerTotal, handler.EnemyTotal, _player.EmotionResources);
326332
_uiPresenter.SetCompetitionEmotion(_forcedEmotion.GetPreviousEmotion());
@@ -335,24 +341,58 @@ await _uiPresenter.OnCompetitionEmotionSelected
335341
.Where(emotion => emotion == _forcedEmotion)
336342
.FirstAsync();
337343

344+
handler.ResetTimeout();
338345
_uiPresenter.SetCompetitionEmotionInteractable(false);
339346
_uiPresenter.SetCompetitionRaiseInteractable(true);
340-
341-
while (handler.PlayerRaises.Count < _requiredRaises)
347+
_uiPresenter.OnCompetitionRaise
348+
.Subscribe(_ =>
349+
{
350+
if (handler.PlayerRaises.Count >= _requiredRaises)
351+
return;
352+
353+
if (!handler.TryPlayerRaise(_forcedEmotion, _player))
354+
return;
355+
356+
SeManager.Instance.PlaySe(_forcedEmotion.ToResourceSeName(), pitch: 1f);
357+
_uiPresenter.UpdateCompetitionBids(handler.PlayerTotal, handler.EnemyTotal);
358+
_uiPresenter.UpdateCompetitionResources(_player.EmotionResources);
359+
360+
if (handler.PlayerRaises.Count >= _requiredRaises)
361+
{
362+
_uiPresenter.SetCompetitionRaiseInteractable(false);
363+
return;
364+
}
365+
366+
pendingEnemyRaiseCount++;
367+
if (pendingEnemyRaiseCount == 1)
368+
{
369+
nextEnemyRaiseTime = Time.time
370+
+ Random.Range(EnemyRaiseDelayMinMilliseconds, EnemyRaiseDelayMaxMilliseconds + 1) / 1000f;
371+
}
372+
})
373+
.AddTo(disposables);
374+
375+
while (handler.PlayerRaises.Count < _requiredRaises || !handler.IsTimedOut)
342376
{
343-
await _uiPresenter.OnCompetitionRaise.FirstAsync();
344-
if (!handler.TryPlayerRaise(_forcedEmotion, _player))
345-
continue;
346-
347-
SeManager.Instance.PlaySe(_forcedEmotion.ToResourceSeName(), pitch: 1f);
348-
_uiPresenter.UpdateCompetitionBids(handler.PlayerTotal, handler.EnemyTotal);
349-
_uiPresenter.UpdateCompetitionResources(_player.EmotionResources);
350-
351-
if (handler.PlayerRaises.Count >= _requiredRaises)
352-
break;
353-
354-
_enemyAI.TryCompetitionRaise(handler);
355-
_uiPresenter.UpdateCompetitionBids(handler.PlayerTotal, handler.EnemyTotal);
377+
var remainingTime = handler.PlayerRaises.Count < _requiredRaises
378+
? GameConstants.COMPETITION_TIMEOUT_SECONDS
379+
: handler.RemainingTime;
380+
_uiPresenter.UpdateCompetitionTimer(remainingTime, GameConstants.COMPETITION_TIMEOUT_SECONDS);
381+
382+
if (pendingEnemyRaiseCount > 0 && Time.time >= nextEnemyRaiseTime)
383+
{
384+
_enemyAI.TryCompetitionRaise(handler);
385+
pendingEnemyRaiseCount--;
386+
_uiPresenter.UpdateCompetitionBids(handler.PlayerTotal, handler.EnemyTotal);
387+
388+
if (pendingEnemyRaiseCount > 0)
389+
{
390+
nextEnemyRaiseTime = Time.time
391+
+ Random.Range(EnemyRaiseDelayMinMilliseconds, EnemyRaiseDelayMaxMilliseconds + 1) / 1000f;
392+
}
393+
}
394+
395+
await UniTask.Yield();
356396
}
357397

358398
_uiPresenter.SetCompetitionRaiseInteractable(false);

0 commit comments

Comments
 (0)