BlueGit

blue-star tribegen

Files

tribegen / web / src / Utilities / GameHelper.php

GameHelper.php

various fixes
timfa Tim · pushed by timfa · 9 months ago
49730f61 History
GameHelper.php 4.7 KiB Download Raw
1<?php
2
3class GameHelper
4{
5
6 /**
7 * Get stat display label from numeric value
8 */
9 public static function getStatLabel($value)
10 {
11 $value = max(0, min(100, $value));
12
13 if ($value >= 90)
14 return 'godlike';
15 if ($value >= 80)
16 return 'divine';
17 if ($value >= 70)
18 return 'master';
19 if ($value >= 60)
20 return 'fantastic';
21 if ($value >= 50)
22 return 'excellent';
23 if ($value >= 40)
24 return 'good';
25 if ($value >= 30)
26 return 'decent';
27 if ($value >= 20)
28 return 'unskilled';
29 if ($value >= 10)
30 return 'bad';
31 return 'terrible';
32 }
33
34 /**
35 * Roll 1d100 under value
36 */
37 public static function rollUnder($value)
38 {
39 $value = max(0, min(100, $value));
40 $roll = rand(1, 100);
41 return $roll <= $value;
42 }
43
44 /**
45 * Get age category for display
46 */
47 public static function getAgeCategory($age)
48 {
49 if ($age < 0)
50 return 'egg';
51 if ($age < 4)
52 return 'baby';
53 if ($age < 35)
54 return 'adult';
55 if ($age < 60)
56 return 'old';
57 return 'very_old';
58 }
59
60 /**
61 * Get sprite name for age category
62 */
63 public static function getAgeSprite($ageCategory)
64 {
65 $spriteMap = [
66 'egg' => 'egg',
67 'baby' => 'baby',
68 'young' => 'young',
69 'adult' => 'adult',
70 'old' => 'old'
71 ];
72
73 return $spriteMap[$ageCategory] ?? 'adult';
74 }
75
76 /**
77 * Get season for month number
78 */
79 public static function getSeason($month)
80 {
81 $seasons = ['spring', 'summer', 'autumn', 'winter'];
82 return $seasons[($month / 3) % 4];
83 }
84
85 /**
86 * Check if kobold can have old-age injury
87 */
88 public static function shouldCheckOldAgeInjury($age)
89 {
90 return $age >= 35;
91 }
92
93 /**
94 * Get stat value with age scaling
95 */
96 public static function getEffectiveStat($baseStat, $age)
97 {
98 $ageCategory = self::getAgeCategory($age);
99
100 // For babies and eggs, scale by age
101 if ($ageCategory === 'egg') {
102 return 0; // Eggs can't do anything
103 }
104
105 if ($ageCategory === 'baby') {
106 // Progress from 0 to 4 years = 0% to 100%
107 $progress = $age / 4;
108 return (int) ($baseStat * $progress);
109 }
110
111 // Adults at full value
112 return $baseStat;
113 }
114
115 /**
116 * Get random name from list
117 */
118 public static function getRandomKoboldName()
119 {
120 $names = [
121 'Zyx',
122 'Krellin',
123 'Tik',
124 'Borp',
125 'Schnax',
126 'Grell',
127 'Vix',
128 'Nok',
129 'Pix',
130 'Grin',
131 'Skitter',
132 'Blort',
133 'Zap',
134 'Clicket',
135 'Snort',
136 'Gik',
137 'Spork',
138 'Krunk',
139 'Vik',
140 'Tock',
141 'Blix',
142 'Zazzle',
143 'Sprocket',
144 'Klik',
145 'Fizz',
146 'Gorp',
147 'Skronk',
148 'Thrall',
149 'Glint',
150 'Zink',
151 'Plock',
152 'Bzzzt'
153 ];
154
155 return $names[array_rand($names)];
156 }
157
158 /**
159 * Generate random stats
160 */
161 public static function generateRandomStats()
162 {
163 $stats = [];
164 $statNames = ['vitality', 'intelligence', 'tinkering', 'medicine', 'crafting', 'personality', 'will'];
165
166 foreach ($statNames as $stat) {
167 $stats[$stat] = rand(0, 100);
168 }
169
170 return $stats;
171 }
172
173 /**
174 * Format story text (for narrative generation)
175 */
176 public static function formatStory($text)
177 {
178 // Could add markdown parsing, formatting, etc.
179 return nl2br(htmlspecialchars($text));
180 }
181
182 /**
183 * Get injury cure type
184 */
185 public static function getInjuryCure($injuryCategory)
186 {
187 $cureMap = [
188 'wound' => 'basic_medicine',
189 'fracture' => 'bone_setting',
190 'infection' => 'healing_herbs',
191 'poison' => 'antidote',
192 'burn' => 'burn_salve',
193 'malnourished' => 'food',
194 'old-age' => null
195 ];
196
197 return $cureMap[$injuryCategory] ?? null;
198 }
199
200 /**
201 * Check if injury is treatable
202 */
203 public static function isInjuryTreatable($injuryCategory)
204 {
205 return self::getInjuryCure($injuryCategory) !== null;
206 }
207
208 /**
209 * Capitalize words
210 */
211 public static function humanize($text)
212 {
213 return ucfirst(str_replace('_', ' ', $text));
214 }
215}