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

            Line data    Source code
       1              : package query
       2              : 
       3              : import (
       4              :         gc "github.com/kijimaD/ruins/internal/components"
       5              :         "github.com/kijimaD/ruins/internal/consts"
       6              :         "github.com/kijimaD/ruins/internal/rawschema"
       7              :         w "github.com/kijimaD/ruins/internal/world"
       8              :         "github.com/mlange-42/ark/ecs"
       9              : )
      10              : 
      11              : // 代謝の定数。値は実プレイで調整する
      12              : const (
      13              :         // metabolismVitBonus は VIT 1 あたり回復へ足す%
      14              :         metabolismVitBonus = 3
      15              :         // metabolismSleepingBonus は睡眠中に回復へ足す基準%。寝具 Quality を掛ける
      16              :         metabolismSleepingBonus = 50
      17              : )
      18              : 
      19              : // RecoverySources は回復レートへの寄与を内訳として返す。命中・速度と同じ 熟練 × 身体機能 の形で、
      20              : // 熟練側は VIT・睡眠の加算、身体機能側は代謝の値の乗算差分として載せる。空腹・疲労は代謝を、
      21              : // 意識は行動を下げるが回復には効かせない。痛くても傷は治るので痛みも回復には効かない。
      22              : // Metabolism と Effects タブが同じこの導出を読むので値と内訳がずれない
      23              : func RecoverySources(world w.World, entity ecs.Entity) []gc.ProficiencySource {
      24            1 :         var srcs []gc.ProficiencySource
      25            1 : 
      26              :         // 熟練側。基準 100 に VIT・睡眠を積む
      27            1 :         prof := int(consts.PercentBase)
      28            1 :         if world.Components.Abilities.Has(entity) {
      29            1 :                 vit := world.Components.Abilities.Get(entity).Vitality.Total
      30            1 :                 if v := vit * metabolismVitBonus; v != 0 {
      31            1 :                         srcs = append(srcs, gc.ProficiencySource{Kind: gc.SourceAbility, Ability: rawschema.Vit, Amount: vit, Value: v})
      32            1 :                         prof += v
      33            1 :                 }
      34              :         }
      35            1 :         if world.Components.Sleeping.Has(entity) {
      36            1 :                 quality := world.Components.Sleeping.Get(entity).Quality
      37            1 :                 if v := quality.ApplyInt(metabolismSleepingBonus); v != 0 {
      38            1 :                         srcs = append(srcs, gc.ProficiencySource{Kind: gc.SourceSleeping, Value: v})
      39            1 :                         prof += v
      40            1 :                 }
      41              :         }
      42              : 
      43              :         // 身体機能側。代謝の値を熟練へ乗算し、内訳には加法差分で載せる。命中の畳み込みと同じ形
      44            1 :         metab := EffectiveBodyFuncs(world, entity).Metabolism
      45            1 :         if withCap := metab.ApplyInt(prof); withCap != prof {
      46            1 :                 srcs = append(srcs, gc.ProficiencySource{Kind: gc.SourceBodyFunc, BodyFunc: gc.BodyFuncMetabolism, Amount: int(metab), Value: withCap - prof})
      47            1 :         }
      48            1 :         return srcs
      49              : }
      50              : 
      51              : // Metabolism は HP の自然回復と病気の回復にかかる速度係数を返す。基準は 100、下限は 0。
      52              : // RecoverySources の合計を取る
      53              : func Metabolism(world w.World, entity ecs.Entity) consts.Percent {
      54            1 :         total := int(consts.PercentBase)
      55            1 :         for _, s := range RecoverySources(world, entity) {
      56            1 :                 total += s.Value
      57            1 :         }
      58            1 :         return consts.Percent(max(total, 0))
      59              : }
        

Generated by: LCOV version 2.0-1