feat: activate riven mod (get a random challenge) #721

Merged
Sainan merged 1 commits from activate-riven into main 2025-01-05 20:35:57 -08:00
Owner

Closes #462

Closes #462
coderabbitai[bot] commented 2025-01-05 02:59:59 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

This pull request introduces several changes to enhance the functionality of a gaming-related application. The modifications include updating a dependency version in package.json to ^0.5.21, adding a new controller activateRandomModController.ts for handling random mod activation, updating the API routes in api.ts to include a new endpoint for random mod activation, and expanding the rngService.ts with two new utility functions for random element selection and integer generation. The changes appear to be focused on implementing a mechanism for activating random modifications in a user's inventory.

Assessment against linked issues

Objective Addressed Explanation
Resolve riven task unlocking issues [#462] Unable to definitively confirm full resolution without more context about specific task unlocking mechanisms
Prevent potential server crashes related to riven tasks The new random mod controller introduces additional logic, but cannot conclusively determine if it resolves crash scenarios
Improve riven task activation process New activateRandomModController provides a structured approach to mod activation

The assessment indicates partial progress towards addressing the reported issues, but a comprehensive validation would require more detailed testing and verification of the specific crash and unlocking problems mentioned in the issue.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough This pull request introduces several changes to enhance the functionality of a gaming-related application. The modifications include updating a dependency version in `package.json` to `^0.5.21`, adding a new controller `activateRandomModController.ts` for handling random mod activation, updating the API routes in `api.ts` to include a new endpoint for random mod activation, and expanding the `rngService.ts` with two new utility functions for random element selection and integer generation. The changes appear to be focused on implementing a mechanism for activating random modifications in a user's inventory. ## Assessment against linked issues | Objective | Addressed | Explanation | |-----------|-----------|-------------| | Resolve riven task unlocking issues [#462] | ❓ | Unable to definitively confirm full resolution without more context about specific task unlocking mechanisms | | Prevent potential server crashes related to riven tasks | ❓ | The new random mod controller introduces additional logic, but cannot conclusively determine if it resolves crash scenarios | | Improve riven task activation process | ✅ | New `activateRandomModController` provides a structured approach to mod activation | The assessment indicates partial progress towards addressing the reported issues, but a comprehensive validation would require more detailed testing and verification of the specific crash and unlocking probl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qGoS8tzoGp8dJYVByX0CaeOLT3tLjhHBFNBBJCYYksGIoAm3s6AW6qieC6NQmC+BN4Ijz5vRhW46V4FQ/yHfYGpNAYwQNPMQyhrq5o1AvBnBUA1CU4WMuc91VzEt07wX5LnIQeCFIXJ52JQkjGxwvmBDOAqLEjJX3qrfoByPzMGsMjLXOffIYcvL978qaIpmZFzGSzh6G4qCA6ia6gCpI4hG8NUsdFMVeBDG+hgK3JiK0q1KzrwNQqziSq21g5kkVqw1ktUawFnfRa2BDa0WwnWtjpx7gZ0VwWBAFgAMAKFcCoB4FgBfEInqDIMu1XRezx3e0+1xyZDu1QMdULSW3amwPhWHQKAfh4BzDzERED34I2GoCoLWFEN62XX61oKYNkAYMJzkLu2vSPUCiMga0kRF0snvRB1KTYAcjKGcifXqU8mUG8g0F8gMgClABEjkm6HwAAH05hkAHDAg2wW4GAHDQNxp/I1DbCAAODAd6IQPYB6QsDAZ6Z6d6B6HYd6HYMgGIgAZnekLD2DIESMSPzHoHemekSKEELHeiYELHiEiLIGel8KChgHsk0CcPoBcLcOWG73oAcLEkMCAA --> <!-- internal state end --> <!-- tips_start --> --- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit <commit_id>, please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta)) - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-05 03:02:22 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 1

🧹 Nitpick comments (5)
src/controllers/api/activateRandomModController.ts (3)

44-53: Consider concurrency and partial failures.

After pushing the new upgrade on line 45, the code immediately saves the entire inventory. If another asynchronous modification to the same inventory occurs simultaneously, a race condition could lead to conflicts or overwrites. Ensure that your DB layer or model integrates concurrency protections (e.g., version locking) if needed.


55-65: Document interfaces fully.

IActiveRandomModRequest and IRandomModChallenge are straightforward, but more explicit docstrings or property comments (especially for Complication) may help future maintainers understand their usage, boundaries, and constraints (e.g., countRange in the challenge).


66-98: Revisit hardcoded mappings and weighting.

The rivenRawToRealWeighted map effectively links raw item types to rare item types, repeatedly listing certain items for weighting. Consider centralizing these data into configuration or a database for flexibility and future scaling instead of leaving them as large, duplicated arrays in source code.

src/services/rngService.ts (1)

13-19: Check range validity for random integer generation.

getRandomInt gracefully handles integer rounding, but if min > max, you might return unexpected results or zero. Consider validating the range or throwing an error to alert the caller.

src/routes/api.ts (1)

111-111: Route name alignment.

The new POST route ends with .php, which may be a legacy carry-over. Consider normalizing route naming, e.g., /api/activateRandomMod, to keep consistency with typical REST naming conventions.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06bc0123ba and 8a9b106a55.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json (1 hunks)
  • src/controllers/api/activateRandomModController.ts (1 hunks)
  • src/routes/api.ts (2 hunks)
  • src/services/rngService.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (4)
src/controllers/api/activateRandomModController.ts (3)

9-18: Double-check item removal logic.

The call to addMods with ItemCount: -1 implies removing an item from the inventory. Ensure this correctly handles cases when the user does not have the item or the item is already at zero quantity. Consider handling an error scenario if the quantity is insufficient, to avoid negative inventory states.


26-41: Secure complication multiplier.

While multiplying fingerprintChallenge.Required by complication.countMultiplier offers dynamic challenge scaling, you risk extremely large or negative values if data is incorrect. Consider ensuring a minimum valid range or adding safe guards to reject out-of-range multipliers.


1-8: 🛠️ Refactor suggestion

Use stricter input validation and error handling.

Currently, the code trusts req.body to be valid JSON. Consider adding try/catch blocks around getJSONfromString, and verify that accountId and inventory exist before proceeding. This will help avoid runtime exceptions and ensure the request is well-formed.

src/services/rngService.ts (1)

9-11: Ensure array length safety.

If arr is empty or undefined, getRandomElement will cause a runtime error. A quick guard clause or an error throw when arr.length === 0 would make the function safer.

**Actionable comments posted: 1** <details> <summary>🧹 Nitpick comments (5)</summary><blockquote> <details> <summary>src/controllers/api/activateRandomModController.ts (3)</summary><blockquote> `44-53`: **Consider concurrency and partial failures.** After pushing the new upgrade on line 45, the code immediately saves the entire inventory. If another asynchronous modification to the same inventory occurs simultaneously, a race condition could lead to conflicts or overwrites. Ensure that your DB layer or model integrates concurrency protections (e.g., version locking) if needed. --- `55-65`: **Document interfaces fully.** `IActiveRandomModRequest` and `IRandomModChallenge` are straightforward, but more explicit docstrings or property comments (especially for `Complication`) may help future maintainers understand their usage, boundaries, and constraints (e.g., `countRange` in the challenge). --- `66-98`: **Revisit hardcoded mappings and weighting.** The `rivenRawToRealWeighted` map effectively links raw item types to rare item types, repeatedly listing certain items for weighting. Consider centralizing these data into configuration or a database for flexibility and future scaling instead of leaving them as large, duplicated arrays in source code. </blockquote></details> <details> <summary>src/services/rngService.ts (1)</summary><blockquote> `13-19`: **Check range validity for random integer generation.** `getRandomInt` gracefully handles integer rounding, but if `min > max`, you might return unexpected results or zero. Consider validating the range or throwing an error to alert the caller. </blockquote></details> <details> <summary>src/routes/api.ts (1)</summary><blockquote> `111-111`: **Route name alignment.** The new POST route ends with `.php`, which may be a legacy carry-over. Consider normalizing route naming, e.g., `/api/activateRandomMod`, to keep consistency with typical REST naming conventions. </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 06bc0123baee78b6d339bea8da8c734132b49620 and 8a9b106a5590292e023961e334d953b69c6f55e5. </details> <details> <summary>⛔ Files ignored due to path filters (1)</summary> * `package-lock.json` is excluded by `!**/package-lock.json` </details> <details> <summary>📒 Files selected for processing (4)</summary> * `package.json` (1 hunks) * `src/controllers/api/activateRandomModController.ts` (1 hunks) * `src/routes/api.ts` (2 hunks) * `src/services/rngService.ts` (1 hunks) </details> <details> <summary>✅ Files skipped from review due to trivial changes (1)</summary> * package.json </details> <details> <summary>🔇 Additional comments (4)</summary><blockquote> <details> <summary>src/controllers/api/activateRandomModController.ts (3)</summary> `9-18`: **Double-check item removal logic.** The call to `addMods` with `ItemCount: -1` implies removing an item from the inventory. Ensure this correctly handles cases when the user does not have the item or the item is already at zero quantity. Consider handling an error scenario if the quantity is insufficient, to avoid negative inventory states. --- `26-41`: **Secure complication multiplier.** While multiplying `fingerprintChallenge.Required` by `complication.countMultiplier` offers dynamic challenge scaling, you risk extremely large or negative values if data is incorrect. Consider ensuring a minimum valid range or adding safe guards to reject out-of-range multipliers. --- `1-8`: _:hammer_and_wrench: Refactor suggestion_ **Use stricter input validation and error handling.** Currently, the code trusts `req.body` to be valid JSON. Consider adding try/catch blocks around `getJSONfromString`, and verify that `accountId` and `inventory` exist before proceeding. This will help avoid runtime exceptions and ensure the request is well-formed. </details> <details> <summary>src/services/rngService.ts (1)</summary> `9-11`: **Ensure array length safety.** If `arr` is empty or `undefined`, `getRandomElement` will cause a runtime error. A quick guard clause or an error throw when `arr.length === 0` would make the function safer. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -0,0 +22,4 @@
Type: challenge.fullName,
Progress: 0,
Required: getRandomInt(challenge.countRange[0], challenge.countRange[1])
};
coderabbitai[bot] (Migrated from github.com) commented 2025-01-05 03:02:20 -08:00
Author
Owner

⚠️ Potential issue

Validate the random type selection.

If request.ItemType is missing or not found in rivenRawToRealWeighted, getRandomElement(...) may throw. Similarly, ExportUpgrades[rivenType].availableChallenges! can be undefined if no challenges exist. Consider adding fallback handling (e.g., returning a 400 error) if no valid riven or challenge is found.

_:warning: Potential issue_ **Validate the random type selection.** If `request.ItemType` is missing or not found in `rivenRawToRealWeighted`, `getRandomElement(...)` may throw. Similarly, `ExportUpgrades[rivenType].availableChallenges!` can be undefined if no challenges exist. Consider adding fallback handling (e.g., returning a 400 error) if no valid riven or challenge is found. <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.