| 1 | <?php |
| 2 | |
| 3 | namespace TribeGen\Events; |
| 4 | |
| 5 | class ExplorationEvent extends Event |
| 6 | { |
| 7 | public function execute() |
| 8 | { |
| 9 | $this->story = "The exploration party ventured forth into uncharted territory...\n\n"; |
| 10 | |
| 11 | $kobolds = $this->tribe->getAliveKobolds(); |
| 12 | |
| 13 | if (empty($kobolds)) { |
| 14 | $this->story .= "But there were no kobolds to send exploring!"; |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | // Randomly select 1-3 explorers |
| 19 | $explorerCount = rand(1, min(3, count($kobolds))); |
| 20 | $explorers = array_slice(array_values($kobolds), 0, $explorerCount); |
| 21 | |
| 22 | $this->story .= "A group of " . count($explorers) . " intrepid explorers set out:\n"; |
| 23 | foreach ($explorers as $explorer) { |
| 24 | $this->story .= "- " . $explorer->getName() . " (Intelligence: " . $this->statDisplay($explorer->getStat('intelligence')) . ")\n"; |
| 25 | } |
| 26 | $this->story .= "\n"; |
| 27 | |
| 28 | // Chance to find food (50% base) |
| 29 | $foodFound = rand(1, 100) <= 50; |
| 30 | if ($foodFound) { |
| 31 | $baseFood = rand(5, 15); |
| 32 | // Intelligence affects food discovery - smarter kobolds find more |
| 33 | $avgIntelligence = array_sum(array_map(function($k) { return $k->getStat('intelligence'); }, $explorers)) / count($explorers); |
| 34 | $foodBonus = intval($avgIntelligence / 20); // Max +5 food from intelligence |
| 35 | $totalFood = $baseFood + $foodBonus; |
| 36 | |
| 37 | $this->tribe->addFood($totalFood); |
| 38 | $this->story .= "Success! The explorers discovered edible plants and small game.\n"; |
| 39 | $this->story .= "The tribe gained " . $totalFood . " units of food.\n\n"; |
| 40 | } else { |
| 41 | $this->story .= "The terrain was barren. No food was found.\n\n"; |
| 42 | } |
| 43 | |
| 44 | // Chance for injury (35% - someone trips on loose stone) |
| 45 | $injuryChance = rand(1, 100) <= 35; |
| 46 | if ($injuryChance && count($explorers) > 0) { |
| 47 | // Vitality affects injury chance - higher vitality = less likely to be injured |
| 48 | $avgVitality = array_sum(array_map(function($k) { return $k->getStat('vitality'); }, $explorers)) / count($explorers); |
| 49 | $injuryProbability = (100 - $avgVitality) / 100; |
| 50 | |
| 51 | if (rand(1, 100) / 100 <= $injuryProbability) { |
| 52 | // Select a random explorer to get injured |
| 53 | $injuredKobold = $explorers[array_rand($explorers)]; |
| 54 | |
| 55 | $this->story .= "Disaster! " . $injuredKobold->getName() . " tripped over a loose stone!\n"; |
| 56 | |
| 57 | // Create injury array (since we're in file-based storage) |
| 58 | $injuries = $injuredKobold->getInjuries(); |
| 59 | $newInjury = [ |
| 60 | 'id' => uniqid('inj_'), |
| 61 | 'kobold_id' => $injuredKobold->getId(), |
| 62 | 'injury_type' => 'twisted_ankle', |
| 63 | 'category' => 'wound', |
| 64 | 'severity' => rand(2, 5), |
| 65 | 'created_at' => date('Y-m-d H:i:s') |
| 66 | ]; |
| 67 | $injuries[] = $newInjury; |
| 68 | $injuredKobold->setInjuries($injuries); |
| 69 | |
| 70 | $this->story .= $injuredKobold->getName() . " suffered a twisted ankle (severity: " . $newInjury['severity'] . "/10).\n"; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | $this->story .= "\nThe exploration party returned to the tribe with their findings."; |
| 75 | |
| 76 | return $this->story; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Convert internal stat value to display text |
| 81 | */ |
| 82 | private function statDisplay($stat) |
| 83 | { |
| 84 | if ($stat <= 10) return "terrible"; |
| 85 | if ($stat <= 20) return "bad"; |
| 86 | if ($stat <= 30) return "unskilled"; |
| 87 | if ($stat <= 40) return "decent"; |
| 88 | if ($stat <= 50) return "good"; |
| 89 | if ($stat <= 60) return "excellent"; |
| 90 | if ($stat <= 70) return "fantastic"; |
| 91 | if ($stat <= 80) return "master"; |
| 92 | if ($stat <= 90) return "divine"; |
| 93 | return "godlike"; |
| 94 | } |
| 95 | } |