cmd

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2019 License: BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(t has.Thing, input string) string

Parse initiates processing of the input string for the specified Thing. The input string is expected to be input from a player. The actual command processed will be returned. For example GET or DROP.

Parse runs with state.scripting set to false, disallowing scripting specific commands from being executed by players directly.

When sync handles a command the command may determine it needs to hold additional locks. In this case sync will return false and should be called again. This repeats until the list of locks is complete, the command processed and sync returns true.

func Script added in v0.0.4

func Script(t has.Thing, input string) string

Script processes the input string the same as Parse. However Script runs with the state.scripting flag set to true, permitting scripting specific commands to be executed.

Types

type Result added in v0.0.13

type Result struct {
	has.Thing
	Unknown   string
	NotEnough string
}

Result is the result of a Match. If the match is successful then Thing will be the matched Thing and Unknown and NotEnough will both be empty strings. If the match fails Thing will be nil. If the match fails due to unknown words then Unknown will be set to the unknown words. If the match fails because there are not enough matching Thing to satisfy a limit then NotEnough will be set to the words matched.

func Match added in v0.0.13

func Match(words []string, things ...[]has.Thing) ([]Result, []string)

Match takes a list of alias and qualifier words, and lists of Things and returns a subset of the Things that match the aliases and qualifiers as a list of Results. See the Result type for details. Match will also return any unprocessed words. The word list may contain special limit qualifiers such as ALL, 3, 2nd or 2-4. See the specialQualifier function for details.

For example, given the words: {"ALL", "SMALL", "BALL", "ALL", "GREEN", "BALL"}

Match processes the words in reverse order. In this case starting with the last word 'BALL'.

Match will try to identify Things in the list with an alias of 'BALL'.

If there are no matches a Result of 'unknown' will be returned.

If there are matches then the word 'BALL' will be consumed. The matches will then be reduced to those Things with a qualifier of 'GREEN' - which is now the last word in the list.

If the matches cannot be reduced the original matches will be used. If the matches are reduced the qualifier 'GREEN' will be consumed.

The matches will then be reduced by limits. The default limit is the first match. This may be changed by using a special qualifier such as ALL, 3, 2nd, etc. In this example we have 'ALL' so all of the current matches will be returned. If there are not enough remaining matches to satisfy the limits requested a result of 'not enough' will be returned. If a special qualifier is found it will be consumed and removed from the word list.

Assuming we have at least one Thing that matches our example the words 'BALL', 'GREEN' and 'ALL' will have been consumed. The remaing, unprocessed words in the word list will be returned.

The reaming words can then be used to a subsequent call to Match for further matching. See also MatchAll.

func MatchAll added in v0.0.13

func MatchAll(words []string, things ...[]has.Thing) (matches []Result)

MatchAll repeatedly calls Match until all of the words are consumed. The returned Results will only contain unique Things.

Notes

Bugs

  • Terminal with is hardcoded to be 80 characters wide

  • If you examine another player you can see their inventory items. For now we only describe the inventory if not examining a player.

  • It should be possible to put a GET Veto on a player. However due to the way GET applies Vetoes we can't yet.

  • If a container is not collectable then it and its content will not be saved - even if it contains collectable items.

  • We don't treat observer differently to observers - should we?

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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