Skip to content

Fix: Item Stats - #381

Merged
AngeloTadeucci merged 2 commits into
masterfrom
item-stats
Mar 24, 2025
Merged

Fix: Item Stats#381
AngeloTadeucci merged 2 commits into
masterfrom
item-stats

Conversation

@AngeloTadeucci

@AngeloTadeucci AngeloTadeucci commented Mar 24, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Refactor
    • Streamlined the internal calculation process for item statistics, ensuring clearer and more efficient attribute processing.
  • Bug Fixes
    • Adjusted computation logic for item variations to maintain consistent and reliable outcomes across all scenarios.
    • Enhanced clarity in value calculations for item variations.

@coderabbitai

coderabbitai Bot commented Mar 24, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in the ItemStatsCalculator.cs file involve significant modifications to the RandomizeValues method and the GetValue method signature. The RandomizeValues method now calls GetValue with fewer parameters, specifically removing the item and itemOptionMetadata parameters. Instead, it directly passes the attribute or specialAttribute along with the relevant tableValues or tableRates and rollMax parameters. Additionally, the GetItemVariationValue method has been updated for clearer arithmetic operations and consistent return values.

Changes

File(s) Change Summary
Maple2.Server.Game/.../ItemStatsCalculator.cs - Refactored Method Signature: In GetValue, removed item and itemOptionMetadata parameters.
- Arithmetic Adjustment: Modified multiplication precedence in GetItemVariationValue for clarity and consistent returns.

Assessment against linked issues

Objective Addressed Explanation
Fix item stats display for Life Data Storage Necklace (377)

Possibly related PRs

  • Fix: Stats #242: Addresses modifications in the RandomizeValues method with the introduction of the rollMax parameter, affecting item statistics calculations.
  • Differentiate Random Stats by Random Make Type #302: Involves similar updates in the ItemStatsCalculator class, focusing on item variation handling and changes in the signature of the GetValue method.

Suggested reviewers

  • Zintixx

Poem

I'm a rabbit on a coding spree,
Hoping through changes so light and free.
Parameters slimmed and math aligned,
In stat calculations, clarity we find.
Carrots and code, together we bind!
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (1)

221-356: ⚠️ Potential issue

Method signature doesn't match implementation requirements

The GetValue method signature has been changed to remove Item item and ItemOption itemOptionMetadata parameters, but the method body still references these variables extensively in the following places:

  • Lines 224-262: Uses item.Type.IsPet and item.Rarity
  • Lines 270-352: Uses item.Metadata.Option properties
  • Lines 340-349: Uses itemOptionMetadata.Entries

You need to either:

  1. Keep the parameters in the method signature
  2. Refactor the method to not use these parameters
  3. Make these parameters class-level fields
-int GetValue(BasicAttribute? attribute = null, SpecialAttribute? specialAttribute = null, ItemEquipVariationTable.Set<int>[]? tableValues = null, ItemEquipVariationTable.Set<float>[]? tableRates = null, bool rollMax = false) {
+int GetValue(Item item, ItemOption itemOptionMetadata, BasicAttribute? attribute = null, SpecialAttribute? specialAttribute = null, ItemEquipVariationTable.Set<int>[]? tableValues = null, ItemEquipVariationTable.Set<float>[]? tableRates = null, bool rollMax = false) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc4cf5c and 96f4656.

📒 Files selected for processing (1)
  • Maple2.Server.Game/Util/ItemStatsCalculator.cs (3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (3)
Maple2.Model/Game/Item/ItemOption.cs (1)
  • BasicOption (9-9)
Maple2.Tools/Extensions/EnumerableExtensions.cs (1)
  • TryGetValue (74-82)
Maple2.File.Ingest/Utils/AttributeExtensions.cs (1)
  • BasicAttribute (6-44)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: format
  • GitHub Check: build
🔇 Additional comments (3)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (3)

449-451: Improved arithmetic clarity with parentheses

Good use of parentheses to explicitly show the order of operations, making the code more readable and less error-prone.


469-471: Improved arithmetic clarity with parentheses

Similar to the previous instance, the use of parentheses here improves readability and ensures the correct order of operations.


455-480: Added proper return values for all control paths

The changes to ensure all code paths return a value is a good improvement, preventing potential undefined behavior.

However, ensure that returning value for basic attributes and (int)(rate * 1000) for special attributes is the correct behavior for your application logic.

Comment thread Maple2.Server.Game/Util/ItemStatsCalculator.cs
Comment thread Maple2.Server.Game/Util/ItemStatsCalculator.cs
Comment thread Maple2.Server.Game/Util/ItemStatsCalculator.cs Outdated
Comment thread Maple2.Server.Game/Util/ItemStatsCalculator.cs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (2)

209-216: ⚠️ Potential issue

Parameter mismatch in GetValue calls for special attributes.

Similar to the previous issue, this section also has the same parameter mismatch with the implementation.

Apply the same fix as suggested for the basic attributes:

-int value = GetValue(specialAttribute: attribute, tableValues: values, rollMax: rollMax);
-int rateInt = GetValue(specialAttribute: attribute, tableRates: rates, rollMax: rollMax);
+int value = GetValue(item, itemOptionMetadata, specialAttribute: attribute, tableValues: values, rollMax: rollMax);
+int rateInt = GetValue(item, itemOptionMetadata, specialAttribute: attribute, tableRates: rates, rollMax: rollMax);

200-207: ⚠️ Potential issue

Fixed method parameter mismatch, but introduced a different issue.

The implementation now correctly calls the updated GetValue method signature by removing the item and itemOptionMetadata parameters, which aligns with the new signature. However, the GetValue method implementation still references these parameters internally (lines 224-346), which will cause errors.

You have two options to fix this:

  1. Update the GetValue method implementation to no longer use item and itemOptionMetadata
  2. Keep these as parameters and pass them in the method calls
-int value = GetValue(attribute, tableValues: values, rollMax: rollMax);
-int rateInt = GetValue(attribute, tableRates: rates, rollMax: rollMax);
+// Option 1: Make item and itemOptionMetadata class fields and reference them directly
+// Option 2: Keep the previous implementation and pass the parameters
+int value = GetValue(item, itemOptionMetadata, attribute, tableValues: values, rollMax: rollMax);
+int rateInt = GetValue(item, itemOptionMetadata, attribute, tableRates: rates, rollMax: rollMax);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96f4656 and e27d4a1.

📒 Files selected for processing (1)
  • Maple2.Server.Game/Util/ItemStatsCalculator.cs (3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (3)
Maple2.Model/Game/Item/ItemOption.cs (1)
  • BasicOption (9-9)
Maple2.Tools/Extensions/EnumerableExtensions.cs (1)
  • TryGetValue (74-82)
Maple2.File.Ingest/Utils/AttributeExtensions.cs (1)
  • BasicAttribute (6-44)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (4)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (4)

449-451: Improved clarity of arithmetic operations.

The explicit parentheses around the multiplication operations improve readability and make the order of operations clearer.


455-461: Improved return value handling for basic attributes.

The code now has a more consistent and explicit approach to returning values for basic attributes, with clear conditional blocks for different scenarios.


473-475: Improved clarity of arithmetic operations for special attributes.

Similar to the basic attributes case, the explicit parentheses around multiplications improve readability.


479-485: Improved return value handling for special attributes.

The code now has a more consistent and explicit approach to returning values for special attributes, making it easier to understand the logic flow.

Comment thread Maple2.Server.Game/Util/ItemStatsCalculator.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Item Stats Bugged for Life Data Storage Necklace

2 participants