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