modifier

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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)
)
View Source
const PercentBase = scale.Base

PercentBase is the denominator percentage terms are expressed against.

View Source
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

func ParseBounds(raw []byte) (Bounds, error)

ParseBounds reads a bounds declaration. It never touches the filesystem.

func (Bounds) Validate

func (b Bounds) Validate() error

Validate checks the bounds themselves are coherent.

type Mode

type Mode uint8

Mode is how a modifier's amount is read.

const (
	// Flat adds the amount to the value directly.
	Flat Mode = iota
	// Percent adds the amount, in parts per thousand, to the value's scale.
	// An amount of 300 is a thirty percent increase, -300 a thirty percent cut.
	Percent
)

func ParseMode

func ParseMode(name string) (Mode, error)

ParseMode resolves a mode name as written in the data files.

func (Mode) String

func (m Mode) String() string

type Modifier

type Modifier struct {
	Target Target
	Mode   Mode
	Amount int64
}

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

func (m Modifier) MarshalJSON() ([]byte, error)

MarshalJSON writes the modifier by name.

func (Modifier) String

func (m Modifier) String() string

func (*Modifier) UnmarshalJSON

func (m *Modifier) UnmarshalJSON(raw []byte) error

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.

func (Modifier) Validate

func (m Modifier) Validate() error

Validate rejects a term that cannot be applied.

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) Add

func (s *Set) Add(m Modifier) error

Add accumulates one term. Terms of the same target and mode sum.

func (*Set) AddAll

func (s *Set) AddAll(modifiers ...Modifier) error

AddAll accumulates several terms, stopping at the first invalid one.

func (Set) Affinity

func (s Set) Affinity(multiplier, neutral int, bounds Bounds) int

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) Flat

func (s Set) Flat(target Target) int64

Flat returns the summed flat term for a target.

func (Set) Percent

func (s Set) Percent(target Target) int64

Percent returns the summed percentage term for a target, before clamping.

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

func (s Set) Stat(kind progression.Kind, base int64, ceiling int64, bounds Bounds) int64

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

func ParseTarget(name string) (Target, error)

ParseTarget resolves a target name as written in the data files.

func Targets

func Targets() []Target

Targets returns every target in declaration order.

func (Target) IsStat

func (t Target) IsStat() bool

IsStat reports whether the target is one of the four stats.

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.

func (Target) String

func (t Target) String() string

func (Target) Valid

func (t Target) Valid() bool

Valid reports whether the value is a declared target.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL