LCOV - code coverage report
Current view: top level - systems - debug_invincible.go Coverage Total Hit
Test: coverage.lcov Lines: 100.0 % 39 39
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package systems
       2              : 
       3              : import (
       4              :         gc "github.com/kijimaD/ruins/internal/components"
       5              :         w "github.com/kijimaD/ruins/internal/world"
       6              :         "github.com/mlange-42/ark/ecs"
       7              : )
       8              : 
       9              : // DebugInvincibleSystem はデバッグの無敵の間、プレイヤーの HP・体温・空腹・疲労を満たし、怪我や病気の不調を消し、倒れていれば起こす。
      10              : // 死の判定より前に毎フレーム走るので、致死の一撃を受けても死なない
      11              : type DebugInvincibleSystem struct{}
      12              : 
      13              : // String はシステム名を返す
      14              : // w.Updater interfaceを実装
      15              : func (sys DebugInvincibleSystem) String() string {
      16            1 :         return "DebugInvincibleSystem"
      17            1 : }
      18              : 
      19              : // Update はデバッグの無敵の間、プレイヤーを満たす
      20              : // w.Updater interfaceを実装
      21              : func (sys *DebugInvincibleSystem) Update(world w.World) error {
      22            1 :         cfg := world.Resources.Config
      23            1 :         if cfg == nil || !cfg.DebugInvincible {
      24            1 :                 return nil
      25            1 :         }
      26            1 :         var players []ecs.Entity
      27            1 :         q := ecs.NewFilter1[gc.Player](world.ECS).Query()
      28            1 :         for q.Next() {
      29            1 :                 players = append(players, q.Entity())
      30            1 :         }
      31            1 :         for _, p := range players {
      32            1 :                 if world.Components.Dead.Has(p) {
      33            1 :                         world.Components.Dead.Remove(p)
      34            1 :                 }
      35            1 :                 if world.Components.HP.Has(p) {
      36            1 :                         hp := world.Components.HP.Get(p)
      37            1 :                         hp.Current = hp.Max
      38            1 :                 }
      39            1 :                 if world.Components.HealthStatus.Has(p) {
      40            1 :                         hs := world.Components.HealthStatus.Get(p)
      41            1 :                         hs.BodyTempOffset = 0
      42            1 :                         healed := false
      43            1 :                         for i := range hs.Parts {
      44            1 :                                 if len(hs.Parts[i].Conditions) > 0 {
      45            1 :                                         hs.Parts[i].Conditions = nil
      46            1 :                                         healed = true
      47            1 :                                 }
      48              :                         }
      49              :                         // 不調は能力値を下げるので、消したら能力値を計算し直させる
      50            1 :                         if healed && !world.Components.StatsChanged.Has(p) {
      51            1 :                                 world.Components.StatsChanged.Add(p, &gc.StatsChanged{})
      52            1 :                         }
      53              :                 }
      54            1 :                 if world.Components.Hunger.Has(p) {
      55            1 :                         hunger := world.Components.Hunger.Get(p)
      56            1 :                         hunger.Current = hunger.Max
      57            1 :                 }
      58            1 :                 if world.Components.Fatigue.Has(p) {
      59            1 :                         world.Components.Fatigue.Get(p).Current = 0
      60            1 :                 }
      61              :         }
      62            1 :         return nil
      63              : }
        

Generated by: LCOV version 2.0-1