Module: Gamefic::Plot::CommandMount

Defined in:
lib/gamefic/plot/command_mount.rb

Instance Method Summary collapse

Instance Method Details

#action(command, *queries, &proc) ⇒ Object

Deprecated.


52
53
54
# File 'lib/gamefic/plot/command_mount.rb', line 52

def action(command, *queries, &proc)
  respond command, *queries, &proc
end

#actionsArray<Action>

Get an Array of all Actions defined in the Plot.

Returns:



116
117
118
# File 'lib/gamefic/plot/command_mount.rb', line 116

def actions
  playbook.actions
end

#disambiguate {|, | ... } ⇒ Object

Declare a dismabiguation response for actions. The disambigurator is executed when an action expects an argument to reference a specific entity but its query matched more than one. For example, “red” might refer to either a red key or a red book.

If a disambiguator is not defined, the playbook will use its default implementation.

Examples:

Tell the player the list of ambiguous entities.

disambiguate do |actor, entities|
  actor.tell "I don't know which you mean: #{entities.join_or}."
end

Yield Parameters:



71
72
73
# File 'lib/gamefic/plot/command_mount.rb', line 71

def disambiguate &block
  playbook.disambiguate &block
end

#interpret(command, translation) ⇒ Syntax

Create an alternate Syntax for an Action. The command and its translation can be parameterized.

Examples:

Create a synonym for the Inventory Action.

interpret "catalogue", "inventory"
# The command "catalogue" will be translated to "inventory"

Create a parameterized synonym for the Look Action.

interpret "scrutinize :entity", "look :entity"
# The command "scrutinize chair" will be translated to "look chair"

Parameters:

  • command (String)

    The format of the original command

  • translation (String)

    The format of the translated command

Returns:

  • (Syntax)

    the Syntax object



96
97
98
# File 'lib/gamefic/plot/command_mount.rb', line 96

def interpret command, translation
  playbook.interpret command, translation
end

#meta(command, *queries) {|| ... } ⇒ Object

Create a Meta Action that responds to a command. Meta Actions are very similar to standard Actions, except the Plot understands them to be commands that operate above and/or outside of the actual game world. Examples of Meta Actions are commands that report the player’s current score, save and restore saved games, or list the game’s credits.

Examples:

A simple Meta Action

meta :credits do |actor|
  actor.tell "This game was written by John Smith."
end

Parameters:

  • command (Symbol)

    An imperative verb for the command

  • *queries (Array<Query::Base>)

    Queries to filter the command’s tokens

Yield Parameters:



47
48
49
# File 'lib/gamefic/plot/command_mount.rb', line 47

def meta(command, *queries, &proc)
  playbook.meta command, *queries, &proc
end

#respond(command, *queries) {|| ... } ⇒ Object

Create an Action that responds to a command. An Action uses the command argument to identify the imperative verb that triggers the action. It can also accept queries to tokenize the remainder of the input and filter for particular entities or properties. The block argument contains the code to be executed when the input matches all of the Action’s criteria (i.e., verb and queries).

Examples:

A simple Action.

respond :salute do |actor|
  actor.tell "Hello, sir!"
end
# The command "salute" will respond "Hello, sir!"

An Action that accepts a Character

respond :salute, Use.visible(Character) do |actor, character|
  actor.tell "#{The character} returns your salute."
end

Parameters:

  • command (Symbol)

    An imperative verb for the command

  • *queries (Array<Query::Base>)

    Queries to filter the command’s tokens

Yield Parameters:



28
29
30
# File 'lib/gamefic/plot/command_mount.rb', line 28

def respond(command, *queries, &proc)
  playbook.respond(command, *queries, &proc)
end

#validate {|| ... } ⇒ Object

Validate an order before a character can execute its command.

Yield Parameters:



78
79
80
# File 'lib/gamefic/plot/command_mount.rb', line 78

def validate &block
  playbook.validate &block
end

#verbs(to_s: false) ⇒ Array<Symbol|String>

Get an Array of available verbs. If the to_s parameter is true, convert Symbols to Strings.

Returns:



109
110
111
# File 'lib/gamefic/plot/command_mount.rb', line 109

def verbs to_s: false
  to_s ? playbook.verbs.map { |v| v.to_s } : playbook.verbs
end

#xlate(command, translation) ⇒ Object

Deprecated.


101
102
103
# File 'lib/gamefic/plot/command_mount.rb', line 101

def xlate command, translation
  interpret command, translation
end