BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / LargeFloodEvent.php

LargeFloodEvent.php

test
timfa Tim Falken · pushed by timfa · 9 months ago
8d0ee02f History
LargeFloodEvent.php 2.3 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4
5class LargeFloodEvent 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 85;
25 }
26
27 public function isAvailable()
28 {
29 return $this->tribe->getCurrentSeason() === 'autumn';
30 }
31
32 public function execute()
33 {
34 if (!isset($this->tribe->dataStore)) {
35 $this->tribe->dataStore = new stdClass();
36 }
37 $this->tribe->dataStore->floodedThisMonth = true;
38
39 $currentFood = $this->tribe->getFoodCount();
40 $foodLost = 0;
41 if ($currentFood > 0) {
42 $percent = rand(30, 60);
43 $foodLost = (int) floor($currentFood * ($percent / 100));
44 if ($foodLost > 0) {
45 $this->tribe->removeFood($foodLost);
46 }
47 }
48
49 $alive = array_values($this->tribe->getAliveKobolds());
50 $drowned = [];
51 if (!empty($alive)) {
52 $percent = rand(10, 50);
53 $count = (int) floor(count($alive) * ($percent / 100));
54 if ($count > 0) {
55 shuffle($alive);
56 $drowned = array_slice($alive, 0, $count);
57 foreach ($drowned as $kobold) {
58 $kobold->die();
59 }
60 }
61 }
62
63 $drownedNames = array_map(fn($k) => $k->getName(), $drowned);
64 $lossText = $foodLost > 0 ? "The flood ruined {$this->tribe->foodTimeStr($foodLost)} of food." : "Food stores were battered but not fully ruined.";
65 $drownText = empty($drownedNames)
66 ? "Miraculously, no one was swept away."
67 : "The waters took " . implode(', ', $drownedNames) . ", and the tribe grieved as the flood passed.";
68
69 $variations = [
70 "Autumn rains swelled into a massive flood that tore through the camp. {$lossText} {$drownText}",
71 "The river burst its banks and swallowed the lower dens. {$lossText} {$drownText}",
72 "A roaring flood swept across the tribe's ground and left ruin behind. {$lossText} {$drownText}"
73 ];
74
75 $this->story = $variations[array_rand($variations)];
76 }
77}