BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / HeatWaveEvent.php

HeatWaveEvent.php

upd
timfa Tim Falken · pushed by timfa · 9 months ago
3298ef22 History
HeatWaveEvent.php 1.8 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4
5class HeatWaveEvent extends MonthEndEvent
6{
7 public function getMinAge()
8 {
9 return 0;
10 }
11
12 public function getMinParticipants()
13 {
14 return 0;
15 }
16
17 public function getMaxParticipants()
18 {
19 return 0;
20 }
21
22 public function getCost()
23 {
24 return 50;
25 }
26
27 public function isAvailable()
28 {
29 if ($this->tribe->getCurrentSeason() !== 'summer') {
30 return false;
31 }
32
33 return empty($this->tribe->dataStore->heatWaveActive);
34 }
35
36 private function getMonthsUntilNextSeason()
37 {
38 $monthOfYear = (($this->tribe->getCurrentMonth() - 1) % 12) + 1;
39 $monthInSeason = (($monthOfYear - 1) % 3) + 1;
40 return max(1, 3 - $monthInSeason + 1);
41 }
42
43 public function execute()
44 {
45 if (!isset($this->tribe->dataStore)) {
46 $this->tribe->dataStore = new stdClass();
47 }
48
49 $this->tribe->dataStore->heatWaveActive = rand(1, $this->getMonthsUntilNextSeason());
50
51 foreach ($this->tribe->getKobolds() as $kobold) {
52 $vitality = (int) ($kobold->getStat('vitality') ?? 0);
53 $fatigue = (int) ceil($vitality * 0.25);
54 if ($fatigue > 0) {
55 $kobold->addFatigue($fatigue);
56 }
57 }
58
59 $variations = [
60 "A punishing heat wave settled over the camp and left everyone drained. The tribe moved slowly under the sun, and their fatigue deepened.",
61 "The air shimmered with heat for days. Kobolds labored through it, and the whole tribe felt the heavy exhaustion.",
62 "Summer's worst heat arrived, and even simple tasks became burdens. The tribe endured the wave with sore limbs and weary eyes."
63 ];
64
65 $this->story = $variations[array_rand($variations)];
66 }
67}