gamefic 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gamefic/action.rb +7 -6
- data/lib/gamefic/before.rb +12 -0
- data/lib/gamefic/character.rb +1 -1
- data/lib/gamefic/core_ext/array.rb +4 -0
- data/lib/gamefic/core_ext/string.rb +0 -31
- data/lib/gamefic/describable.rb +68 -8
- data/lib/gamefic/director.rb +108 -75
- data/lib/gamefic/engine.rb +74 -10
- data/lib/gamefic/entity.rb +3 -3
- data/lib/gamefic/import/basics/actions/close.rb +16 -0
- data/lib/gamefic/import/basics/actions/commands.rb +3 -0
- data/lib/gamefic/import/basics/actions/drop-in.rb +17 -0
- data/lib/gamefic/import/basics/actions/drop-on.rb +16 -0
- data/lib/gamefic/import/basics/actions/drop.rb +30 -0
- data/lib/gamefic/import/basics/actions/enter.rb +16 -0
- data/lib/gamefic/import/basics/actions/{traversal.rb → go.rb} +35 -35
- data/lib/gamefic/import/basics/actions/inventory.rb +8 -49
- data/lib/gamefic/import/basics/actions/leave.rb +29 -0
- data/lib/gamefic/import/basics/actions/look-in-at.rb +27 -0
- data/lib/gamefic/import/basics/actions/look-under.rb +3 -0
- data/lib/gamefic/import/basics/actions/look.rb +71 -67
- data/lib/gamefic/import/basics/actions/nil.rb +25 -0
- data/lib/gamefic/import/basics/actions/open.rb +23 -0
- data/lib/gamefic/import/basics/actions/quit.rb +3 -0
- data/lib/gamefic/import/basics/actions/take.rb +107 -0
- data/lib/gamefic/import/basics/entities/container.rb +8 -24
- data/lib/gamefic/import/basics/entities/entity.rb +11 -0
- data/lib/gamefic/import/basics/entities/fixture.rb +5 -5
- data/lib/gamefic/import/basics/entities/item.rb +5 -7
- data/lib/gamefic/import/basics/entities/portal.rb +40 -43
- data/lib/gamefic/import/basics/entities/room.rb +30 -24
- data/lib/gamefic/import/basics/entities/scenery.rb +5 -3
- data/lib/gamefic/import/basics/entities/supporter.rb +6 -0
- data/lib/gamefic/import/basics/entities/thing.rb +16 -0
- data/lib/gamefic/import/basics/queries/reachable.rb +38 -0
- data/lib/gamefic/import/basics/queries/room.rb +8 -0
- data/lib/gamefic/import/basics/queries/visible.rb +32 -0
- data/lib/gamefic/import/basics/rules/has-enough-light.rb +14 -0
- data/lib/gamefic/import/{basics → basics.old}/actions/container.rb +13 -12
- data/lib/gamefic/import/basics.old/actions/inventory.rb +50 -0
- data/lib/gamefic/import/basics.old/actions/look.rb +53 -0
- data/lib/gamefic/import/basics.old/actions/meta.rb +6 -0
- data/lib/gamefic/import/basics.old/actions/traversal.rb +35 -0
- data/lib/gamefic/import/{basics → basics.old}/actions.rb +0 -0
- data/lib/gamefic/import/basics.old/entities/container.rb +3 -0
- data/lib/gamefic/import/basics.old/entities/fixture.rb +3 -0
- data/lib/gamefic/import/basics.old/entities/item.rb +3 -0
- data/lib/gamefic/import/basics.old/entities/portal.rb +43 -0
- data/lib/gamefic/import/basics.old/entities/room.rb +27 -0
- data/lib/gamefic/import/basics.old/entities/scenery.rb +3 -0
- data/lib/gamefic/import/basics.old/entities/supporter.rb +3 -0
- data/lib/gamefic/import/{basics → basics.old}/entities.rb +0 -0
- data/lib/gamefic/import/basics.old/room_modes.rb +48 -0
- data/lib/gamefic/import/basics.rb +6 -2
- data/lib/gamefic/import/{basics/room_modes.rb → room_modes.rb} +6 -6
- data/lib/gamefic/import/standard.rb +1 -0
- data/lib/gamefic/meta.rb +12 -0
- data/lib/gamefic/optionset.rb +114 -0
- data/lib/gamefic/plot.rb +54 -21
- data/lib/gamefic/query.rb +214 -188
- data/lib/gamefic/requirement.rb +14 -0
- data/lib/gamefic/shell.rb +7 -4
- data/lib/gamefic/syntax.rb +35 -18
- data/lib/gamefic/thing.rb +7 -0
- data/lib/gamefic.rb +5 -1
- metadata +46 -12
- data/lib/gamefic/import/basics/actions/meta.rb +0 -6
- data/lib/gamefic/import/basics/entities/itemized.rb +0 -3
- data/lib/gamefic/import/basics/entities/portable.rb +0 -3
- data/lib/gamefic/user.rb +0 -66
@@ -1,43 +1,40 @@
|
|
1
|
-
class Portal < Entity
|
2
|
-
attr_accessor :destination
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
1
|
+
class Portal < Entity
|
2
|
+
attr_accessor :destination
|
3
|
+
def find_reverse
|
4
|
+
rev = Portal.reverse(self.name)
|
5
|
+
if rev != nil
|
6
|
+
destination.children.that_are(Portal).each { |c|
|
7
|
+
if c.name == rev
|
8
|
+
return c
|
9
|
+
end
|
10
|
+
}
|
11
|
+
end
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
def self.reverse(direction)
|
15
|
+
case direction.downcase
|
16
|
+
when "north"
|
17
|
+
"south"
|
18
|
+
when "south"
|
19
|
+
"north"
|
20
|
+
when "west"
|
21
|
+
"east"
|
22
|
+
when "east"
|
23
|
+
"west"
|
24
|
+
when "northwest"
|
25
|
+
"southeast"
|
26
|
+
when "southeast"
|
27
|
+
"northwest"
|
28
|
+
when "northeast"
|
29
|
+
"southwest"
|
30
|
+
when "southwest"
|
31
|
+
"northeast"
|
32
|
+
when "up"
|
33
|
+
"down"
|
34
|
+
when "down"
|
35
|
+
"up"
|
36
|
+
else
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,24 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
reverse
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
:
|
13
|
-
:
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
portal
|
18
|
-
end
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
class Room < Entity
|
2
|
+
def connect(destination, direction, type = Portal, two_way = true)
|
3
|
+
portal = type.new self.plot, :name => direction, :parent => self, :destination => destination
|
4
|
+
portal.proper_named = true
|
5
|
+
if two_way == true
|
6
|
+
reverse = Portal.reverse(direction)
|
7
|
+
if reverse == nil
|
8
|
+
raise "\"#{direction.cap_first}\" does not have an opposite direction"
|
9
|
+
end
|
10
|
+
portal2 = type.new(self.plot, {
|
11
|
+
:name => reverse,
|
12
|
+
:parent => destination,
|
13
|
+
:destination => self
|
14
|
+
})
|
15
|
+
portal2.proper_named = true
|
16
|
+
end
|
17
|
+
portal
|
18
|
+
end
|
19
|
+
def synonyms
|
20
|
+
super.to_s + " around here room"
|
21
|
+
end
|
22
|
+
def tell(message, refresh = false)
|
23
|
+
children.each { |c|
|
24
|
+
c.tell message, refresh
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
options(Room, :lighted, :dark).default = :lighted
|
30
|
+
options(Room, :enterable, :not_enterable)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
options(Thing, :located, :contained, :supported, :attached).default = :located
|
2
|
+
options(Thing, :itemized, :not_itemized)
|
3
|
+
set_default_for(Thing, :portable)
|
4
|
+
|
5
|
+
class Thing
|
6
|
+
def parent=(entity)
|
7
|
+
super
|
8
|
+
if parent.kind_of?(Supporter)
|
9
|
+
is :supported
|
10
|
+
elsif parent.kind_of?(Container)
|
11
|
+
is :contained
|
12
|
+
else
|
13
|
+
is :located
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# This query filters for objects that the player might be able to handle or
|
2
|
+
# manipulate, including the following:
|
3
|
+
#
|
4
|
+
# * Siblings (other entities with the same parent)
|
5
|
+
# * The subject's children
|
6
|
+
# * Entities on reachable supporters
|
7
|
+
# * Entities in reachable open containers
|
8
|
+
# * Entities attached to reachable entities
|
9
|
+
#
|
10
|
+
# It excludes anything that may be visible but are not reachable:
|
11
|
+
# * Entities inside closed transparent containers
|
12
|
+
# * Entities that share the same room as the subject, but not the same parent.
|
13
|
+
|
14
|
+
class Query::Reachable < Query::Family
|
15
|
+
def context_from(subject)
|
16
|
+
array = super
|
17
|
+
if subject.is?(:supported) or subject.is?(:contained)
|
18
|
+
array.push subject.parent
|
19
|
+
end
|
20
|
+
array.each { |thing|
|
21
|
+
if thing.kind_of?(Container)
|
22
|
+
if thing.is? :open
|
23
|
+
array += thing.children.that_are(:contained)
|
24
|
+
end
|
25
|
+
elsif thing.kind_of?(Supporter)
|
26
|
+
array += thing.children.that_are(:supported)
|
27
|
+
end
|
28
|
+
thing.children.that_are(:attached).each { |att|
|
29
|
+
array.push att
|
30
|
+
if att.kind_of?(Supporter) or att.is?(:open)
|
31
|
+
array += att.children.that_are(:contained)
|
32
|
+
array += att.children.that_are(:supported)
|
33
|
+
end
|
34
|
+
}
|
35
|
+
}
|
36
|
+
array.uniq
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This query filters for objects that the player can see, regardless of
|
2
|
+
# whether they are reachable. It includes the following:
|
3
|
+
#
|
4
|
+
# * Siblings (other entities with the same parent)
|
5
|
+
# * The subject's children
|
6
|
+
# * Children of the subject's room (if room is not parent)
|
7
|
+
# * Entities on reachable supporters
|
8
|
+
# * Entities inside reachable open containers
|
9
|
+
# * Entities inside reachable transparent containers
|
10
|
+
# * Entities attached to reachable entities
|
11
|
+
|
12
|
+
class Query::Visible < Query::Family
|
13
|
+
def base_specificity
|
14
|
+
40
|
15
|
+
end
|
16
|
+
def context_from(subject)
|
17
|
+
array = super
|
18
|
+
array += subject.room.children
|
19
|
+
array.uniq!
|
20
|
+
array.each { |thing|
|
21
|
+
if thing.kind_of?(Container)
|
22
|
+
if thing.is? :open or thing.is? :transparent
|
23
|
+
array += thing.children.that_are(:contained)
|
24
|
+
end
|
25
|
+
elsif thing.kind_of?(Supporter)
|
26
|
+
array += thing.children.that_are(:supported)
|
27
|
+
end
|
28
|
+
array += thing.children.that_are(:attached)
|
29
|
+
}
|
30
|
+
array
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
assert :has_enough_light do |actor|
|
2
|
+
if actor.room.is? :lighted
|
3
|
+
true
|
4
|
+
else
|
5
|
+
actor.tell "It's too dark in here."
|
6
|
+
false
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Allow the go command in dark rooms
|
11
|
+
before :go, Query::Siblings.new(Portal) do |actor, portal|
|
12
|
+
pass :has_enough_light
|
13
|
+
passthru
|
14
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
respond :look, Query.new(
|
1
|
+
respond :look, Query::Family.new(Container) do |actor, thing|
|
2
2
|
passthru
|
3
3
|
if thing.closeable?
|
4
4
|
actor.tell "#{thing.longname.specify.cap_first} is #{thing.closed? ? 'closed' : 'open'}."
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
respond :look_inside, Query.new(
|
8
|
+
respond :look_inside, Query::Family.new(Container) do |actor, container|
|
9
9
|
if container.closed?
|
10
10
|
actor.tell "#{container.longname.cap_first.specify} is closed."
|
11
11
|
else
|
@@ -24,7 +24,7 @@ xlate "look inside :container", :look_inside, :container
|
|
24
24
|
xlate "search :container", :look_inside, :container
|
25
25
|
xlate "look in :container", :look_inside, :container
|
26
26
|
|
27
|
-
respond :look_in_at, Query.new(
|
27
|
+
respond :look_in_at, Query::Family.new(Container), Query::Subquery.new(Entity) do |actor, container, item|
|
28
28
|
if container.closed?
|
29
29
|
actor.tell "#{container.longname.cap_first.specify} is closed."
|
30
30
|
else
|
@@ -32,7 +32,7 @@ respond :look_in_at, Query.new(:family, Container), Subquery.new(:children, Enti
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
respond :look_in_at, Query.new(
|
35
|
+
respond :look_in_at, Query::Family.new(Container), Query::Text.new() do |actor, container, item|
|
36
36
|
if container.closed?
|
37
37
|
actor.tell "#{container.longname.cap_first.specify} is closed."
|
38
38
|
else
|
@@ -43,7 +43,8 @@ end
|
|
43
43
|
xlate "look at :item in :container", :look_in_at, :container, :item
|
44
44
|
xlate "look :item in :container", :look_in_at, :container, :item
|
45
45
|
|
46
|
-
respond :take_from, Query.new(
|
46
|
+
respond :take_from, Query::Family.new(Container), Query::Subquery.new(Thing) do |actor, container, item|
|
47
|
+
# TODO: Make sure thing is portable
|
47
48
|
if container.closed?
|
48
49
|
actor.tell "#{container.longname.cap_first.specify} is closed."
|
49
50
|
else
|
@@ -55,7 +56,7 @@ xlate "take :item from :container", :take_from, :container, :item
|
|
55
56
|
xlate "get :item from :container", :take_from, :container, :item
|
56
57
|
xlate "remove :item from :container", :take_from, :container, :item
|
57
58
|
|
58
|
-
respond :drop_in, Query.new(
|
59
|
+
respond :drop_in, Query::Family.new(Container), Query::Children.new() do |actor, container, item|
|
59
60
|
if container.closed?
|
60
61
|
actor.tell "#{container.longname.cap_first.specify} is closed."
|
61
62
|
else
|
@@ -67,15 +68,15 @@ xlate "drop :item in :container", :drop_in, :container, :item
|
|
67
68
|
xlate "put :item in :container", :drop_in, :container, :item
|
68
69
|
xlate "place :item in :container", :drop_in, :container, :item
|
69
70
|
|
70
|
-
respond :open, Query.new(
|
71
|
+
respond :open, Query::Text.new() do |actor, string|
|
71
72
|
actor.tell "You don't see any \"#{string}\" here."
|
72
73
|
end
|
73
74
|
|
74
|
-
respond :open, Query.new(
|
75
|
+
respond :open, Query::Family.new(Entity) do |actor, thing|
|
75
76
|
actor.tell "You can't open #{thing.longname.specify}."
|
76
77
|
end
|
77
78
|
|
78
|
-
respond :open, Query.new(
|
79
|
+
respond :open, Query::Family.new(Container) do |actor, container|
|
79
80
|
if container.closeable?
|
80
81
|
if container.closed?
|
81
82
|
actor.tell "You open #{container.longname.specify}."
|
@@ -89,15 +90,15 @@ respond :open, Query.new(:family, Container) do |actor, container|
|
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
92
|
-
respond :close, Query.new(
|
93
|
+
respond :close, Query::Text.new() do |actor, string|
|
93
94
|
actor.tell "You don't see any \"#{string}\" here."
|
94
95
|
end
|
95
96
|
|
96
|
-
respond :close, Query.new(
|
97
|
+
respond :close, Query::Family.new(Entity) do |actor, thing|
|
97
98
|
actor.tell "You can't close #{thing.longname.specify}."
|
98
99
|
end
|
99
100
|
|
100
|
-
respond :close, Query.new(
|
101
|
+
respond :close, Query::Family.new(Container) do |actor, container|
|
101
102
|
if container.closeable?
|
102
103
|
if container.closed?
|
103
104
|
actor.tell "It's already closed."
|
@@ -0,0 +1,50 @@
|
|
1
|
+
respond :inventory do |actor|
|
2
|
+
if actor.children.length > 0
|
3
|
+
actor.tell actor.children.join(', ')
|
4
|
+
else
|
5
|
+
actor.tell "You aren't carrying anything."
|
6
|
+
end
|
7
|
+
end
|
8
|
+
xlate "i", :inventory
|
9
|
+
|
10
|
+
respond :take, Query::Siblings.new(Thing) do |actor, thing|
|
11
|
+
# TODO: Make sure the thing is portable or whatever
|
12
|
+
thing.parent = actor
|
13
|
+
actor.tell "You take #{the thing}.", true
|
14
|
+
end
|
15
|
+
|
16
|
+
respond :take, Query::Siblings.new() do |actor, thing|
|
17
|
+
actor.tell "You can't carry #{the thing}."
|
18
|
+
end
|
19
|
+
|
20
|
+
respond :take, Query::Text.new() do |actor, thing|
|
21
|
+
containers = actor.children.that_are(Container)
|
22
|
+
containers = containers + actor.parent.children.that_are(Container)
|
23
|
+
found = false
|
24
|
+
containers.each { |container|
|
25
|
+
if container.closed? == false
|
26
|
+
query = Query::Children.new(Portable)
|
27
|
+
result = query.execute(container, thing)
|
28
|
+
if result.objects.length == 1
|
29
|
+
found = true
|
30
|
+
actor.perform "take #{result.objects[0].name} from #{container.name}"
|
31
|
+
break
|
32
|
+
end
|
33
|
+
end
|
34
|
+
}
|
35
|
+
if found == false
|
36
|
+
actor.tell "You don't see any \"#{thing}\" here."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
respond :drop, Query::Children.new() do |actor, thing|
|
41
|
+
thing.parent = actor.parent
|
42
|
+
actor.tell "You drop #{the thing}.", true
|
43
|
+
end
|
44
|
+
|
45
|
+
xlate "get :thing", :take, :thing
|
46
|
+
xlate "pick :thing up", :take, :thing
|
47
|
+
xlate "pick up :thing", :take, :thing
|
48
|
+
|
49
|
+
xlate "put down :thing", :drop, :thing
|
50
|
+
xlate "put :thing down", :drop, :thing
|
@@ -0,0 +1,53 @@
|
|
1
|
+
OptionSet.new(Thing, :itemized)
|
2
|
+
|
3
|
+
respond :look, Query::Parent.new() do |actor, room|
|
4
|
+
actor.tell actor.parent.name.cap_first
|
5
|
+
actor.tell actor.parent.description
|
6
|
+
chars = actor.parent.children.that_are(Character) - [actor]
|
7
|
+
if chars.length > 0
|
8
|
+
actor.tell "Others here: #{chars.join(", ")}"
|
9
|
+
end
|
10
|
+
items = actor.parent.children.that_are(:itemized) - [actor]
|
11
|
+
if items.length > 0
|
12
|
+
actor.tell "Visible items: #{items.join(", ")}"
|
13
|
+
end
|
14
|
+
portals = actor.parent.children.that_are(Portal)
|
15
|
+
if portals.length > 0
|
16
|
+
actor.tell "Obvious exits: #{portals.join(', ')}"
|
17
|
+
else
|
18
|
+
actor.tell "Obvious exits: none"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
xlate "look", :look, "around"
|
22
|
+
|
23
|
+
respond :look, Query::Family.new() do |actor, thing|
|
24
|
+
actor.tell thing.description
|
25
|
+
end
|
26
|
+
|
27
|
+
respond :look, Query::Text.new() do |actor, string|
|
28
|
+
containers = actor.children.that_are(Container)
|
29
|
+
containers = containers + actor.parent.children.that_are(Container)
|
30
|
+
found = false
|
31
|
+
containers.each { |container|
|
32
|
+
if container.closed? == false
|
33
|
+
query = Query::Children.new(Portable)
|
34
|
+
result = query.execute(container, string)
|
35
|
+
if result.objects.length == 1
|
36
|
+
found = true
|
37
|
+
actor.tell "You look at #{result.objects[0].name.specify} in #{container.name.specify}."
|
38
|
+
actor.perform "look #{result.objects[0].name} in #{container.name}"
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
}
|
43
|
+
if found == false
|
44
|
+
actor.tell "You don't see any \"#{string}\" here."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
xlate "look at :thing", :look, :thing
|
49
|
+
xlate "l", :look
|
50
|
+
xlate "l :thing", :look, :thing
|
51
|
+
xlate "examine :thing", :look, :thing
|
52
|
+
xlate "exam :thing", :look, :thing
|
53
|
+
xlate "x :thing", :look, :thing
|
@@ -0,0 +1,35 @@
|
|
1
|
+
respond :go, Query::Siblings.new(Portal) do |actor, portal|
|
2
|
+
actor.parent = portal.destination
|
3
|
+
actor.tell "You go #{portal.name}."
|
4
|
+
actor.perform "look"
|
5
|
+
end
|
6
|
+
|
7
|
+
respond :go, Query::Text.new() do |actor, string|
|
8
|
+
actor.tell "You don't see any exit \"#{string}\" from here."
|
9
|
+
end
|
10
|
+
|
11
|
+
respond :go do |actor|
|
12
|
+
actor.tell "Where do you want to go?"
|
13
|
+
end
|
14
|
+
|
15
|
+
xlate "north", :go, "north"
|
16
|
+
xlate "south", :go, "south"
|
17
|
+
xlate "west", :go, "west"
|
18
|
+
xlate "east", :go, "east"
|
19
|
+
xlate "up", :go, "up"
|
20
|
+
xlate "down", :go, "down"
|
21
|
+
xlate "northwest", :go, "northwest"
|
22
|
+
xlate "northeast", :go, "northeast"
|
23
|
+
xlate "southwest", :go, "southwest"
|
24
|
+
xlate "southeast", :go, "southeast"
|
25
|
+
|
26
|
+
xlate "n", :go, "north"
|
27
|
+
xlate "s", :go, "south"
|
28
|
+
xlate "w", :go, "west"
|
29
|
+
xlate "e", :go, "east"
|
30
|
+
xlate "u", :go, "up"
|
31
|
+
xlate "d", :go, "down"
|
32
|
+
xlate "nw", :go, "northwest"
|
33
|
+
xlate "ne", :go, "northeast"
|
34
|
+
xlate "sw", :go, "southwest"
|
35
|
+
xlate "se", :go, "southeast"
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Portal < Entity
|
2
|
+
attr_accessor :destination
|
3
|
+
#def initialize
|
4
|
+
# super
|
5
|
+
# @destination = nil
|
6
|
+
#end
|
7
|
+
def find_reverse
|
8
|
+
rev = Portal.reverse(self.name)
|
9
|
+
if rev != nil
|
10
|
+
destination.children.that_are(Portal).each { |c|
|
11
|
+
if c.name == rev
|
12
|
+
return c
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def self.reverse(direction)
|
18
|
+
case direction.downcase
|
19
|
+
when "north"
|
20
|
+
"south"
|
21
|
+
when "south"
|
22
|
+
"north"
|
23
|
+
when "west"
|
24
|
+
"east"
|
25
|
+
when "east"
|
26
|
+
"west"
|
27
|
+
when "northwest"
|
28
|
+
"southeast"
|
29
|
+
when "southeast"
|
30
|
+
"northwest"
|
31
|
+
when "northeast"
|
32
|
+
"southwest"
|
33
|
+
when "southwest"
|
34
|
+
"northeast"
|
35
|
+
when "up"
|
36
|
+
"down"
|
37
|
+
when "down"
|
38
|
+
"up"
|
39
|
+
else
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import 'basics/entities/portal'
|
2
|
+
|
3
|
+
class Room < Entity
|
4
|
+
def connect(destination, direction, type = Portal, two_way = true)
|
5
|
+
portal = type.new self.plot, :name => direction, :parent => self, :destination => destination
|
6
|
+
if two_way == true
|
7
|
+
reverse = Portal.reverse(direction)
|
8
|
+
if reverse == nil
|
9
|
+
raise "\"#{direction.cap_first}\" does not have an opposite direction"
|
10
|
+
end
|
11
|
+
portal2 = type.new(self.plot, {
|
12
|
+
:name => reverse,
|
13
|
+
:parent => destination,
|
14
|
+
:destination => self
|
15
|
+
})
|
16
|
+
end
|
17
|
+
portal
|
18
|
+
end
|
19
|
+
def synonyms
|
20
|
+
super.to_s + " around"
|
21
|
+
end
|
22
|
+
def tell(message, refresh = false)
|
23
|
+
children.each { |c|
|
24
|
+
c.tell message, refresh
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module RoomModes
|
2
|
+
attr_writer :description_mode
|
3
|
+
def description_seen
|
4
|
+
@description_seen ||= Array.new
|
5
|
+
end
|
6
|
+
def description_seen=(value)
|
7
|
+
if value.kind_of?(Array)
|
8
|
+
@description_seen = value
|
9
|
+
else
|
10
|
+
raise "Character#description_seen must be an Array"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
def description_mode
|
14
|
+
@description_mode ||= "verbose"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Character
|
19
|
+
include RoomModes
|
20
|
+
end
|
21
|
+
|
22
|
+
respond :go, Query::Siblings.new(Portal) do |actor, portal|
|
23
|
+
actor.tell "You go #{portal.name}."
|
24
|
+
actor.parent = portal.destination
|
25
|
+
if actor.description_mode == "superbrief" or (actor.description_mode == "brief" and actor.description_seen.include?(actor.parent))
|
26
|
+
actor.tell actor.parent.longname.cap_first
|
27
|
+
else
|
28
|
+
actor.perform "look"
|
29
|
+
end
|
30
|
+
if actor.description_seen.include?(actor.parent) == false
|
31
|
+
actor.description_seen.push actor.parent
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
respond :brief do |actor|
|
36
|
+
actor.description_mode = "brief"
|
37
|
+
actor.tell "You are now in BRIEF mode. Detailed descriptions of rooms will only be displayed the first time you visit them. Other options are SUPERBRIEF and VERBOSE."
|
38
|
+
end
|
39
|
+
|
40
|
+
respond :verbose do |actor|
|
41
|
+
actor.description_mode = "verbose"
|
42
|
+
actor.tell "You are now in VERBOSE mode. Detailed descriptions will be displayed every time you enter a room. Other options are BRIEF and SUPERBRIEF."
|
43
|
+
end
|
44
|
+
|
45
|
+
respond :superbrief do |actor|
|
46
|
+
actor.description_mode = "superbrief"
|
47
|
+
actor.tell "You are now in SUPERBRIEF mode. Detailed room descriptions will never be displayed unless you LOOK AROUND. Other options are BRIEF and VERBOSE."
|
48
|
+
end
|