Skip to content
Merged
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
31 changes: 15 additions & 16 deletions Maple2.Server.Game/Manager/ItemEnchantManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ public bool Enchant(long itemUid) {
return false;
}

void ApplyEnchantStats() {
// GetBasicOptions() again to ensure rates match those in table.
// This *MUST* be called before incrementing Enchants.
foreach ((BasicAttribute attribute, BasicOption option) in GetEnchant(session, upgradeItem).BasicOptions) {
if (upgradeItem.Enchant.BasicOptions.TryGetValue(attribute, out BasicOption existing)) {
upgradeItem.Enchant.BasicOptions[attribute] = option + existing;
} else {
upgradeItem.Enchant.BasicOptions[attribute] = option;
}
}
upgradeItem.Enchant.Enchants++;
}

switch (Type) {
case EnchantType.Ophelia:
float roll = Random.Shared.NextSingle() * MaxRate;
Expand All @@ -236,16 +249,7 @@ public bool Enchant(long itemUid) {
logger.Debug("Enchant result: {Roll} / {Total} = {Result}", roll, totalRate, enchantResult.ToString());

if (enchantResult == EnchantResult.Success) {
// GetBasicOptions() again to ensure rates match those in table.
// This *MUST* be called before incrementing Enchants.
foreach ((BasicAttribute attribute, BasicOption option) in GetEnchant(session, upgradeItem).BasicOptions) {
if (upgradeItem.Enchant.BasicOptions.TryGetValue(attribute, out BasicOption existing)) {
upgradeItem.Enchant.BasicOptions[attribute] = option + existing;
} else {
upgradeItem.Enchant.BasicOptions[attribute] = option;
}
}
upgradeItem.Enchant.Enchants++;
ApplyEnchantStats();

session.ConditionUpdate(ConditionType.enchant_result, codeLong: (int) EnchantResult.Success, targetLong: upgradeItem.Enchant.Enchants);
session.Send(ItemEnchantPacket.Success(upgradeItem, attributeDeltas));
Expand All @@ -261,12 +265,7 @@ public bool Enchant(long itemUid) {
upgradeItem.Enchant.EnchantExp += GainExp[enchants];
if (upgradeItem.Enchant.EnchantExp >= MaxExp) {
upgradeItem.Enchant.EnchantExp = 0;
// GetBasicOptions() again to ensure rates match those in table.
// This *MUST* be called before incrementing Enchants.
foreach ((BasicAttribute attribute, BasicOption option) in GetEnchant(session, upgradeItem).BasicOptions) {
upgradeItem.Enchant.BasicOptions[attribute] = option;
}
upgradeItem.Enchant.Enchants++;
ApplyEnchantStats();

session.ConditionUpdate(ConditionType.enchant_result, codeLong: (int) EnchantResult.Success, targetLong: upgradeItem.Enchant.Enchants);
session.Send(ItemEnchantPacket.Success(upgradeItem, attributeDeltas));
Expand Down
Loading