Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions Maple2.Server.Game/PacketHandlers/ChangeAttributesScrollHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ private void HandleChange(GameSession session, IByteReader packet) {
return;
}

if (!TableMetadata.ItemOptionRandomTable.Options.TryGetValue(changeItem.Metadata.Option.RandomId, changeItem.Rarity, out ItemOption? itemOptionMetadata)) {
session.Send(ChangeAttributesScrollPacket.Error(ChangeAttributesScrollError.s_itemremake_scroll_error_impossible_item));
return;
}

if (itemRemakeScrollMetadata.RollAttribute) {
// Randomize attributes.
if (lockItem != null) {
Expand All @@ -138,24 +133,27 @@ private void HandleChange(GameSession session, IByteReader packet) {
}
}
} else {
ItemStats.Option changeOption = changeItem.Stats[ItemStats.Type.Random];

if (!ItemStatsCalc.RandomizeValues(changeItem, itemOptionMetadata, ref changeOption)) {
session.Send(ChangeAttributesScrollPacket.Error(ChangeAttributesScrollError.s_itemremake_scroll_error_server_fail_remake));
return;
}

// Restore locked attribute values.
// Fixed attributes.
if (lockItem != null) {
ItemStats.Option option = item.Stats[ItemStats.Type.Random];
// Restore locked attribute values.
if (isSpecialAttribute) {
var specialAttribute = (SpecialAttribute) attribute;
changeOption.Special[specialAttribute] = option.Special[specialAttribute];
if (!ItemStatsCalc.UpdateFixedOption(ref changeItem, new LockOption((SpecialAttribute) attribute, true))) {
session.Send(ChangeAttributesPacket.Error(ChangeAttributesError.s_itemremake_error_server_default));
return;
}
} else {
var basicAttribute = (BasicAttribute) attribute;
changeOption.Basic[basicAttribute] = option.Basic[basicAttribute];
if (!ItemStatsCalc.UpdateFixedOption(ref changeItem, new LockOption((BasicAttribute) attribute, true))) {
session.Send(ChangeAttributesPacket.Error(ChangeAttributesError.s_itemremake_error_server_default));
return;
}
}
} else {
if (!ItemStatsCalc.UpdateFixedOption(ref changeItem)) {
session.Send(ChangeAttributesPacket.Error(ChangeAttributesError.s_itemremake_error_server_default));
return;
}
}

}

// Try to consume both items.
Expand Down
42 changes: 42 additions & 0 deletions Maple2.Server.Game/Util/ItemStatsCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,48 @@ public bool UpdateRandomOption(ref Item item, params LockOption[] presets) {
return true;
}

public bool UpdateFixedOption(ref Item item, params LockOption[] presets) {
if (item.Metadata.Option == null || item.Stats == null) {
return false;
}

ItemStats.Option option = item.Stats[ItemStats.Type.Random];
if (option.Count == 0) {
return false;
}

// Get fixed options (with right MultiplyFactor)
if (!TableMetadata.ItemOptionRandomTable.Options.TryGetValue(item.Metadata.Option.RandomId, item.Rarity, out ItemOption? itemOption)) {
return false;
}
var statResult = new Dictionary<BasicAttribute, BasicOption>(option.Basic);
var specialResult = new Dictionary<SpecialAttribute, SpecialOption>(option.Special);
var fixedOption = new ItemStats.Option(statResult, specialResult, multiplyFactor: itemOption.MultiplyFactor);

if (!RandomizeValues(item, itemOption, ref fixedOption)) {
return false;
}

// Restore locked values.
foreach (LockOption lockOption in presets) {
if (lockOption.TryGet(out BasicAttribute basic, out bool lockBasicValue)) {
if (lockBasicValue) {
Debug.Assert(option.Basic.ContainsKey(basic), "Missing basic attribute after using lock.");
fixedOption.Basic[basic] = option.Basic[basic];
}
} else if (lockOption.TryGet(out SpecialAttribute special, out bool lockSpecialValue)) {
if (lockSpecialValue) {
Debug.Assert(option.Special.ContainsKey(special), "Missing special attribute after using lock.");
fixedOption.Special[special] = option.Special[special];
}
}
}

// Update item with result.
item.Stats[ItemStats.Type.Random] = fixedOption;
return true;
}

/// <param name="item">Item</param>
/// <param name="itemOptionMetadata">Item's Random Option Metadata</param>
/// <param name="option"></param>
Expand Down
Loading