BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / ExplorationEvent.php

ExplorationEvent.php

fix errors
timfa Tim · pushed by timfa · 9 months ago
e130a216 History
ExplorationEvent.php 4.4 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 $this->tribe->addFood($totalFood);
86 $this->story .= "Success! The explorers discovered edible plants and small game.\n";
87 $this->story .= "The tribe gained " . $this->tribe->foodTimeStr($totalFood) . " of food.\n\n";
88 } else {
89 $this->story .= "The terrain was barren. No food was found.\n\n";
90 }
91
92 $injuryChance = rand(1, 100) <= 20;
93 if ($injuryChance && count($explorers) > 0) {
94
95 // Select a random explorer to get injured
96 $injuredKobold = $explorers[array_rand($explorers)];
97
98 $this->story .= "Disaster! " . $injuredKobold->getName() . " tripped over a loose stone!\n";
99
100 $injuredKobold->addInjury("brokenLeg");
101
102 $this->story .= $injuredKobold->getName() . " broke a leg!\n";
103 }
104
105 $stickFound = rand(1, 100) <= 20;
106 if ($stickFound) {
107 $bestKobold = GameHelper::findBestKoboldForStat($explorers, "crafting");
108
109 $success = $bestKobold->checkStat("crafting");
110
111 if ($success) {
112 $boneItem = GameHelper::loadItem('bone-setting');
113 if ($boneItem) {
114 $this->tribe->addToStorage($boneItem);
115 $this->story .= "{$bestKobold->getName()} finds a nice stick and fashions it into a Splint the tribe can use to treat fractures.\n";
116 }
117 } else {
118 $this->story .= "{$bestKobold->getName()} finds a stick suitable to be a splint, but it breaks as {$bestKobold->he()} tries to craft it.\n";
119 }
120 }
121
122 $eggFound = rand(1, 100) <= 3;
123 if ($eggFound) {
124 $this->tribe->addKobold(Kobold::generate($this->tribe->getUserId(), $this->tribe->getSaveId(), rand(-6, -1)));
125 $this->story .= "The party finds a lost Kobold egg... What might be inside?\n";
126 }
127
128 $this->story .= "\nThe exploration party returned to the tribe with their findings.";
129
130 return $this->story;
131 }
132}