1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-02 17:27:23 -04:00
OpenDiablo2/d2core/d2stats/diablo2stats/diablo2stats.go
lord 9e61079e93
Stats refactor (#617)
* add interface for stats, d2 is an implementation

* fix incorrect comment, remove ennecessary int

* simplified description functions, remove duplicates

* moved default stringer functions

* fixed incorrect stat combine method

* change `Create` to `New` in method names

* d2stats + diablo2stats refactored again

- simplified `NewStat` provider function
- added initializer for stat values that sets the stringer functions, value types, and combination types for values when created
- removed redundant description functions
- added stat value combination types `sum` and `static`

`static` stat values which are not altered when stats are combined. this makes sense for stats like proc-on-hit or +skills to class

example:
	Stat A: `10% reanimate as: skeleton mage`
	Stat B: `8% reanimate as: skeleton archer`
	Stat C: `6% reanimate as: skeleton archer`

	A and B can not be combined
	B and C can be combined to `14% reanimate as: skeleton archer`
2020-07-23 22:12:48 -04:00

48 lines
1.0 KiB
Go

package diablo2stats
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2stats"
)
// NewStat creates a stat instance with the given record and values
func NewStat(key string, values ...float64) d2stats.Stat {
record := d2datadict.ItemStatCosts[key]
if record == nil {
return nil
}
stat := &diablo2Stat{
record: record,
}
stat.init(values...) // init stat values, value types, and value combination rules
return stat
}
// NewStatList creates a stat list
func NewStatList(stats ...d2stats.Stat) d2stats.StatList {
return &Diablo2StatList{stats}
}
// NewValue creates a stat value of the given type
func NewValue(t d2stats.StatNumberType, c d2stats.ValueCombineType) d2stats.StatValue {
sv := &Diablo2StatValue{
numberType: t,
combineType: c,
}
switch t {
case d2stats.StatValueFloat:
sv.stringerFn = stringerUnsignedFloat
case d2stats.StatValueInt:
sv.stringerFn = stringerUnsignedInt
default:
sv.stringerFn = stringerEmpty
}
return sv
}