BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / ExplorationEvent.php

ExplorationEvent.php

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