Refactor and Unify Vendor Item Generation for Premium and Boy Items #7924
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.
Overview
This PR refactors the vendor item generation logic in Diablo/Hellfire to simplify and consolidate common validation and generation routines for both premium items and boy items. The changes aim to improve code clarity, reduce duplication, and ensure consistency across different item types.
Key Changes
Helper Function Extraction:
SpawnOnePremiumandSpawnBoyfunctions.ItemTypeis allowed for a specific hero class.INT_MAX) with an explicit boolean check.Refactored SpawnOnePremium and SpawnBoy:
Benefits
The separation of concerns makes the code easier to understand and maintain.
Shared helper functions ensure that validations and generation steps are consistent across different vendor scenarios.
Changes to the validation logic or generation parameters can be made in one place, affecting all vendor item generation functions.
The use of explicit item type restrictions via
IsItemTypeAllowedForClassavoids reliance on “magic” values and makes disqualification logic clear and explicit.Clearing the item data after exceeding maximum attempts prevents the game from using an unsuitable item and avoids potential downstream issues.
Conclusion
This refactor centralizes the logic for item generation and validation, making the codebase more maintainable and robust. By introducing clear helper functions and explicitly handling the scenario where no suitable item is generated (by clearing the item data), we improve both readability and reliability. Feedback and further improvements are welcome.