BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / BigStormEvent.php

BigStormEvent.php

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