feat: opening relics in endless missions #713

Merged
Sainan merged 3 commits from open-relic into main 2025-01-05 20:35:36 -08:00
Owner

A partial solution for #415 without touching missionInventoryUpdate.

A partial solution for #415 without touching missionInventoryUpdate.
coderabbitai[bot] commented 2025-01-04 19:02:15 -08:00 (Migrated from github.com)
Author
Owner

Warning

Rate limit exceeded

@Sainan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 43 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 38d8fc448e and 8e74609320.

📒 Files selected for processing (1)
  • src/services/rngService.ts (1 hunks)

Walkthrough

This pull request introduces a new feature for managing void projection rewards in a gaming system. The changes include the addition of a new controller (getVoidProjectionRewardsController.ts) that handles the logic for processing void projection rewards, a route in the API router to expose this functionality, and a new random reward selection method in the RNG service.

The new controller processes incoming requests about void projection rewards, determines reward eligibility, selects a random reward based on weighted probabilities, and updates the user's inventory accordingly. The API route /getVoidProjectionRewards.php is added to enable client access to this new reward mechanism. The getRandomWeightedReward2 function in the RNG service provides a more sophisticated method for selecting rewards based on rarity and predefined weights.

These changes extend the game's reward system by introducing a new method for obtaining rewards through void projections, with careful attention to type safety and structured data handling.


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 --> <!-- This is an auto-generated comment: rate limited by coderabbit.ai --> > [!WARNING] > ## Rate limit exceeded > > @Sainan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait **24 minutes and 43 seconds** before requesting another review. > > <details> > <summary>⌛ How to resolve this issue?</summary> > > After the wait time has elapsed, a review can be triggered using the `@coderabbitai review` command as a PR comment. Alternatively, push new commits to this PR. > > We recommend that you space out your commits to avoid hitting the rate limit. > > </details> > > > <details> > <summary>🚦 How do rate limits work?</summary> > > CodeRabbit enforces hourly rate limits for each developer per organization. > > Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. > > Please see our [FAQ](https://docs.coderabbit.ai/faq) for further information. > > </details> > > <details> > <summary>📥 Commits</summary> > > Reviewing files that changed from the base of the PR and between 38d8fc448e93d50031b3cb5a20627ad51c26a40a and 8e746093200a4d402daf184ac93ac7b29ffe4389. > > </details> > > <details> > <summary>📒 Files selected for processing (1)</summary> > > * `src/services/rngService.ts` (1 hunks) > > </details> <!-- end of auto-generated comment: rate limited by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough This pull request introduces a new feature for managing void projection rewards in a gaming system. The changes include the addition of a new controller (`getVoidProjectionRewardsController.ts`) that handles the logic for processing void projection rewards, a route in the API router to expose this functionality, and a new random reward selection method in the RNG service. The new controller processes incoming requests about void projection rewards, determines reward eligibility, selects a random reward based on weighted probabilities, and updates the user's inventory accordingly. The API route `/getVoidProjectionRewards.php` is added to enable client access to this new reward mechanism. The `getRandomWeightedReward2` function in the RNG service provides a more sophisticated method for selecting rewards based on rarity and predefined weights. These changes extend the game's reward system by introducing a new method for obtaining rewards through void projections, with careful attention to type safety and structured data handling. <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAMzJaHkJeCkQsEgCyH0QmVAzoCnpo5FRWFGREQixkWOgAdwxUZFwhCvw6RgUI+C9cZGpHXSxsTCxGdEQVLEl4xBjm6CxnISGAdgBGAGYtOD6+KkRWV0V4wiYBwXje9Ds0VCI0Vl5ojlnoeNwsCWrR3PwikCP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APrTDIBiGBDZiKQMBiEoKcwMQ0EiHbAAAc9Aah8QTA3I3IahZAAAnNsPQHyAAAymHbCbBCDbBMBCB8gYCTymEABsk86wcofImwTAk8ThGA3IphNIL4whUAohmgEhKk0hD0Cwvs9AYhH4hgQAA== --> <!-- 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-04 19:05:08 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 3

🧹 Nitpick comments (4)
src/services/rngService.ts (1)

44-45: Clarify function naming convention

The new function name getRandomWeightedReward2 might not be self-explanatory. Consider a more descriptive name if it’s intended to support a different variant of reward logic, or integrate both functionalities into a single, generalized function to avoid confusion.

src/controllers/api/getVoidProjectionRewardsController.ts (3)

11-18: Validate request parameters

Before proceeding with logic, consider validating the structure of data.ParticipantInfo, data.CurrentWave, and data.DifficultyTier. This ensures safety if the client provides malformed JSON or leaves out required fields.


30-42: Consider concurrency or revert logic

When removing a relic from the user’s inventory and granting a reward, ensure transactional integrity is maintained. If one operation fails (e.g., database lock, network issues), you may want to roll back the other.


73-99: Enhance documentation for data interfaces

Describe each interface field (e.g., DifficultyTier, VoidTier) in docstrings or inline comments. This helps new contributors understand how to use and extend these interfaces correctly.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ea59665a0c and 38d8fc448e.

📒 Files selected for processing (3)
  • src/controllers/api/getVoidProjectionRewardsController.ts (1 hunks)
  • src/routes/api.ts (2 hunks)
  • src/services/rngService.ts (1 hunks)
🔇 Additional comments (5)
src/services/rngService.ts (2)

45-47: Ensure type consistency across modules

The function parameter expects pool items in { type: string; itemCount: number; rarity: TRarity } format, whereas getRandomWeightedReward expects { Item: string; Rarity: TRarity }. Confirm that the difference in field capitalization is intentional and consistent throughout the codebase.


50-52: Validate rarityCounts usage

Each iteration of the loop increments rarityCounts[entry.rarity]. Verify that entry.rarity is guaranteed to be one of the four keys (COMMON, UNCOMMON, RARE, LEGENDARY). If there’s a possibility of a different or undefined rarity, consider adding a safety check.

src/controllers/api/getVoidProjectionRewardsController.ts (1)

46-71: Adjust refinement probabilities if needed

The refinementToWeights mapping sets fixed probabilities. Verify with game design requirements that these distribution values (e.g., 0.76, 0.22, etc.) align with the intended user experience.

src/routes/api.ts (2)

29-29: Maintain alphabetical grouping
If import statements are being sorted or grouped by type, ensure that this new import (getVoidProjectionRewardsController) follows the same pattern or style rules your codebase uses for imports. Otherwise, ignore this.


124-124: Check for route duplication
Ensure /getVoidProjectionRewards.php is not duplicated in any other place, possibly hidden behind environment toggles or conditional logic in your codebase.

Verification successful

Route /getVoidProjectionRewards.php is not duplicated
The route is only defined once in the codebase at src/routes/api.ts, with no duplicates found in other files or behind environment toggles.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Script to verify that '/getVoidProjectionRewards.php' is only defined once in the codebase.

rg "/getVoidProjectionRewards\.php"

Length of output: 140

**Actionable comments posted: 3** <details> <summary>🧹 Nitpick comments (4)</summary><blockquote> <details> <summary>src/services/rngService.ts (1)</summary><blockquote> `44-45`: **Clarify function naming convention** The new function name `getRandomWeightedReward2` might not be self-explanatory. Consider a more descriptive name if it’s intended to support a different variant of reward logic, or integrate both functionalities into a single, generalized function to avoid confusion. </blockquote></details> <details> <summary>src/controllers/api/getVoidProjectionRewardsController.ts (3)</summary><blockquote> `11-18`: **Validate request parameters** Before proceeding with logic, consider validating the structure of `data.ParticipantInfo`, `data.CurrentWave`, and `data.DifficultyTier`. This ensures safety if the client provides malformed JSON or leaves out required fields. --- `30-42`: **Consider concurrency or revert logic** When removing a relic from the user’s inventory and granting a reward, ensure transactional integrity is maintained. If one operation fails (e.g., database lock, network issues), you may want to roll back the other. --- `73-99`: **Enhance documentation for data interfaces** Describe each interface field (e.g., `DifficultyTier`, `VoidTier`) in docstrings or inline comments. This helps new contributors understand how to use and extend these interfaces correctly. </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 ea59665a0c66d3552774a6e463ed60edcf1fbc4c and 38d8fc448e93d50031b3cb5a20627ad51c26a40a. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/controllers/api/getVoidProjectionRewardsController.ts` (1 hunks) * `src/routes/api.ts` (2 hunks) * `src/services/rngService.ts` (1 hunks) </details> <details> <summary>🔇 Additional comments (5)</summary><blockquote> <details> <summary>src/services/rngService.ts (2)</summary> `45-47`: **Ensure type consistency across modules** The function parameter expects `pool` items in `{ type: string; itemCount: number; rarity: TRarity }` format, whereas `getRandomWeightedReward` expects `{ Item: string; Rarity: TRarity }`. Confirm that the difference in field capitalization is intentional and consistent throughout the codebase. --- `50-52`: **Validate `rarityCounts` usage** Each iteration of the loop increments `rarityCounts[entry.rarity]`. Verify that `entry.rarity` is guaranteed to be one of the four keys (COMMON, UNCOMMON, RARE, LEGENDARY). If there’s a possibility of a different or undefined rarity, consider adding a safety check. </details> <details> <summary>src/controllers/api/getVoidProjectionRewardsController.ts (1)</summary> `46-71`: **Adjust refinement probabilities if needed** The `refinementToWeights` mapping sets fixed probabilities. Verify with game design requirements that these distribution values (e.g., 0.76, 0.22, etc.) align with the intended user experience. </details> <details> <summary>src/routes/api.ts (2)</summary> `29-29`: **Maintain alphabetical grouping** If import statements are being sorted or grouped by type, ensure that this new import (`getVoidProjectionRewardsController`) follows the same pattern or style rules your codebase uses for imports. Otherwise, ignore this. --- `124-124`: **Check for route duplication** Ensure `/getVoidProjectionRewards.php` is not duplicated in any other place, possibly hidden behind environment toggles or conditional logic in your codebase. <details> <summary>✅ Verification successful</summary> **Route `/getVoidProjectionRewards.php` is not duplicated** The route is only defined once in the codebase at `src/routes/api.ts`, with no duplicates found in other files or behind environment toggles. </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Script to verify that '/getVoidProjectionRewards.php' is only defined once in the codebase. rg "/getVoidProjectionRewards\.php" ``` Length of output: 140 </details> </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -0,0 +25,4 @@
weights
)!;
logger.debug(`relic rolled`, reward);
response.ParticipantInfo.Reward = reward.type;
coderabbitai[bot] (Migrated from github.com) commented 2025-01-04 19:05:07 -08:00
Author
Owner

⚠️ Potential issue

Confirm relic existence

When retrieving relic from ExportRelics[data.ParticipantInfo.VoidProjection], handle the case where the key might not exist. An undefined relic lookup could cause runtime errors.

-        const relic = ExportRelics[data.ParticipantInfo.VoidProjection];
+        const relicKey = data.ParticipantInfo.VoidProjection;
+        if (!ExportRelics[relicKey]) {
+            logger.warn(`Relic with key '${relicKey}' not found`);
+            return res.status(400).json({ error: "Invalid relic" });
+        }
+        const relic = ExportRelics[relicKey];

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Confirm relic existence** When retrieving `relic` from `ExportRelics[data.ParticipantInfo.VoidProjection]`, handle the case where the key might not exist. An undefined relic lookup could cause runtime errors. ```diff - const relic = ExportRelics[data.ParticipantInfo.VoidProjection]; + const relicKey = data.ParticipantInfo.VoidProjection; + if (!ExportRelics[relicKey]) { + logger.warn(`Relic with key '${relicKey}' not found`); + return res.status(400).json({ error: "Invalid relic" }); + } + const relic = ExportRelics[relicKey]; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
@ -0,0 +39,4 @@
// Give reward
await handleStoreItemAcquisition(reward.type, accountId, reward.itemCount);
}
coderabbitai[bot] (Migrated from github.com) commented 2025-01-04 19:05:07 -08:00
Author
Owner

🛠️ Refactor suggestion

Graceful handling of missing reward

When calling getRandomWeightedReward2, the result could be undefined if the pool is empty. In such a case, handle that scenario explicitly instead of using the non-null assertion operator (!). This helps prevent unexpected crashes.

-        )!;
+        );
+        if (!reward) {
+            logger.warn("Unable to determine reward from relic pool");
+            return res.status(400).json({ error: "Reward could not be determined" });
+        }

Committable suggestion skipped: line range outside the PR's diff.

_:hammer_and_wrench: Refactor suggestion_ **Graceful handling of missing reward** When calling `getRandomWeightedReward2`, the result could be `undefined` if the pool is empty. In such a case, handle that scenario explicitly instead of using the non-null assertion operator (`!`). This helps prevent unexpected crashes. ```diff - )!; + ); + if (!reward) { + logger.warn("Unable to determine reward from relic pool"); + return res.status(400).json({ error: "Reward could not be determined" }); + } ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) commented 2025-01-04 19:05:07 -08:00
Author
Owner

🛠️ Refactor suggestion

Double-check item counts

You always set itemCount to 1 for each reward. If itemCount in the pool has a different meaning or is intended to vary, you might need to use entry.itemCount to preserve the correct quantity or clarify why the function sets it to 1.

-            itemCount: 1,
+            itemCount: entry.itemCount,

Committable suggestion skipped: line range outside the PR's diff.

_:hammer_and_wrench: Refactor suggestion_ **Double-check item counts** You always set `itemCount` to `1` for each reward. If `itemCount` in the pool has a different meaning or is intended to vary, you might need to use `entry.itemCount` to preserve the correct quantity or clarify why the function sets it to 1. ```diff - itemCount: 1, + itemCount: entry.itemCount, ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.