BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / ExplorationEvent.php

ExplorationEvent.php

various fixes
timfa Tim · pushed by timfa · 9 months ago
49730f61 History
ExplorationEvent.php 4.0 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/Event.php';
4
5class ExplorationEvent extends Event
6{
7 public function execute()
8 {
9 $this->story = "The exploration party ventured forth into uncharted territory...\n\n";
10
11 $kobolds = $this->tribe->getAliveKobolds();
12
13 if (empty($kobolds)) {
14 $this->story .= "But there were no kobolds to send exploring!";
15 return;
16 }
17
18 // Randomly select 1-3 explorers
19 $explorerCount = rand(1, min(3, count($kobolds)));
20 $explorers = array_slice(array_values($kobolds), 0, $explorerCount);
21
22 $this->story .= "A group of " . count($explorers) . " intrepid explorers set out:\n";
23 foreach ($explorers as $explorer) {
24 $this->story .= "- " . $explorer->getName() . " (Intelligence: " . $this->statDisplay($explorer->getStat('intelligence')) . ")\n";
25 }
26 $this->story .= "\n";
27
28 // Chance to find food (50% base)
29 $foodFound = rand(1, 100) <= 50;
30 if ($foodFound) {
31 $baseFood = rand(5, 15);
32 // Intelligence affects food discovery - smarter kobolds find more
33 $avgIntelligence = array_sum(array_map(function ($k) {
34 return $k->getStat('intelligence'); }, $explorers)) / count($explorers);
35 $foodBonus = intval($avgIntelligence / 20); // Max +5 food from intelligence
36 $totalFood = $baseFood + $foodBonus;
37
38 $this->tribe->addFood($totalFood);
39 $this->story .= "Success! The explorers discovered edible plants and small game.\n";
40 $this->story .= "The tribe gained " . $totalFood . " units of food.\n\n";
41 } else {
42 $this->story .= "The terrain was barren. No food was found.\n\n";
43 }
44
45 // Chance for injury (35% - someone trips on loose stone)
46 $injuryChance = rand(1, 100) <= 35;
47 if ($injuryChance && count($explorers) > 0) {
48 // Vitality affects injury chance - higher vitality = less likely to be injured
49 $avgVitality = array_sum(array_map(function ($k) {
50 return $k->getStat('vitality'); }, $explorers)) / count($explorers);
51 $injuryProbability = (100 - $avgVitality) / 100;
52
53 if (rand(1, 100) / 100 <= $injuryProbability) {
54 // Select a random explorer to get injured
55 $injuredKobold = $explorers[array_rand($explorers)];
56
57 $this->story .= "Disaster! " . $injuredKobold->getName() . " tripped over a loose stone!\n";
58
59 // Create injury array (since we're in file-based storage)
60 $injuries = $injuredKobold->getInjuries();
61 $newInjury = [
62 'id' => uniqid('inj_'),
63 'kobold_id' => $injuredKobold->getId(),
64 'injury_type' => 'twisted_ankle',
65 'category' => 'wound',
66 'severity' => rand(2, 5),
67 'created_at' => date('Y-m-d H:i:s')
68 ];
69 $injuries[] = $newInjury;
70 $injuredKobold->setInjuries($injuries);
71
72 $this->story .= $injuredKobold->getName() . " suffered a twisted ankle (severity: " . $newInjury['severity'] . "/10).\n";
73 }
74 }
75
76 $this->story .= "\nThe exploration party returned to the tribe with their findings.";
77
78 return $this->story;
79 }
80
81 /**
82 * Convert internal stat value to display text
83 */
84 private function statDisplay($stat)
85 {
86 if ($stat <= 10)
87 return "terrible";
88 if ($stat <= 20)
89 return "bad";
90 if ($stat <= 30)
91 return "unskilled";
92 if ($stat <= 40)
93 return "decent";
94 if ($stat <= 50)
95 return "good";
96 if ($stat <= 60)
97 return "excellent";
98 if ($stat <= 70)
99 return "fantastic";
100 if ($stat <= 80)
101 return "master";
102 if ($stat <= 90)
103 return "divine";
104 return "godlike";
105 }
106}