BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / ActivityInjuryEvent.php

ActivityInjuryEvent.php

fix errors
timfa Tim · pushed by timfa · 9 months ago
e130a216 History
ActivityInjuryEvent.php 2.6 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4require_once __DIR__ . '/../../src/Classes/Kobold.php';
5
6class ActivityInjuryEvent extends MonthEndEvent
7{
8 public function getMinAge()
9 {
10 return 12;
11 }
12
13 public function getMinParticipants()
14 {
15 return 2;
16 }
17
18 public function getMaxParticipants()
19 {
20 return 5;
21 }
22
23 public function getCost()
24 {
25 return 30;
26 }
27
28 public function isAvailable()
29 {
30 return true;
31 }
32
33 public function execute()
34 {
35 $this->story = '';
36
37 $eligible = array_filter($this->tribe->getAliveKobolds(), fn($k) => $k->getAge() >= $this->getMinAge());
38 $eligible = array_values($eligible);
39
40 if (count($eligible) < $this->getMinParticipants()) {
41 return;
42 }
43
44 // Randomly select 2-5 participants
45 shuffle($eligible);
46 $count = rand($this->getMinParticipants(), min($this->getMaxParticipants(), count($eligible)));
47 $participants = array_slice($eligible, 0, $count);
48
49 $participantNames = array_map(fn($k) => $k->getName(), $participants);
50
51 $activities = [
52 'gathering expedition',
53 'hunting trip',
54 'fishing outing',
55 'water crossing',
56 'climbing exercise',
57 ];
58
59 $activity = $activities[array_rand($activities)];
60
61 $injuryTypes = ['smallCut', 'sunburn', 'brokenLeg'];
62
63 // Randomly injure 1-2 participants
64 $injuredCount = rand(1, min(2, count($participants)));
65 for ($i = 0; $i < $injuredCount; $i++) {
66 $injured = $participants[array_rand($participants)];
67 $injuryType = $injuryTypes[array_rand($injuryTypes)];
68 $injured->addInjury($injuryType);
69 $injured->save();
70 }
71
72 $namesStr = implode(' and ', $participantNames);
73
74 $variations = [
75 "During a {$activity}, {$namesStr} had a rough time, with some coming away injured.",
76 "Things went awry during a {$activity}. Not all of the group made it back unscathed.",
77 "A {$activity} was more treacherous than expected, and several members returned hurt.",
78 "Accidents happened during a {$activity}, leaving some of the participants bruised.",
79 "A {$activity} was poorly executed, resulting in injuries for some participants.",
80 "{$namesStr} engaged in a {$activity} that did not go as planned, with injuries sustained.",
81 "A {$activity} left several of the participants nursing wounds they received.",
82 ];
83
84 $this->story = $variations[array_rand($variations)];
85 }
86}