Skip to content

Commit

Permalink
- slight stat simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
vigo2 committed Oct 13, 2023
1 parent faa8f44 commit ed0fabe
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 300 deletions.
2 changes: 1 addition & 1 deletion sim/core/aura_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (character *Character) NewTemporaryStatsAuraWrapped(auraLabel string, actio
if sim.Log != nil {
character.Log(sim, "Lost %s from fading %s.", buffs.FlatString(), actionID)
}
character.AddStatsDynamic(sim, buffs.Multiply(-1))
character.AddStatsDynamic(sim, buffs.Invert())
},
}

Expand Down
2 changes: 1 addition & 1 deletion sim/core/debuffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ func apReductionEffect(aura *Aura, apReduction float64) *ExclusiveEffect {
ee.Aura.Unit.AddStatsDynamic(sim, statReduction)
},
OnExpire: func(ee *ExclusiveEffect, sim *Simulation) {
ee.Aura.Unit.AddStatsDynamic(sim, statReduction.Multiply(-1))
ee.Aura.Unit.AddStatsDynamic(sim, statReduction.Invert())
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion sim/core/pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (pet *Pet) Disable(sim *Simulation) {

// Remove inherited stats on dismiss if not permanent
if pet.isGuardian || pet.timeoutAction != nil {
pet.AddStatsDynamic(sim, pet.inheritedStats.Multiply(-1))
pet.AddStatsDynamic(sim, pet.inheritedStats.Invert())
pet.inheritedStats = stats.Stats{}
}

Expand Down
44 changes: 21 additions & 23 deletions sim/core/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,20 @@ func (s Stat) StatName() string {
}

func FromFloatArray(values []float64) Stats {
stats := Stats{}
var stats Stats
copy(stats[:], values)
return stats
}

// Adds two Stats together, returning the new Stats.
func (stats Stats) Add(other Stats) Stats {
var newStats Stats
for k, v := range stats {
newStats[k] = v + other[k]
for k := range stats {
stats[k] += other[k]
}
return newStats
return stats
}

// Adds another to Stats to this, in-place.
// Adds another to Stats to this, in-place. For performance, only.
func (stats *Stats) AddInplace(other *Stats) {
for k := range stats {
stats[k] += other[k]
Expand All @@ -206,38 +205,37 @@ func (stats *Stats) AddInplace(other *Stats) {

// Subtracts another Stats from this one, returning the new Stats.
func (stats Stats) Subtract(other Stats) Stats {
var newStats Stats
for k := range stats {
stats[k] -= other[k]
}
return stats
}

func (stats Stats) Invert() Stats {
for k, v := range stats {
newStats[k] = v - other[k]
stats[k] = -v
}
return newStats
return stats
}

func (stats Stats) Multiply(multiplier float64) Stats {
var newStats Stats
for k, v := range stats {
newStats[k] = v * multiplier
for k := range stats {
stats[k] *= multiplier
}
return newStats
return stats
}

// Multiplies two Stats together by multiplying the values of corresponding
// stats, like a dot product operation.
func (stats Stats) DotProduct(other Stats) Stats {
var newStats Stats
for k, v := range stats {
newStats[k] = v * other[k]
for k := range stats {
stats[k] *= other[k]
}
return newStats
return stats
}

func (stats Stats) Equals(other Stats) bool {
for k, v := range stats {
if v != other[k] {
return false
}
}
return true
return stats == other
}

func (stats Stats) EqualsWithTolerance(other Stats, tolerance float64) bool {
Expand Down
Loading

0 comments on commit ed0fabe

Please sign in to comment.