fix: removing an archon shard doesn't refund it #729

Merged
Sainan merged 1 commits from shard-refund into main 2025-01-05 16:21:02 -08:00
Owner

Fixup for #724. Should finally complete #288.

Fixup for #724. Should finally complete #288.
coderabbitai[bot] commented 2025-01-05 14:30:49 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

The pull request introduces modifications to the infestedFoundryController in the src/controllers/api/infestedFoundryController.ts file, focusing on the shard removal process within the "x" case. The changes implement a mechanism to refund a shard when it is removed from a suit. This involves identifying the shard based on the upgrade's color, creating a miscItemChanges entry to record the refund, and adding the shard back to the inventory with an ItemCount of 1.

The update also includes resetting the ArchonCrystalUpgrades at the specified slot to an empty object, signaling the upgrade's removal. Additionally, the code now decrements the "HelminthBile" resource count by 300 during the shard removal process. The response to the client has been updated to include the InfestedFoundry state, providing comprehensive inventory information after the operation.


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 The pull request introduces modifications to the `infestedFoundryController` in the `src/controllers/api/infestedFoundryController.ts` file, focusing on the shard removal process within the "x" case. The changes implement a mechanism to refund a shard when it is removed from a suit. This involves identifying the shard based on the upgrade's color, creating a `miscItemChanges` entry to record the refund, and adding the shard back to the inventory with an `ItemCount` of 1. The update also includes resetting the `ArchonCrystalUpgrades` at the specified slot to an empty object, signaling the upgrade's removal. Additionally, the code now decrements the "HelminthBile" resource count by 300 during the shard removal process. The response to the client has been updated to include the `InfestedFoundry` state, providing comprehensive inventory information after the operation. <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAM0QADx5A1kIpRCwSTBxXJnhCHGR4V0Z6QlksAHJwwPjcLEZNWOgAdwxUZFwhVk06R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BisjDIJW4ToD8ZDhB8Mzi7wKWoWIEgYlkkX4pINbpTysU06M5uLWQRx2Utk1JYS6v+coXhYFWoozXNFJrYgG0fCoyNkDO8osI04SeRdTV2/njLIHqElkBisQABJkD4fRLPAABCiDRGirRDAAzAADKPnIULtTNHeLCN8scQKyN9DzjEs/1MJzaX+WqnDQKUfw+A3XFkFPEP0K5HxZNn835Q5WDqcbWk6WVNXG6CorygAUg4ADyK71xXs3Rk8RyYhzev5AmFILi323l4HmnB+by1/nOAkKcvABR8qgCg3lwqdRnuHfw8VE4wk0IoIYFBuhnFDrTeujdcyYECNmGkdEO6KEWiIMY8E7TDGticMYExAhmmkBSc+rkEF804mpb0FxE6YHiHQDqJxCDYjooleWFgrB2R8Io1GU1NryiLiCNR+jPJkCSHcKg8FQbXCEGqDanAoq+WADAFczoYS6MTk6Qx4hjF6KwKgMxFjvTWIELY+x0BHGSApG0E00AYHwJwBCdA414hASsrEYCQkRLgWpvCKizk4IxAYpwVILE3IcXIdhNOeEND8SItkkiCFNAAH0FjIBaYETIZBYn0Bae/KxglhJNOHlaGWVoACso99jxHoAANgwPsXYo9h77AmWQdZahh5zO2EIFQ+wMBzLNNsYeMtxBWm2EMnJzT8BtPoB0rpiAekMBaRBQwQA --> <!-- 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 14:38:39 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/controllers/api/infestedFoundryController.ts (1)

81-81: Ensure consistent response payload
Returning InfestedFoundry: inventory.toJSON().InfestedFoundry is helpful for the client, but confirm that client-side code expects and processes this shape. Make sure to maintain consistency with other responses to avoid confusion.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82621ebe0f and 3414509fd6.

📒 Files selected for processing (1)
  • src/controllers/api/infestedFoundryController.ts (1 hunks)
🔇 Additional comments (1)
src/controllers/api/infestedFoundryController.ts (1)

60-66: Check capacity and other constraints when refunding shards
Currently, the code simply adds the shard back to the inventory but does not handle capacity checks or any potential conflicts. If your app logic requires additional constraints (e.g., inventory limits), you may need to validate them before adding items.

**Actionable comments posted: 2** <details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>src/controllers/api/infestedFoundryController.ts (1)</summary><blockquote> `81-81`: **Ensure consistent response payload** Returning `InfestedFoundry: inventory.toJSON().InfestedFoundry` is helpful for the client, but confirm that client-side code expects and processes this shape. Make sure to maintain consistency with other responses to avoid confusion. </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 82621ebe0f3b02391ab9a94df291b0cf2d1bc0a5 and 3414509fd6a920395e5eab367bde9a6ce731ec47. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/controllers/api/infestedFoundryController.ts` (1 hunks) </details> <details> <summary>🔇 Additional comments (1)</summary><blockquote> <details> <summary>src/controllers/api/infestedFoundryController.ts (1)</summary> `60-66`: **Check capacity and other constraints when refunding shards** Currently, the code simply adds the shard back to the inventory but does not handle capacity checks or any potential conflicts. If your app logic requires additional constraints (e.g., inventory limits), you may need to validate them before adding items. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -55,0 +56,4 @@
// refund shard
const shard = Object.entries(colorToShard).find(
([color]) => color == suit.ArchonCrystalUpgrades![request.Slot].Color
)![1];
coderabbitai[bot] (Migrated from github.com) commented 2025-01-05 14:38:39 -08:00
Author
Owner

⚠️ Potential issue

Validate that a matching shard color is always found
If find() returns undefined (due to an unexpected color string), the ! non-null assertion may cause a runtime error. Consider adding a fallback or error handling to avoid potential crashes.

 const shardEntry = Object.entries(colorToShard).find(([color]) => 
   color === suit.ArchonCrystalUpgrades![request.Slot].Color
 );
-if (!shardEntry) throw new Error("Invalid archon crystal color");
-const shard = shardEntry[1];
+if (!shardEntry) {
+  // handle invalid color scenario
+  return res.status(400).json({ error: "Invalid archon crystal color" });
+}
+const shard = shardEntry[1];

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

_:warning: Potential issue_ **Validate that a matching shard color is always found** If `find()` returns `undefined` (due to an unexpected color string), the `!` non-null assertion may cause a runtime error. Consider adding a fallback or error handling to avoid potential crashes. ```diff const shardEntry = Object.entries(colorToShard).find(([color]) => color === suit.ArchonCrystalUpgrades![request.Slot].Color ); -if (!shardEntry) throw new Error("Invalid archon crystal color"); -const shard = shardEntry[1]; +if (!shardEntry) { + // handle invalid color scenario + return res.status(400).json({ error: "Invalid archon crystal color" }); +} +const shard = shardEntry[1]; ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
@ -57,3 +73,4 @@
x => x.ItemType == "/Lotus/Types/Items/InfestedFoundry/HelminthBile"
)!;
bile.Count -= 300;
coderabbitai[bot] (Migrated from github.com) commented 2025-01-05 14:38:38 -08:00
Author
Owner

🛠️ Refactor suggestion

Avoid negative resource counts
Subtracting 300 from bile.Count without checking if there's enough HelminthBile could produce negative counts. This might lead to inconsistencies in the user’s resource inventory.

- bile.Count -= 300;
+ if (bile.Count < 300) {
+   bile.Count = 0; 
+   // or handle insufficient HelminthBile scenario
+ } else {
+   bile.Count -= 300;
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

            // remove bile
            const bile = inventory.InfestedFoundry!.Resources!.find(
                x => x.ItemType == "/Lotus/Types/Items/InfestedFoundry/HelminthBile"
            )!;
            if (bile.Count < 300) {
                bile.Count = 0;
                // or handle insufficient HelminthBile scenario
            } else {
                bile.Count -= 300;
            }
_:hammer_and_wrench: Refactor suggestion_ **Avoid negative resource counts** Subtracting 300 from `bile.Count` without checking if there's enough HelminthBile could produce negative counts. This might lead to inconsistencies in the user’s resource inventory. ```diff - bile.Count -= 300; + if (bile.Count < 300) { + bile.Count = 0; + // or handle insufficient HelminthBile scenario + } else { + bile.Count -= 300; + } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion // remove bile const bile = inventory.InfestedFoundry!.Resources!.find( x => x.ItemType == "/Lotus/Types/Items/InfestedFoundry/HelminthBile" )!; if (bile.Count < 300) { bile.Count = 0; // or handle insufficient HelminthBile scenario } else { bile.Count -= 300; } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.