modifier

package
v0.0.0-...-7afa4bb Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Penalty = iota
	Bonus
	Multiplier
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Modifier

type Modifier struct {
	// contains filtered or unexported fields
}

Modifier represents a modifier, i.e. to a die.Roll.

func New

func New(operator, operand int) (*Modifier, error)

New takes as input an operator and an operand. The operator can be one of modifier.Penalty, modifier.Bonus, or modifier.Multiplier. The operand can take any integer value. It returns a pointer to a modifier.Modifier or an error.

func Parse

func Parse(literal string) (*Modifier, error)

Parse takes as input a string representing a modifier, e.g., "+1", "-1" or "×3". The structure of the input must exactly match the regular expression, `^\s*([\+\-–\*×])?(\d+)\s*$. Assuming the input string can be successfully parsed, a pointer to a modifier.Modifier will be returned. Otherwise, an error will be returned.

func (*Modifier) Eval

func (m *Modifier) Eval(score int) int

Eval evaluates the modifier against the caller-supplied score, returning the new score.

func (*Modifier) Operand

func (m *Modifier) Operand() int

Operand returns a copy of the value of the modifier's operand.

func (*Modifier) Operator

func (m *Modifier) Operator() int

Operator returns a copy of the numeric ID of the modifier's operator.

func (*Modifier) String

func (m *Modifier) String() string

String returns a human-readable representation of the Modifier, e.g., "+0", "–1" or "×3". Note that the Unicode 'MINUS SIGN' U+2212 and 'MULTIPLICATION SIGN' U+00D7 will be substituted for modifier.Penalty ('-') and modifier.Multiplier ('*'), respectively.

Jump to

Keyboard shortcuts

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