BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / BigStormEvent.php

BigStormEvent.php

test
timfa Tim Falken · pushed by timfa · 9 months ago
8d0ee02f History
BigStormEvent.php 2.2 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4
5class BigStormEvent 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 55;
25 }
26
27 public function isAvailable()
28 {
29 return true;
30 }
31
32 public function execute()
33 {
34 if (!isset($this->tribe->dataStore)) {
35 $this->tribe->dataStore = new stdClass();
36 }
37
38 $foodLost = 0;
39 $currentFood = $this->tribe->getFoodCount();
40 if ($currentFood > 0 && rand(1, 100) <= 70) {
41 $percent = rand(5, 20);
42 $foodLost = (int) floor($currentFood * ($percent / 100));
43 if ($foodLost > 0) {
44 $this->tribe->removeFood($foodLost);
45 }
46 }
47
48 $lightningVictim = null;
49 if (rand(1, 100) <= 5) {
50 $alive = array_values($this->tribe->getAliveKobolds());
51 if (!empty($alive)) {
52 $lightningVictim = $alive[array_rand($alive)];
53 $lightningVictim->die();
54 }
55 }
56
57 $intros = [
58 "A violent storm rolled over the tribe, tearing at tents and shaking the ground.",
59 "Dark clouds gathered quickly, and a brutal storm swept across the camp.",
60 "Wind and rain arrived in force, and the tribe huddled through a fierce storm."
61 ];
62
63 $details = [];
64 if ($foodLost > 0) {
65 $details[] = "Some stores were ruined in the downpour, costing the tribe {$this->tribe->foodTimeStr($foodLost)} of food.";
66 } else {
67 $details[] = "The stores held up better than expected, and no food was lost.";
68 }
69
70 if ($lightningVictim) {
71 $details[] = "Tragedy struck when lightning found {$lightningVictim->getName()}, and the tribe mourned the loss.";
72 } else {
73 $details[] = "No one was lost to the storm, though the camp will remember the night.";
74 }
75
76 $this->story = $intros[array_rand($intros)] . ' ' . $details[0] . ' ' . $details[1];
77 }
78}