lord

package
v0.0.0-...-de649ee Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 12 Imported by: ? 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 lord plays the Legend of the Red Dragon model, lord.sysml: a Game runs the model in a persistent session of the public API, the menu's keys become the model's signals and actions, and the screen is a projection of the warrior's feature values. No rule of the game lives here.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrModelInvalid is a model with analysis errors, which cannot be played.
	ErrModelInvalid = errors.New("the model has errors")
	// ErrNoSuchCommand is a signal or action the model does not declare.
	ErrNoSuchCommand = errors.New("no such command")
	// ErrNotHere is a signal no transition out of the current state accepts.
	ErrNotHere = errors.New("that is not a choice here")
	// ErrRefused is a signal the current state accepts whose guard does not hold.
	ErrRefused = errors.New("the game refuses that now")
	// ErrBadArgument is an argument the action's parameter does not take.
	ErrBadArgument = errors.New("bad argument")
)
View Source
var ErrStaleSave = errors.New("the saved game cannot be resumed")

ErrStaleSave is a saved game that cannot be resumed: another model's, or one with a move that no longer plays.

Functions

func IntValue

func IntValue(n int64) opensysml.Value

IntValue is an Integer argument for an action's parameter.

func ModelDigest

func ModelDigest(modelSource []byte) string

ModelDigest names a model's source, so a save tells which model it belongs to.

func RandomSeed

func RandomSeed() uint64

RandomSeed draws the dice a new game is played with.

Types

type Character

type Character struct {
	Name   string `json:"name"`
	Female bool   `json:"female"`
	// Class is a literal of Lord::CharacterClass: deathKnight, mysticalSkills or thievingSkills.
	Class string `json:"class"`
}

Character is what a player chooses before the first day: the warrior's name, sex and skill guild, written to the hero's declared attributes.

type Choice

type Choice struct {
	Key     string  `json:"key"`
	Label   string  `json:"label"`
	Signal  string  `json:"signal,omitempty"`
	Action  string  `json:"action,omitempty"`
	Params  []Param `json:"params,omitempty"`
	Enabled bool    `json:"enabled"`
}

Choice is one line of the menu the player is shown: a key, what it does, and whether the day machine would take it right now.

type Foe

type Foe struct {
	Present    bool   `json:"present"`
	Dragon     bool   `json:"dragon"`
	Name       string `json:"name"`
	Weapon     string `json:"weapon"`
	HitPoints  int64  `json:"hitPoints"`
	Strength   int64  `json:"strength"`
	Defense    int64  `json:"defense"`
	Gold       int64  `json:"gold"`
	Experience int64  `json:"experience"`
}

Foe is the monster before the warrior as the model holds it: none between fights.

type Game

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

Game is one warrior's run of the model: a session of its own on the public API, the hero instantiated in it, and the day state machine the hero exhibits.

func NewGame

func NewGame(modelSource []byte, seed uint64, character Character) (*Game, error)

NewGame parses the model source in a client of its own, opens a session on it, instantiates the hero and starts its day, with the schedule's dice seeded so two games differ. Close releases the game.

func Resume

func Resume(modelSource []byte, save *Save) (*Game, error)

Resume plays a saved game again: a new game with its seed and character, its moves replayed. Another model's save, or one whose move no longer plays, is ErrStaleSave.

func (*Game) Bool

func (g *Game) Bool(attribute string) (bool, error)

Bool reads a Boolean attribute of the warrior.

func (*Game) Close

func (g *Game) Close() error

Close releases the session and the client the game plays in.

func (*Game) Eval

func (g *Game) Eval(expr string) (opensysml.Value, error)

Eval evaluates a model expression in the hero's scope: a part of the town (`town.weapons.dagger`), a literal (`Stat::strength`) or an attribute.

func (*Game) Feature

func (g *Game) Feature(inst opensysml.InstanceID, attribute string) (opensysml.Value, error)

Feature reads an attribute of any object the session holds.

func (*Game) Instance

func (g *Game) Instance(v opensysml.Value) (opensysml.InstanceID, bool)

Instance reads a value that is an object of the session, such as a shop's weapon.

func (*Game) Int

func (g *Game) Int(attribute string) (int64, error)

Int reads an Integer attribute of the warrior.

func (*Game) Invoke

func (g *Game) Invoke(action string, args map[string]opensysml.Value) (*Outcome, error)

Invoke performs one of the warrior's actions directly with the given arguments, then lets the day machine take any completion transition it enables. The deed is refused when the model turns the warrior away at its opening decision.

func (*Game) Literal

func (g *Game) Literal(attribute string) (string, error)

Literal reads an enumeration-typed attribute of the warrior as its literal's name.

func (*Game) Location

func (g *Game) Location() string

Location is the state of the day machine the warrior is in.

func (*Game) Members

func (g *Game) Members(fqn string) ([]string, error)

Members lists the named members a definition or part of the Lord package declares, in declaration order: the shop's weapons, the enumeration's literals.

func (*Game) Menu

func (g *Game) Menu() (*Screen, error)

Menu is the screen for the state the day machine is in: the signals its transitions accept, each decided against the warrior as it stands, and the direct actions the menu offers there.

func (*Game) Play

func (g *Game) Play(key string, inputs map[string]string) (*Outcome, error)

Play takes the key the player pressed on the current screen with the inputs they gave, binds them as the model's values and runs the choice. A play that ran, refused or not, is recorded for Save; one the menu turned down is not.

func (*Game) Played

func (g *Game) Played(outcome *Outcome) (*View, error)

Played is the view after a turn: the outcome narrated, or when there is nothing to tell, where the warrior went, that the model refused, or that nothing came of it.

func (*Game) Returned

func (g *Game) Returned() (*View, error)

Returned is the first view of a warrior whose game was resumed.

func (*Game) Save

func (g *Game) Save() *Save

Save records the game as played so far: what Resume needs to reach this state again.

func (*Game) Send

func (g *Game) Send(signal string) (*Outcome, error)

Send offers the day machine a signal of the LordPlay package and, where the current state takes it and its guard holds, dispatches it and runs what follows.

func (*Game) SendWith

func (g *Game) SendWith(signal string, args map[string]opensysml.Value) (*Outcome, error)

SendWith sends a signal carrying the given attributes as its payload.

func (*Game) SetPreference

func (g *Game) SetPreference(attribute string, value opensysml.Value) error

SetPreference writes one of the warrior's own attributes outside any deed.

func (*Game) Snapshot

func (g *Game) Snapshot() (*Snapshot, error)

Snapshot reads the warrior's attributes from the model.

func (*Game) String

func (g *Game) String(attribute string) (string, error)

String reads a String attribute of the warrior.

func (*Game) View

func (g *Game) View(lines ...string) (*View, error)

View projects the game for the page, with the given lines as what just happened.

func (*Game) Welcome

func (g *Game) Welcome() (*View, error)

Welcome is the first view of a new warrior.

type Move

type Move struct {
	Key    string            `json:"key"`
	Inputs map[string]string `json:"inputs,omitempty"`
}

Move is one play: the key pressed and the inputs its choice asked for.

type Option

type Option struct {
	Value  string `json:"value"`
	Label  string `json:"label"`
	Detail string `json:"detail,omitempty"`
}

Option is one of a parameter's choices, named as the model names it.

type Outcome

type Outcome struct {
	From, To      string
	Before, After *Snapshot
	Choices       []opensysml.ChoicePoint
	// Refused is a deed the model turned down at its opening decision; one it
	// carried out that changed nothing is not refused.
	Refused bool
}

Outcome is what one command made of the model: where the day machine went, the warrior before and after, whether the model refused the deed, and the dice the run drew on the way.

func (*Outcome) Moved

func (o *Outcome) Moved() bool

Moved reports whether the day machine changed state.

func (*Outcome) Narrate

func (o *Outcome) Narrate(g *Game) []string

Narrate tells the outcome as the game's screens did: the foe met, each side's blow, the old man's dice or the bard's song, and every change to the warrior's standing.

type Param

type Param struct {
	Name    string   `json:"name"`
	Prompt  string   `json:"prompt"`
	Integer bool     `json:"integer,omitempty"`
	Options []Option `json:"options,omitempty"`
}

Param is an input an action's parameter takes: a whole number, or one of the options the model declares for it (a weapon of the shop, a literal of an enumeration).

type Save

type Save struct {
	Model string `json:"model"`
	// Seed travels as a string: a JSON number would lose it past 2^53.
	Seed      uint64    `json:"seed,string"`
	Character Character `json:"character"`
	Moves     []Move    `json:"moves"`
}

Save is a game as the record that replays it: the model it was played against, its dice, the character and every move since, in order.

type Screen

type Screen struct {
	Title   string   `json:"title"`
	Choices []Choice `json:"choices"`
}

Screen is the menu for one state: its title, and the choices in the order shown.

type Snapshot

type Snapshot struct {
	Name             string `json:"name"`
	Sex              string `json:"sex"`
	Class            string `json:"class"`
	Level            int64  `json:"level"`
	Experience       int64  `json:"experience"`
	HitPoints        int64  `json:"hitPoints"`
	MaxHitPoints     int64  `json:"maxHitPoints"`
	Strength         int64  `json:"strength"`
	Defense          int64  `json:"defense"`
	WeaponTier       int64  `json:"weaponTier"`
	Weapon           string `json:"weapon"`
	ArmourTier       int64  `json:"armourTier"`
	Armour           string `json:"armour"`
	Gold             int64  `json:"gold"`
	BankGold         int64  `json:"bankGold"`
	Gems             int64  `json:"gems"`
	Charm            int64  `json:"charm"`
	DeathKnightUses  int64  `json:"deathKnightUses"`
	MysticalUses     int64  `json:"mysticalUses"`
	ThievingUses     int64  `json:"thievingUses"`
	DeathKnightSkill int64  `json:"deathKnightPoints"`
	MysticalSkill    int64  `json:"mysticalPoints"`
	ThievingSkill    int64  `json:"thievingPoints"`
	ForestFightsLeft int64  `json:"forestFightsLeft"`
	PlayerFightsLeft int64  `json:"playerFightsLeft"`
	Day              int64  `json:"daysPlayed"`
	Alive            bool   `json:"alive"`
	DragonKills      int64  `json:"dragonKills"`
	PlayerKills      int64  `json:"playerKills"`
	Spouse           string `json:"spouse"`
	Children         int64  `json:"children"`
	Horse            bool   `json:"horse"`
	Fairy            bool   `json:"fairy"`
	InnRoom          bool   `json:"innRoom"`
	Bribed           bool   `json:"bribed"`
	TrainedToday     bool   `json:"trainedToday"`
	News             string `json:"news"`
	Foe              Foe    `json:"foe"`
}

Snapshot is the warrior's standing as the model holds it, read attribute by attribute from the hero instance; the screen renders it and outcomes diff it.

type View

type View struct {
	Character bool      `json:"character"`
	Location  string    `json:"location"`
	Warrior   *Snapshot `json:"warrior,omitempty"`
	Screen    *Screen   `json:"screen,omitempty"`
	Lines     []string  `json:"lines"`
	Refused   bool      `json:"refused,omitempty"`
}

View is what the page renders after every turn: the warrior as the model holds them, the screen the day machine is on, and what just happened.

func CharacterView

func CharacterView(lines ...string) *View

CharacterView is the screen shown while no warrior walks the realm.

Jump to

Keyboard shortcuts

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