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

            Line data    Source code
       1              : package components
       2              : 
       3              : import "github.com/kijimaD/ruins/internal/rawschema"
       4              : 
       5              : const (
       6              :         // DefaultMaxHunger はデフォルトの最大満腹度
       7              :         DefaultMaxHunger = 500
       8              :         // DefaultInitialHunger はデフォルトの初期満腹度
       9              :         DefaultInitialHunger = 400
      10              :         // HungerDrainTurns は満腹度が1減るまでの平均ターン数の基準。空腹進行100%のときの値。
      11              :         // 大きくするほど空腹の進行が緩やかになる。progressHunger が確率ゲートの分母に使う。
      12              :         HungerDrainTurns = 3
      13              : )
      14              : 
      15              : // Hunger は空腹度を表す。プレイヤーなどのキャラクターが保持する。
      16              : // 0が飢餓状態、値が大きいほど満腹
      17              : type Hunger Pool[int]
      18              : 
      19              : // GetLevel は現在の空腹度レベルを取得する。段階の境目は defs が持つ
      20              : func (h *Hunger) GetLevel(defs NeedDefs) rawschema.HungerStageId {
      21            1 :         if h.Max <= 0 {
      22            1 :                 return rawschema.HungerStageIdSatiated
      23            1 :         }
      24            1 :         return defs.hungerStage(float64(h.Current) / float64(h.Max)).Level
      25              : }
      26              : 
      27              : // Increase は満腹度を増加させる(食事によって満腹になる)
      28              : func (h *Hunger) Increase(amount int) {
      29            1 :         h.Current += amount
      30            1 :         if h.Current > h.Max {
      31            1 :                 h.Current = h.Max
      32            1 :         }
      33            1 :         if h.Current < 0 {
      34            1 :                 h.Current = 0
      35            1 :         }
      36              : }
      37              : 
      38              : // Decrease は満腹度を減少させる(行動によって腹が減る)
      39              : func (h *Hunger) Decrease(amount int) {
      40            1 :         h.Current -= amount
      41            1 :         if h.Current < 0 {
      42            1 :                 h.Current = 0
      43            1 :         }
      44              : }
      45              : 
      46              : // NewHunger は新しいHungerを作成する
      47              : func NewHunger() *Hunger {
      48            1 :         return &Hunger{
      49            1 :                 Max:     DefaultMaxHunger,     // 最大満腹度
      50            1 :                 Current: DefaultInitialHunger, // 初期状態は満腹
      51            1 :         }
      52              : }
        

Generated by: LCOV version 2.0-1