BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / DroughtEvent.php

DroughtEvent.php

upd
timfa Tim Falken · pushed by timfa · 9 months ago
3298ef22 History
DroughtEvent.php 1.8 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4
5class DroughtEvent 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 45;
25 }
26
27 public function isAvailable()
28 {
29 if ($this->tribe->getCurrentSeason() !== 'summer') {
30 return false;
31 }
32
33 if (!empty($this->tribe->dataStore->draught)) {
34 return false;
35 }
36
37 if (isset($this->tribe->dataStore) && isset($this->tribe->dataStore->floodedThisMonth) && $this->tribe->dataStore->floodedThisMonth) {
38 return false;
39 }
40
41 return true;
42 }
43
44 private function getMonthsUntilNextSeason()
45 {
46 $monthOfYear = (($this->tribe->getCurrentMonth() - 1) % 12) + 1;
47 $monthInSeason = (($monthOfYear - 1) % 3) + 1;
48 return max(1, 3 - $monthInSeason + 1);
49 }
50
51 public function execute()
52 {
53 if (!isset($this->tribe->dataStore)) {
54 $this->tribe->dataStore = new stdClass();
55 }
56
57 $this->tribe->dataStore->draught = rand(1, $this->getMonthsUntilNextSeason());
58
59 $variations = [
60 "The heat lingered and the land cracked. No rain came, and the tribe marked the month as a drought, watching the streams grow thin.",
61 "Summer skies stayed empty of rain. The tribe endured a drought and set aside what little moisture remained.",
62 "Days passed with no relief, and the camp felt the weight of drought. The elders warned that the dry season might worsen before it breaks."
63 ];
64
65 $this->story = $variations[array_rand($variations)];
66 }
67}