BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / ExplorationEvent.php

ExplorationEvent.php

event tweaks
timfa Tim Falken · pushed by timfa · 9 months ago
fd114d31 History
ExplorationEvent.php 3.7 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/Event.php';
4require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
5
6class ExplorationEvent extends Event
7{
8 public function execute()
9 {
10 $this->story = "The exploration party ventured forth into uncharted territory...\n\n";
11
12 $available = $this->tribe->getAliveKobolds();
13
14 if (empty($available)) {
15 $this->story .= "But there were no kobolds to send exploring!";
16 return;
17 }
18
19 // Exploration must be started with explicit participants (player-started)
20 $participantIds = $this->getParticipants();
21 if (empty($participantIds) || !is_array($participantIds)) {
22 throw new \Exception('ExplorationEvent requires a participants array of kobold IDs.');
23 }
24
25 $explorers = [];
26 foreach ($participantIds as $pid) {
27 $k = $this->tribe->getKobold($pid);
28 if ($k && !$k->isDead())
29 $explorers[] = $k;
30 }
31
32 if (empty($explorers)) {
33 throw new \Exception('No valid living kobolds found in participants list.');
34 }
35
36 $this->story .= count($explorers) > 1 ?
37 "A group of " . count($explorers) . " intrepid explorers set out:\n"
38 : $explorers[0]->getName() . " sets out to explore.\n";
39
40 if (count($explorers) > 1) {
41 foreach ($explorers as $explorer) {
42 $this->story .= "- " . $explorer->getName() . "\n";
43 }
44 $this->story .= "\n";
45 }
46
47 // Chance to find food (50% base)
48 $foodFound = rand(1, 100) <= 50;
49 if ($foodFound) {
50 $baseFood = rand(5, 15);
51 // Intelligence affects food discovery - smarter kobolds find more
52 $avgIntelligence = array_sum(array_map(function ($k) {
53 return $k->getStat('intelligence');
54 }, $explorers)) / count($explorers);
55
56 $foodBonus = intval($avgIntelligence / 20); // Max +5 food from intelligence
57 $totalFood = $baseFood + $foodBonus;
58
59 $this->tribe->addFood($totalFood);
60 $this->story .= "Success! The explorers discovered edible plants and small game.\n";
61 $this->story .= "The tribe gained " . $totalFood . " units of food.\n\n";
62 } else {
63 $this->story .= "The terrain was barren. No food was found.\n\n";
64 }
65
66 $injuryChance = rand(1, 100) <= 20;
67 if ($injuryChance && count($explorers) > 0) {
68
69 // Select a random explorer to get injured
70 $injuredKobold = $explorers[array_rand($explorers)];
71
72 $this->story .= "Disaster! " . $injuredKobold->getName() . " tripped over a loose stone!\n";
73
74 $injuredKobold->addInjury("brokenLeg");
75
76 $this->story .= $injuredKobold->getName() . " broke a leg!\n";
77 }
78
79 $stickFound = rand(1, 100) <= 200;
80 if ($stickFound) {
81 $bestKobold = GameHelper::findBestKoboldForStat($explorers, "crafting");
82
83 $success = $bestKobold->checkStat("crafting");
84
85 if ($success) {
86 $boneItem = GameHelper::loadItem('bone-setting');
87 if ($boneItem) {
88 $this->tribe->addToStorage($boneItem);
89 $this->story .= "{$bestKobold->getName()} finds a nice stick and fashions it into a Splint the tribe can use to treat fractures.\n";
90 }
91 } else {
92 $this->story .= "{$bestKobold->getName()} finds a stick suitable to be a splint, but it breaks as {$bestKobold->he()} tries to craft it.\n";
93 }
94 }
95 $this->story .= "\nThe exploration party returned to the tribe with their findings.";
96
97 return $this->story;
98 }
99}