Class: GamesAndRpgParadise::Mud::Shell

Inherits:
Base
  • Object
show all
Includes:
GamesAndRpgParadise
Defined in:
lib/games_and_rpg_paradise/mud/shell/shell.rb

Overview

GamesAndRpgParadise::Mud::Shell

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
NON_MUD_CMD =
#

NON_MUD_CMD

#
'[NonMudCommand] '
IMG =
#

IMG

#
ENV['IMG'].to_s
SHELL_NAME =
#

SHELL_NAME

#
'MUD AdminShell '+::GamesAndRpgParadise.version?
DEFAULT_PROMPT =
#

DEFAULT_PROMPT

#
' > '

Constants included from GamesAndRpgParadise

COLOUR_SETTLEMENT, DATA_DIR, DEBUG, DIRECTORY_AM_RANDE_DER_NACHT, DIRECTORY_TO_THE_IMAGES_OF_THE_THEME_SYMBOLS, ERROR_LINE, FILE_DND_CHARACTERS, FILE_MAGICAL_ITEMS, FILE_TAI_NAMES, HOME_DIRECTORY_OF_THE_USER_X, HOME_X_DATA, IMG_DIR, LAST_UPDATE, GamesAndRpgParadise::MAGICAL_ITEMS, N, PROJECT_BASE_DIRECTORY, PROJECT_YAML_DIR, RPG_IMG_DIR, RUBY_HEADER, SARLEM, SARLEM_MAP, SARLEM_YAML, STD_FONT_SIZE, TAI_MAP, TEMP_DIR, UNHAPPY_SMILEY, USE_THIS_PORT, VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GamesAndRpgParadise

available_gamebooks?, available_magic_themes?, bold_yellow, calculates, cat, cd, chdir, convert, copy_file, delete, disable_colours, e, embeddable_interface, enable_colours, ensure_that_the_log_directory_exists, esystem, file_good_dos_games, file_good_windows_games, gamebook_dataset_for, gamebooks_directory?, generate_name, image_directory?, is_on_roebe?, load_gamebook_dataset, load_npc, minfo, mkdir, mv, n_cards_are_registered_in_the_local_magic_collection?, pngopt, project_base_directory?, project_image_directory?, project_yaml_directory?, rds, return_array_available_magic_theme_icons, return_sarlem_name, #rev, rev, riddles, roll, run_app, run_gamebooks_app, sfile, show_dnd_xp_table, silently_roll_this_die, speak_to_group, #speak_to_your_group, steelblue, string_draw_a_card_from_the_deck_of_many_things, temp_dir?, use_colours?, version?, word_wrap

Methods inherited from Base

#find_adverb_for, #lang_wnum, #sentence, #word_wrap

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ Shell

#

initialize

#


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 61

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  register_sigint
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

RpgParadise::Mud::Shell[]

#


358
359
360
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 358

def self.[](i = '')
  new(i)
end

Instance Method Details

#all_arguments?Boolean Also known as: a?

#

all_arguments?

#

Returns:

  • (Boolean)


207
208
209
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 207

def all_arguments?
  @all_arguments
end

#disable(i) ⇒ Object

#

disable

#


214
215
216
217
218
219
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 214

def disable(i)
  case i.to_s
  when 'debug'
    MudObject.disable_debug
  end
end

#display_the_promptObject

#

display_the_prompt

#


157
158
159
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 157

def display_the_prompt
  print DEFAULT_PROMPT
end

#do_simple_emote(which_emote = 'hop', how = nil) ⇒ Object

#

do_simple_emote (simple tag)

A simple emote is one that is simple, such as “You smile happily.” or “You hop around.

#


190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 190

def do_simple_emote(
    which_emote = 'hop', how = nil
  )
  which_emote = which_emote.to_s
  _ = 'You '+which_emote.dup
  # ======================================================================= #
  # Some emotes need extra descriptions.
  # ======================================================================= #
  _ << ' around' if which_emote == 'hop'
  _ << ' '+find_adverb_for(how.to_s) unless how.to_s.empty?
  _ << '.'
  e _
end

#drop(i) ⇒ Object

#

drop (drop tag)

#


337
338
339
340
341
342
343
344
345
346
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 337

def drop(i)
  if i.nil? or i.empty?
    e 'drop what?'
  else
    sentence "You drop a #{i}"
    item = inventory?.select {|entry| entry == i }.first
    inventory?.remove(item)
    array_rooms?.add item
  end
end

#enable(i) ⇒ Object

#

enable

#


164
165
166
167
168
169
170
171
172
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 164

def enable(i)
  case i.to_s
  # ======================================================================= #
  # === enable debug
  # ======================================================================= #
  when 'debug'
    MudObject.enable_debug
  end
end

#enter_the_main_loopObject

#

enter_the_main_loop

#


365
366
367
368
369
370
371
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 365

def enter_the_main_loop
  loop {
    obtain_the_user_input
    menu
    break if @user_input == :exit
  }
end

#look_at(what) ⇒ Object

#

look_at

This can be invoked via e. g.:

l at sword
#


263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 263

def look_at(what)
  if what.nil?
    array_rooms?.first.show_description
  else
    what.gsub!(/at /,'')
    e "You look at a #{what}."
    object = inventory?.find(what)
    if object
      object.show_description
    else
      e 'Look at what?'
    end
  end
end
#

menu (menu tag)

#


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 124

def menu(
    i = user_input?
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === moan
    # ===================================================================== #
    when 'moan'
      moan_emote(a?)
    # ===================================================================== #
    # === quit
    # ===================================================================== #
    when /quit$/i,
         /^q$/
      @user_input = :exit
    else # else tag
      if i.start_with?('@')
        e 'Trying to obtain the value of '+i+' next.'
        e instance_variable_get(i)
      else # else tag
        e
        display_the_prompt
      end
    end
  end
end

#moan_emote(i = nil) ⇒ Object

#

moan_emote

#


177
178
179
180
181
182
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 177

def moan_emote(i = nil)
  _ = 'You moan'.dup
  _ << ' '+i.to_s unless i.to_s.empty?
  _ << '.'
  e _
end

#obtain_the_user_inputObject Also known as: get_user_input

#

obtain_the_user_input

#


247
248
249
250
251
252
253
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 247

def obtain_the_user_input
  if Object.const_defined? :Readline
    @user_input = Readline.readline(DEFAULT_PROMPT, true)
  else
    @user_input = $stdin.gets.chomp
  end
end

#open_mud_project_filesObject

#

open_mud_project_files

#


323
324
325
326
327
328
329
330
331
332
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 323

def open_mud_project_files
  base_dir = "#{HOME_DIRECTORY_OF_USER_X}programming/ruby/src/rpg_paradise/lib/rpg_paradise/mud/"
  array = %w(
    shell/shell.rb
  ).map {|entry| base_dir+entry }
  array.each {|file|
    e file
    system 'bluefish '+file
  }
end

#register_sigintObject

#

register_sigint

#


99
100
101
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 99

def register_sigint
  Signal.trap('SIGINT') { exit }
end

#resetObject

#

reset (reset tag)

#


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 76

def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :hash_adverbs
  # ======================================================================= #
  @internal_hash[:hash_adverbs] = Adverbs.all? # This is a hash.
  # ======================================================================= #
  # === :character
  # ======================================================================= #
  @internal_hash[:character] = GamesAndRpgParadise::Mud::Character.new
end

#runObject

#

run (run tag)

#


376
377
378
379
380
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 376

def run
  run_startup_tasks
  display_the_prompt
  enter_the_main_loop
end

#run_startup_tasksObject

#

run_startup_tasks

#


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

def run_startup_tasks
  show_welcome_message
  perform_startup_actions if startup_actions?
end

#show_inventoryObject

#

show_inventory

#


300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 300

def show_inventory
  inventory?.show_inventory
  e
  e 'You are wearing a camouflage cloak, a left strong leather boot, a medium'
  e 'leather backpack, a pair of leather gauntlets and a right strong leather'
  e 'boot.'
  e
  e 'Under that you are wearing a gemmed golden ring, a leather quiver, a massive'
  e 'black ring, a padded tunic, a pair of leather thigh-guards and a studded'
  e 'leather jacket.'
  e
  e '  You are carrying a bluish-gray whetstone, a book with the title'
  e '  "Excellent Training Book", some bronze coins, a compass, many copper'
  e '  coins, two gold coins, two brown sable furs, a leather cap, a long'
  e '  slender dagger, an ornamented lyre, a quality brown mink fur, two'
  e '  scalps of goblins, a scalp of a orc, eleven silver coins, a strong'
  e '  ornamented composite-longbow, a tinderbox and many wooden arrows.'
  e
end

#show_last_object_usedObject Also known as: list_all_specific_objects

#

show_last_object_used

#


351
352
353
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 351

def show_last_object_used
  pp last_object_used?
end

#show_welcome_messageObject

#

show_welcome_message

This method will show a welcome message. Shows our prompt as well.

#


291
292
293
294
295
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 291

def show_welcome_message
  cliner
  e 'Welcome to '+SHELL_NAME+'. Please type in something now:'
  cliner
end

#try_to_load_startup_actions(i = project_yaml_dir?+'mud/mud_admin_shell/mud_shell_startup_actions.yml') ⇒ Object

#

try_to_load_startup_actions

#


106
107
108
109
110
111
112
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 106

def try_to_load_startup_actions(
    i = project_yaml_dir?+'mud/mud_admin_shell/mud_shell_startup_actions.yml'
  )
  if File.exist? i
    @startup_actions = YAML.load_file(i)
  end
end

#user_input?Boolean Also known as: input?

#

user_input?

#

Returns:

  • (Boolean)


117
118
119
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 117

def user_input?
  @user_input
end

#wear(i = nil) ⇒ Object

#

wear

This entry point can be used to wear some armour or clothing.

To test this, do:

wear robe
#


231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/games_and_rpg_paradise/mud/shell/shell.rb', line 231

def wear(i = nil)
  if i.nil?
    e 'Wear what?'
  else # Else a command was issued.
    armour = Armour.new(i)
    if armour.is_wearable?
      e 'You wear the '+armour.name?+'.'
    else
      e armour.name?+' is not wearable.'
    end
  end
end