Allow customizing the first line of the report#60
Open
ritinae wants to merge 2 commits intoEliteMasterEric:masterfrom
Open
Allow customizing the first line of the report#60ritinae wants to merge 2 commits intoEliteMasterEric:masterfrom
ritinae wants to merge 2 commits intoEliteMasterEric:masterfrom
Conversation
ritinae
commented
Jun 27, 2025
Comment on lines
+236
to
+248
| // NOTE: obtaining a random number is skipped if there is only one result. This may be relavant for synced randoms. | ||
| if (result.Length > 1) | ||
| { | ||
| var index = random.Next(result.Length); | ||
| return result[index]; | ||
| } | ||
|
|
||
| // NOTE: Assumes GetValuesByTag always returns a non-empty array. | ||
| return result[0]; |
Author
There was a problem hiding this comment.
I left the superfluous length check in to better match the old behaviour, just in case there is some effect to synced randoms that I missed.
If skipping the random isn't critical for synced randoms, then as we anyway assume that GetValuesByTag returns a non-empty array, this could be simplified down to just:
var index = random.Next(result.Length);
return result[index];fb2bfcf to
8a10c89
Compare
Refactor the language string randomization to be a feature of the LanguageHander instead of being tied to the AdvancedDeathTracker. This allows re-using the same code for randomizing strings that are not death messages or funny notes.
Tweak the report generating code to pick a random first line for the report, in case there are multiple available. This makes the reports slightly more customizable. I am likely going to use this as a hack to get rare alternative titles for the reports by e.g. copy-pasting the default "Cause of death" a few times in the xml file and adding rare variants after those. No need to implement e.g. weighted random or anything more sophisticated, this works good enough.
b59708d to
39d09b8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use case
We had this great idea to customize the lang files to replace the "Cause of death:" on the first line of the report with "Skill issue:". However, as not all deaths are necessarily skill issues (although some of them surely are), we found the thought of randomly picking either of those very amusing. Making one of the options a rare/easter-egg kind of thing would be next level, but let's not get ahead of ourselves. Just being able to randomize the first line of the report would be great!
The issue
To our great disappointment, it turns out, the report only ever uses the first
UINotesorUICauseOfDeathdefined in the language XML. A somewhat of a major setback, as this prevents any chance of randomizing the darn thing.The solution
Being a persistent bunch of idiots, we didn't let this stop us! When there's a will there's a way!
Rundown of the changes in this PR:
StringifyCauseOfDeath/SelectCauseOfDeathand called it a day, but that would have been a bit messy.LanguageHandler.GetRandomValueByTag(similar toLanguageHandler.GetFirstValueByTag)SelectCauseOfDeathhappened to get the full list of translation values, which was somewhat incompatible with the idea of generalizing the logic. I needed to tweak this to work only with the language tags instead of getting the full list of values.StringifyCauseOfDeathcan simply call eitherGetRandomValueByTagorGetFirstValueByTag, depending on the value ofshouldRandomize. Theresult.Length > 1check is now an implementation detail ofGetRandomValueByTag, so it could be removed from here.HUDManagerPatch.csare very simple: Instead of always callingGetFirstValueByTagwith theTAG_UI_DEATHandTAG_UI_NOTES, use the newGetRandomValueByTag.I tested the changes by adding a bunch of translation variations for
TAG_UI_DEATHandTAG_UI_NOTES, and then proceeding to die in various ways. Seemed to work like a charm, the reports were properly randomized, the first line included.