Line data Source code
1 : package components
2 :
3 : import "github.com/kijimaD/ruins/internal/rawschema"
4 :
5 : const (
6 : // DefaultMaxFatigue はデフォルトの最大疲労。起床中は毎ターン FatigueGainPerTurn 増える
7 : DefaultMaxFatigue = 2000
8 : // FatigueGainPerTurn は起床している間に毎ターン蓄積する疲労
9 : FatigueGainPerTurn = 1
10 : )
11 :
12 : // Fatigue は蓄積した疲労を表す。起きている間に増え、睡眠でのみ減る。
13 : // Current は Max でクランプし、上限に達しても死なず Exhausted のペナルティが続く
14 : type Fatigue Pool[int]
15 :
16 : // GetLevel は現在の疲労段階を返す。段階の境目は defs が持ち、Current/Max の比率で決める
17 : func (f *Fatigue) GetLevel(defs NeedDefs) rawschema.FatigueStageId {
18 1 : if f.Max <= 0 {
19 1 : return rawschema.FatigueStageIdRested
20 1 : }
21 1 : return defs.fatigueStage(float64(f.Current) / float64(f.Max)).Level
22 : }
23 :
24 : // FatigueSeverity は疲労段階を過労の不調の重症度へ写す。ok=false なら不調は立たない
25 : func (f *Fatigue) FatigueSeverity(defs NeedDefs) (Severity, bool) {
26 1 : if f.Max <= 0 {
27 0 : return SeverityNone, false
28 0 : }
29 1 : s := defs.fatigueStage(float64(f.Current) / float64(f.Max))
30 1 : return s.Condition, s.Condition != SeverityNone
31 : }
32 :
33 : // NewFatigue は新しい Fatigue を作成する。初期は疲れていない
34 : func NewFatigue() *Fatigue {
35 1 : return &Fatigue{
36 1 : Max: DefaultMaxFatigue,
37 1 : Current: 0,
38 1 : }
39 : }
|