BlueGit

blue-star tribegen

male/female sprites, fixed age calculations, injuries and curing

timfa Tim Falken · pushed by timfa

Authored 2026-01-28 · 9 months ago

Hash
c277cc746bb05caaf87ae2ee4ada52741aad2a64
Parent
025e6a5e
13 files changed +113 −108
web/assets/sprites/standard/adult.png deleted Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/adult_female.png added Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/adult_male.png added Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/old.png deleted Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/old_female.png added Binary file +0 −0

The contents of this binary file are not shown.

web/assets/sprites/standard/old_male.png added Binary file +0 −0

The contents of this binary file are not shown.

web/index.php +4 −0
@@ -45,6 +45,10 @@ if (strpos($path, '/api/') === 0) {
45 45 include __DIR__ . '/src/api/game.php';
46 46 } elseif ($apiPath === 'game/giveItem') {
47 47 include __DIR__ . '/src/api/game.php';
48 } elseif ($apiPath === 'game/returnItem') {
49 include __DIR__ . '/src/api/game.php';
50 } elseif ($apiPath === 'game/cureInjury') {
51 include __DIR__ . '/src/api/game.php';
48 52 } else {
49 53 http_response_code(404);
50 54 echo json_encode(['error' => 'Not found']);
@@ -45,6 +45,10 @@ if (strpos($path, '/api/') === 0) {
45 include __DIR__ . '/src/api/game.php';
45 include __DIR__ . '/src/api/game.php';
46 } elseif ($apiPath === 'game/giveItem') {
46 } elseif ($apiPath === 'game/giveItem') {
47 include __DIR__ . '/src/api/game.php';
47 include __DIR__ . '/src/api/game.php';
48 } elseif ($apiPath === 'game/returnItem') {
49 include __DIR__ . '/src/api/game.php';
50 } elseif ($apiPath === 'game/cureInjury') {
51 include __DIR__ . '/src/api/game.php';
48 } else {
52 } else {
49 http_response_code(404);
53 http_response_code(404);
50 echo json_encode(['error' => 'Not found']);
54 echo json_encode(['error' => 'Not found']);
web/js/app.js +27 −5
@@ -447,13 +447,21 @@ class TribeGenApp
447 447
448 448 this.currentTribe.kobolds.forEach(kobold =>
449 449 {
450 const spriteUrl = `api/game/sprite?userId=${this.currentUser.id}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;
450 451 const item = document.createElement('div');
451 452 item.className = 'tribe-item';
452 453 item.innerHTML = `
454 <table style="width:100%">
455 <td>
456 <img src="${spriteUrl}"/>
457 </td>
458 <td>
453 459 <div>
454 460 <div class="tribe-item-name">${kobold.name}</div>
455 461 <div class="tribe-item-age">${kobold.age} years</div>
456 462 </div>
463 </td>
464 </table>
457 465 `;
458 466 item.addEventListener('click', () => this.showKoboldModal(kobold));
459 467 list.appendChild(item);
@@ -768,7 +776,6 @@ class TribeGenApp
768 776 // Refresh game state
769 777 await this.loadGame(this.currentSave.id);
770 778 const kob = this.currentTribe.kobolds.find(k => k.id === koboldId);
771 if (kob) this.showKoboldModal(kob);
772 779 } else
773 780 {
774 781 alert(data.error || 'Failed to give item');
@@ -792,7 +799,7 @@ class TribeGenApp
792 799 {
793 800 const modal = document.getElementById('koboldModal');
794 801 document.getElementById('koboldModalName').textContent = kobold.name;
795 document.getElementById('koboldModalAge').textContent = `${kobold.age} years old`;
802 document.getElementById('koboldModalAge').textContent = `${(kobold.male ? "male" : "female")}, ${kobold.age} years old`;
796 803 document.getElementById('koboldModalDescription').textContent = `A ${kobold.ageCategory} Kobold`;
797 804
798 805 this.renderKoboldStats(kobold);
@@ -869,6 +876,17 @@ class TribeGenApp
869 876 return;
870 877 }
871 878
879 // Mapping of injury category to required cure item (matches PHP Injury::$cureMap)
880 const cureMap = {
881 'wound': 'basic_medicine',
882 'fracture': 'bone-setting',
883 'infection': 'healing_herbs',
884 'poison': 'antidote',
885 'burn': 'burn_salve',
886 'malnourished': 'food',
887 'old-age': null
888 };
889
872 890 kobold.injuries.forEach(injury =>
873 891 {
874 892 const el = document.createElement('div');
@@ -888,7 +906,13 @@ class TribeGenApp
888 906 // malnourished has no cure button here
889 907 if (injury.category !== 'malnourished')
890 908 {
891 const required = injury.required_medicine || injury.requiredMedicine || null;
909 // Get required medicine from server or calculate from cureMap
910 let required = injury.required_medicine || injury.requiredMedicine || null;
911 if (!required && injury.category)
912 {
913 required = cureMap[injury.category] || null;
914 }
915
892 916 if (required)
893 917 {
894 918 // check if kobold has item with this id
@@ -917,7 +941,6 @@ class TribeGenApp
917 941 await this.loadGame(this.currentSave.id);
918 942 // reopen kobold modal after refresh
919 943 const refreshed = this.currentTribe.kobolds.find(k => k.id === kobold.id);
920 if (refreshed) this.showKoboldModal(refreshed);
921 944 } else
922 945 {
923 946 alert(data.error || 'Failed to cure injury');
@@ -1005,7 +1028,6 @@ class TribeGenApp
1005 1028 // Refresh game state
1006 1029 await this.loadGame(this.currentSave.id);
1007 1030 const refreshed = this.currentTribe.kobolds.find(k => k.id === kobold.id);
1008 if (refreshed) this.showKoboldModal(refreshed);
1009 1031 } else
1010 1032 {
1011 1033 alert(data.error || 'Failed to return item');
@@ -447,13 +447,21 @@ class TribeGenApp
447
447
448 this.currentTribe.kobolds.forEach(kobold =>
448 this.currentTribe.kobolds.forEach(kobold =>
449 {
449 {
450 const spriteUrl = `api/game/sprite?userId=${this.currentUser.id}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;
450 const item = document.createElement('div');
451 const item = document.createElement('div');
451 item.className = 'tribe-item';
452 item.className = 'tribe-item';
452 item.innerHTML = `
453 item.innerHTML = `
454 <table style="width:100%">
455 <td>
456 <img src="${spriteUrl}"/>
457 </td>
458 <td>
453 <div>
459 <div>
454 <div class="tribe-item-name">${kobold.name}</div>
460 <div class="tribe-item-name">${kobold.name}</div>
455 <div class="tribe-item-age">${kobold.age} years</div>
461 <div class="tribe-item-age">${kobold.age} years</div>
456 </div>
462 </div>
463 </td>
464 </table>
457 `;
465 `;
458 item.addEventListener('click', () => this.showKoboldModal(kobold));
466 item.addEventListener('click', () => this.showKoboldModal(kobold));
459 list.appendChild(item);
467 list.appendChild(item);
@@ -768,7 +776,6 @@ class TribeGenApp
768 // Refresh game state
776 // Refresh game state
769 await this.loadGame(this.currentSave.id);
777 await this.loadGame(this.currentSave.id);
770 const kob = this.currentTribe.kobolds.find(k => k.id === koboldId);
778 const kob = this.currentTribe.kobolds.find(k => k.id === koboldId);
771 if (kob) this.showKoboldModal(kob);
772 } else
779 } else
773 {
780 {
774 alert(data.error || 'Failed to give item');
781 alert(data.error || 'Failed to give item');
@@ -792,7 +799,7 @@ class TribeGenApp
792 {
799 {
793 const modal = document.getElementById('koboldModal');
800 const modal = document.getElementById('koboldModal');
794 document.getElementById('koboldModalName').textContent = kobold.name;
801 document.getElementById('koboldModalName').textContent = kobold.name;
795 document.getElementById('koboldModalAge').textContent = `${kobold.age} years old`;
802 document.getElementById('koboldModalAge').textContent = `${(kobold.male ? "male" : "female")}, ${kobold.age} years old`;
796 document.getElementById('koboldModalDescription').textContent = `A ${kobold.ageCategory} Kobold`;
803 document.getElementById('koboldModalDescription').textContent = `A ${kobold.ageCategory} Kobold`;
797
804
798 this.renderKoboldStats(kobold);
805 this.renderKoboldStats(kobold);
@@ -869,6 +876,17 @@ class TribeGenApp
869 return;
876 return;
870 }
877 }
871
878
879 // Mapping of injury category to required cure item (matches PHP Injury::$cureMap)
880 const cureMap = {
881 'wound': 'basic_medicine',
882 'fracture': 'bone-setting',
883 'infection': 'healing_herbs',
884 'poison': 'antidote',
885 'burn': 'burn_salve',
886 'malnourished': 'food',
887 'old-age': null
888 };
889
872 kobold.injuries.forEach(injury =>
890 kobold.injuries.forEach(injury =>
873 {
891 {
874 const el = document.createElement('div');
892 const el = document.createElement('div');
@@ -888,7 +906,13 @@ class TribeGenApp
888 // malnourished has no cure button here
906 // malnourished has no cure button here
889 if (injury.category !== 'malnourished')
907 if (injury.category !== 'malnourished')
890 {
908 {
891 const required = injury.required_medicine || injury.requiredMedicine || null;
909 // Get required medicine from server or calculate from cureMap
910 let required = injury.required_medicine || injury.requiredMedicine || null;
911 if (!required && injury.category)
912 {
913 required = cureMap[injury.category] || null;
914 }
915
892 if (required)
916 if (required)
893 {
917 {
894 // check if kobold has item with this id
918 // check if kobold has item with this id
@@ -917,7 +941,6 @@ class TribeGenApp
917 await this.loadGame(this.currentSave.id);
941 await this.loadGame(this.currentSave.id);
918 // reopen kobold modal after refresh
942 // reopen kobold modal after refresh
919 const refreshed = this.currentTribe.kobolds.find(k => k.id === kobold.id);
943 const refreshed = this.currentTribe.kobolds.find(k => k.id === kobold.id);
920 if (refreshed) this.showKoboldModal(refreshed);
921 } else
944 } else
922 {
945 {
923 alert(data.error || 'Failed to cure injury');
946 alert(data.error || 'Failed to cure injury');
@@ -1005,7 +1028,6 @@ class TribeGenApp
1005 // Refresh game state
1028 // Refresh game state
1006 await this.loadGame(this.currentSave.id);
1029 await this.loadGame(this.currentSave.id);
1007 const refreshed = this.currentTribe.kobolds.find(k => k.id === kobold.id);
1030 const refreshed = this.currentTribe.kobolds.find(k => k.id === kobold.id);
1008 if (refreshed) this.showKoboldModal(refreshed);
1009 } else
1031 } else
1010 {
1032 {
1011 alert(data.error || 'Failed to return item');
1033 alert(data.error || 'Failed to return item');
web/src/Classes/Injury.php +1 −78
@@ -4,16 +4,9 @@ require_once __DIR__ . '/../../src/Database/Database.php';
4 4
5 5 class Injury
6 6 {
7 private $id;
8 private $injuryType;
9 private $description;
10 private $category;
11 private $severity;
12 private $statModifications = [];
13
14 7 private static $cureMap = [
15 8 'wound' => 'basic_medicine',
16 'fracture' => 'bone_setting',
9 'fracture' => 'bone-setting',
17 10 'infection' => 'healing_herbs',
18 11 'poison' => 'antidote',
19 12 'burn' => 'burn_salve',
@@ -21,78 +14,8 @@ class Injury
21 14 'old-age' => null // Cannot be cured
22 15 ];
23 16
24 public function __construct($id, $injuryType, $description, $category, $severity, $statModifications = [])
25 {
26 $this->id = $id;
27 $this->description = $description;
28 $this->injuryType = $injuryType;
29 $this->category = $category;
30 $this->severity = $severity;
31 $this->statModifications = $statModifications;
32 }
33
34 public static function load($id)
35 {
36 $db = Database::getInstance();
37 $pdo = $db->getPDO();
38
39 $stmt = $pdo->prepare("SELECT * FROM injuries WHERE id = ?");
40 $stmt->execute([$id]);
41 $row = $stmt->fetch();
42
43 if (!$row) {
44 return null;
45 }
46
47 return new self($row['id'], $row['kobold_id'], $row['injury_type'], $row['category'], $row['severity']);
48 }
49
50 public function getId()
51 {
52 return $this->id;
53 }
54
55 public function getInjuryType()
56 {
57 return $this->injuryType;
58 }
59
60 public function getCategory()
61 {
62 return $this->category;
63 }
64
65 public function getSeverity()
66 {
67 return $this->severity;
68 }
69
70 public function canBeCured()
71 {
72 return isset(self::$cureMap[$this->category]) && self::$cureMap[$this->category] !== null;
73 }
74
75 public function getRequiredMedicine()
76 {
77 return self::$cureMap[$this->category] ?? null;
78 }
79
80 17 public static function getCureForCategory($category)
81 18 {
82 19 return self::$cureMap[$category] ?? null;
83 20 }
84
85 public function getDescription()
86 {
87 return ucfirst(str_replace('_', ' ', $this->injuryType));
88 }
89
90 public function delete()
91 {
92 $db = Database::getInstance();
93 $pdo = $db->getPDO();
94
95 $stmt = $pdo->prepare("DELETE FROM injuries WHERE id = ?");
96 $stmt->execute([$this->id]);
97 }
98 21 }
@@ -4,16 +4,9 @@ require_once __DIR__ . '/../../src/Database/Database.php';
4
4
5class Injury
5class Injury
6{
6{
7 private $id;
8 private $injuryType;
9 private $description;
10 private $category;
11 private $severity;
12 private $statModifications = [];
13
14 private static $cureMap = [
7 private static $cureMap = [
15 'wound' => 'basic_medicine',
8 'wound' => 'basic_medicine',
16 'fracture' => 'bone_setting',
9 'fracture' => 'bone-setting',
17 'infection' => 'healing_herbs',
10 'infection' => 'healing_herbs',
18 'poison' => 'antidote',
11 'poison' => 'antidote',
19 'burn' => 'burn_salve',
12 'burn' => 'burn_salve',
@@ -21,78 +14,8 @@ class Injury
21 'old-age' => null // Cannot be cured
14 'old-age' => null // Cannot be cured
22 ];
15 ];
23
16
24 public function __construct($id, $injuryType, $description, $category, $severity, $statModifications = [])
25 {
26 $this->id = $id;
27 $this->description = $description;
28 $this->injuryType = $injuryType;
29 $this->category = $category;
30 $this->severity = $severity;
31 $this->statModifications = $statModifications;
32 }
33
34 public static function load($id)
35 {
36 $db = Database::getInstance();
37 $pdo = $db->getPDO();
38
39 $stmt = $pdo->prepare("SELECT * FROM injuries WHERE id = ?");
40 $stmt->execute([$id]);
41 $row = $stmt->fetch();
42
43 if (!$row) {
44 return null;
45 }
46
47 return new self($row['id'], $row['kobold_id'], $row['injury_type'], $row['category'], $row['severity']);
48 }
49
50 public function getId()
51 {
52 return $this->id;
53 }
54
55 public function getInjuryType()
56 {
57 return $this->injuryType;
58 }
59
60 public function getCategory()
61 {
62 return $this->category;
63 }
64
65 public function getSeverity()
66 {
67 return $this->severity;
68 }
69
70 public function canBeCured()
71 {
72 return isset(self::$cureMap[$this->category]) && self::$cureMap[$this->category] !== null;
73 }
74
75 public function getRequiredMedicine()
76 {
77 return self::$cureMap[$this->category] ?? null;
78 }
79
80 public static function getCureForCategory($category)
17 public static function getCureForCategory($category)
81 {
18 {
82 return self::$cureMap[$category] ?? null;
19 return self::$cureMap[$category] ?? null;
83 }
20 }
84
85 public function getDescription()
86 {
87 return ucfirst(str_replace('_', ' ', $this->injuryType));
88 }
89
90 public function delete()
91 {
92 $db = Database::getInstance();
93 $pdo = $db->getPDO();
94
95 $stmt = $pdo->prepare("DELETE FROM injuries WHERE id = ?");
96 $stmt->execute([$this->id]);
97 }
98}
21}
web/src/Classes/Kobold.php +38 −12
@@ -1,6 +1,7 @@
1 1 <?php
2 2
3 3 require_once __DIR__ . '/../../src/System/SaveManager.php';
4 require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
4 5
5 6 class Kobold
6 7 {
@@ -24,6 +25,8 @@ class Kobold
24 25 private $colourSecondary;
25 26 private $colourTertiary;
26 27
28 private $male;
29
27 30 private static $statNames = [
28 31 'vitality',
29 32 'intelligence',
@@ -43,6 +46,7 @@ class Kobold
43 46 $this->age = $age;
44 47 $this->spriteMorph = $spriteMorph;
45 48 $this->isLeader = $isLeader;
49 $this->male = rand(0, 100) > 50;
46 50
47 51 $min = 120;
48 52 $mx = 240;
@@ -76,6 +80,21 @@ class Kobold
76 80 }
77 81 }
78 82
83 public function he()
84 {
85 return $this->male ? "he" : "she";
86 }
87
88 public function him()
89 {
90 return $this->male ? "him" : "her";
91 }
92
93 public function his()
94 {
95 return $this->male ? "his" : "her";
96 }
97
79 98 public static function generate($userId, $saveId, $age = null)
80 99 {
81 100 if ($age === null) {
@@ -199,6 +218,7 @@ class Kobold
199 218 $kobold->items = $data['items'] ?? [];
200 219 $kobold->fatherId = $data['father_id'] ?? null;
201 220 $kobold->motherId = $data['mother_id'] ?? null;
221 $kobold->male = $data['male'] ?? rand(0, 100) > 50;
202 222
203 223 $kobold->colourPrimary = $data['colour_primary'] ?? '#FFFFFF';
204 224 $kobold->colourSecondary = $data['colour_secondary'] ?? '#FFFFFF';
@@ -225,7 +245,8 @@ class Kobold
225 245 'mother_id' => $this->motherId,
226 246 'colour_primary' => $this->colourPrimary,
227 247 'colour_secondary' => $this->colourSecondary,
228 'colour_tertiary' => $this->colourTertiary
248 'colour_tertiary' => $this->colourTertiary,
249 'male' => $this->male
229 250 ];
230 251 }
231 252
@@ -243,6 +264,10 @@ class Kobold
243 264 private function initializeSprite()
244 265 {
245 266 $ageSprite = $this->getAgeSpriteName();
267
268 if ($ageSprite === "old" || $ageSprite === "adult")
269 $ageSprite = $ageSprite . "_" . ($this->male ? "male" : "female");
270
246 271 $spriteDir = $this->saveManager->getKoboldSpritePathBase($this->userId, $this->id, $ageSprite);
247 272 $sourceFile = __DIR__ . '/../../assets/sprites/' . $this->spriteMorph . '/' . $ageSprite . '.png';
248 273 $destFile = $spriteDir;
@@ -267,7 +292,7 @@ class Kobold
267 292 'baby' => 'baby',
268 293 'young' => 'young',
269 294 'adult' => 'adult',
270 'old' => 'old' // Reuse old sprite for very_old
295 'old' => 'old'
271 296 ];
272 297
273 298 return $spriteMap[$ageCategory] ?? 'adult';
@@ -280,6 +305,10 @@ class Kobold
280 305 {
281 306 $spriteDir = $this->saveManager->getKoboldSpritePathBase($this->userId, $this->id, $age);
282 307 $ageSprite = $age ?? $this->getAgeSpriteName();
308
309 if ($ageSprite === "old" || $ageSprite === "adult")
310 $ageSprite = $ageSprite . "_" . ($this->male ? "male" : "female");
311
283 312 $destFile = $spriteDir;
284 313
285 314 if (!file_exists($destFile)) {
@@ -297,12 +326,17 @@ class Kobold
297 326 return $destFile;
298 327 }
299 328
329 public function getMale()
330 {
331 return $this->male;
332 }
333
300 334 public function getId()
301 335 {
302 336 return $this->id;
303 337 }
304 338
305 public function getName()
339 public function getName(): string
306 340 {
307 341 return $this->name;
308 342 }
@@ -329,15 +363,7 @@ class Kobold
329 363
330 364 public function getAgeCategory()
331 365 {
332 if ($this->age < 0)
333 return 'egg';
334 if ($this->age < 4)
335 return 'baby';
336 if ($this->age < 35)
337 return 'young';
338 if ($this->age < 60)
339 return 'adult';
340 return 'old';
366 return GameHelper::getAgeCategory($this->age);
341 367 }
342 368
343 369 public function getAgeProgress()
@@ -1,6 +1,7 @@
1<?php
1<?php
2
2
3require_once __DIR__ . '/../../src/System/SaveManager.php';
3require_once __DIR__ . '/../../src/System/SaveManager.php';
4require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
4
5
5class Kobold
6class Kobold
6{
7{
@@ -24,6 +25,8 @@ class Kobold
24 private $colourSecondary;
25 private $colourSecondary;
25 private $colourTertiary;
26 private $colourTertiary;
26
27
28 private $male;
29
27 private static $statNames = [
30 private static $statNames = [
28 'vitality',
31 'vitality',
29 'intelligence',
32 'intelligence',
@@ -43,6 +46,7 @@ class Kobold
43 $this->age = $age;
46 $this->age = $age;
44 $this->spriteMorph = $spriteMorph;
47 $this->spriteMorph = $spriteMorph;
45 $this->isLeader = $isLeader;
48 $this->isLeader = $isLeader;
49 $this->male = rand(0, 100) > 50;
46
50
47 $min = 120;
51 $min = 120;
48 $mx = 240;
52 $mx = 240;
@@ -76,6 +80,21 @@ class Kobold
76 }
80 }
77 }
81 }
78
82
83 public function he()
84 {
85 return $this->male ? "he" : "she";
86 }
87
88 public function him()
89 {
90 return $this->male ? "him" : "her";
91 }
92
93 public function his()
94 {
95 return $this->male ? "his" : "her";
96 }
97
79 public static function generate($userId, $saveId, $age = null)
98 public static function generate($userId, $saveId, $age = null)
80 {
99 {
81 if ($age === null) {
100 if ($age === null) {
@@ -199,6 +218,7 @@ class Kobold
199 $kobold->items = $data['items'] ?? [];
218 $kobold->items = $data['items'] ?? [];
200 $kobold->fatherId = $data['father_id'] ?? null;
219 $kobold->fatherId = $data['father_id'] ?? null;
201 $kobold->motherId = $data['mother_id'] ?? null;
220 $kobold->motherId = $data['mother_id'] ?? null;
221 $kobold->male = $data['male'] ?? rand(0, 100) > 50;
202
222
203 $kobold->colourPrimary = $data['colour_primary'] ?? '#FFFFFF';
223 $kobold->colourPrimary = $data['colour_primary'] ?? '#FFFFFF';
204 $kobold->colourSecondary = $data['colour_secondary'] ?? '#FFFFFF';
224 $kobold->colourSecondary = $data['colour_secondary'] ?? '#FFFFFF';
@@ -225,7 +245,8 @@ class Kobold
225 'mother_id' => $this->motherId,
245 'mother_id' => $this->motherId,
226 'colour_primary' => $this->colourPrimary,
246 'colour_primary' => $this->colourPrimary,
227 'colour_secondary' => $this->colourSecondary,
247 'colour_secondary' => $this->colourSecondary,
228 'colour_tertiary' => $this->colourTertiary
248 'colour_tertiary' => $this->colourTertiary,
249 'male' => $this->male
229 ];
250 ];
230 }
251 }
231
252
@@ -243,6 +264,10 @@ class Kobold
243 private function initializeSprite()
264 private function initializeSprite()
244 {
265 {
245 $ageSprite = $this->getAgeSpriteName();
266 $ageSprite = $this->getAgeSpriteName();
267
268 if ($ageSprite === "old" || $ageSprite === "adult")
269 $ageSprite = $ageSprite . "_" . ($this->male ? "male" : "female");
270
246 $spriteDir = $this->saveManager->getKoboldSpritePathBase($this->userId, $this->id, $ageSprite);
271 $spriteDir = $this->saveManager->getKoboldSpritePathBase($this->userId, $this->id, $ageSprite);
247 $sourceFile = __DIR__ . '/../../assets/sprites/' . $this->spriteMorph . '/' . $ageSprite . '.png';
272 $sourceFile = __DIR__ . '/../../assets/sprites/' . $this->spriteMorph . '/' . $ageSprite . '.png';
248 $destFile = $spriteDir;
273 $destFile = $spriteDir;
@@ -267,7 +292,7 @@ class Kobold
267 'baby' => 'baby',
292 'baby' => 'baby',
268 'young' => 'young',
293 'young' => 'young',
269 'adult' => 'adult',
294 'adult' => 'adult',
270 'old' => 'old' // Reuse old sprite for very_old
295 'old' => 'old'
271 ];
296 ];
272
297
273 return $spriteMap[$ageCategory] ?? 'adult';
298 return $spriteMap[$ageCategory] ?? 'adult';
@@ -280,6 +305,10 @@ class Kobold
280 {
305 {
281 $spriteDir = $this->saveManager->getKoboldSpritePathBase($this->userId, $this->id, $age);
306 $spriteDir = $this->saveManager->getKoboldSpritePathBase($this->userId, $this->id, $age);
282 $ageSprite = $age ?? $this->getAgeSpriteName();
307 $ageSprite = $age ?? $this->getAgeSpriteName();
308
309 if ($ageSprite === "old" || $ageSprite === "adult")
310 $ageSprite = $ageSprite . "_" . ($this->male ? "male" : "female");
311
283 $destFile = $spriteDir;
312 $destFile = $spriteDir;
284
313
285 if (!file_exists($destFile)) {
314 if (!file_exists($destFile)) {
@@ -297,12 +326,17 @@ class Kobold
297 return $destFile;
326 return $destFile;
298 }
327 }
299
328
329 public function getMale()
330 {
331 return $this->male;
332 }
333
300 public function getId()
334 public function getId()
301 {
335 {
302 return $this->id;
336 return $this->id;
303 }
337 }
304
338
305 public function getName()
339 public function getName(): string
306 {
340 {
307 return $this->name;
341 return $this->name;
308 }
342 }
@@ -329,15 +363,7 @@ class Kobold
329
363
330 public function getAgeCategory()
364 public function getAgeCategory()
331 {
365 {
332 if ($this->age < 0)
366 return GameHelper::getAgeCategory($this->age);
333 return 'egg';
334 if ($this->age < 4)
335 return 'baby';
336 if ($this->age < 35)
337 return 'young';
338 if ($this->age < 60)
339 return 'adult';
340 return 'old';
341 }
367 }
342
368
343 public function getAgeProgress()
369 public function getAgeProgress()
web/src/Events/ExplorationEvent.php +18 −8
@@ -57,8 +57,7 @@ class ExplorationEvent extends Event
57 57 $this->story .= "The terrain was barren. No food was found.\n\n";
58 58 }
59 59
60 // Chance for injury (large chance for testing) - someone trips on loose stone
61 $injuryChance = rand(1, 100) <= 99; // higher for testing
60 $injuryChance = rand(1, 100) <= 20;
62 61 if ($injuryChance && count($explorers) > 0) {
63 62
64 63 // Select a random explorer to get injured
@@ -71,13 +70,24 @@ class ExplorationEvent extends Event
71 70 $this->story .= $injuredKobold->getName() . " broke a leg!\n";
72 71 }
73 72
74 // For testing: add a 'bone-setting' item to tribe storage so player can cure fractures
75 $boneItem = GameHelper::loadItem('bone-setting');
76 if ($boneItem) {
77 $this->tribe->addToStorage($boneItem);
78 $this->story .= "The explorers also salvaged a Bone-setting kit and brought it back to storage.\n";
73 $stickFound = rand(1, 100) <= 20;
74 if ($stickFound) {
75 $bestKobold = GameHelper::findBestKoboldForStat($explorers, "crafting");
76
77 $success = $bestKobold->checkStat("crafting");
78
79 if ($success) {
80 $boneItem = GameHelper::loadItem('bone-setting');
81 if ($boneItem) {
82 $this->tribe->addToStorage($boneItem);
83 $this->story .= "The explorers also salvaged a Bone-setting kit and brought it back to storage.\n";
84 }
85 }
86 else
87 {
88 $this->story .= "$bestKobold->getName() finds a stick suitable to be a splint, but it breaks as $bestKobold->he() tries to craft it.\n";
89 }
79 90 }
80
81 91 $this->story .= "\nThe exploration party returned to the tribe with their findings.";
82 92
83 93 return $this->story;
@@ -57,8 +57,7 @@ class ExplorationEvent extends Event
57 $this->story .= "The terrain was barren. No food was found.\n\n";
57 $this->story .= "The terrain was barren. No food was found.\n\n";
58 }
58 }
59
59
60 // Chance for injury (large chance for testing) - someone trips on loose stone
60 $injuryChance = rand(1, 100) <= 20;
61 $injuryChance = rand(1, 100) <= 99; // higher for testing
62 if ($injuryChance && count($explorers) > 0) {
61 if ($injuryChance && count($explorers) > 0) {
63
62
64 // Select a random explorer to get injured
63 // Select a random explorer to get injured
@@ -71,13 +70,24 @@ class ExplorationEvent extends Event
71 $this->story .= $injuredKobold->getName() . " broke a leg!\n";
70 $this->story .= $injuredKobold->getName() . " broke a leg!\n";
72 }
71 }
73
72
74 // For testing: add a 'bone-setting' item to tribe storage so player can cure fractures
73 $stickFound = rand(1, 100) <= 20;
75 $boneItem = GameHelper::loadItem('bone-setting');
74 if ($stickFound) {
76 if ($boneItem) {
75 $bestKobold = GameHelper::findBestKoboldForStat($explorers, "crafting");
77 $this->tribe->addToStorage($boneItem);
76
78 $this->story .= "The explorers also salvaged a Bone-setting kit and brought it back to storage.\n";
77 $success = $bestKobold->checkStat("crafting");
78
79 if ($success) {
80 $boneItem = GameHelper::loadItem('bone-setting');
81 if ($boneItem) {
82 $this->tribe->addToStorage($boneItem);
83 $this->story .= "The explorers also salvaged a Bone-setting kit and brought it back to storage.\n";
84 }
85 }
86 else
87 {
88 $this->story .= "$bestKobold->getName() finds a stick suitable to be a splint, but it breaks as $bestKobold->he() tries to craft it.\n";
89 }
79 }
90 }
80
81 $this->story .= "\nThe exploration party returned to the tribe with their findings.";
91 $this->story .= "\nThe exploration party returned to the tribe with their findings.";
82
92
83 return $this->story;
93 return $this->story;
web/src/Utilities/GameHelper.php +22 −4
@@ -50,11 +50,12 @@ class GameHelper
50 50 return 'egg';
51 51 if ($age < 4)
52 52 return 'baby';
53 if ($age < 35)
53 if ($age < 17)
54 return 'young';
55 if ($age < 40)
54 56 return 'adult';
55 if ($age < 60)
56 return 'old';
57 return 'very_old';
57
58 return 'old';
58 59 }
59 60
60 61 /**
@@ -275,7 +276,24 @@ class GameHelper
275 276 $inj['category'] = $data['category'] ?? null;
276 277 $inj['severity'] = $data['severity'] ?? ($data['severity'] ?? 1);
277 278 $inj['stat_modifications'] = $data['statModifications'] ?? $data['stat_modifications'] ?? [];
279 $inj['required_medicine'] = Injury::getCureForCategory($inj['category']);
278 280
279 281 return $inj;
280 282 }
283
284 public static function findBestKoboldForStat(array $kobolds, string $skillId): Kobold
285 {
286 $highest = -1;
287 $selected = null;
288
289 for ($k = 0; $k < count($kobolds); $k++) {
290 $kobold = $kobolds[$k];
291 if ($kobold->stats[$skillId] > $highest) {
292 $highest = $kobold->stats[$skillId];
293 $selected = $kobold;
294 }
295 }
296
297 return $selected;
298 }
281 299 }
@@ -50,11 +50,12 @@ class GameHelper
50 return 'egg';
50 return 'egg';
51 if ($age < 4)
51 if ($age < 4)
52 return 'baby';
52 return 'baby';
53 if ($age < 35)
53 if ($age < 17)
54 return 'young';
55 if ($age < 40)
54 return 'adult';
56 return 'adult';
55 if ($age < 60)
57
56 return 'old';
58 return 'old';
57 return 'very_old';
58 }
59 }
59
60
60 /**
61 /**
@@ -275,7 +276,24 @@ class GameHelper
275 $inj['category'] = $data['category'] ?? null;
276 $inj['category'] = $data['category'] ?? null;
276 $inj['severity'] = $data['severity'] ?? ($data['severity'] ?? 1);
277 $inj['severity'] = $data['severity'] ?? ($data['severity'] ?? 1);
277 $inj['stat_modifications'] = $data['statModifications'] ?? $data['stat_modifications'] ?? [];
278 $inj['stat_modifications'] = $data['statModifications'] ?? $data['stat_modifications'] ?? [];
279 $inj['required_medicine'] = Injury::getCureForCategory($inj['category']);
278
280
279 return $inj;
281 return $inj;
280 }
282 }
283
284 public static function findBestKoboldForStat(array $kobolds, string $skillId): Kobold
285 {
286 $highest = -1;
287 $selected = null;
288
289 for ($k = 0; $k < count($kobolds); $k++) {
290 $kobold = $kobolds[$k];
291 if ($kobold->stats[$skillId] > $highest) {
292 $highest = $kobold->stats[$skillId];
293 $selected = $kobold;
294 }
295 }
296
297 return $selected;
298 }
281}
299}
web/src/api/game.php +3 −1
@@ -5,6 +5,7 @@ require_once __DIR__ . '/../../src/Database/Database.php';
5 5 require_once __DIR__ . '/../../src/Classes/User.php';
6 6 require_once __DIR__ . '/../../src/Classes/Tribe.php';
7 7 require_once __DIR__ . '/../../src/Classes/Kobold.php';
8 require_once __DIR__ . '/../../src/Classes/Injury.php';
8 9 require_once __DIR__ . '/../../src/System/SaveManager.php';
9 10
10 11 foreach (glob(__DIR__ . "/../../src/Events/*Event.php") as $file) {
@@ -530,7 +531,8 @@ if ($method === 'POST') {
530 531 'will' => $kobold->getStat('will')
531 532 ],
532 533 'items' => $kobold->getItems() ?? [],
533 'injuries' => $kInjuries
534 'injuries' => $kInjuries,
535 'male' => $kobold->getMale()
534 536 ];
535 537 }
536 538
@@ -5,6 +5,7 @@ require_once __DIR__ . '/../../src/Database/Database.php';
5require_once __DIR__ . '/../../src/Classes/User.php';
5require_once __DIR__ . '/../../src/Classes/User.php';
6require_once __DIR__ . '/../../src/Classes/Tribe.php';
6require_once __DIR__ . '/../../src/Classes/Tribe.php';
7require_once __DIR__ . '/../../src/Classes/Kobold.php';
7require_once __DIR__ . '/../../src/Classes/Kobold.php';
8require_once __DIR__ . '/../../src/Classes/Injury.php';
8require_once __DIR__ . '/../../src/System/SaveManager.php';
9require_once __DIR__ . '/../../src/System/SaveManager.php';
9
10
10foreach (glob(__DIR__ . "/../../src/Events/*Event.php") as $file) {
11foreach (glob(__DIR__ . "/../../src/Events/*Event.php") as $file) {
@@ -530,7 +531,8 @@ if ($method === 'POST') {
530 'will' => $kobold->getStat('will')
531 'will' => $kobold->getStat('will')
531 ],
532 ],
532 'items' => $kobold->getItems() ?? [],
533 'items' => $kobold->getItems() ?? [],
533 'injuries' => $kInjuries
534 'injuries' => $kInjuries,
535 'male' => $kobold->getMale()
534 ];
536 ];
535 }
537 }
536
538