LCOV - code coverage report
Current view: top level - activity - wait.go Coverage Total Hit
Test: coverage.lcov Lines: 95.3 % 43 41
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package activity
       2              : 
       3              : import (
       4              :         gc "github.com/kijimaD/ruins/internal/components"
       5              :         "github.com/kijimaD/ruins/internal/consts"
       6              :         "github.com/kijimaD/ruins/internal/gamelog"
       7              :         w "github.com/kijimaD/ruins/internal/world"
       8              : 
       9              :         "github.com/kijimaD/ruins/internal/world/query"
      10              :         "github.com/mlange-42/ark/ecs"
      11              : )
      12              : 
      13              : // WaitBehavior はBehaviorの実装
      14              : type WaitBehavior struct{}
      15              : 
      16              : // Info はBehaviorの実装
      17              : func (wb *WaitBehavior) Info() Info {
      18            1 :         return Info{
      19            1 :                 Name:            "Wait",
      20            1 :                 Description:     "Wait for a specified amount of time",
      21            1 :                 Interruptible:   true,
      22            1 :                 Resumable:       true,
      23            1 :                 ActionPointCost: consts.StandardActionCost,
      24            1 :         }
      25              : }
      26              : 
      27              : // Name はBehaviorの実装
      28              : func (wb *WaitBehavior) Name() gc.BehaviorName {
      29            1 :         return gc.BehaviorWait
      30            1 : }
      31              : 
      32              : // NewWaitActivity は待機回数を指定して待機アクティビティを組む。待機は時間経過なので
      33              : // Progress.Max に待機回数を直接据える。
      34              : func NewWaitActivity(duration consts.Turn) *gc.Activity {
      35            1 :         turns := int(duration)
      36            1 :         if turns <= 0 {
      37            0 :                 turns = 1
      38            0 :         }
      39            1 :         return NewActivity(gc.BehaviorWait, turns)
      40              : }
      41              : 
      42              : // Validate は待機アクティビティの検証を行う
      43              : func (wb *WaitBehavior) Validate(comp *gc.Activity, _ ecs.Entity, _ w.World) error {
      44              :         // 待機は基本的に常に実行可能
      45              :         // ただし、最低限のチェックは行う
      46              : 
      47            1 :         if comp.Progress.Max <= 0 {
      48            1 :                 return ErrWaitInvalidDuration
      49            1 :         }
      50              : 
      51            1 :         return nil
      52              : }
      53              : 
      54              : // Start は待機開始時の処理を実行する
      55              : func (wb *WaitBehavior) Start(comp *gc.Activity, actor ecs.Entity, _ w.World) error {
      56            1 :         log.Debug("wait started", "actor", actor, "required", comp.Progress.Max)
      57            1 :         return nil
      58            1 : }
      59              : 
      60              : // DoTurn は待機アクティビティの1ターン分の処理を実行する
      61              : func (wb *WaitBehavior) DoTurn(comp *gc.Activity, actor ecs.Entity, world w.World) error {
      62              :         // 長い待機は敵が近づいたら中断する。1回だけのターン送りとAIの手番調整は
      63              :         // その場で完結する行動なので対象にしない
      64            1 :         if comp.Progress.Max > 1 && !query.IsAreaSafe(world, actor) {
      65            1 :                 Cancel(comp, "wait interrupted because enemies are nearby")
      66            1 :                 return nil
      67            1 :         }
      68              : 
      69              :         // 1ターン進行
      70            1 :         comp.Progress.Current++
      71            1 :         log.Debug("wait progressing", "progress", GetProgressPercent(comp))
      72            1 : 
      73              :         // 完了チェック
      74            1 :         if comp.Progress.Current >= comp.Progress.Max {
      75            1 :                 Complete(comp)
      76            1 :         }
      77              : 
      78            1 :         return nil
      79              : }
      80              : 
      81              : // Finish は待機完了時の処理を実行する
      82              : func (wb *WaitBehavior) Finish(comp *gc.Activity, actor ecs.Entity, world w.World) error {
      83            1 :         log.Debug("wait finished", "actor", actor)
      84            1 : 
      85              :         // 複数ターン待機の場合のみログを表示する
      86            1 :         if comp.Progress.Max > 1 && world.Components.Player.Has(actor) {
      87            1 :                 gamelog.New(query.GetGameLog(world)).
      88            1 :                         Markup(query.T(world, "Finished waiting")).
      89            1 :                         Log()
      90            1 :         }
      91              : 
      92            1 :         return nil
      93              : }
      94              : 
      95              : // Canceled は待機キャンセル時の処理を実行する
      96              : func (wb *WaitBehavior) Canceled(comp *gc.Activity, actor ecs.Entity, _ w.World) error {
      97            1 :         log.Debug("wait canceled", "actor", actor, "reason", comp.CancelReason)
      98            1 :         return nil
      99            1 : }
        

Generated by: LCOV version 2.0-1