farm overhaul
@@ -0,0 +1,15 @@
1
{
2
"injuryType": "Sunburn",
3
"description": "Painful, inflamed skin from too much sun exposure, reducing endurance and focus.",
4
"category": "burn",
5
"severity": 1,
6
"statModifications": {
7
"vitality": -3,
8
"intelligence": -1,
9
"medicine": 0,
10
"crafting": -2,
11
"personality": -1,
12
"will": -2,
13
"fighting": -3
14
}
15
}
@@ -0,0 +1,15 @@1
{2
"injuryType": "Sunburn",3
"description": "Painful, inflamed skin from too much sun exposure, reducing endurance and focus.",4
"category": "burn",5
"severity": 1,6
"statModifications": {7
"vitality": -3,8
"intelligence": -1,9
"medicine": 0,10
"crafting": -2,11
"personality": -1,12
"will": -2,13
"fighting": -314
}15
}@@ -17,6 +17,7 @@ class Tribe
17
17
private $createdAt;
18
18
private $lastPlayed;
19
19
private $saveManager;
20
public $dataStore;
20
21
21
22
// Food requirement by age tier (portion units)
22
23
public $foodRequirements = [
@@ -70,6 +71,7 @@ class Tribe
70
71
$this->environmentId = $data['environment_id'] ?? null;
71
72
$this->createdAt = $data['created_at'] ?? date('Y-m-d H:i:s');
72
73
$this->lastPlayed = $data['last_played'] ?? date('Y-m-d H:i:s');
74
$this->dataStore = $data['data_store'] ?? new stdClass();
73
75
}
74
76
}
75
77
@@ -125,7 +127,8 @@ class Tribe
125
127
'food_months_left' => $this->foodMonthsLeft($this->foodCount),
126
128
'environment_id' => $this->environmentId,
127
129
'created_at' => $this->createdAt,
128
'last_played' => $this->lastPlayed
130
'last_played' => $this->lastPlayed,
131
'data_store' => $this->dataStore ?? new stdClass()
129
132
];
130
133
131
134
$this->saveManager->saveJson($savePath . '/save.json', $tribeData);
@@ -17,6 +17,7 @@ class Tribe17
private $createdAt;17
private $createdAt;18
private $lastPlayed;18
private $lastPlayed;19
private $saveManager;19
private $saveManager;20
public $dataStore;20
21
21
// Food requirement by age tier (portion units)22
// Food requirement by age tier (portion units)22
public $foodRequirements = [23
public $foodRequirements = [@@ -70,6 +71,7 @@ class Tribe70
$this->environmentId = $data['environment_id'] ?? null;71
$this->environmentId = $data['environment_id'] ?? null;71
$this->createdAt = $data['created_at'] ?? date('Y-m-d H:i:s');72
$this->createdAt = $data['created_at'] ?? date('Y-m-d H:i:s');72
$this->lastPlayed = $data['last_played'] ?? date('Y-m-d H:i:s');73
$this->lastPlayed = $data['last_played'] ?? date('Y-m-d H:i:s');74
$this->dataStore = $data['data_store'] ?? new stdClass();73
}75
}74
}76
}75
77
@@ -125,7 +127,8 @@ class Tribe125
'food_months_left' => $this->foodMonthsLeft($this->foodCount),127
'food_months_left' => $this->foodMonthsLeft($this->foodCount),126
'environment_id' => $this->environmentId,128
'environment_id' => $this->environmentId,127
'created_at' => $this->createdAt,129
'created_at' => $this->createdAt,128
'last_played' => $this->lastPlayed130
'last_played' => $this->lastPlayed,131
'data_store' => $this->dataStore ?? new stdClass()129
];132
];130
133
131
$this->saveManager->saveJson($savePath . '/save.json', $tribeData);134
$this->saveManager->saveJson($savePath . '/save.json', $tribeData);@@ -19,11 +19,11 @@ class FarmingEvent extends Event
19
19
{
20
20
switch ($this->tribe->getCurrentSeason()) {
21
21
case 'spring':
22
return 20;
23
case 'summer':
24
22
return 25;
23
case 'summer':
24
return 15;
25
25
case 'autumn':
26
return 30;
26
return 20;
27
27
case 'winter':
28
28
return 60;
29
29
default:
@@ -33,26 +33,36 @@ class FarmingEvent extends Event
33
33
34
34
public function isAvailable()
35
35
{
36
return $this->tribe->getCurrentSeason() !== 'winter';
37
}
36
if ($this->tribe->getCurrentSeason() !== 'winter') {
37
if ($this->tribe->getCurrentSeason() === 'spring')
38
return !isset($this->tribe->dataStore->wasSowedInSpring) || !$this->tribe->dataStore->wasSowedInSpring;
38
39
39
public function execute()
40
{
41
$participantIds = $this->getParticipants();
42
$explorers = [];
43
foreach ($participantIds as $pid) {
44
$k = $this->tribe->getKobold($pid);
45
if ($k && !$k->isDead())
46
$explorers[] = $k;
40
if ($this->tribe->getCurrentSeason() === 'summer')
41
return isset($this->tribe->dataStore->wasSowedInSpring) && $this->tribe->dataStore->wasSowedInSpring;
42
43
if ($this->tribe->getCurrentSeason() === 'autumn')
44
return isset($this->tribe->dataStore->wasTendedInSummer) && $this->tribe->dataStore->wasTendedInSummer;
47
45
}
48
46
49
$leader = GameHelper::findBestKoboldForStat($explorers, "intelligence");
50
$hardestWorker = GameHelper::findBestKoboldForStat($explorers, "vitality");
47
// reset values since this part of the code is only ever reached in winter so we might as well.
48
$this->tribe->dataStore->wasSowedInSpring = false;
49
$this->tribe->dataStore->wasTendedInSummer = false;
50
return false;
51
}
52
53
public function spring(array $all, Kobold $bestInt, Kobold $bestVit)
54
{
55
$successes = 0;
56
$this->tribe->dataStore->farmYieldMultiplier = 0.5;
57
$this->tribe->dataStore->wasSowedInSpring = true;
51
58
52
$this->story = "The farmers tended to their crops. {$leader->getName()} took the lead.\n";
59
for ($i = 0; $i < count($all); $i++) {
60
$farmer = $all[$i];
53
61
54
for ($i = 0; $i < count($explorers); $i++) {
55
$farmer = $explorers[$i];
62
if ($farmer->checkStat('vitality') && $farmer->checkStat('intelligence')) {
63
$this->tribe->dataStore->farmYieldMultiplier += 1;
64
$successes++;
65
}
56
66
57
67
if (!$farmer->checkStat('will') && rand(1, 100) <= 30) {
58
68
$farmer->addInjury("smallCut");
@@ -61,8 +71,44 @@ class FarmingEvent extends Event
61
71
}
62
72
}
63
73
64
for ($i = 0; $i < count($explorers); $i++) {
65
$farmer = $explorers[$i];
74
$word = "terribly";
75
$perc = ($successes / $this->getMaxParticipants());
76
77
if ($perc >= 0.95)
78
$word = "perfectly";
79
else if ($perc >= 0.75)
80
$word = "great";
81
else if ($perc >= 0.5)
82
$word = "well";
83
else if ($perc >= 0.25)
84
$word = "okay";
85
else if ($perc >= 0.1)
86
$word = "badly";
87
88
$this->story .= "Tilling and sowing the fields went {$word}.\n";
89
90
$this->tribe->dataStore->wasSowedInSpring = true;
91
}
92
93
public function summer(array $all, Kobold $bestInt, Kobold $bestVit)
94
{
95
$successes = 0;
96
$this->tribe->dataStore->wasSowedInSpring = false;
97
$this->tribe->dataStore->wasTendedInSummer = true;
98
99
for ($i = 0; $i < count($all); $i++) {
100
$farmer = $all[$i];
101
102
if ($farmer->checkStat('vitality') && $farmer->checkStat('intelligence')) {
103
$this->tribe->dataStore->farmYieldMultiplier += 0.5;
104
$successes++;
105
}
106
107
if (!$farmer->checkStat('vitality') && rand(1, 100) <= 25) {
108
$farmer->addInjury("sunburn");
109
$this->story .= "{$farmer->getName()} got badly sunburned while working in the fields under the hot sun.\n";
110
break;
111
}
66
112
67
113
if ($farmer->checkStat('intelligence') && rand(1, 100) <= 40) {
68
114
$herbs = GameHelper::loadItem('healing-herbs');
@@ -72,45 +118,91 @@ class FarmingEvent extends Event
72
118
}
73
119
}
74
120
75
if (!$leader->checkStat('intelligence')) {
76
$this->story .= "Unfortunately, {$leader->getName()} made several mistakes in planting and caring for the crops.\n";
77
$this->story .= "Despite {$hardestWorker->getName()}'s best efforts, the crops had rotten and were lost.\n";
78
return $this->story;
79
} else {
80
$totalFood = 0;
81
$mostFood = 0;
82
$mostFarmedBy = '';
121
$word = "terribly";
122
$perc = ($successes / $this->getMaxParticipants());
123
124
if ($perc >= 0.95)
125
$word = "perfectly";
126
else if ($perc >= 0.75)
127
$word = "great";
128
else if ($perc >= 0.5)
129
$word = "well";
130
else if ($perc >= 0.25)
131
$word = "okay";
132
else if ($perc >= 0.1)
133
$word = "badly";
134
135
$this->story .= "Tending to the crops went {$word}.\n";
136
}
83
137
84
for ($i = 0; $i < count($explorers); $i++) {
85
$farmer = $explorers[$i];
138
public function autumn(array $all, Kobold $bestInt, Kobold $bestVit)
139
{
140
$this->tribe->dataStore->wasTendedInSummer = false;
86
141
87
$farmed = rand(0, $this->tribe->foodRequirements[$farmer->getAgeCategory()] * 6);
88
$totalFood += $farmed;
142
$multiplier = $this->tribe->dataStore->farmYieldMultiplier ?? 1.0;
143
if (!$bestInt->checkStat('intelligence')) {
144
$this->story .= "Unfortunately, {$bestInt->getName()} made several mistakes in {$bestInt->his()} plan to harvest the crops.\n";
145
$this->story .= "Despite {$bestVit->getName()}'s best efforts, many crops were lost.\n";
146
$multiplier *= floatval(rand(2, 6)) * 0.1;
147
}
89
148
90
if ($farmed > $mostFood) {
91
$mostFood = $farmed;
92
$mostFarmedBy = $farmer->getName();
93
}
94
}
149
$totalFood = 0;
150
$mostFood = 0;
151
$mostFarmedBy = '';
95
152
96
if ($mostFarmedBy == $hardestWorker->getName()) {
97
$this->story .= "{$hardestWorker->getName()} worked the hardest and managed to produce the most food for the tribe!\n";
98
} else {
99
$this->story .= "Despite {$hardestWorker->getName()} working the hardest out of everyone, it was {$mostFarmedBy} who produced the most food for the tribe.\n";
100
}
153
for ($i = 0; $i < count($all); $i++) {
154
$farmer = $all[$i];
101
155
102
$months = $this->tribe->foodMonthsLeft($totalFood);
103
$this->tribe->addFood($totalFood);
156
$farmed = rand(0, $this->tribe->foodRequirements[$farmer->getAgeCategory()] * 3) * $multiplier;
157
$totalFood += $farmed;
104
158
105
if ($months < 1)
106
$this->story .= "The tribe gained less than a month worth of food from the harvest.\n";
107
else {
108
if ($months == 1)
109
$this->story .= "The tribe gained a month worth of food from the harvest.\n";
110
else
111
$this->story .= "The tribe gained " . $months . " months worth of food from the harvest!\n";
159
if ($farmed > $mostFood) {
160
$mostFood = $farmed;
161
$mostFarmedBy = $farmer->getName();
112
162
}
113
return $this->story;
114
163
}
164
165
if ($mostFarmedBy == $bestVit->getName()) {
166
$this->story .= "{$bestVit->getName()} worked the hardest and managed to harvest the most food for the tribe!\n";
167
} else {
168
$this->story .= "Despite {$bestVit->getName()} working the hardest out of everyone, it was {$mostFarmedBy} who harvested the most food for the tribe.\n";
169
}
170
171
$months = $this->tribe->foodMonthsLeft($totalFood);
172
$this->tribe->addFood($totalFood);
173
174
if ($months < 1)
175
$this->story .= "The tribe gained less than a month worth of food from the harvest.\n";
176
else {
177
if ($months == 1)
178
$this->story .= "The tribe gained a month worth of food from the harvest.\n";
179
else
180
$this->story .= "The tribe gained " . $months . " months worth of food from the harvest!\n";
181
}
182
}
183
184
public function execute()
185
{
186
$participantIds = $this->getParticipants();
187
$explorers = [];
188
foreach ($participantIds as $pid) {
189
$k = $this->tribe->getKobold($pid);
190
if ($k && !$k->isDead())
191
$explorers[] = $k;
192
}
193
194
$leader = GameHelper::findBestKoboldForStat($explorers, "intelligence");
195
$hardestWorker = GameHelper::findBestKoboldForStat($explorers, "vitality");
196
197
$this->story = "The farmers tended to the fields. {$leader->getName()} took the lead.\n";
198
199
if ($this->tribe->getCurrentSeason() === 'spring')
200
$this->spring($explorers, $leader, $hardestWorker);
201
else if ($this->tribe->getCurrentSeason() === 'summer')
202
$this->summer($explorers, $leader, $hardestWorker);
203
else if ($this->tribe->getCurrentSeason() === 'autumn')
204
$this->autumn($explorers, $leader, $hardestWorker);
205
206
return $this->story;
115
207
}
116
208
}
@@ -19,11 +19,11 @@ class FarmingEvent extends Event19
{19
{20
switch ($this->tribe->getCurrentSeason()) {20
switch ($this->tribe->getCurrentSeason()) {21
case 'spring':21
case 'spring':22
return 20;23
case 'summer':24
return 25;22
return 25;23
case 'summer':24
return 15;25
case 'autumn':25
case 'autumn':26
return 30;26
return 20;27
case 'winter':27
case 'winter':28
return 60;28
return 60;29
default:29
default:@@ -33,26 +33,36 @@ class FarmingEvent extends Event33
33
34
public function isAvailable()34
public function isAvailable()35
{35
{36
return $this->tribe->getCurrentSeason() !== 'winter';36
if ($this->tribe->getCurrentSeason() !== 'winter') {37
}37
if ($this->tribe->getCurrentSeason() === 'spring')38
return !isset($this->tribe->dataStore->wasSowedInSpring) || !$this->tribe->dataStore->wasSowedInSpring;38
39
39
public function execute()40
if ($this->tribe->getCurrentSeason() === 'summer')40
{41
return isset($this->tribe->dataStore->wasSowedInSpring) && $this->tribe->dataStore->wasSowedInSpring;41
$participantIds = $this->getParticipants();42
42
$explorers = [];43
if ($this->tribe->getCurrentSeason() === 'autumn')43
foreach ($participantIds as $pid) {44
return isset($this->tribe->dataStore->wasTendedInSummer) && $this->tribe->dataStore->wasTendedInSummer;44
$k = $this->tribe->getKobold($pid);45
if ($k && !$k->isDead())46
$explorers[] = $k;47
}45
}48
46
49
$leader = GameHelper::findBestKoboldForStat($explorers, "intelligence");47
// reset values since this part of the code is only ever reached in winter so we might as well.50
$hardestWorker = GameHelper::findBestKoboldForStat($explorers, "vitality");48
$this->tribe->dataStore->wasSowedInSpring = false;49
$this->tribe->dataStore->wasTendedInSummer = false;50
return false;51
}52
53
public function spring(array $all, Kobold $bestInt, Kobold $bestVit)54
{55
$successes = 0;56
$this->tribe->dataStore->farmYieldMultiplier = 0.5;57
$this->tribe->dataStore->wasSowedInSpring = true;51
58
52
$this->story = "The farmers tended to their crops. {$leader->getName()} took the lead.\n";59
for ($i = 0; $i < count($all); $i++) {60
$farmer = $all[$i];53
61
54
for ($i = 0; $i < count($explorers); $i++) {62
if ($farmer->checkStat('vitality') && $farmer->checkStat('intelligence')) {55
$farmer = $explorers[$i];63
$this->tribe->dataStore->farmYieldMultiplier += 1;64
$successes++;65
}56
66
57
if (!$farmer->checkStat('will') && rand(1, 100) <= 30) {67
if (!$farmer->checkStat('will') && rand(1, 100) <= 30) {58
$farmer->addInjury("smallCut");68
$farmer->addInjury("smallCut");@@ -61,8 +71,44 @@ class FarmingEvent extends Event61
}71
}62
}72
}63
73
64
for ($i = 0; $i < count($explorers); $i++) {74
$word = "terribly";65
$farmer = $explorers[$i];75
$perc = ($successes / $this->getMaxParticipants());76
77
if ($perc >= 0.95)78
$word = "perfectly";79
else if ($perc >= 0.75)80
$word = "great";81
else if ($perc >= 0.5)82
$word = "well";83
else if ($perc >= 0.25)84
$word = "okay";85
else if ($perc >= 0.1)86
$word = "badly";87
88
$this->story .= "Tilling and sowing the fields went {$word}.\n";89
90
$this->tribe->dataStore->wasSowedInSpring = true;91
}92
93
public function summer(array $all, Kobold $bestInt, Kobold $bestVit)94
{95
$successes = 0;96
$this->tribe->dataStore->wasSowedInSpring = false;97
$this->tribe->dataStore->wasTendedInSummer = true;98
99
for ($i = 0; $i < count($all); $i++) {100
$farmer = $all[$i];101
102
if ($farmer->checkStat('vitality') && $farmer->checkStat('intelligence')) {103
$this->tribe->dataStore->farmYieldMultiplier += 0.5;104
$successes++;105
}106
107
if (!$farmer->checkStat('vitality') && rand(1, 100) <= 25) {108
$farmer->addInjury("sunburn");109
$this->story .= "{$farmer->getName()} got badly sunburned while working in the fields under the hot sun.\n";110
break;111
}66
112
67
if ($farmer->checkStat('intelligence') && rand(1, 100) <= 40) {113
if ($farmer->checkStat('intelligence') && rand(1, 100) <= 40) {68
$herbs = GameHelper::loadItem('healing-herbs');114
$herbs = GameHelper::loadItem('healing-herbs');@@ -72,45 +118,91 @@ class FarmingEvent extends Event72
}118
}73
}119
}74
120
75
if (!$leader->checkStat('intelligence')) {121
$word = "terribly";76
$this->story .= "Unfortunately, {$leader->getName()} made several mistakes in planting and caring for the crops.\n";122
$perc = ($successes / $this->getMaxParticipants());77
$this->story .= "Despite {$hardestWorker->getName()}'s best efforts, the crops had rotten and were lost.\n";123
78
return $this->story;124
if ($perc >= 0.95)79
} else {125
$word = "perfectly";80
$totalFood = 0;126
else if ($perc >= 0.75)81
$mostFood = 0;127
$word = "great";82
$mostFarmedBy = '';128
else if ($perc >= 0.5)129
$word = "well";130
else if ($perc >= 0.25)131
$word = "okay";132
else if ($perc >= 0.1)133
$word = "badly";134
135
$this->story .= "Tending to the crops went {$word}.\n";136
}83
137
84
for ($i = 0; $i < count($explorers); $i++) {138
public function autumn(array $all, Kobold $bestInt, Kobold $bestVit)85
$farmer = $explorers[$i];139
{140
$this->tribe->dataStore->wasTendedInSummer = false;86
141
87
$farmed = rand(0, $this->tribe->foodRequirements[$farmer->getAgeCategory()] * 6);142
$multiplier = $this->tribe->dataStore->farmYieldMultiplier ?? 1.0;88
$totalFood += $farmed;143
if (!$bestInt->checkStat('intelligence')) {144
$this->story .= "Unfortunately, {$bestInt->getName()} made several mistakes in {$bestInt->his()} plan to harvest the crops.\n";145
$this->story .= "Despite {$bestVit->getName()}'s best efforts, many crops were lost.\n";146
$multiplier *= floatval(rand(2, 6)) * 0.1;147
}89
148
90
if ($farmed > $mostFood) {149
$totalFood = 0;91
$mostFood = $farmed;150
$mostFood = 0;92
$mostFarmedBy = $farmer->getName();151
$mostFarmedBy = '';93
}94
}95
152
96
if ($mostFarmedBy == $hardestWorker->getName()) {153
for ($i = 0; $i < count($all); $i++) {97
$this->story .= "{$hardestWorker->getName()} worked the hardest and managed to produce the most food for the tribe!\n";154
$farmer = $all[$i];98
} else {99
$this->story .= "Despite {$hardestWorker->getName()} working the hardest out of everyone, it was {$mostFarmedBy} who produced the most food for the tribe.\n";100
}101
155
102
$months = $this->tribe->foodMonthsLeft($totalFood);156
$farmed = rand(0, $this->tribe->foodRequirements[$farmer->getAgeCategory()] * 3) * $multiplier;103
$this->tribe->addFood($totalFood);157
$totalFood += $farmed;104
158
105
if ($months < 1)159
if ($farmed > $mostFood) {106
$this->story .= "The tribe gained less than a month worth of food from the harvest.\n";160
$mostFood = $farmed;107
else {161
$mostFarmedBy = $farmer->getName();108
if ($months == 1)109
$this->story .= "The tribe gained a month worth of food from the harvest.\n";110
else111
$this->story .= "The tribe gained " . $months . " months worth of food from the harvest!\n";112
}162
}113
return $this->story;114
}163
}164
165
if ($mostFarmedBy == $bestVit->getName()) {166
$this->story .= "{$bestVit->getName()} worked the hardest and managed to harvest the most food for the tribe!\n";167
} else {168
$this->story .= "Despite {$bestVit->getName()} working the hardest out of everyone, it was {$mostFarmedBy} who harvested the most food for the tribe.\n";169
}170
171
$months = $this->tribe->foodMonthsLeft($totalFood);172
$this->tribe->addFood($totalFood);173
174
if ($months < 1)175
$this->story .= "The tribe gained less than a month worth of food from the harvest.\n";176
else {177
if ($months == 1)178
$this->story .= "The tribe gained a month worth of food from the harvest.\n";179
else180
$this->story .= "The tribe gained " . $months . " months worth of food from the harvest!\n";181
}182
}183
184
public function execute()185
{186
$participantIds = $this->getParticipants();187
$explorers = [];188
foreach ($participantIds as $pid) {189
$k = $this->tribe->getKobold($pid);190
if ($k && !$k->isDead())191
$explorers[] = $k;192
}193
194
$leader = GameHelper::findBestKoboldForStat($explorers, "intelligence");195
$hardestWorker = GameHelper::findBestKoboldForStat($explorers, "vitality");196
197
$this->story = "The farmers tended to the fields. {$leader->getName()} took the lead.\n";198
199
if ($this->tribe->getCurrentSeason() === 'spring')200
$this->spring($explorers, $leader, $hardestWorker);201
else if ($this->tribe->getCurrentSeason() === 'summer')202
$this->summer($explorers, $leader, $hardestWorker);203
else if ($this->tribe->getCurrentSeason() === 'autumn')204
$this->autumn($explorers, $leader, $hardestWorker);205
206
return $this->story;115
}207
}116
}208
}