BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / ExplorationEvent.php

ExplorationEvent.php

fix events, item giving
timfa Tim Falken · pushed by timfa · 9 months ago
025e6a5e History
ExplorationEvent.php 3.3 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 .= "A group of " . count($explorers) . " intrepid explorers set out:\n";
37 foreach ($explorers as $explorer) {
38 $this->story .= "- " . $explorer->getName() . " (Intelligence: " . GameHelper::getStatLabel($explorer->getStat('intelligence')) . ")\n";
39 }
40 $this->story .= "\n";
41
42 // Chance to find food (50% base)
43 $foodFound = rand(1, 100) <= 50;
44 if ($foodFound) {
45 $baseFood = rand(5, 15);
46 // Intelligence affects food discovery - smarter kobolds find more
47 $avgIntelligence = array_sum(array_map(function ($k) {
48 return $k->getStat('intelligence');
49 }, $explorers)) / count($explorers);
50 $foodBonus = intval($avgIntelligence / 20); // Max +5 food from intelligence
51 $totalFood = $baseFood + $foodBonus;
52
53 $this->tribe->addFood($totalFood);
54 $this->story .= "Success! The explorers discovered edible plants and small game.\n";
55 $this->story .= "The tribe gained " . $totalFood . " units of food.\n\n";
56 } else {
57 $this->story .= "The terrain was barren. No food was found.\n\n";
58 }
59
60 // Chance for injury (large chance for testing) - someone trips on loose stone
61 $injuryChance = rand(1, 100) <= 99; // higher for testing
62 if ($injuryChance && count($explorers) > 0) {
63
64 // Select a random explorer to get injured
65 $injuredKobold = $explorers[array_rand($explorers)];
66
67 $this->story .= "Disaster! " . $injuredKobold->getName() . " tripped over a loose stone!\n";
68
69 $injuredKobold->addInjury("brokenLeg");
70
71 $this->story .= $injuredKobold->getName() . " broke a leg!\n";
72 }
73
74 // For testing: add a 'bone-setting' item to tribe storage so player can cure fractures
75 $boneItem = GameHelper::loadItem('bone-setting');
76 if ($boneItem) {
77 $this->tribe->addToStorage($boneItem);
78 $this->story .= "The explorers also salvaged a Bone-setting kit and brought it back to storage.\n";
79 }
80
81 $this->story .= "\nThe exploration party returned to the tribe with their findings.";
82
83 return $this->story;
84 }
85}