BlueGit

blue-star tribegen

hunt

timfa Tim · pushed by timfa

Authored 2026-01-30 · 9 months ago

Hash
635c19a31e0f29c74ce5147697b176bf0130b388
Parent
abf13f94
3 files changed +201 −13
web/src/Classes/Kobold.php +10 −1
@@ -460,6 +460,13 @@ class Kobold
460 460
461 461 public function addInjury($injuryType)
462 462 {
463 // Reject duplicates
464 foreach ($this->injuries as $inj) {
465 if (($inj['id'] ?? null) === $injuryType) {
466 return false;
467 }
468 }
469
463 470 // If an injury file exists in assets, load it for full data
464 471 $injData = null;
465 472 require_once __DIR__ . '/../Utilities/GameHelper.php';
@@ -469,8 +476,10 @@ class Kobold
469 476 // ensure kobold id
470 477 $injData['kobold_id'] = $this->id;
471 478 $this->injuries[] = $injData;
472 return;
479 return true;
473 480 }
481
482 return false;
474 483 }
475 484
476 485 public function removeInjury($injuryId)
@@ -460,6 +460,13 @@ class Kobold
460
460
461 public function addInjury($injuryType)
461 public function addInjury($injuryType)
462 {
462 {
463 // Reject duplicates
464 foreach ($this->injuries as $inj) {
465 if (($inj['id'] ?? null) === $injuryType) {
466 return false;
467 }
468 }
469
463 // If an injury file exists in assets, load it for full data
470 // If an injury file exists in assets, load it for full data
464 $injData = null;
471 $injData = null;
465 require_once __DIR__ . '/../Utilities/GameHelper.php';
472 require_once __DIR__ . '/../Utilities/GameHelper.php';
@@ -469,8 +476,10 @@ class Kobold
469 // ensure kobold id
476 // ensure kobold id
470 $injData['kobold_id'] = $this->id;
477 $injData['kobold_id'] = $this->id;
471 $this->injuries[] = $injData;
478 $this->injuries[] = $injData;
472 return;
479 return true;
473 }
480 }
481
482 return false;
474 }
483 }
475
484
476 public function removeInjury($injuryId)
485 public function removeInjury($injuryId)
web/src/Events/FarmingEvent.php +4 −4
@@ -65,8 +65,8 @@ class FarmingEvent extends Event
65 65 }
66 66
67 67 if (!$farmer->checkStat('will') && rand(1, 100) <= 30) {
68 $farmer->addInjury("smallCut");
69 $this->story .= "{$farmer->getName()} had an accident plowing the field, cutting {$farmer->his()} leg with the hoe.\n";
68 if ($farmer->addInjury("smallCut"))
69 $this->story .= "{$farmer->getName()} had an accident plowing the field, cutting {$farmer->his()} leg with the hoe.\n";
70 70 break;
71 71 }
72 72 }
@@ -105,8 +105,8 @@ class FarmingEvent extends Event
105 105 }
106 106
107 107 if (!$farmer->checkStat('vitality') && rand(1, 100) <= 25) {
108 $farmer->addInjury("sunburn");
109 $this->story .= "{$farmer->getName()} got badly sunburned while working in the fields under the hot sun.\n";
108 if ($farmer->addInjury("sunburn"))
109 $this->story .= "{$farmer->getName()} got badly sunburned while working in the fields under the hot sun.\n";
110 110 break;
111 111 }
112 112
@@ -65,8 +65,8 @@ class FarmingEvent extends Event
65 }
65 }
66
66
67 if (!$farmer->checkStat('will') && rand(1, 100) <= 30) {
67 if (!$farmer->checkStat('will') && rand(1, 100) <= 30) {
68 $farmer->addInjury("smallCut");
68 if ($farmer->addInjury("smallCut"))
69 $this->story .= "{$farmer->getName()} had an accident plowing the field, cutting {$farmer->his()} leg with the hoe.\n";
69 $this->story .= "{$farmer->getName()} had an accident plowing the field, cutting {$farmer->his()} leg with the hoe.\n";
70 break;
70 break;
71 }
71 }
72 }
72 }
@@ -105,8 +105,8 @@ class FarmingEvent extends Event
105 }
105 }
106
106
107 if (!$farmer->checkStat('vitality') && rand(1, 100) <= 25) {
107 if (!$farmer->checkStat('vitality') && rand(1, 100) <= 25) {
108 $farmer->addInjury("sunburn");
108 if ($farmer->addInjury("sunburn"))
109 $this->story .= "{$farmer->getName()} got badly sunburned while working in the fields under the hot sun.\n";
109 $this->story .= "{$farmer->getName()} got badly sunburned while working in the fields under the hot sun.\n";
110 break;
110 break;
111 }
111 }
112
112
web/src/Events/HuntingEvent.php +187 −8
@@ -2,6 +2,7 @@
2 2
3 3 require_once __DIR__ . '/../../src/Events/Event.php';
4 4 require_once __DIR__ . '/../../src/Classes/Kobold.php';
5 require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
5 6
6 7 class HuntingEvent extends Event
7 8 {
@@ -25,22 +26,200 @@ class HuntingEvent extends Event
25 26 return true;
26 27 }
27 28
29 private function runHunt(array $hunters, string $quarry, int $fullMin, int $fullMax, int $partialMin, int $partialMax)
30 {
31 $totalFood = 0;
32 $successes = 0;
33
34 $injuries = ['smallCut', 'brokenLeg', 'limp'];
35
36 foreach ($hunters as $hunter) {
37 $tracked = $hunter->checkStat('intelligence');
38 $downed = $hunter->checkStat('fighting');
39
40 if ($tracked && $downed) {
41 $totalFood += rand($fullMin, $fullMax);
42 $successes++;
43 } elseif ($tracked || $downed) {
44 $totalFood += rand($partialMin, $partialMax);
45 }
46
47 if (!$hunter->checkStat('vitality') && rand(1, 100) <= 15) {
48 $injury = $injuries[array_rand($injuries)];
49 if ($hunter->addInjury($injury))
50 $this->story .= "{$hunter->getName()} was hurt while chasing {$quarry}, but managed to limp back.\n";
51 }
52 }
53
54 if ($successes === 0) {
55 $this->story .= "The party failed to bring down any {$quarry}.\n";
56 } else {
57 $this->story .= "The party brought down {$quarry} and returned with food.\n";
58 }
59
60 return $totalFood;
61 }
62
63 private function spring(array $hunters, Kobold $bestTracker, Kobold $bestFighter, Kobold $toughest)
64 {
65 $this->story .= "Spring game was plentiful—rabbits and ground birds darted through the brush.\n";
66
67 $totalFood = $this->runHunt($hunters, 'small game', 2, 5, 1, 2);
68
69 if ($bestTracker->checkStat('intelligence') && rand(1, 100) <= 35) {
70 $herbs = GameHelper::loadItem('healing-herbs');
71 if ($herbs) {
72 $this->tribe->addToStorage($herbs, rand(1, 2));
73 $this->story .= "{$bestTracker->getName()} tracked fresh growth and gathered healing herbs along the way.\n";
74 }
75 }
76
77 if (!$toughest->checkStat('vitality') && rand(1, 100) <= 25) {
78 if ($toughest->addInjury('smallCut'))
79 $this->story .= "A thicket tore at {$toughest->getName()}'s arms, leaving a nasty cut.\n";
80 }
81
82 return $totalFood;
83 }
84
85 private function summer(array $hunters, Kobold $bestTracker, Kobold $bestFighter, Kobold $toughest)
86 {
87 $this->story .= "Summer trails led to boar and wild goats, but the heat was punishing.\n";
88
89 $totalFood = $this->runHunt($hunters, 'boar and goats', 4, 8, 1, 3);
90
91 if ($bestFighter->checkStat('fighting') && rand(1, 100) <= 30) {
92 $bonus = rand(3, 6);
93 $totalFood += $bonus;
94 $this->story .= "{$bestFighter->getName()} brought down a stubborn boar, adding extra meat.\n";
95 }
96
97 if (!$toughest->checkStat('vitality') && rand(1, 100) <= 25) {
98 if ($toughest->addInjury('brokenLeg')) {
99 $this->story .= "A charging beast knocked {$toughest->getName()} down, breaking a leg.\n";
100 }
101 }
102
103 return $totalFood;
104 }
105
106 private function autumn(array $hunters, Kobold $bestTracker, Kobold $bestFighter, Kobold $toughest)
107 {
108 $this->story .= "Autumn brought fattened deer and migrating herds to track.\n";
109
110 $totalFood = $this->runHunt($hunters, 'deer', 5, 9, 2, 4);
111
112 if ($bestTracker->checkStat('intelligence') && rand(1, 100) <= 35) {
113 $bonus = rand(2, 6);
114 $totalFood += $bonus;
115 $this->story .= "{$bestTracker->getName()} followed fresh tracks to a second herd.\n";
116 }
117
118 if (!$toughest->checkStat('vitality') && rand(1, 100) <= 20) {
119 if ($toughest->addInjury('limp'))
120 $this->story .= "A hidden root tripped {$toughest->getName()}, leaving {$toughest->him()} limping.\n";
121 }
122
123 return $totalFood;
124 }
125
126 private function winter(array $hunters, Kobold $bestTracker, Kobold $bestFighter, Kobold $toughest)
127 {
128 $this->story .= "Winter was harsh, and only lean game moved across the snow.\n";
129
130 $totalFood = $this->runHunt($hunters, 'winter game', 1, 4, 0, 1);
131
132 if ($bestFighter->checkStat('fighting') && rand(1, 100) <= 25) {
133 $bonus = rand(2, 4);
134 $totalFood += $bonus;
135 $this->story .= "{$bestFighter->getName()} felled a tough quarry in the cold, adding a little extra meat.\n";
136 }
137
138 if (!$toughest->checkStat('vitality') && rand(1, 100) <= 30) {
139 if ($toughest->addInjury('smallCut'))
140 $this->story .= "Freezing winds numbed {$toughest->getName()}'s hands, and a slip left a painful cut.\n";
141 }
142
143 return $totalFood;
144 }
145
28 146 public function execute()
29 147 {
30 148 $this->story = "The hunting party set out into the wilderness...\n\n";
31 149
32 $kobolds = $this->tribe->getAliveKobolds();
150 $participantIds = $this->getParticipants();
151 $hunters = [];
152 foreach ($participantIds as $pid) {
153 $k = $this->tribe->getKobold($pid);
154 if ($k && !$k->isDead())
155 $hunters[] = $k;
156 }
157
158 if (empty($hunters)) {
159 $this->story .= "But there were no kobolds fit to hunt!";
160 return $this->story;
161 }
33 162
34 if (empty($kobolds)) {
35 $this->story .= "But there were no kobolds to hunt!";
36 return;
163 if (count($hunters) > 1) {
164 $this->story .= "A group of " . count($hunters) . " hunters set out:\n";
165 foreach ($hunters as $hunter) {
166 $this->story .= "- " . $hunter->getName() . "\n";
167 }
168 $this->story .= "\n";
169 } else {
170 $this->story .= $hunters[0]->getName() . " set out alone.\n\n";
37 171 }
38 172
39 // TODO: Implement hunting logic
40 // This should use the kobold stats to determine success
41 // Can kill or injure kobolds, find items, etc.
173 $bestTracker = GameHelper::findBestKoboldForStat($hunters, 'intelligence');
174 $bestFighter = GameHelper::findBestKoboldForStat($hunters, 'fighting');
175 $toughest = GameHelper::findBestKoboldForStat($hunters, 'vitality');
176
177 $this->story .= "{$bestTracker->getName()} tracked the trail while {$bestFighter->getName()} led the strike.\n";
178
179 $season = $this->tribe->getCurrentSeason();
180 $totalFood = 0;
181
182 if ($season === 'spring') {
183 $totalFood = $this->spring($hunters, $bestTracker, $bestFighter, $toughest);
184 } elseif ($season === 'summer') {
185 $totalFood = $this->summer($hunters, $bestTracker, $bestFighter, $toughest);
186 } elseif ($season === 'autumn') {
187 $totalFood = $this->autumn($hunters, $bestTracker, $bestFighter, $toughest);
188 } else {
189 $totalFood = $this->winter($hunters, $bestTracker, $bestFighter, $toughest);
190 }
191
192 if ($totalFood > 0) {
193 $months = $this->tribe->foodMonthsLeft($totalFood);
194 $this->tribe->addFood($totalFood);
195 $this->story .= "The tribe gained {$months} months worth of food from the hunt.\n";
196 } else {
197 $this->story .= "The hunt brought back no usable food.\n";
198 }
199
200 if (rand(1, 100) <= 20) {
201 $lucky = $hunters[array_rand($hunters)];
202 if ($lucky->checkStat('intelligence')) {
203 $splint = GameHelper::loadItem('bone-setting');
204 if ($splint) {
205 $this->tribe->addToStorage($splint);
206 $this->story .= "{$lucky->getName()} found a sturdy bone and crafted a splint for the tribe.\n";
207 }
208 }
209 }
210
211 if (rand(1, 100) <= 20) {
212 $unlucky = $hunters[array_rand($hunters)];
213 if (!$unlucky->checkStat('vitality')) {
214 $injuries = ['smallCut', 'brokenLeg', 'limp'];
215 $injury = $injuries[array_rand($injuries)];
216 if ($unlucky->addInjury($injury)) {
217 $this->story .= "Bad luck struck and {$unlucky->getName()} was injured on the way back.\n";
218 }
219 }
220 }
42 221
43 $this->story .= "The hunters returned with valuable supplies.";
222 $this->story .= "\nThe hunters returned to the tribe.";
44 223
45 224 return $this->story;
46 225 }
@@ -2,6 +2,7 @@
2
2
3require_once __DIR__ . '/../../src/Events/Event.php';
3require_once __DIR__ . '/../../src/Events/Event.php';
4require_once __DIR__ . '/../../src/Classes/Kobold.php';
4require_once __DIR__ . '/../../src/Classes/Kobold.php';
5require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
5
6
6class HuntingEvent extends Event
7class HuntingEvent extends Event
7{
8{
@@ -25,22 +26,200 @@ class HuntingEvent extends Event
25 return true;
26 return true;
26 }
27 }
27
28
29 private function runHunt(array $hunters, string $quarry, int $fullMin, int $fullMax, int $partialMin, int $partialMax)
30 {
31 $totalFood = 0;
32 $successes = 0;
33
34 $injuries = ['smallCut', 'brokenLeg', 'limp'];
35
36 foreach ($hunters as $hunter) {
37 $tracked = $hunter->checkStat('intelligence');
38 $downed = $hunter->checkStat('fighting');
39
40 if ($tracked && $downed) {
41 $totalFood += rand($fullMin, $fullMax);
42 $successes++;
43 } elseif ($tracked || $downed) {
44 $totalFood += rand($partialMin, $partialMax);
45 }
46
47 if (!$hunter->checkStat('vitality') && rand(1, 100) <= 15) {
48 $injury = $injuries[array_rand($injuries)];
49 if ($hunter->addInjury($injury))
50 $this->story .= "{$hunter->getName()} was hurt while chasing {$quarry}, but managed to limp back.\n";
51 }
52 }
53
54 if ($successes === 0) {
55 $this->story .= "The party failed to bring down any {$quarry}.\n";
56 } else {
57 $this->story .= "The party brought down {$quarry} and returned with food.\n";
58 }
59
60 return $totalFood;
61 }
62
63 private function spring(array $hunters, Kobold $bestTracker, Kobold $bestFighter, Kobold $toughest)
64 {
65 $this->story .= "Spring game was plentiful—rabbits and ground birds darted through the brush.\n";
66
67 $totalFood = $this->runHunt($hunters, 'small game', 2, 5, 1, 2);
68
69 if ($bestTracker->checkStat('intelligence') && rand(1, 100) <= 35) {
70 $herbs = GameHelper::loadItem('healing-herbs');
71 if ($herbs) {
72 $this->tribe->addToStorage($herbs, rand(1, 2));
73 $this->story .= "{$bestTracker->getName()} tracked fresh growth and gathered healing herbs along the way.\n";
74 }
75 }
76
77 if (!$toughest->checkStat('vitality') && rand(1, 100) <= 25) {
78 if ($toughest->addInjury('smallCut'))
79 $this->story .= "A thicket tore at {$toughest->getName()}'s arms, leaving a nasty cut.\n";
80 }
81
82 return $totalFood;
83 }
84
85 private function summer(array $hunters, Kobold $bestTracker, Kobold $bestFighter, Kobold $toughest)
86 {
87 $this->story .= "Summer trails led to boar and wild goats, but the heat was punishing.\n";
88
89 $totalFood = $this->runHunt($hunters, 'boar and goats', 4, 8, 1, 3);
90
91 if ($bestFighter->checkStat('fighting') && rand(1, 100) <= 30) {
92 $bonus = rand(3, 6);
93 $totalFood += $bonus;
94 $this->story .= "{$bestFighter->getName()} brought down a stubborn boar, adding extra meat.\n";
95 }
96
97 if (!$toughest->checkStat('vitality') && rand(1, 100) <= 25) {
98 if ($toughest->addInjury('brokenLeg')) {
99 $this->story .= "A charging beast knocked {$toughest->getName()} down, breaking a leg.\n";
100 }
101 }
102
103 return $totalFood;
104 }
105
106 private function autumn(array $hunters, Kobold $bestTracker, Kobold $bestFighter, Kobold $toughest)
107 {
108 $this->story .= "Autumn brought fattened deer and migrating herds to track.\n";
109
110 $totalFood = $this->runHunt($hunters, 'deer', 5, 9, 2, 4);
111
112 if ($bestTracker->checkStat('intelligence') && rand(1, 100) <= 35) {
113 $bonus = rand(2, 6);
114 $totalFood += $bonus;
115 $this->story .= "{$bestTracker->getName()} followed fresh tracks to a second herd.\n";
116 }
117
118 if (!$toughest->checkStat('vitality') && rand(1, 100) <= 20) {
119 if ($toughest->addInjury('limp'))
120 $this->story .= "A hidden root tripped {$toughest->getName()}, leaving {$toughest->him()} limping.\n";
121 }
122
123 return $totalFood;
124 }
125
126 private function winter(array $hunters, Kobold $bestTracker, Kobold $bestFighter, Kobold $toughest)
127 {
128 $this->story .= "Winter was harsh, and only lean game moved across the snow.\n";
129
130 $totalFood = $this->runHunt($hunters, 'winter game', 1, 4, 0, 1);
131
132 if ($bestFighter->checkStat('fighting') && rand(1, 100) <= 25) {
133 $bonus = rand(2, 4);
134 $totalFood += $bonus;
135 $this->story .= "{$bestFighter->getName()} felled a tough quarry in the cold, adding a little extra meat.\n";
136 }
137
138 if (!$toughest->checkStat('vitality') && rand(1, 100) <= 30) {
139 if ($toughest->addInjury('smallCut'))
140 $this->story .= "Freezing winds numbed {$toughest->getName()}'s hands, and a slip left a painful cut.\n";
141 }
142
143 return $totalFood;
144 }
145
28 public function execute()
146 public function execute()
29 {
147 {
30 $this->story = "The hunting party set out into the wilderness...\n\n";
148 $this->story = "The hunting party set out into the wilderness...\n\n";
31
149
32 $kobolds = $this->tribe->getAliveKobolds();
150 $participantIds = $this->getParticipants();
151 $hunters = [];
152 foreach ($participantIds as $pid) {
153 $k = $this->tribe->getKobold($pid);
154 if ($k && !$k->isDead())
155 $hunters[] = $k;
156 }
157
158 if (empty($hunters)) {
159 $this->story .= "But there were no kobolds fit to hunt!";
160 return $this->story;
161 }
33
162
34 if (empty($kobolds)) {
163 if (count($hunters) > 1) {
35 $this->story .= "But there were no kobolds to hunt!";
164 $this->story .= "A group of " . count($hunters) . " hunters set out:\n";
36 return;
165 foreach ($hunters as $hunter) {
166 $this->story .= "- " . $hunter->getName() . "\n";
167 }
168 $this->story .= "\n";
169 } else {
170 $this->story .= $hunters[0]->getName() . " set out alone.\n\n";
37 }
171 }
38
172
39 // TODO: Implement hunting logic
173 $bestTracker = GameHelper::findBestKoboldForStat($hunters, 'intelligence');
40 // This should use the kobold stats to determine success
174 $bestFighter = GameHelper::findBestKoboldForStat($hunters, 'fighting');
41 // Can kill or injure kobolds, find items, etc.
175 $toughest = GameHelper::findBestKoboldForStat($hunters, 'vitality');
176
177 $this->story .= "{$bestTracker->getName()} tracked the trail while {$bestFighter->getName()} led the strike.\n";
178
179 $season = $this->tribe->getCurrentSeason();
180 $totalFood = 0;
181
182 if ($season === 'spring') {
183 $totalFood = $this->spring($hunters, $bestTracker, $bestFighter, $toughest);
184 } elseif ($season === 'summer') {
185 $totalFood = $this->summer($hunters, $bestTracker, $bestFighter, $toughest);
186 } elseif ($season === 'autumn') {
187 $totalFood = $this->autumn($hunters, $bestTracker, $bestFighter, $toughest);
188 } else {
189 $totalFood = $this->winter($hunters, $bestTracker, $bestFighter, $toughest);
190 }
191
192 if ($totalFood > 0) {
193 $months = $this->tribe->foodMonthsLeft($totalFood);
194 $this->tribe->addFood($totalFood);
195 $this->story .= "The tribe gained {$months} months worth of food from the hunt.\n";
196 } else {
197 $this->story .= "The hunt brought back no usable food.\n";
198 }
199
200 if (rand(1, 100) <= 20) {
201 $lucky = $hunters[array_rand($hunters)];
202 if ($lucky->checkStat('intelligence')) {
203 $splint = GameHelper::loadItem('bone-setting');
204 if ($splint) {
205 $this->tribe->addToStorage($splint);
206 $this->story .= "{$lucky->getName()} found a sturdy bone and crafted a splint for the tribe.\n";
207 }
208 }
209 }
210
211 if (rand(1, 100) <= 20) {
212 $unlucky = $hunters[array_rand($hunters)];
213 if (!$unlucky->checkStat('vitality')) {
214 $injuries = ['smallCut', 'brokenLeg', 'limp'];
215 $injury = $injuries[array_rand($injuries)];
216 if ($unlucky->addInjury($injury)) {
217 $this->story .= "Bad luck struck and {$unlucky->getName()} was injured on the way back.\n";
218 }
219 }
220 }
42
221
43 $this->story .= "The hunters returned with valuable supplies.";
222 $this->story .= "\nThe hunters returned to the tribe.";
44
223
45 return $this->story;
224 return $this->story;
46 }
225 }