Skip to content

ターン制バトル機能を追加#39

Merged
orukahairuka merged 13 commits intodevelopfrom
feature/battle
Feb 18, 2026
Merged

ターン制バトル機能を追加#39
orukahairuka merged 13 commits intodevelopfrom
feature/battle

Conversation

@orukahairuka
Copy link
Contributor

@orukahairuka orukahairuka commented Feb 18, 2026

Summary

  • Supabase Realtime Broadcast を使ったターン制バトル機能を追加
  • マッチング(バトル作成 / 参加)からバトル画面への自動遷移
  • ready ハンドシェイクによる両者同期後にターン開始
  • 勝敗判定・DB 記録・結果画面表示

主な変更

  • Model/BattlePhase.swift — バトル進行状態の enum
  • Model/BattleDTO.swift — バトル用 DTO 追加(BattleFullRow / MonsterLabelRow / BattleFinishUpdate)
  • ViewModel/BattleViewModel.swift — バトルロジック + Broadcast 同期
  • ViewModel/BattleMatchingViewModel.swift — マッチ成立後の自動遷移・キャンセル処理
  • View/BattleGameView.swift — バトル UI(HP バー・攻撃ボタン・ログ)
  • View/BattleView.swift — セクション struct 化・バトル中タブバー非表示

対応した問題

  • 古い waiting バトルへの誤参加 → 5 分以内フィルタ + キャンセル時 DB 更新
  • Player 1 が waiting のまま stuck → Realtime 購読後の DB フォールバック
  • joinBattle の競合 → 楽観的排他制御(status=waiting の条件付き UPDATE)
  • prepare 失敗で画面 stuck → エラー時 phase = .lost
  • 攻撃 Broadcast 消失 → await 後に勝利判定
  • 終了後のイベント処理 → phase == .battling ガード
  • 同時キルで phase 上書き → 勝利判定前に phase 確認
  • 相手不在で画面固まる → ready ハンドシェイク 10 秒タイムアウト

Test plan

  • バトル作成 → 相手が参加 → ターン制バトルが正常に進行する
  • 勝利 / 敗北後に「戻る」で idle 画面に戻れる
  • バトル中にタブバーが非表示になる
  • 相手不在のバトルに参加した場合、10 秒後にエラー表示される
  • キャンセルしたバトルに他プレイヤーが参加できない

🤖 Generated with Claude Code

orukahairuka and others added 6 commits February 18, 2026 11:36
…ePhase enum を追加

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Broadcast で攻撃イベントを同期し、HP バー・攻撃ボタン・ログを表示する

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
.matched を廃止し、マッチ成立で直接 .battling → BattleGameView に遷移する

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
古い放置バトルに参加してしまう問題を防ぐ

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
放置された waiting バトルに別端末が参加してしまう問題を修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@orukahairuka orukahairuka self-assigned this Feb 18, 2026
orukahairuka and others added 7 commits February 18, 2026 13:30
BattleGameView に onFinish を追加し、BattleView のセクションを private struct に分離

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
購読が完了する前に相手が参加した場合の通知見逃しを防ぐ

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
status=waiting の条件を付けて同時参加による上書きを防止する

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
player2 未設定時に最大5回リトライし、Broadcast の ready 交換後にターンを開始する

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- prepare 失敗時に phase = .lost で結果画面に遷移し戻れるようにする
- broadcast を await してから勝利判定することで cleanup による消失を防ぐ
- handleOpponentAttack / handleOpponentReady に phase チェックを追加

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
broadcast の await 中に相手の攻撃で .lost になった場合、
勝利判定をスキップするよう phase == .battling ガードを追加

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
相手が離脱済みのバトルに参加した場合に画面が固まる問題を修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@orukahairuka orukahairuka merged commit 5ff24ad into develop Feb 18, 2026
@orukahairuka orukahairuka deleted the feature/battle branch February 18, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant