BlueGit

blue-star tribegen

Files

tribegen / web / src / Utilities / GameHelper.php

GameHelper.php

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