| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . '/../../src/Events/Event.php'; |
| 4 | require_once __DIR__ . '/../../src/Classes/Kobold.php'; |
| 5 | require_once __DIR__ . '/../../src/Utilities/GameHelper.php'; |
| 6 | |
| 7 | class HuntingEvent extends Event |
| 8 | { |
| 9 | public function getMinParticipants() |
| 10 | { |
| 11 | return 2; |
| 12 | } |
| 13 | |
| 14 | public function getMaxParticipants() |
| 15 | { |
| 16 | return 5; |
| 17 | } |
| 18 | |
| 19 | public function getCost() |
| 20 | { |
| 21 | return 25; |
| 22 | } |
| 23 | |
| 24 | public function isAvailable() |
| 25 | { |
| 26 | return true; |
| 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 | |
| 146 | public function execute() |
| 147 | { |
| 148 | $this->story = "The hunting party set out into the wilderness...\n\n"; |
| 149 | |
| 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 | } |
| 162 | |
| 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"; |
| 171 | } |
| 172 | |
| 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 | } |
| 221 | |
| 222 | $this->story .= "\nThe hunters returned to the tribe."; |
| 223 | |
| 224 | return $this->story; |
| 225 | } |
| 226 | } |