Rerolling default items on container first opening/destroy without opening #21
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.
Motivation: There is a big issue in world containers item generation and Item Drop Limits flag interaction (BossKillUnlocksCurrentBiomeItems, BossKillUnlocksNextBiomeItems, PlayerMustKnowRecipe, PlayerMustHaveCraftedItem values) due to the latter forcing items not available yet to gate (or break into reagents). Currently, items are added in chests the same moment the default items added by the game, that is, when Awake() method is called for the chest. That happens "too early" (since Awake() can be called for the chest being far away from the player, in other biome, in dungeon the player can't access yet etc - all cases approved by testing) resulting in player "spoiling" chests just by their accident presence.
According to the tests, Awake() is being called once for every chest and not being called again on new game session.
Thus, the proposed solution is to add a new flag that checks whether the player has ever opened the chest and use the flag to roll items again on the first chest opening or on the first destroying without opening. Default items are still being added on Awake to have a proper chest hint (that the chest is not empty) before the first opening. However, the chest is cleared every time before adding the default items to avoid double generation.
Backward compatibility: can have incorrect interaction with other mods changing chest behavior