BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / WalkDiscoveryEvent.php

WalkDiscoveryEvent.php

more events, rivals
timfa Tim Falken · pushed by timfa · 9 months ago
52fdcbf6 History
WalkDiscoveryEvent.php 3.5 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 8;
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 20;
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 $foodVariations = [
58 "{$nameA} found some edible plants during a walk and brought back {$foodAmount} food.",
59 "While exploring, {$nameA} discovered a cache of berries and returned with {$foodAmount} food.",
60 "{$nameA}'s keen eye spotted food sources, adding {$foodAmount} to the tribe's stores.",
61 "A fortunate walk led {$nameA} to gather {$foodAmount} food for the tribe.",
62 "{$nameA} returned from a walk with {$foodAmount} food, a welcome find.",
63 "During a solitary walk, {$nameA} found edible resources and collected {$foodAmount} food.",
64 "{$nameA} stumbled upon a food source during a walk, bringing back {$foodAmount}.",
65 ];
66
67 $this->story = $foodVariations[array_rand($foodVariations)];
68 } else {
69 // Item discovery
70 $items = [
71 ['name' => 'bone-setting', 'displayName' => 'bone-setting kit'],
72 ['name' => 'healing-herbs', 'displayName' => 'healing herbs'],
73 ['name' => 'book', 'displayName' => 'old book'],
74 ];
75
76 $item = $items[array_rand($items)];
77
78 // Load item template
79 $itemData = GameHelper::loadItem($item['name']);
80 if ($itemData) {
81 $this->tribe->addToStorage($itemData);
82
83 $itemVariations = [
84 "{$nameA} discovered an old {$item['displayName']} during a walk.",
85 "While wandering, {$nameA} found a {$item['displayName']} and brought it back.",
86 "{$nameA}'s sharp eyes spotted a {$item['displayName']} lying in the wilderness.",
87 "A lucky find—{$nameA} returned with a {$item['displayName']}.",
88 "{$nameA} came back from a walk carrying a {$item['displayName']}.",
89 "The tribe is pleased that {$nameA} found a {$item['displayName']} on a recent walk.",
90 "{$nameA} stumbled upon a {$item['displayName']} and wisely brought it to the tribe.",
91 ];
92
93 $this->story = $itemVariations[array_rand($itemVariations)];
94 } else {
95 // Fallback if item loading fails
96 $this->story = "{$nameA} returned from a walk with interesting findings.";
97 }
98 }
99 }
100}