| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . '/../../src/Events/MonthEndEvent.php'; |
| 4 | |
| 5 | class IncompetenceFrustrationEvent extends MonthEndEvent |
| 6 | { |
| 7 | public function getMinAge() |
| 8 | { |
| 9 | return 10; |
| 10 | } |
| 11 | |
| 12 | public function getMinParticipants() |
| 13 | { |
| 14 | return 2; |
| 15 | } |
| 16 | |
| 17 | public function getMaxParticipants() |
| 18 | { |
| 19 | return 2; |
| 20 | } |
| 21 | |
| 22 | public function getCost() |
| 23 | { |
| 24 | return 20; |
| 25 | } |
| 26 | |
| 27 | public function isAvailable() |
| 28 | { |
| 29 | $eligible = array_filter($this->tribe->getKobolds(), function ($kobold) { |
| 30 | return $kobold->getAge() >= $this->getMinAge(); |
| 31 | }); |
| 32 | |
| 33 | if (count($eligible) < 2) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | foreach ($eligible as $kobold) { |
| 38 | $statName = $kobold->getHighestStatName(); |
| 39 | $statValue = $statName ? $kobold->getStat($statName) : null; |
| 40 | if ($statValue !== null && $statValue >= 50 && $statValue <= 60) { |
| 41 | return true; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | private function ensureLikes($kobold) |
| 49 | { |
| 50 | if (!isset($kobold->dataStore)) { |
| 51 | $kobold->dataStore = new stdClass(); |
| 52 | } |
| 53 | if (!isset($kobold->dataStore->likes) || !is_array($kobold->dataStore->likes)) { |
| 54 | $kobold->dataStore->likes = []; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public function execute() |
| 59 | { |
| 60 | $kobolds = array_values($this->tribe->getKobolds()); |
| 61 | if (count($kobolds) < 2) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | $targets = array_values(array_filter($kobolds, function ($kobold) { |
| 66 | $statName = $kobold->getHighestStatName(); |
| 67 | $statValue = $statName ? $kobold->getStat($statName) : null; |
| 68 | return $statValue !== null && $statValue >= 50 && $statValue <= 60; |
| 69 | })); |
| 70 | |
| 71 | if (empty($targets)) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | $target = $targets[array_rand($targets)]; |
| 76 | $others = array_values(array_filter($kobolds, fn($k) => $k->getId() !== $target->getId())); |
| 77 | if (empty($others)) { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | $frustrated = $others[array_rand($others)]; |
| 82 | $statName = $target->getHighestStatName(); |
| 83 | |
| 84 | $this->ensureLikes($frustrated); |
| 85 | $current = $frustrated->dataStore->likes[$target->getId()] ?? 0; |
| 86 | $frustrated->dataStore->likes[$target->getId()] = $current - 2; |
| 87 | |
| 88 | $variations = [ |
| 89 | "{$frustrated->getName()} grew frustrated with {$target->getName()}'s shaky {$statName} skills. The strain left a colder feeling between them.", |
| 90 | "After another mistake from {$target->getName()}, {$frustrated->getName()} lost patience with {$target->getName()}'s {$statName} work.", |
| 91 | "{$frustrated->getName()} watched {$target->getName()} struggle at {$statName} tasks and felt irritation build, dampening their goodwill." |
| 92 | ]; |
| 93 | |
| 94 | $this->story = $variations[array_rand($variations)]; |
| 95 | $frustrated->save(); |
| 96 | } |
| 97 | } |