Class: GamesAndRpgParadise::Mud::Room
- Inherits:
-
MudObject
- Object
- MudObject
- GamesAndRpgParadise::Mud::Room
show all
- Defined in:
- lib/games_and_rpg_paradise/mud/room/room.rb,
lib/games_and_rpg_paradise/mud/room/server/server.rb
Overview
Every room is a mud-object.
Defined Under Namespace
Classes: Server
Constant Summary
Constants inherited
from MudObject
MudObject::DEFAULT_NAME, MudObject::NAMESPACE
Instance Method Summary
collapse
Methods inherited from MudObject
[], #add, #add_prop, #add_to_inventory, #alias_action, #can_speak?, #define_action, #describe_the_mud_object, disable_debug, #empty?, enable_debug, #enable_speak, #find, #has_inventory?, #height?, #id?, #inspect, #internal_hash?, #inventory?, #is_armour?, #is_inventory?, #is_mud_object?, #is_weapon?, #is_wearable?, #length?, #method_missing, #name=, #name?, #obtain_name_from_filename, #random_inventory_element, #report_height, #report_weight, #set_height, #set_is_an_armour, #set_is_inventory, #set_is_wearable, #set_length, #set_name, #set_object_name, #set_value, #set_weight, shall_we_debug?, #show_inventory, #store, #store_where?, #value?, #wear, #wearables?, #weight?, #who_am_i?, #wields?
Constructor Details
#initialize(run_already = true) ⇒ Room
#
initialize
The most important part of the initialization process is that the proper description of the room’s content will be shown.
#
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 38
def initialize(
run_already = true
)
reset
super('Standard Room')
if block_given?
yielded = yield
if yielded.is_a? Hash
if yielded.has_key? :description
set_description(yielded.delete(:description))
end
end
end
run if run_already
end
|
Instance Method Details
#add_exit(direction, room_object = nil) ⇒ Object
#
add_exit
Adds a new exit. The direction is mandatory, e. g. “east” or “south” and so forth.
Note that this method will NOT check whether a given exit already exists with the same name.
#
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 261
def add_exit(
direction,
room_object = nil
)
unless room_object
raise 'Must be a room object.' unless room_object.is_a_room?
end
direction = direction.to_s
exits?[direction] = room_object
end
|
#add_random_exit(file_name) ⇒ Object
#
add_random_exit
This method will add a random exit to the room at hand.
#
155
156
157
158
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 155
def add_random_exit(file_name)
_ = random_exit
add_exit(_, file_name)
end
|
#connect_to(this_room, which_exit = 'se', also_connect_this_room = true) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 216
def connect_to(
this_room,
which_exit = 'se',
also_connect_this_room = true
)
@exits[which_exit] = this_room
pp @exits
p which_exit
p inverse_exit(which_exit)
if also_connect_this_room
this_room.connect_to(self, inverse_exit(which_exit), false)
end
end
|
#debug ⇒ Object
203
204
205
206
207
208
209
210
211
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 203
def debug
e '-'*80
e 'Debugging info from: '
e self.object_id
pp self.exits?
e self.inspect
e '-'*80
e
end
|
#description? ⇒ Boolean
Also known as:
desc?, long_description?
111
112
113
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 111
def description?
@description
end
|
#display(title = title?
) ⇒ Object
119
120
121
122
123
124
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 119
def display(
title = title?
)
e title if title
e description?
end
|
#exit_east(where_to = :karoshi_cemetary_entrance) ⇒ Object
#
exit_east
Add an east exit.
#
239
240
241
242
243
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 239
def exit_east(
where_to = :karoshi_cemetary_entrance )
add_exit(:east, where_to)
end
|
#exits? ⇒ Boolean
Also known as:
exits
281
282
283
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 281
def exits?
@exits
end
|
#is_a_room? ⇒ Boolean
248
249
250
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 248
def is_a_room?
true
end
|
#random_exit ⇒ Object
#
random_exit
Pick a random exit with this method.
#
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 165
def random_exit
exit_where_to = rand(8)+1
case exit_where_to
when 1 then 'north'
when 2 then 'northeast'
when 3 then 'east'
when 4 then 'southeast'
when 5 then 'south'
when 6 then 'southwest'
when 7 then 'west'
when 8 then 'northwest'
end
end
|
#reset ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 63
def reset
super()
set_description
set_title
reset_exits
set_default_exits
set_is_inventory end
|
#reset_exits ⇒ Object
75
76
77
78
79
80
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 75
def reset_exits
@exits = {} end
|
#run ⇒ Object
275
276
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 275
def run end
|
#sanitize_the_description ⇒ Object
#
sanitize_the_description
This will improve our descriptions. Not sure if we wont change this one day. Maybe we should move this to the description-setter method
#
100
101
102
103
104
105
106
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 100
def sanitize_the_description
if @description.include? ' '
@description.squeeze!(' ')
end
@description.lstrip! end
|
#set_default_exits ⇒ Object
#
set_default_exits
This sets the room exits as hash. The hash points to another room. An exit will normally store the object_id of another room. Exits will point to object id. Default value is nil, for initialization purposes.
#
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 187
def set_default_exits
@exits['n'] = nil
@exits['ne'] = nil
@exits['e'] = nil
@exits['se'] = nil
@exits['s'] = nil
@exits['sw'] = nil
@exits['w'] = nil
@exits['nw'] = nil
end
|
#set_description(i = 'A basic room.') ⇒ Object
#
set_description
This will describe the content of the room.
#
87
88
89
90
91
92
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 87
def set_description(
i = 'A basic room.'
)
@description = i
sanitize_the_description
end
|
146
147
148
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 146
def set_input(i = '')
@input = i
end
|
#set_title(this_title = '') ⇒ Object
Also known as:
title=
#
title=
Use this method to set a short title (an identifier) of the room, i.e. “Throne room”
#
132
133
134
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 132
def set_title(this_title = '')
@title = this_title.to_s
end
|
#title? ⇒ Boolean
Also known as:
title
139
140
141
|
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 139
def title?
@title
end
|