| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . '/../../src/Events/MonthEndEvent.php'; |
| 4 | require_once __DIR__ . '/../../src/Classes/Kobold.php'; |
| 5 | require_once __DIR__ . '/../../src/Utilities/GameHelper.php'; |
| 6 | |
| 7 | class WalkDiscoveryEvent extends MonthEndEvent |
| 8 | { |
| 9 | public function getMinAge() |
| 10 | { |
| 11 | return 13; |
| 12 | } |
| 13 | |
| 14 | public function getMinParticipants() |
| 15 | { |
| 16 | return 1; |
| 17 | } |
| 18 | |
| 19 | public function getMaxParticipants() |
| 20 | { |
| 21 | return 1; |
| 22 | } |
| 23 | |
| 24 | public function getCost() |
| 25 | { |
| 26 | return 40; |
| 27 | } |
| 28 | |
| 29 | public function isAvailable() |
| 30 | { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | public function execute() |
| 35 | { |
| 36 | $this->story = ''; |
| 37 | |
| 38 | $eligible = array_filter($this->tribe->getAliveKobolds(), fn($k) => $k->getAge() >= $this->getMinAge()); |
| 39 | $eligible = array_values($eligible); |
| 40 | |
| 41 | if (empty($eligible)) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | $kobold = $eligible[array_rand($eligible)]; |
| 46 | |
| 47 | // Determine what was found |
| 48 | $roll = rand(1, 100); |
| 49 | |
| 50 | $nameA = $kobold->getName(); |
| 51 | |
| 52 | if ($roll <= 60) { |
| 53 | // Food discovery |
| 54 | $foodAmount = rand(3, 8); |
| 55 | |
| 56 | $reason = $this->tribe->modifyFoodGain($foodAmount); |
| 57 | if ($foodAmount < 1) { |
| 58 | $foodAmount = 1; |
| 59 | } |
| 60 | $this->tribe->addFood($foodAmount); |
| 61 | |
| 62 | $foodStr = $this->tribe->foodTimeStr($foodAmount); |
| 63 | |
| 64 | $foodVariations = [ |
| 65 | "{$nameA} found some edible plants during a walk and brought back {$foodStr} worth of food.", |
| 66 | "While exploring, {$nameA} discovered a cache of berries and returned with {$foodStr} worth of food.", |
| 67 | "{$nameA}'s keen eye spotted food sources, adding {$foodStr} worth of food to the tribe's stores.", |
| 68 | "A fortunate walk led {$nameA} to gather {$foodStr} worth of food for the tribe.", |
| 69 | "{$nameA} returned from a walk with {$foodStr} worth of food, a welcome find.", |
| 70 | "During a solitary walk, {$nameA} found edible resources and collected {$foodStr} worth of food.", |
| 71 | "{$nameA} stumbled upon a food source during a walk, bringing back {$foodStr} worth of food.", |
| 72 | ]; |
| 73 | |
| 74 | $this->story = $foodVariations[array_rand($foodVariations)]; |
| 75 | if ($reason === 'draught') { |
| 76 | $this->story .= " The drought kept the find small."; |
| 77 | } elseif ($reason === 'heatWave') { |
| 78 | $this->story .= " The heat kept the find small."; |
| 79 | } |
| 80 | } else { |
| 81 | // Item discovery |
| 82 | $items = [ |
| 83 | ['name' => 'bone-setting', 'displayName' => 'bone-setting kit'], |
| 84 | ['name' => 'healing-herbs', 'displayName' => 'healing herbs'], |
| 85 | ['name' => 'book', 'displayName' => 'old book'], |
| 86 | ]; |
| 87 | |
| 88 | $item = $items[array_rand($items)]; |
| 89 | |
| 90 | // Load item template |
| 91 | $itemData = GameHelper::loadItem($item['name']); |
| 92 | if ($itemData) { |
| 93 | $this->tribe->addToStorage($itemData); |
| 94 | |
| 95 | $itemVariations = [ |
| 96 | "{$nameA} discovered an old {$item['displayName']} during a walk.", |
| 97 | "While wandering, {$nameA} found a {$item['displayName']} and brought it back.", |
| 98 | "{$nameA}'s sharp eyes spotted a {$item['displayName']} lying in the wilderness.", |
| 99 | "A lucky find—{$nameA} returned with a {$item['displayName']}.", |
| 100 | "{$nameA} came back from a walk carrying a {$item['displayName']}.", |
| 101 | "The tribe is pleased that {$nameA} found a {$item['displayName']} on a recent walk.", |
| 102 | "{$nameA} stumbled upon a {$item['displayName']} and wisely brought it to the tribe.", |
| 103 | ]; |
| 104 | |
| 105 | $this->story = $itemVariations[array_rand($itemVariations)]; |
| 106 | } else { |
| 107 | // Fallback if item loading fails |
| 108 | $this->story = "{$nameA} returned from a walk with interesting findings."; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |