1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-16 09:25:57 -05:00
OpenDiablo2/d2core/d2stats/stat_value.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

60 lines
1.7 KiB
Go

package d2stats
// StatNumberType is a value type for a stat value
type StatNumberType int
// Stat value types
const (
StatValueInt StatNumberType = iota
StatValueFloat
)
// ValueCombineType is a rule for combining stat values
type ValueCombineType int
const (
// StatValueCombineSum means that the values are simply summed
StatValueCombineSum ValueCombineType = iota
// StatValueCombineStatic means that values can be combined only if they
// have the same number value, and that the combination does not alter
// the number value. This is typically for things like static skill level
// monster/skill index for on proc stats where it doesnt make sense to sum
// the values
// example 1:
// if
// Stat_A := `25% chance to cast level 2 Frozen Orb on attack`
// Stat_B := `25% chance to cast level 3 Frozen Orb on attack`
// then
// Stat_A can NOT be combined with Stat_B
// even though the skills are the same, the levels are different
//
// example 2:
// if
// Stat_A := `25% chance to cast level 20 Frost Nova on attack`
// Stat_B := `25% chance to cast level 20 Frost Nova on attack`
// then
// the skills and skill levels are the same, so it can be combined
// (Stat_A + Stat_B) == `50% chance to cast level 20 Frost Nova on attack`
StatValueCombineStatic
)
// StatValue is something that can have both integer and float
// number components, as well as a means of retrieving a string for
// its values.
type StatValue interface {
NumberType() StatNumberType
CombineType() ValueCombineType
Clone() StatValue
SetInt(int) StatValue
SetFloat(float64) StatValue
SetStringer(func(StatValue) string) StatValue
Int() int
Float() float64
String() string
Stringer() func(StatValue) string
}