Documentation
¶
Overview ¶
Package modifier holds the buff and debuff layer: the temporary terms that sit between a unit's resolved stat line and the numbers a hit is calculated from.
Two decisions here shape everything downstream.
Flat terms apply before percentage terms, so a stat resolves as (base + flat) * (1000 + percent) / 1000. The alternative order lets a small flat buff be multiplied by a large percentage buff, which makes the two kinds of term impossible to price independently.
Percentage terms of the same target add rather than compose. Three separate fifty-percent buffs come to +150%, not to 3.375x. Composition looks harmless on two buffs and explodes on four, and a battle where several supports stack on one carry is exactly where four happens.
The summed terms are then saturated rather than clamped, so a stat approaches its limit without ever reaching it and each further buff is worth less than the last. See scale.Saturate. A consequence worth knowing: because a large term saturates rather than overflowing, a debuff can safely be authored well past a hundred percent, and a modest buff lands close to its face value.
Everything is integer arithmetic on parts per thousand, so a battle replays identically from its seed.
Index ¶
- Constants
- type Bounds
- type Mode
- type Modifier
- type Set
- func (s *Set) Add(m Modifier) error
- func (s *Set) AddAll(modifiers ...Modifier) error
- func (s Set) Affinity(multiplier, neutral int, bounds Bounds) int
- func (s Set) Flat(target Target) int64
- func (s Set) Percent(target Target) int64
- func (s Set) Raw(kind progression.Kind, base int64) int64
- func (s Set) Stat(kind progression.Kind, base int64, ceiling int64, bounds Bounds) int64
- func (s Set) Stats(base progression.Values, ceilings progression.Values, bounds Bounds) progression.Values
- type Target
Constants ¶
const ( HP = Target(progression.HP) Attack = Target(progression.Attack) Defense = Target(progression.Defense) Speed = Target(progression.Speed) Accuracy = Target(progression.Accuracy) Dodge = Target(progression.Dodge) // Affinity is the effectiveness of an elemental advantage rather than a // stat, so it sits just past the stat range and shares the same indexing. Affinity = Target(progression.KindCount) )
const PercentBase = scale.Base
PercentBase is the denominator percentage terms are expressed against.
const TargetCount = int(Affinity) + 1
TargetCount is the number of modifier targets.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bounds ¶
type Bounds struct {
// Headroom sets the value a buffed stat approaches, in parts per thousand
// of its progression ceiling. It is never reached, so it is a limit rather
// than a cap; the larger it is, the closer a single buff lands to its face
// value and the more room a stack has before it flattens out.
Headroom int64 `json:"headroom"`
// FloorFraction sets the value a debuffed stat approaches, in parts per
// thousand of the stat's unmodified value. It is never reached either, so a
// stat can be crushed but never removed.
FloorFraction int64 `json:"floor_fraction"`
// MaxAffinityScale caps how far an elemental advantage can be scaled, in
// parts per thousand, in either direction.
//
// This one is a hard clamp rather than a saturation, unlike every stat.
// Saturating from zero would take a haircut off even a single term, because
// the limit here is the same order of magnitude as the terms themselves,
// whereas a stat's limit is far above its usual value.
MaxAffinityScale int64 `json:"max_affinity_scale"`
}
Bounds are the limits accumulated modifiers saturate towards.
func ParseBounds ¶
ParseBounds reads a bounds declaration. It never touches the filesystem.
type Mode ¶
type Mode uint8
Mode is how a modifier's amount is read.
type Modifier ¶
Modifier is one buff or debuff term. A negative amount is a debuff; there is no separate type for one, because every rule that bounds a buff has to bound a debuff by the same reasoning.
func (Modifier) MarshalJSON ¶
MarshalJSON writes the modifier by name.
func (*Modifier) UnmarshalJSON ¶
UnmarshalJSON reads a modifier written as {"target":..,"mode":..,"amount":..}.
⚠️ **A field this shape does not know is refused, not ignored**, and this is the level that has to do it. `DisallowUnknownFields` stops at a custom unmarshaller, so a status book that sets the flag never reaches inside a modifier: `{"target":"attack","mode":"add","amount":100,"amout":100}` parsed clean, the typo went nowhere, and the buff was silently the one number rather than two. That is the same defect the status book's own strict read was written for, one level down.
It is here rather than in any of the three readers because the type is shared: statuses, traits and skills all declare modifiers, so a check written in one of them would leave the other two open — and a rule declared three times is the mistake this repository keeps a list of.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is the accumulated modifiers on one unit. The zero value is an unmodified unit.
func (Set) Affinity ¶
Affinity scales an elemental multiplier.
The term multiplies how far the matchup already deviates from neutral, so it is worth more the worse the defender's matchup is: the same buff adds more against a stacked weakness than against a single one. Adding a flat amount instead would do the opposite, since a fixed bonus is a smaller share of a bigger multiplier.
It only moves a multiplier that is already an advantage. A term that lifted a neutral or resisted matchup would let a unit buff its way out of a bad matchup, which is the one thing the elemental chart exists to prevent, so the term rewards attacking into a weakness rather than papering over a resistance. A negative term can strip an advantage back to neutral but never past it, so a debuff cannot turn a strength into a weakness.
func (Set) Raw ¶
func (s Set) Raw(kind progression.Kind, base int64) int64
Raw returns what a stat would be with no saturation: flat terms first, then the summed percentage. It exists so a report can show what the saturation actually absorbed.
func (Set) Stat ¶
Stat resolves one stat. Flat terms apply first, then the summed percentage, and the whole change is then saturated towards the headroom limit above or the floor below, so the result approaches either limit without reaching it.
func (Set) Stats ¶
func (s Set) Stats(base progression.Values, ceilings progression.Values, bounds Bounds) progression.Values
Stats resolves every stat against the progression ceilings.
type Target ¶
type Target uint8
Target names what a modifier changes.
func ParseTarget ¶
ParseTarget resolves a target name as written in the data files.
func (Target) Stat ¶
func (t Target) Stat() progression.Kind
Stat returns the stat this target refers to. It is only meaningful when IsStat reports true.