Skip to content

Commit

Permalink
Move reforging up to apply before enchants
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicKevinFerm committed Feb 29, 2024
1 parent 7d8f3c0 commit d591898
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions sim/core/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,6 @@ func NewItem(itemSpec ItemSpec) Item {
panic(fmt.Sprintf("No item with id: %d", itemSpec.ID))
}

if itemSpec.Reforging != nil {
if validateReforging(&item, *itemSpec.Reforging) {
item.Reforging = itemSpec.Reforging
} else {
panic(fmt.Sprintf("When validating reforging for item %d, the stat reforging for %s to %s could not be validated", itemSpec.ID, itemSpec.Reforging.FromStat.String(), itemSpec.Reforging.ToStat.String()))
}
}

if itemSpec.Enchant != 0 {
if enchant, ok := EnchantsByEffectID[itemSpec.Enchant]; ok {
item.Enchant = enchant
Expand All @@ -288,6 +280,14 @@ func NewItem(itemSpec ItemSpec) Item {
// }
}

if itemSpec.Reforging != nil {
if validateReforging(&item, *itemSpec.Reforging) {
item.Reforging = itemSpec.Reforging
} else {
panic(fmt.Sprintf("When validating reforging for item %d, the stat reforging for %s to %s could not be validated", itemSpec.ID, itemSpec.Reforging.FromStat.String(), itemSpec.Reforging.ToStat.String()))
}
}

if len(itemSpec.Gems) > 0 {
// Need to do this to account for possible extra gem sockets.
numGems := len(item.GemSockets)
Expand Down Expand Up @@ -371,6 +371,18 @@ func (equipment *Equipment) Stats() stats.Stats {
equipStats = equipStats.Add(item.Stats)
equipStats = equipStats.Add(item.Enchant.Stats)

if item.Reforging != nil {
reforgingChanges := stats.Stats{}

fromStatValue := equipStats[item.Reforging.FromStat]
reduction := math.Floor(fromStatValue * 0.4) // Calculate 40% reduction floored

reforgingChanges[item.Reforging.FromStat] = -reduction
reforgingChanges[item.Reforging.ToStat] = +reduction

equipStats = equipStats.Add(reforgingChanges) // Apply reforging changes
}

for _, gem := range item.Gems {
equipStats = equipStats.Add(gem.Stats)
}
Expand All @@ -388,17 +400,7 @@ func (equipment *Equipment) Stats() stats.Stats {
equipStats = equipStats.Add(item.SocketBonus)
}
}
if item.Reforging != nil {
reforgingChanges := stats.Stats{}

fromStatValue := equipStats[item.Reforging.FromStat]
reduction := math.Floor(fromStatValue * 0.4) // Calculate 40% reduction floored

reforgingChanges[item.Reforging.FromStat] = -reduction
reforgingChanges[item.Reforging.ToStat] = +reduction

equipStats = equipStats.Add(reforgingChanges) // Apply reforging changes
}
}
return equipStats
}
Expand Down

0 comments on commit d591898

Please sign in to comment.