-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnutrition.gd
More file actions
142 lines (120 loc) · 3.82 KB
/
nutrition.gd
File metadata and controls
142 lines (120 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class_name Nutrition
extends RefCounted
enum Status {
DEAD, # <= -200
STARVING, # -100 to -199
FAINTING, # -1 to -99
WEAK, # 0 to 49
HUNGRY, # 50 to 149
NORMAL, # 150 to 999
SATIATED, # 1000 to 2000
OVERSATIATED, # > 2000 (Risk of choking!)
}
const STARTING_NUTRITION := 900
const MAX_NUTRITION := 2000
const THRESHOLD_OVERSATIATED := 2000
const THRESHOLD_SATIATED := 1000
const THRESHOLD_NORMAL := 150
const THRESHOLD_HUNGRY := 50
const THRESHOLD_WEAK := 0
const THRESHOLD_FAINTING := -1
const THRESHOLD_STARVING := -100
const THRESHOLD_DEAD := -200
class NutritionChangeResult:
var message: String = ""
var choking: bool = false
var died: bool = false
var value: int = STARTING_NUTRITION
func decrease(amount: int) -> NutritionChangeResult:
var result := NutritionChangeResult.new()
var old_value := value
value = maxi(THRESHOLD_DEAD, value - amount)
# Check if we crossed any thresholds and set appropriate messages
if old_value >= THRESHOLD_NORMAL and value < THRESHOLD_NORMAL:
result.message = "You are beginning to feel hungry."
elif old_value >= THRESHOLD_WEAK and value < THRESHOLD_WEAK:
result.message = "You are getting weak from hunger."
elif old_value >= THRESHOLD_FAINTING and value < THRESHOLD_FAINTING:
result.message = "You feel faint from hunger."
elif old_value >= THRESHOLD_STARVING and value < THRESHOLD_STARVING:
result.message = "You are starving!"
elif value <= THRESHOLD_DEAD:
result.message = "You die from starvation."
result.died = true
return result
func increase(amount: int) -> NutritionChangeResult:
var result := NutritionChangeResult.new()
var old_value := value
value = mini(value + amount, THRESHOLD_OVERSATIATED + 200) # Allow slight overflow for choking check
# Check for choking when going over maximum
if value > THRESHOLD_OVERSATIATED:
if old_value <= THRESHOLD_OVERSATIATED:
result.message = "You're having a hard time getting all of it down."
# NetHack-style choking check: roll d20, choke on 1
if Dice.roll(1, 20) == 1:
result.message = "You choke over your food!"
result.choking = true
result.died = true
return result
func get_status() -> Status:
if value <= THRESHOLD_DEAD:
return Status.DEAD
elif value <= THRESHOLD_STARVING:
return Status.STARVING
elif value <= THRESHOLD_FAINTING:
return Status.FAINTING
elif value <= THRESHOLD_WEAK:
return Status.WEAK
elif value <= THRESHOLD_HUNGRY:
return Status.HUNGRY
elif value <= THRESHOLD_SATIATED:
return Status.NORMAL
elif value <= THRESHOLD_OVERSATIATED:
return Status.SATIATED
else:
return Status.OVERSATIATED
static func get_status_name(status: Status) -> String:
match status:
Status.DEAD:
return "Dead"
Status.STARVING:
return "Starving"
Status.FAINTING:
return "Fainting"
Status.WEAK:
return "Weak"
Status.HUNGRY:
return "Hungry"
Status.NORMAL:
return "" # No display when normal
Status.SATIATED:
return "Satiated"
Status.OVERSATIATED:
return "Oversatiated"
_:
return "Unknown"
static func get_status_rich_text_label(status: Status) -> String:
var red := GameColors.RED.to_html()
var orange := GameColors.ORANGE.to_html()
var yellow := GameColors.YELLOW.to_html()
var green := GameColors.GREEN.to_html()
var gray := GameColors.SUBTLE.to_html()
match status:
Status.DEAD:
return "[color=%s]Dead[/color]" % gray
Status.STARVING:
return "[color=%s][pulse]Starving[/pulse][/color]" % red
Status.FAINTING:
return "[color=%s][pulse]Fainting[/pulse][/color]" % orange
Status.WEAK:
return "[color=%s][pulse]Weak[/pulse][/color]" % orange
Status.HUNGRY:
return "[color=%s]Hungry[/color]" % yellow
Status.NORMAL:
return "" # No display when normal
Status.SATIATED:
return "[color=%s]Satiated[/color]" % green
Status.OVERSATIATED:
return "[color=%s][pulse]Oversatiated[/pulse][/color]" % red
_:
return "Unknown"