Closed brandon-clair closed 2 years ago
it was a mistake to use GetAmount at all, since the requirement is a custom made one that doesn't actually use quality. see the new version
Edit:
Nope, I probably just misunderstand the engine still. I just tried the latest release, 0.4.3, and it worked exactly as expected. Thanks for taking care of this!
Original Post:
Cool! I think I'm following along better, and there may still be a problem with this calculation, throwing off the game's recipe logic:
During the validation of a recipe, when building the list of items to sort into the freeRepairs, notEnoughRepairs, or enoughRepairs lists, even though a cumulative amount of requirements are considered, given the items level, that cost is not reflected by the consumption logic.
I think that this section, when checking to see what items should be consumed for the repair, also needs to consider the quality of the item. It looks like it's only using the build cost of the current level of the item, not the current level plus all the levels preceding it.
I believe the
Piece.Requirement()
generated inRepairRecipe()
needs to have itsGetAmount()
method overridden to return the cumulative amount of items required for the requested item level. By default, it will return only the requirements needed to craft or upgrade the item to the desired level. This (assuming amaterialRequirementMult
of 1.0) effectively makes, for instance, a level 1 Hammer cost 3 Wood and 2 Stone to repair, and a level 2 Hammer cost 1 Wood and 1 Stone.Here's the current code:
https://github.com/aedenthorn/ValheimMods/blob/5159b855541b537d35ff529791d03ef862dda695/RepairRequiresMats/BepInExPlugin.cs#L225-L246
And here's what I'm guessing needs to happen. Consider this pseudocode, I'm not familiar enough with this language to know precisely how to implement the fix.