Fix: Add enchant stats to character - #453
Conversation
在 `StatsManager.cs` 文件中,添加了对装备强化属性的处理逻辑。新增了对 `item.Enchant` 和 `item.Enchant.BasicOptions` 的检查,以便将强化属性加到角色的属性值中,从而使角色的 GearScore 计算更加准确,考虑了装备的强化效果。Fixed the issue that enhancements were not implemented/applied to character attributes.(MS2Community#452)
WalkthroughThe Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
Maple2.File.Ingest/Mapper/TableMapper.cs(1 hunks)Maple2.Model/Metadata/Table/ScrollTable.cs(1 hunks)Maple2.Server.Game/Manager/StatsManager.cs(3 hunks)Maple2.Server.Game/PacketHandlers/ChangeAttributesHandler.cs(2 hunks)Maple2.Server.Game/PacketHandlers/ChangeAttributesScrollHandler.cs(7 hunks)
🔇 Additional comments (12)
Maple2.Model/Metadata/Table/ScrollTable.cs (2)
32-35: LGTM! Clean metadata extension for item remake scrolls.The new fields
RollAttribute,RollValueType, andOnlyPetfollow the existing pattern and naming conventions. The additions enhance the metadata structure to support more sophisticated scroll behavior.
37-41: Well-defined enum with logical progression.The
RollValueTypeenum has clear, meaningful names and follows a logical numerical progression. The values (None=0, Normal=1, HigherEnd=2) suggest increasing levels of enhancement.Maple2.Server.Game/PacketHandlers/ChangeAttributesHandler.cs (2)
169-170: Consistent refactoring in HandleSelect method.Good consistency applying the same
GetGear()method change in bothHandleChangeandHandleSelectmethods.
64-65:Details
✅ Verification successful
Improved encapsulation with GetGear method.
The change from direct inventory lookup to
session.Item.GetGear(itemUid)improves code encapsulation and readability. The fallback to pets inventory remains intact.Verify that
GetGear()method provides equivalent functionality to the original inventory lookup:
🏁 Script executed:
#!/bin/bash # Description: Verify GetGear method implementation and ensure it handles the same scenarios as the original code # Search for GetGear method definition ast-grep --pattern $'GetGear($uid) { $$$ }' # Also search for any GetGear method calls to understand usage patterns rg -A 5 -B 2 "GetGear\("Length of output: 7664
GetGear method verified – behavior matches and extends original lookup
The
GetGear(long uid)implementation inMaple2.Server.Game/Manager/Items/ItemManager.csfirst calls:Inventory.Get(uid, InventoryType.Gear)and then falls back to:
Equips.Gear.Values.FirstOrDefault(gear => gear.Uid == uid)This covers both gear in the player’s inventory and equipped gear, meeting or exceeding the original direct inventory lookup. The refactoring improves encapsulation and preserves the pets fallback. No further changes needed.
Maple2.Server.Game/Manager/StatsManager.cs (1)
160-166: Critical enhancement: Enchantment attributes now properly applied to character stats.This implementation correctly addresses the core PR objective by ensuring enchantment attributes contribute to character stats calculation. The code:
✅ Properly null-checks both
item.Enchantanditem.Enchant.BasicOptions
✅ Iterates through all basic enchantment options
✅ Adds values to the character's total stats usingValues[kvp.Key].AddTotal(kvp.Value)
✅ Follows the existing code pattern in the same methodThis fix ensures that equipment enhancements are accurately reflected in the character's GearScore and overall attribute calculations.
Maple2.File.Ingest/Mapper/TableMapper.cs (1)
892-895: Proper data mapping for new scroll metadata fields.The field mappings correctly populate the new metadata properties:
RollAttribute: scroll.addOpKind == 1- logical boolean conversionRollValueType: (RollValueType) scroll.addOpValue- appropriate enum castOnlyPet: scroll.onlyPet- direct mappingThese mappings integrate seamlessly with the metadata extensions in
ScrollTable.csand provide the data foundation for enhanced scroll behavior.Maple2.Server.Game/PacketHandlers/ChangeAttributesScrollHandler.cs (6)
1-1: LGTM: Standard library import added.The addition of
System.Diagnostics.CodeAnalysisis appropriate for nullable reference type support.
65-65: LGTM: Enhanced item retrieval to support pets.The fallback to Pets inventory properly extends the functionality to handle pet items alongside gear items.
75-76: LGTM: Improved method signature for better data flow.The addition of the output parameter eliminates duplicate metadata retrieval and improves code efficiency.
162-184: Excellent improvement: Atomic consumption with rollback.This implementation properly handles the consumption of both items atomically, with appropriate rollback logic if either operation fails. This prevents partial state corruption and provides clear error messaging.
186-189: LGTM: Proper pet binding implementation.The conditional binding logic correctly handles pet items with
BindPettransfer type and appropriately notifies the client with an inventory update.
221-253: LGTM: Enhanced compatibility validation with pet support.The method signature improvement and the addition of
OnlyPetvalidation logic properly extend the compatibility checking to handle pet-specific scrolls. The validation logic correctly ensures pet-only scrolls are used exclusively on pet items.
|
Can you update your base branch so my changes don't show up? |
Zintixx
left a comment
There was a problem hiding this comment.
Looks good! Although not implemented yet, you could go ahead and add the stats in the same way for limit break
if (item.LimitBreak is not null) {
foreach (KeyValuePair<BasicAttribute, BasicOption> kvp in item.LimitBreak.BasicOptions) {
Values[kvp.Key].AddTotal(kvp.Value);
}
}
在
StatsManager.cs文件中,添加了对装备强化属性的处理逻辑。新增了对item.Enchant和item.Enchant.BasicOptions的检查,以便将强化属性加到角色的属性值中,从而使角色的 GearScore 计算更加准确,考虑了装备的强化效果。Fixed the issue that enhancements were not implemented/applied to character attributes.(#452)Summary by CodeRabbit
New Features
Bug Fixes