BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / InjuryRecoveryEvent.php

InjuryRecoveryEvent.php

fix errors
timfa Tim · pushed by timfa · 9 months ago
e130a216 History
InjuryRecoveryEvent.php 3.1 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4require_once __DIR__ . '/../../src/Classes/Kobold.php';
5
6class InjuryRecoveryEvent extends MonthEndEvent
7{
8 public function getMinAge()
9 {
10 return 0;
11 }
12
13 public function getMinParticipants()
14 {
15 return 1;
16 }
17
18 public function getMaxParticipants()
19 {
20 return 1;
21 }
22
23 public function getCost()
24 {
25 return 40;
26 }
27
28 public function isAvailable()
29 {
30 $eligible = array_filter($this->tribe->getAliveKobolds(), function ($k) {
31 $injuries = $k->getInjuries() ?? [];
32 foreach ($injuries as $inj) {
33 $category = $inj['category'] ?? null;
34 // Only these categories can heal naturally
35 if (in_array($category, ['cut', 'bruise', 'burn'])) {
36 return true;
37 }
38 }
39 return false;
40 });
41
42 $eligible = array_values($eligible);
43 return !empty($eligible);
44 }
45
46 public function execute()
47 {
48 $this->story = '';
49
50 // Find a kobold with injuries that can heal naturally
51 $eligible = array_filter($this->tribe->getAliveKobolds(), function ($k) {
52 $injuries = $k->getInjuries() ?? [];
53 foreach ($injuries as $inj) {
54 $category = $inj['category'] ?? null;
55 // Only these categories can heal naturally
56 if (in_array($category, ['cut', 'bruise', 'burn'])) {
57 return true;
58 }
59 }
60 return false;
61 });
62
63 $eligible = array_values($eligible);
64
65 if (empty($eligible)) {
66 return;
67 }
68
69 $kobold = $eligible[array_rand($eligible)];
70 $injuries = $kobold->getInjuries() ?? [];
71
72 // Find first healable injury
73 $healableInjuries = [];
74 foreach ($injuries as $inj) {
75 $category = $inj['category'] ?? null;
76 if (in_array($category, ['cut', 'bruise', 'burn'])) {
77 $healableInjuries[] = $inj;
78 }
79 }
80
81 if (empty($healableInjuries)) {
82 return;
83 }
84
85 $toHeal = $healableInjuries[array_rand($healableInjuries)];
86 $kobold->removeInjury($toHeal['id']);
87
88 $nameA = $kobold->getName();
89 $injuryName = $toHeal['injury_type'] ?? $toHeal['injuryType'] ?? 'injury';
90
91 $recoveryVariations = [
92 "{$nameA} has healed from the {$injuryName} and is feeling much better.",
93 "Time and rest worked wonders for {$nameA}, who has recovered from the {$injuryName}.",
94 "{$nameA}'s {$injuryName} finally healed after a month of careful rest.",
95 "The tribe is relieved to see {$nameA}'s {$injuryName} finally resolved.",
96 "{$nameA} is back to full strength, the {$injuryName} now a fading memory.",
97 "A period of quiet recovery allowed {$nameA} to heal from the {$injuryName}.",
98 "{$nameA} has made a full recovery from the {$injuryName}.",
99 ];
100
101 $this->story = $recoveryVariations[array_rand($recoveryVariations)];
102
103 $kobold->save();
104 }
105}