Class: GamesAndRpgParadise::Mud::Room

Inherits:
MudObject
  • Object
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.

Direct Known Subclasses

Sarlem::Entrance, Sarlem::WesternGate

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
    # ===================================================================== #
    # === Handle Hashes next
    # ===================================================================== #
    if yielded.is_a? Hash
      # =================================================================== #
      # === :description
      # =================================================================== #
      if yielded.has_key? :description
        set_description(yielded.delete(:description))
      end
    end
  end
  run if run_already
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GamesAndRpgParadise::Mud::MudObject

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

#

connect_to

#


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
# DEBUGGING part:
pp @exits
p which_exit
p inverse_exit(which_exit)
  # ======================================================================= #
  # Also connect that room to the other one. Can lead to a loop though.
  # ======================================================================= #
  if also_connect_this_room
    this_room.connect_to(self, inverse_exit(which_exit), false)
  end
end

#debugObject

#

debug

For debugging

#


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?

#

description?

#

Returns:

  • (Boolean)


111
112
113
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 111

def description?
  @description
end

#display(title = title? ) ⇒ Object

#

display

#


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 # 'KAROSHI_CEMETARY/entrance.rb'
  )
  add_exit(:east, where_to)
end

#exits?Boolean Also known as: exits

#

exits?

#

Returns:

  • (Boolean)


281
282
283
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 281

def exits?
  @exits
end

#is_a_room?Boolean

#

is_a_room?

#

Returns:

  • (Boolean)


248
249
250
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 248

def is_a_room?
  true
end

#random_exitObject

#

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

#resetObject

#

reset (reset tag)

#


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 # A room can contain other objects.
end

#reset_exitsObject

#

reset_exits

#


75
76
77
78
79
80
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 75

def reset_exits
  # ======================================================================= #
  # === @exits
  # ======================================================================= #
  @exits = {} # A hash.
end

#runObject

#

run

#


275
276
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 275

def run # (run tag)
end

#sanitize_the_descriptionObject

#

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.word_wrap! 80
    @description.squeeze!('  ')
  end
  @description.lstrip! # mandatory
end

#set_default_exitsObject

#

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

#set_input(i = '') ⇒ Object

#

set_input

#


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

#

title?

#

Returns:

  • (Boolean)


139
140
141
# File 'lib/games_and_rpg_paradise/mud/room/room.rb', line 139

def title?
  @title
end