BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / InjuryRecoveryEvent.php

InjuryRecoveryEvent.php

more events, rivals
timfa Tim Falken · pushed by timfa · 9 months ago
52fdcbf6 History
InjuryRecoveryEvent.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 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 5;
26 }
27
28 public function isAvailable()
29 {
30 return true;
31 }
32
33 public function execute()
34 {
35 $this->story = '';
36
37 // Find a kobold with injuries that can heal naturally
38 $eligible = array_filter($this->tribe->getAliveKobolds(), function ($k) {
39 $injuries = $k->getInjuries() ?? [];
40 foreach ($injuries as $inj) {
41 $category = $inj['category'] ?? null;
42 // Only these categories can heal naturally
43 if (in_array($category, ['cut', 'bruise', 'burn'])) {
44 return true;
45 }
46 }
47 return false;
48 });
49
50 $eligible = array_values($eligible);
51
52 if (empty($eligible)) {
53 return;
54 }
55
56 $kobold = $eligible[array_rand($eligible)];
57 $injuries = $kobold->getInjuries() ?? [];
58
59 // Find first healable injury
60 $healableInjuries = [];
61 foreach ($injuries as $inj) {
62 $category = $inj['category'] ?? null;
63 if (in_array($category, ['cut', 'bruise', 'burn'])) {
64 $healableInjuries[] = $inj;
65 }
66 }
67
68 if (empty($healableInjuries)) {
69 return;
70 }
71
72 $toHeal = $healableInjuries[array_rand($healableInjuries)];
73 $kobold->removeInjury($toHeal['id']);
74
75 $nameA = $kobold->getName();
76 $injuryName = $toHeal['injury_type'] ?? $toHeal['injuryType'] ?? 'injury';
77
78 $recoveryVariations = [
79 "{$nameA} has healed from the {$injuryName} and is feeling much better.",
80 "Time and rest worked wonders for {$nameA}, who has recovered from the {$injuryName}.",
81 "{$nameA}'s {$injuryName} finally healed after a month of careful rest.",
82 "The tribe is relieved to see {$nameA}'s {$injuryName} finally resolved.",
83 "{$nameA} is back to full strength, the {$injuryName} now a fading memory.",
84 "A period of quiet recovery allowed {$nameA} to heal from the {$injuryName}.",
85 "{$nameA} has made a full recovery from the {$injuryName}.",
86 ];
87
88 $this->story = $recoveryVariations[array_rand($recoveryVariations)];
89
90 $kobold->save();
91 }
92}