better death logging
@@ -563,8 +563,25 @@ class Kobold
563
563
$injData['kobold_id'] = $this->id;
564
564
$this->injuries[] = $injData;
565
565
566
if ($this->isDead())
567
return "{$this->getName()} died due to a {$injuryType}.";
566
if ($this->isDead()) {
567
if (!isset($this->dataStore)) {
568
$this->dataStore = new stdClass();
569
}
570
571
$injuryLabel = str_replace(['_', '-'], ' ', $injuryType);
572
$deathVariations = [
573
"{$this->getName()} died from {$injuryLabel}.",
574
"{$this->getName()} succumbed to {$injuryLabel}.",
575
"{$this->getName()} could not survive {$injuryLabel}.",
576
"{$injuryLabel} claimed {$this->getName()}.",
577
"{$this->getName()} passed away after suffering {$injuryLabel}."
578
];
579
580
$deathMessage = $deathVariations[array_rand($deathVariations)];
581
$this->dataStore->lastDeathMessage = $deathMessage;
582
583
return $deathMessage;
584
}
568
585
569
586
return true;
570
587
}
@@ -563,8 +563,25 @@ class Kobold563
$injData['kobold_id'] = $this->id;563
$injData['kobold_id'] = $this->id;564
$this->injuries[] = $injData;564
$this->injuries[] = $injData;565
565
566
if ($this->isDead())566
if ($this->isDead()) {567
return "{$this->getName()} died due to a {$injuryType}.";567
if (!isset($this->dataStore)) {568
$this->dataStore = new stdClass();569
}570
571
$injuryLabel = str_replace(['_', '-'], ' ', $injuryType);572
$deathVariations = [573
"{$this->getName()} died from {$injuryLabel}.",574
"{$this->getName()} succumbed to {$injuryLabel}.",575
"{$this->getName()} could not survive {$injuryLabel}.",576
"{$injuryLabel} claimed {$this->getName()}.",577
"{$this->getName()} passed away after suffering {$injuryLabel}."578
];579
580
$deathMessage = $deathVariations[array_rand($deathVariations)];581
$this->dataStore->lastDeathMessage = $deathMessage;582
583
return $deathMessage;584
}568
585
569
return true;586
return true;570
}587
}@@ -1044,14 +1044,38 @@ class Tribe
1044
1044
}
1045
1045
1046
1046
if (!isset($reportedDeaths[$deadId])) {
1047
$monthEventStory .= $kobold->getName() . " died during the {$eventLabel}.\n";
1047
$deathMessage = null;
1048
if (isset($kobold->dataStore) && $kobold->dataStore instanceof stdClass) {
1049
$deathMessage = $kobold->dataStore->lastDeathMessage ?? null;
1050
if ($deathMessage) {
1051
unset($kobold->dataStore->lastDeathMessage);
1052
}
1053
}
1054
1055
if ($deathMessage) {
1056
$monthEventStory .= $deathMessage . "\n";
1057
} else {
1058
$monthEventStory .= $kobold->getName() . " died during the {$eventLabel}.\n";
1059
}
1048
1060
$reportedDeaths[$deadId] = true;
1049
1061
}
1050
1062
}
1051
1063
1052
1064
foreach ($participants as $participant) {
1053
1065
if ($participant->isDead() && !isset($reportedDeaths[$participant->getId()])) {
1054
$monthEventStory .= $participant->getName() . " has died.\n";
1066
$deathMessage = null;
1067
if (isset($participant->dataStore) && $participant->dataStore instanceof stdClass) {
1068
$deathMessage = $participant->dataStore->lastDeathMessage ?? null;
1069
if ($deathMessage) {
1070
unset($participant->dataStore->lastDeathMessage);
1071
}
1072
}
1073
1074
if ($deathMessage) {
1075
$monthEventStory .= $deathMessage . "\n";
1076
} else {
1077
$monthEventStory .= $participant->getName() . " has died.\n";
1078
}
1055
1079
$reportedDeaths[$participant->getId()] = true;
1056
1080
}
1057
1081
$participant->save();
@@ -1121,11 +1145,23 @@ class Tribe
1121
1145
continue;
1122
1146
}
1123
1147
1124
$injuryDeath = $kobold->getTotalInjurySeverity() >= (int) ($kobold->getStat('vitality') ?? 0);
1125
if ($injuryDeath) {
1126
$foodStory .= "\n" . $kobold->getName() . " succumbed to injuries.";
1148
$deathMessage = null;
1149
if (isset($kobold->dataStore) && $kobold->dataStore instanceof stdClass) {
1150
$deathMessage = $kobold->dataStore->lastDeathMessage ?? null;
1151
if ($deathMessage) {
1152
unset($kobold->dataStore->lastDeathMessage);
1153
}
1154
}
1155
1156
if ($deathMessage) {
1157
$foodStory .= "\n" . $deathMessage;
1127
1158
} else {
1128
$foodStory .= "\n" . $kobold->getName() . " died.";
1159
$injuryDeath = $kobold->getTotalInjurySeverity() >= (int) ($kobold->getStat('vitality') ?? 0);
1160
if ($injuryDeath) {
1161
$foodStory .= "\n" . $kobold->getName() . " succumbed to injuries.";
1162
} else {
1163
$foodStory .= "\n" . $kobold->getName() . " died.";
1164
}
1129
1165
}
1130
1166
$reportedDeaths[$deadId] = true;
1131
1167
}
@@ -1044,14 +1044,38 @@ class Tribe1044
}1044
}1045
1045
1046
if (!isset($reportedDeaths[$deadId])) {1046
if (!isset($reportedDeaths[$deadId])) {1047
$monthEventStory .= $kobold->getName() . " died during the {$eventLabel}.\n";1047
$deathMessage = null;1048
if (isset($kobold->dataStore) && $kobold->dataStore instanceof stdClass) {1049
$deathMessage = $kobold->dataStore->lastDeathMessage ?? null;1050
if ($deathMessage) {1051
unset($kobold->dataStore->lastDeathMessage);1052
}1053
}1054
1055
if ($deathMessage) {1056
$monthEventStory .= $deathMessage . "\n";1057
} else {1058
$monthEventStory .= $kobold->getName() . " died during the {$eventLabel}.\n";1059
}1048
$reportedDeaths[$deadId] = true;1060
$reportedDeaths[$deadId] = true;1049
}1061
}1050
}1062
}1051
1063
1052
foreach ($participants as $participant) {1064
foreach ($participants as $participant) {1053
if ($participant->isDead() && !isset($reportedDeaths[$participant->getId()])) {1065
if ($participant->isDead() && !isset($reportedDeaths[$participant->getId()])) {1054
$monthEventStory .= $participant->getName() . " has died.\n";1066
$deathMessage = null;1067
if (isset($participant->dataStore) && $participant->dataStore instanceof stdClass) {1068
$deathMessage = $participant->dataStore->lastDeathMessage ?? null;1069
if ($deathMessage) {1070
unset($participant->dataStore->lastDeathMessage);1071
}1072
}1073
1074
if ($deathMessage) {1075
$monthEventStory .= $deathMessage . "\n";1076
} else {1077
$monthEventStory .= $participant->getName() . " has died.\n";1078
}1055
$reportedDeaths[$participant->getId()] = true;1079
$reportedDeaths[$participant->getId()] = true;1056
}1080
}1057
$participant->save();1081
$participant->save();@@ -1121,11 +1145,23 @@ class Tribe1121
continue;1145
continue;1122
}1146
}1123
1147
1124
$injuryDeath = $kobold->getTotalInjurySeverity() >= (int) ($kobold->getStat('vitality') ?? 0);1148
$deathMessage = null;1125
if ($injuryDeath) {1149
if (isset($kobold->dataStore) && $kobold->dataStore instanceof stdClass) {1126
$foodStory .= "\n" . $kobold->getName() . " succumbed to injuries.";1150
$deathMessage = $kobold->dataStore->lastDeathMessage ?? null;1151
if ($deathMessage) {1152
unset($kobold->dataStore->lastDeathMessage);1153
}1154
}1155
1156
if ($deathMessage) {1157
$foodStory .= "\n" . $deathMessage;1127
} else {1158
} else {1128
$foodStory .= "\n" . $kobold->getName() . " died.";1159
$injuryDeath = $kobold->getTotalInjurySeverity() >= (int) ($kobold->getStat('vitality') ?? 0);1160
if ($injuryDeath) {1161
$foodStory .= "\n" . $kobold->getName() . " succumbed to injuries.";1162
} else {1163
$foodStory .= "\n" . $kobold->getName() . " died.";1164
}1129
}1165
}1130
$reportedDeaths[$deadId] = true;1166
$reportedDeaths[$deadId] = true;1131
}1167
}