BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / ExplorationEvent.php

ExplorationEvent.php

ExplorationEvent.php 4.7 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/Event.php';
4require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
5require_once __DIR__ . '/../../src/Classes/Kobold.php';
6
7class ExplorationEvent extends Event
8{
9 public function getMinAge()
10 {
11 return 14;
12 }
13
14 public function getMinParticipants()
15 {
16 return 1;
17 }
18
19 public function getMaxParticipants()
20 {
21 return 10;
22 }
23
24 public function getCost()
25 {
26 return 12;
27 }
28
29 public function isAvailable()
30 {
31 return true;
32 }
33
34 public function execute()
35 {
36 $this->story = "The exploration party ventured forth into uncharted territory...\n\n";
37
38 $available = $this->tribe->getAliveKobolds();
39
40 if (empty($available)) {
41 $this->story .= "But there were no kobolds to send exploring!";
42 return;
43 }
44
45 // Exploration must be started with explicit participants (player-started)
46 $participantIds = $this->getParticipants();
47 if (empty($participantIds) || !is_array($participantIds)) {
48 throw new \Exception('ExplorationEvent requires a participants array of kobold IDs.');
49 }
50
51 $explorers = [];
52 foreach ($participantIds as $pid) {
53 $k = $this->tribe->getKobold($pid);
54 if ($k && !$k->isDead())
55 $explorers[] = $k;
56 }
57
58 if (empty($explorers)) {
59 throw new \Exception('No valid living kobolds found in participants list.');
60 }
61
62 $this->story .= count($explorers) > 1 ?
63 "A group of " . count($explorers) . " intrepid explorers set out:\n"
64 : $explorers[0]->getName() . " sets out to explore.\n";
65
66 if (count($explorers) > 1) {
67 foreach ($explorers as $explorer) {
68 $this->story .= "- " . $explorer->getName() . "\n";
69 }
70 $this->story .= "\n";
71 }
72
73 // Chance to find food (50% base)
74 $foodFound = rand(1, 100) <= 50;
75 if ($foodFound) {
76 $baseFood = rand(5, 15);
77 // Intelligence affects food discovery - smarter kobolds find more
78 $avgIntelligence = array_sum(array_map(function ($k) {
79 return $k->getStat('intelligence');
80 }, $explorers)) / count($explorers);
81
82 $foodBonus = intval($avgIntelligence / 20); // Max +5 food from intelligence
83 $totalFood = $baseFood + $foodBonus;
84
85 $reason = $this->tribe->modifyFoodGain($totalFood);
86 if ($reason === 'draught') {
87 $this->story .= "The drought stunted the forage, cutting it down.\n";
88 } elseif ($reason === 'heatWave') {
89 $this->story .= "The heat sapped the harvest, cutting it down.\n";
90 }
91
92 $this->tribe->addFood($totalFood);
93 $this->story .= "Success! The explorers discovered edible plants and small game.\n";
94 $this->story .= "The tribe gained " . $this->tribe->foodTimeStr($totalFood) . " of food.\n\n";
95 } else {
96 $this->story .= "The terrain was barren. No food was found.\n\n";
97 }
98
99 $injuryChance = rand(1, 100) <= 20;
100 if ($injuryChance && count($explorers) > 0) {
101
102 // Select a random explorer to get injured
103 $injuredKobold = $explorers[array_rand($explorers)];
104
105 $this->story .= "Disaster! " . $injuredKobold->getName() . " tripped over a loose stone!\n";
106
107 $injuredKobold->addInjury("brokenLeg");
108
109 $this->story .= $injuredKobold->getName() . " broke a leg!\n";
110 }
111
112 $stickFound = rand(1, 100) <= 20;
113 if ($stickFound) {
114 $bestKobold = GameHelper::findBestKoboldForStat($explorers, "crafting");
115
116 $success = $bestKobold->checkStat("crafting");
117
118 if ($success) {
119 $boneItem = GameHelper::loadItem('bone-setting');
120 if ($boneItem) {
121 $this->tribe->addToStorage($boneItem);
122 $this->story .= "{$bestKobold->getName()} finds a nice stick and fashions it into a Splint the tribe can use to treat fractures.\n";
123 }
124 } else {
125 $this->story .= "{$bestKobold->getName()} finds a stick suitable to be a splint, but it breaks as {$bestKobold->he()} tries to craft it.\n";
126 }
127 }
128
129 $eggFound = rand(1, 100) <= 5;
130 if ($eggFound) {
131 $this->tribe->addKobold(Kobold::generate($this->tribe->getUserId(), $this->tribe->getSaveId(), rand(-6, -1)));
132 $this->story .= "The party finds a lost Kobold egg... Who might be inside?\n";
133 }
134
135 $this->story .= "\nThe exploration party returned to the tribe with their findings.";
136
137 return $this->story;
138 }
139}