Class: GamesAndRpgParadise::Mud::CharacterCreationProcess

Inherits:
Object
  • Object
show all
Includes:
Colours
Defined in:
lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb

Overview

RpgParadise::Mud::CharacterCreationProcess

Constant Summary collapse

FORBIDDEN_NAMES =
YAML.load_file(RpgParadise::Mud::FILE_FORBIDDEN_NAMES)

Constants included from Colours

Colours::WHITE

Instance Method Summary collapse

Methods included from Colours

#brown, #cfile, #convert_colour, convert_colour, #fancy, #normal, #pink, #red, #yel

Constructor Details

#initialize(run_already = true) ⇒ CharacterCreationProcess

#

initialize

#


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 40

def initialize(
    run_already = true
  )
  reset
  case run_already
  # ======================================================================= #
  # === :interactive
  # ======================================================================= #
  when :interactive
    is_interactive
  end
  run if run_already
end

Instance Method Details

#assign_ageObject

#

assign_age

#


181
182
183
184
185
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 181

def assign_age
  _ = get_user_input
  _ = rand(30)+14 if _ =~ /ran/
  return _
end

#debugObject

#

debug

#


172
173
174
175
176
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 172

def debug
  opn; e 'Debugging now in '+sfile(__FILE__)
  pp self
  pp @hash
end

#determine_character_nameObject

#

determine_character_name

#


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 108

def determine_character_name
  _ = get_user_input # Get user input.
  if FORBIDDEN_NAMES.include? _
    e 'This name ('+_+') is not allowed. Please pick another name.'
    determine_character_name
  else
    if _ # Else, the user pressed sigint.
      if _.empty? or _ == 'random'
        _ = NameGenerator.new._
      end
      _ = _.capitalize
      @hash[:character_name] = _
    end
  end
end

#hash?Boolean

#

hash?

#

Returns:

  • (Boolean)


101
102
103
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 101

def hash?
  @hash
end

#interactive?Boolean

#

interactive?

#

Returns:

  • (Boolean)


87
88
89
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 87

def interactive?
  @interactive
end

#resetObject

#

reset (reset tag)

#


57
58
59
60
61
62
63
64
65
66
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 57

def reset
  # ======================================================================= #
  # === @hash
  # ======================================================================= #
  @hash = {} # This is the main hash.
  # ======================================================================= #
  # === @interactive
  # ======================================================================= #
  @interactive = false
end

#runObject

#

run (run tag)

#


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 146

def run
  if interactive? # if true then we query the user for data
    e 'Welcome to the character creation process.'
    e 'What shall be the '+sfancy('name')+rev+' of your '+
       'character? [input '+grey('"random"')+rev
     e 'or leave blank so that we can auto-generate '+
       'a random name for you'
    e 'once the gender was defined.]'
    result = determine_character_name
    if result
      opn; e sfancy('Gender')+' [male/female]'
      @hash[:gender] = get_user_input
      sanitize_the_gender
      opn; e sfancy('Age')+' of your character [input "random" for a dice-roll]'
      @hash[:age] = assign_age
      store_dataset
    else
      e 'User interrupt - thus, we will not continue.'
      exit
    end
  end
end

#sanitize_the_genderObject

#

sanitize_the_gender

#


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 71

def sanitize_the_gender
  _ = @hash[:gender]
  case _
  when 'm','1','male','mal' # These are shortcuts.
    @hash[:gender] = 'male'
  when 'f','2','female','fem'
    @hash[:gender] = 'female'
  else
    e 'Setting to male as default.' # This is the failsave fallback.
    @hash[:gender] = 'male'
  end
end

#set_interactiveObject Also known as: is_interactive

#

set_interactive

#


94
95
96
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 94

def set_interactive
  @interactive = true
end

#store_datasetObject

#

store_dataset

#


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/games_and_rpg_paradise/mud/characters/character_creation_process.rb', line 127

def store_dataset
  if @hash.empty?
    opn; e 'We can not store as our dataset is empty.'
  else
    saved_characters_location = MUD_YAML_DIRECTORY+'saved_characters/'
    mkdir(saved_characters_location)
    save_here = saved_characters_location+
                 @hash[:character_name].downcase.gsub(/ /,'_')+
                 '.yml'
    opn; e 'All done. We will store the result into'
    opn; e '  '+sfile(save_here)+'.'
    mkdir(MUD_YAML_DIRECTORY)
    save_file(YAML.dump(hash?), save_here)
  end
end