BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / ExplorationEvent.php

ExplorationEvent.php

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