| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . '/../../src/Events/MonthEndEvent.php'; |
| 4 | require_once __DIR__ . '/../../src/Classes/Kobold.php'; |
| 5 | require_once __DIR__ . '/../../src/Classes/NPC.php'; |
| 6 | |
| 7 | class RivalEncounterEvent extends MonthEndEvent |
| 8 | { |
| 9 | public function getMinAge() |
| 10 | { |
| 11 | return 15; |
| 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 25; |
| 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 | // Initialize rivals if not present |
| 48 | if (!isset($this->tribe->dataStore->rivals)) { |
| 49 | $this->tribe->dataStore->rivals = []; |
| 50 | } |
| 51 | |
| 52 | $rivals = $this->tribe->dataStore->rivals; |
| 53 | |
| 54 | // Generate or pick a rival |
| 55 | $rival = null; |
| 56 | |
| 57 | if (count($rivals) < 10 && rand(1, 100) <= 40) { |
| 58 | // Generate a new rival |
| 59 | $rivalNames = ['Gruk', 'Zag', 'Mog', 'Drog', 'Bik', 'Kra', 'Nik', 'Tug', 'Vox', 'Warg']; |
| 60 | $rivalName = $rivalNames[array_rand($rivalNames)]; |
| 61 | $rival = NPC::create($this->tribe->getSaveId(), $rivalName, 'individual', true); |
| 62 | $this->tribe->dataStore->rivals[] = $rival->toArray(); |
| 63 | } elseif (!empty($rivals)) { |
| 64 | // Pick an existing rival |
| 65 | $rivalData = $rivals[array_rand($rivals)]; |
| 66 | $rival = NPC::fromArray($rivalData); |
| 67 | } |
| 68 | |
| 69 | // If no rival exists, return |
| 70 | if (!$rival) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | $koboldName = $kobold->getName(); |
| 75 | $rivalName = $rival->getName(); |
| 76 | |
| 77 | // Check personality (kobold's perspective toward the rival) |
| 78 | $personalityCheck = $kobold->checkStat('personality'); |
| 79 | |
| 80 | $injuryTypes = ['smallCut', 'brokenLeg']; |
| 81 | |
| 82 | if ($personalityCheck) { |
| 83 | // Positive encounter |
| 84 | // Initialize kobold's likes if needed |
| 85 | if (!isset($kobold->dataStore)) { |
| 86 | $kobold->dataStore = new stdClass(); |
| 87 | } |
| 88 | if (!isset($kobold->dataStore->likes)) { |
| 89 | $kobold->dataStore->likes = []; |
| 90 | } |
| 91 | |
| 92 | // Like the rival |
| 93 | $currentLike = $kobold->dataStore->likes[$rival->getId()] ?? 0; |
| 94 | $kobold->dataStore->likes[$rival->getId()] = $currentLike + 3; |
| 95 | |
| 96 | $positiveVariations = [ |
| 97 | "{$koboldName} encountered {$rivalName} and the two exchanged pleasantries. Relations improved slightly.", |
| 98 | "When {$koboldName} met {$rivalName}, the encounter was surprisingly cordial.", |
| 99 | "{$koboldName} and {$rivalName} ran into each other and found common ground.", |
| 100 | "A chance meeting between {$koboldName} and {$rivalName} resulted in friendly conversation.", |
| 101 | "{$koboldName} discovered that {$rivalName} might not be such a bad sort after all.", |
| 102 | ]; |
| 103 | |
| 104 | // Chance of receiving a gift |
| 105 | if (rand(1, 100) <= 40) { |
| 106 | $gifts = ['bone-setting', 'healing-herbs', 'book']; |
| 107 | $giftName = $gifts[array_rand($gifts)]; |
| 108 | |
| 109 | $giftVariations = [ |
| 110 | $positiveVariations[array_rand($positiveVariations)] . " {$rivalName} even gifted {$koboldName} with a {$giftName}.", |
| 111 | $positiveVariations[array_rand($positiveVariations)] . " The encounter ended with {$rivalName} generously offering {$koboldName} a {$giftName}.", |
| 112 | ]; |
| 113 | |
| 114 | $this->story = $giftVariations[array_rand($giftVariations)]; |
| 115 | |
| 116 | // Try to add gift to storage (if item loading available) |
| 117 | if (class_exists('GameHelper')) { |
| 118 | $itemData = GameHelper::loadItem($giftName); |
| 119 | if ($itemData) { |
| 120 | $this->tribe->addToStorage($itemData); |
| 121 | } |
| 122 | } |
| 123 | } else { |
| 124 | $this->story = $positiveVariations[array_rand($positiveVariations)]; |
| 125 | } |
| 126 | } else { |
| 127 | // Negative encounter - they fight |
| 128 | $negativeVariations = [ |
| 129 | "{$koboldName} and {$rivalName} clashed bitterly when they met.", |
| 130 | "An encounter between {$koboldName} and {$rivalName} quickly escalated into violence.", |
| 131 | "{$koboldName} and {$rivalName} came to blows, leaving both wounded.", |
| 132 | "When {$koboldName} crossed paths with {$rivalName}, tempers flared into a fight.", |
| 133 | "{$koboldName} and {$rivalName} settled their differences through combat.", |
| 134 | ]; |
| 135 | |
| 136 | // Randomly injure the kobold |
| 137 | if (rand(1, 100) <= 70) { |
| 138 | $injury = $injuryTypes[array_rand($injuryTypes)]; |
| 139 | $kobold->addInjury($injury); |
| 140 | |
| 141 | $injuredVariations = [ |
| 142 | $negativeVariations[array_rand($negativeVariations)] . " {$koboldName} came away with an injury.", |
| 143 | $negativeVariations[array_rand($negativeVariations)] . " {$koboldName} was hurt in the confrontation.", |
| 144 | ]; |
| 145 | |
| 146 | $this->story = $injuredVariations[array_rand($injuredVariations)]; |
| 147 | } else { |
| 148 | $this->story = $negativeVariations[array_rand($negativeVariations)]; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | $kobold->save(); |
| 153 | } |
| 154 | } |