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 ¶
- Variables
- func IntValue(n int64) opensysml.Value
- func ModelDigest(modelSource []byte) string
- func RandomSeed() uint64
- type Character
- type Choice
- type Foe
- type Game
- func (g *Game) Bool(attribute string) (bool, error)
- func (g *Game) Close() error
- func (g *Game) Eval(expr string) (opensysml.Value, error)
- func (g *Game) Feature(inst opensysml.InstanceID, attribute string) (opensysml.Value, error)
- func (g *Game) Instance(v opensysml.Value) (opensysml.InstanceID, bool)
- func (g *Game) Int(attribute string) (int64, error)
- func (g *Game) Invoke(action string, args map[string]opensysml.Value) (*Outcome, error)
- func (g *Game) Literal(attribute string) (string, error)
- func (g *Game) Location() string
- func (g *Game) Members(fqn string) ([]string, error)
- func (g *Game) Menu() (*Screen, error)
- func (g *Game) Play(key string, inputs map[string]string) (*Outcome, error)
- func (g *Game) Played(outcome *Outcome) (*View, error)
- func (g *Game) Returned() (*View, error)
- func (g *Game) Save() *Save
- func (g *Game) Send(signal string) (*Outcome, error)
- func (g *Game) SendWith(signal string, args map[string]opensysml.Value) (*Outcome, error)
- func (g *Game) SetPreference(attribute string, value opensysml.Value) error
- func (g *Game) Snapshot() (*Snapshot, error)
- func (g *Game) String(attribute string) (string, error)
- func (g *Game) View(lines ...string) (*View, error)
- func (g *Game) Welcome() (*View, error)
- type Move
- type Option
- type Outcome
- type Param
- type Save
- type Screen
- type Snapshot
- type View
Constants ¶
This section is empty.
Variables ¶
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") )
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 ModelDigest ¶
ModelDigest names a model's source, so a save tells which model it belongs to.
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 ¶
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 ¶
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) Eval ¶
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) Instance ¶
Instance reads a value that is an object of the session, such as a shop's weapon.
func (*Game) Invoke ¶
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 ¶
Literal reads an enumeration-typed attribute of the warrior as its literal's name.
func (*Game) Members ¶
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 ¶
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 ¶
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 ¶
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) Save ¶
Save records the game as played so far: what Resume needs to reach this state again.
func (*Game) Send ¶
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) SetPreference ¶
SetPreference writes one of the warrior's own attributes outside any deed.
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.
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 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 ¶
CharacterView is the screen shown while no warrior walks the realm.