gamefic-standard 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8449554314b654b07a264e2d7726bbedac25212a65cc0feba5aea75c32e120c4
4
- data.tar.gz: 2d1bedb7f9f780db43afc42994676e22625fc434bf46dfa16ccf7f6340217266
3
+ metadata.gz: 755a0c99a63ecce4d48bbbf7381e744c0b7bba4afe57d63c77a8d7febbeba51c
4
+ data.tar.gz: dcd68b55305fa872123273e76bec293bacf3b396608249291f483d3f01627bf9
5
5
  SHA512:
6
- metadata.gz: a2bba15cb8c073bc68182f773fcc6b5b6b658ff4556d8995588c6ee2950598494e941d3e260693103e1f17f903d84ba5ea29cac36f75e65de6bf7e3fb3201a0c
7
- data.tar.gz: e0c0999196d96e5a44f855fa76f3310b58acca624de2fc3d51bc95b8d74f1e6e6600c7b83f742ec79590e70aa5dbdfb92478deaa4d9dc3231092b5781963bd0e
6
+ metadata.gz: 19c17e7ae751826ef14a8533b406b2d9d978fbaad606949aebd2547f34a4a6ee7a901613e4d128694c784e8a8cf993b3c60d8cb6ba050de46a80e70455e0ff55
7
+ data.tar.gz: f10f11412b6128ec91057c060ef418fd54789cd9d616c24178b4e2c070f00cf5c4c478f56e49fe07eea029d29114c11df14566c1826d00bb962f7e581702cb13
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 2.2.0 - June 21, 2021
2
+ - Insert, place, and wear try take first
3
+ - Improved verb recognition
4
+ - Openable doors
5
+
1
6
  # 2.1.0 - March 7, 2021
2
7
  - Remove sticky attribute
3
8
  - Use set_player_class
@@ -9,3 +9,4 @@ require 'gamefic-standard/direction'
9
9
  require 'gamefic-standard/entities'
10
10
  require 'gamefic-standard/actions'
11
11
  require 'gamefic-standard/container'
12
+ require 'gamefic-standard/door'
@@ -24,27 +24,27 @@ Gamefic.script do
24
24
  actor.tell "Where do you want to go?"
25
25
  end
26
26
 
27
- xlate "north", "go north"
28
- xlate "south", "go south"
29
- xlate "west", "go west"
30
- xlate "east", "go east"
31
- xlate "up", "go up"
32
- xlate "down", "go down"
33
- xlate "northwest", "go northwest"
34
- xlate "northeast", "go northeast"
35
- xlate "southwest", "go southwest"
36
- xlate "southeast", "go southeast"
27
+ interpret "north", "go north"
28
+ interpret "south", "go south"
29
+ interpret "west", "go west"
30
+ interpret "east", "go east"
31
+ interpret "up", "go up"
32
+ interpret "down", "go down"
33
+ interpret "northwest", "go northwest"
34
+ interpret "northeast", "go northeast"
35
+ interpret "southwest", "go southwest"
36
+ interpret "southeast", "go southeast"
37
37
 
38
- xlate "n", "go north"
39
- xlate "s", "go south"
40
- xlate "w", "go west"
41
- xlate "e", "go east"
42
- xlate "u", "go up"
43
- xlate "d", "go down"
44
- xlate "nw", "go northwest"
45
- xlate "ne", "go northeast"
46
- xlate "sw", "go southwest"
47
- xlate "se", "go southeast"
38
+ interpret "n", "go north"
39
+ interpret "s", "go south"
40
+ interpret "w", "go west"
41
+ interpret "e", "go east"
42
+ interpret "u", "go up"
43
+ interpret "d", "go down"
44
+ interpret "nw", "go northwest"
45
+ interpret "ne", "go northeast"
46
+ interpret "sw", "go southwest"
47
+ interpret "se", "go southeast"
48
48
 
49
49
  interpret "go to :place", "go :place"
50
50
  end
@@ -1,20 +1,13 @@
1
- # script 'standard'
2
1
  Gamefic.script do
3
2
  respond :insert, Use.available, Use.available do |actor, thing, target|
4
3
  actor.tell "You can't put #{the thing} inside #{the target}."
5
4
  end
6
5
 
7
- respond :insert, Use.children, Use.available(Receptacle) do |actor, thing, receptacle|
8
- actor.tell "You put #{the thing} in #{the receptacle}."
9
- thing.parent = receptacle
10
- end
11
-
12
6
  respond :insert, Use.available, Use.available(Receptacle) do |actor, thing, receptacle|
13
- if thing.parent == actor
14
- actor.proceed
15
- else
16
- actor.tell "You don't have #{the thing}."
17
- end
7
+ actor.perform :take, thing unless thing.parent == actor
8
+ next unless thing.parent == actor
9
+ thing.parent = receptacle
10
+ actor.tell "You put #{the thing} in #{the receptacle}."
18
11
  end
19
12
 
20
13
  interpret "drop :item in :container", "insert :item :container"
@@ -1,7 +1,8 @@
1
1
  Gamefic.script do
2
2
  meta nil, Gamefic::Query::Text.new do |actor, string|
3
3
  words = string.split_words
4
- list = verbs
4
+ # @todo There should probably be an Active#verbs or Active#command_words method
5
+ list = actor.playbooks.flat_map(&:syntaxes).flat_map(&:first_word)
5
6
  if list.include?(words[0])
6
7
  if words.length > 1
7
8
  found = Gamefic::Query::Available.new.resolve(actor, words[1..-1].join(' ')).objects
@@ -3,14 +3,11 @@ Gamefic.script do
3
3
  actor.tell "You can't put #{the thing} on #{the supporter}."
4
4
  end
5
5
 
6
- respond :place, Use.visible, Use.reachable(Supporter) do |actor, thing, supporter|
7
- if thing.parent != actor
8
- actor.perform :take, thing
9
- end
10
- if thing.parent == actor
11
- thing.parent = supporter
12
- actor.tell "You put #{the thing} on #{the supporter}."
13
- end
6
+ respond :place, Use.available, Use.available(Supporter) do |actor, thing, supporter|
7
+ actor.perform :take, thing unless thing.parent == actor
8
+ next unless thing.parent == actor
9
+ thing.parent = supporter
10
+ actor.tell "You put #{the thing} on #{the supporter}."
14
11
  end
15
12
 
16
13
  respond :place, Use.children, Use.reachable(Supporter) do |actor, thing, supporter|
@@ -18,7 +15,7 @@ Gamefic.script do
18
15
  actor.tell "You put #{the thing} on #{the supporter}."
19
16
  end
20
17
 
21
- respond :place, Use.visible, Use.text do |actor, thing, supporter|
18
+ respond :place, Use.visible, Use.text do |actor, _thing, supporter|
22
19
  actor.tell "You don't see anything called \"#{supporter}\" here."
23
20
  end
24
21
 
@@ -30,10 +27,10 @@ Gamefic.script do
30
27
  actor.tell "I don't know what you mean by \"#{thing}\" or \"#{supporter}.\""
31
28
  end
32
29
 
33
- xlate "put :thing on :supporter", "place :thing :supporter"
34
- xlate "put :thing down on :supporter", "place :thing :supporter"
35
- xlate "set :thing on :supporter", "place :thing :supporter"
36
- xlate "set :thing down on :supporter", "place :thing :supporter"
37
- xlate "drop :thing on :supporter", "place :thing :supporter"
38
- xlate "place :thing on :supporter", "place :thing :supporter"
30
+ interpret "put :thing on :supporter", "place :thing :supporter"
31
+ interpret "put :thing down on :supporter", "place :thing :supporter"
32
+ interpret "set :thing on :supporter", "place :thing :supporter"
33
+ interpret "set :thing down on :supporter", "place :thing :supporter"
34
+ interpret "drop :thing on :supporter", "place :thing :supporter"
35
+ interpret "place :thing on :supporter", "place :thing :supporter"
39
36
  end
@@ -8,7 +8,7 @@ Gamefic.script do
8
8
  end
9
9
  end
10
10
 
11
- xlate "remove :clothing", "doff :clothing"
12
- xlate "take off :clothing", "doff :clothing"
13
- xlate "take :clothing off", "doff :clothing"
11
+ interpret "remove :clothing", "doff :clothing"
12
+ interpret "take off :clothing", "doff :clothing"
13
+ interpret "take :clothing off", "doff :clothing"
14
14
  end
@@ -1,8 +1,7 @@
1
1
  Gamefic.script do
2
2
  respond :wear, Use.available(Clothing) do |actor, clothing|
3
- if clothing.parent != actor
4
- actor.tell "You don't have #{the clothing}."
5
- end
3
+ actor.perform :take, clothing unless clothing.parent == actor
4
+ next unless clothing.parent == actor
6
5
  if clothing.attached?
7
6
  actor.tell "You're already wearing #{the clothing}."
8
7
  else
@@ -16,7 +15,7 @@ Gamefic.script do
16
15
  end
17
16
  end
18
17
 
19
- xlate "put on :clothing", "wear :clothing"
20
- xlate "put :clothing on", "wear :clothing"
21
- xlate "don :clothing", "wear :clothing"
18
+ interpret "put on :clothing", "wear :clothing"
19
+ interpret "put :clothing on", "wear :clothing"
20
+ interpret "don :clothing", "wear :clothing"
22
21
  end
@@ -1,53 +1,54 @@
1
1
  class Direction
2
2
  include Gamefic::Serialize
3
3
 
4
- attr_accessor :name, :adjective, :adverb, :reverse
4
+ attr_writer :adjective, :adverb, :reverse
5
5
 
6
- def initialize args = {}
6
+ # @return [String]
7
+ attr_accessor :name
8
+
9
+ def initialize **args
7
10
  args.each { |key, value|
8
11
  send "#{key}=", value
9
12
  }
10
- if !reverse.nil?
11
- reverse.reverse = self
12
- end
13
13
  end
14
14
 
15
+ # @return [String]
15
16
  def adjective
16
17
  @adjective || @name
17
18
  end
18
19
 
20
+ # @return [String]
19
21
  def adverb
20
22
  @adverb || @name
21
23
  end
22
24
 
23
- def reverse=(dir)
24
- @reverse = dir
25
- end
26
-
25
+ # @return [String]
27
26
  def synonyms
28
27
  "#{adjective} #{adverb}"
29
28
  end
30
29
 
30
+ def reverse
31
+ Direction.find @reverse
32
+ end
33
+
31
34
  def to_s
32
35
  @name
33
36
  end
34
37
 
35
38
  class << self
36
39
  def compass
37
- if @compass.nil?
38
- @compass = {}
39
- @compass[:north] = Direction.new(:name => 'north', :adjective => 'northern')
40
- @compass[:south] = Direction.new(:name => 'south', :adjective => 'southern', :reverse => @compass[:north])
41
- @compass[:west] = Direction.new(:name => 'west', :adjective => 'western')
42
- @compass[:east] = Direction.new(:name => 'east', :adjective => 'eastern', :reverse => @compass[:west])
43
- @compass[:northwest] = Direction.new(:name => 'northwest', :adjective => 'northwestern')
44
- @compass[:southeast] = Direction.new(:name => 'southeast', :adjective => 'southeastern', :reverse => @compass[:northwest])
45
- @compass[:northeast] = Direction.new(:name => 'northeast', :adjective => 'northeastern')
46
- @compass[:southwest] = Direction.new(:name => 'southwest', :adjective => 'southwestern', :reverse => @compass[:northeast])
47
- @compass[:up] = Direction.new(:name => 'up', :adjective => 'upwards')
48
- @compass[:down] = Direction.new(:name => 'down', :adjective => 'downwards', :reverse => @compass[:up])
49
- end
50
- @compass
40
+ @compass ||= {
41
+ north: Direction.new(name: 'north', adjective: 'northern', reverse: :south),
42
+ south: Direction.new(name: 'south', adjective: 'southern', reverse: :north),
43
+ west: Direction.new(name: 'west', adjective: 'western', reverse: :east),
44
+ east: Direction.new(name: 'east', adjective: 'eastern', reverse: :west),
45
+ northwest: Direction.new(name: 'northwest', adjective: 'northwestern', reverse: :southeast),
46
+ southeast: Direction.new(name: 'southeast', adjective: 'southeastern', reverse: :northwest),
47
+ northeast: Direction.new(name: 'northeast', adjective: 'northeastern', reverse: :southwest),
48
+ southwest: Direction.new(name: 'southwest', adjective: 'southwestern', reverse: :northeast),
49
+ up: Direction.new(name: 'up', adjective: 'upwards', reverse: :down),
50
+ down: Direction.new(name: 'down', adjective: 'downwards', reverse: :up)
51
+ }
51
52
  end
52
53
 
53
54
  # @param dir [Direction, string]
@@ -0,0 +1,49 @@
1
+ require 'gamefic-standard/openable'
2
+
3
+ # An openable portal.
4
+ #
5
+ class Door < Portal
6
+ include Openable
7
+ include Lockable
8
+
9
+ def post_initialize
10
+ update_reverse_open
11
+ end
12
+
13
+ def open= bool
14
+ super
15
+ update_reverse_open
16
+ end
17
+
18
+ def locked= bool
19
+ super
20
+ update_reverse_lock
21
+ end
22
+
23
+ def two_way_lock_key= key
24
+ lock_key = key
25
+ return if reverse.nil?
26
+ reverse.lock_key = key
27
+ end
28
+
29
+ private
30
+
31
+ def update_reverse_open
32
+ rev = find_reverse
33
+ return if rev.nil? || rev.open? == open?
34
+ rev.open = open?
35
+ end
36
+
37
+ def update_reverse_lock
38
+ rev = find_reverse
39
+ return if rev.nil? || rev.locked? == locked?
40
+ rev.locked = locked?
41
+ end
42
+ end
43
+
44
+ Gamefic.script do
45
+ respond :go, Use.available(Door) do |actor, door|
46
+ actor.perform :open, door unless door.open?
47
+ actor.proceed if door.open?
48
+ end
49
+ end
@@ -1,23 +1,23 @@
1
- # @gamefic.script standard/edible
2
-
3
- module Edibility
4
- attr_writer :edible
5
- def edible?
6
- @edible ||= false
7
- end
8
- end
9
-
10
- class Thing
11
- include Edibility
12
- end
13
-
14
- Gamefic.script do
15
- respond :eat, Use.available do |actor, item|
16
- actor.tell "You can't eat #{the item}."
17
- end
18
-
19
- respond :eat, Use.available(:edible?) do |actor, item|
20
- actor.tell "You eat #{the item}."
21
- destroy item
22
- end
23
- end
1
+ # @gamefic.script standard/edible
2
+
3
+ module Edibility
4
+ attr_writer :edible
5
+ def edible?
6
+ @edible ||= false
7
+ end
8
+ end
9
+
10
+ class Thing
11
+ include Edibility
12
+ end
13
+
14
+ Gamefic.script do
15
+ respond :eat, Use.available do |actor, item|
16
+ actor.tell "You can't eat #{the item}."
17
+ end
18
+
19
+ respond :eat, Use.available(:edible?) do |actor, item|
20
+ actor.tell "You eat #{the item}."
21
+ destroy item
22
+ end
23
+ end
@@ -15,12 +15,13 @@ class Portal < Thing
15
15
  # Find the portal in the destination that returns to this portal's parent
16
16
  #
17
17
  # @return [Room, nil]
18
- def find_reverse
18
+ def reverse
19
19
  return nil if destination.nil?
20
20
  destination.children.that_are(Portal).find do |portal|
21
21
  portal.destination == parent
22
22
  end
23
23
  end
24
+ alias find_reverse reverse
24
25
 
25
26
  def direction= dir
26
27
  @direction = Direction.find(dir)
@@ -1,14 +1,17 @@
1
1
  class Thing < Gamefic::Entity
2
2
  include Grammar::Attributes
3
3
 
4
+ # @return [Boolean]
4
5
  attr_writer :itemized
5
6
 
7
+ # @return [Boolean]
6
8
  attr_writer :portable
7
9
 
8
10
  # An optional description to use when itemizing entities in room
9
11
  # descriptions. The locale_description will be used instead of adding
10
12
  # the entity's name to a list.
11
13
  #
14
+ # @return [String, nil]
12
15
  attr_accessor :locale_description
13
16
 
14
17
  set_default itemized: true
@@ -25,9 +25,14 @@ module Lockable
25
25
  @locked ||= false
26
26
  end
27
27
 
28
- def has_lock_key?
28
+ def unlocked?
29
+ !locked?
30
+ end
31
+
32
+ def lock_key?
29
33
  !@lock_key.nil?
30
34
  end
35
+ alias has_lock_key? lock_key?
31
36
  end
32
37
 
33
38
  Gamefic.script do
@@ -46,4 +46,9 @@ Gamefic.script do
46
46
  actor.tell "#{The thing} is already open."
47
47
  end
48
48
  end
49
+
50
+ respond :look, Use.available(Thing, Openable) do |actor, thing|
51
+ actor.proceed
52
+ actor.tell "#{The thing} is #{thing.open? ? 'open' : 'closed'}."
53
+ end
49
54
  end
@@ -7,9 +7,10 @@
7
7
  class Pathfinder
8
8
  # @return [Room]
9
9
  attr_reader :origin
10
+
10
11
  # @return [Room]
11
12
  attr_reader :destination
12
-
13
+
13
14
  def initialize origin, destination
14
15
  @origin = origin
15
16
  @destination = destination
@@ -19,9 +20,7 @@ class Pathfinder
19
20
  if @origin == @destination
20
21
  @path = []
21
22
  else
22
- while @path.nil? and @paths.length > 0
23
- embark
24
- end
23
+ embark while @path.nil? && @paths.length > 0
25
24
  end
26
25
  end
27
26
 
@@ -34,7 +33,7 @@ class Pathfinder
34
33
 
35
34
  # @return [Boolean]
36
35
  def valid?
37
- path.length > 0 or origin == destination
36
+ path.length > 0 || origin == destination
38
37
  end
39
38
 
40
39
  private
@@ -1,5 +1,5 @@
1
1
  module Gamefic
2
2
  module Standard
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic-standard
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-07 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gamefic
@@ -138,6 +138,7 @@ files:
138
138
  - lib/gamefic-standard/clothing/entities/shoes.rb
139
139
  - lib/gamefic-standard/container.rb
140
140
  - lib/gamefic-standard/direction.rb
141
+ - lib/gamefic-standard/door.rb
141
142
  - lib/gamefic-standard/edible.rb
142
143
  - lib/gamefic-standard/entities.rb
143
144
  - lib/gamefic-standard/entities/character.rb
@@ -167,7 +168,7 @@ homepage: http://gamefic.com
167
168
  licenses:
168
169
  - MIT
169
170
  metadata: {}
170
- post_install_message:
171
+ post_install_message:
171
172
  rdoc_options: []
172
173
  require_paths:
173
174
  - lib
@@ -182,8 +183,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  - !ruby/object:Gem::Version
183
184
  version: '0'
184
185
  requirements: []
185
- rubygems_version: 3.1.2
186
- signing_key:
186
+ rubygems_version: 3.1.6
187
+ signing_key:
187
188
  specification_version: 4
188
189
  summary: The Gamefic standard script library.
189
190
  test_files: []