BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / WalkDiscoveryEvent.php

WalkDiscoveryEvent.php

fix errors
timfa Tim · pushed by timfa · 9 months ago
e130a216 History
WalkDiscoveryEvent.php 3.6 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4require_once __DIR__ . '/../../src/Classes/Kobold.php';
5require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
6
7class WalkDiscoveryEvent extends MonthEndEvent
8{
9 public function getMinAge()
10 {
11 return 13;
12 }
13
14 public function getMinParticipants()
15 {
16 return 1;
17 }
18
19 public function getMaxParticipants()
20 {
21 return 1;
22 }
23
24 public function getCost()
25 {
26 return 40;
27 }
28
29 public function isAvailable()
30 {
31 return true;
32 }
33
34 public function execute()
35 {
36 $this->story = '';
37
38 $eligible = array_filter($this->tribe->getAliveKobolds(), fn($k) => $k->getAge() >= $this->getMinAge());
39 $eligible = array_values($eligible);
40
41 if (empty($eligible)) {
42 return;
43 }
44
45 $kobold = $eligible[array_rand($eligible)];
46
47 // Determine what was found
48 $roll = rand(1, 100);
49
50 $nameA = $kobold->getName();
51
52 if ($roll <= 60) {
53 // Food discovery
54 $foodAmount = rand(3, 8);
55 $this->tribe->addFood($foodAmount);
56
57 $foodStr = $this->tribe->foodTimeStr($foodAmount);
58
59 $foodVariations = [
60 "{$nameA} found some edible plants during a walk and brought back {$foodStr} worth of food.",
61 "While exploring, {$nameA} discovered a cache of berries and returned with {$foodStr} worth of food.",
62 "{$nameA}'s keen eye spotted food sources, adding {$foodStr} worth of food to the tribe's stores.",
63 "A fortunate walk led {$nameA} to gather {$foodStr} worth of food for the tribe.",
64 "{$nameA} returned from a walk with {$foodStr} worth of food, a welcome find.",
65 "During a solitary walk, {$nameA} found edible resources and collected {$foodStr} worth of food.",
66 "{$nameA} stumbled upon a food source during a walk, bringing back {$foodStr} worth of food.",
67 ];
68
69 $this->story = $foodVariations[array_rand($foodVariations)];
70 } else {
71 // Item discovery
72 $items = [
73 ['name' => 'bone-setting', 'displayName' => 'bone-setting kit'],
74 ['name' => 'healing-herbs', 'displayName' => 'healing herbs'],
75 ['name' => 'book', 'displayName' => 'old book'],
76 ];
77
78 $item = $items[array_rand($items)];
79
80 // Load item template
81 $itemData = GameHelper::loadItem($item['name']);
82 if ($itemData) {
83 $this->tribe->addToStorage($itemData);
84
85 $itemVariations = [
86 "{$nameA} discovered an old {$item['displayName']} during a walk.",
87 "While wandering, {$nameA} found a {$item['displayName']} and brought it back.",
88 "{$nameA}'s sharp eyes spotted a {$item['displayName']} lying in the wilderness.",
89 "A lucky find—{$nameA} returned with a {$item['displayName']}.",
90 "{$nameA} came back from a walk carrying a {$item['displayName']}.",
91 "The tribe is pleased that {$nameA} found a {$item['displayName']} on a recent walk.",
92 "{$nameA} stumbled upon a {$item['displayName']} and wisely brought it to the tribe.",
93 ];
94
95 $this->story = $itemVariations[array_rand($itemVariations)];
96 } else {
97 // Fallback if item loading fails
98 $this->story = "{$nameA} returned from a walk with interesting findings.";
99 }
100 }
101 }
102}