Class: GamesAndRpgParadise::Mud::MonsterFactory

Inherits:
Base
  • Object
show all
Includes:
Colours
Defined in:
lib/games_and_rpg_paradise/mud/monsters/monster_factory.rb

Overview

RpgParadise::Mud::MonsterFactory

Constant Summary collapse

DEFAULT_MONSTER =
#

DEFAULT_MONSTER

#
:unicorn

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

Methods inherited from Base

#find_adverb_for, #lang_wnum, #sentence, #word_wrap

Constructor Details

#initialize(create_which_monster = ARGV) ⇒ MonsterFactory

#

initialize

#


28
29
30
31
32
33
34
35
36
# File 'lib/games_and_rpg_paradise/mud/monsters/monster_factory.rb', line 28

def initialize(
    create_which_monster = ARGV
  )
  super()
  # ===================================================================== #
  # === @create_which_monster
  # ===================================================================== #
  @create_which_monster = create_which_monster
end

Instance Method Details

#create_monster(this_name = @create_which_monster, be_verbose = true) ⇒ Object Also known as: cm

#

create_monster

This method will create (and return) a new monster of the specified type.

Check for “allowed monster” names in intercept_monster_name.

#


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/games_and_rpg_paradise/mud/monsters/monster_factory.rb', line 64

def create_monster(
    this_name  = @create_which_monster,
    be_verbose = true
  )
  this_name = intercept_monster_name(this_name) # now the name is ok
  class_name = this_name.capitalize.gsub(/ /,'_').to_sym # also exchange ' ' with _
  # Run the following only if it wasnt defined yet:
  _ = Object.const_set(class_name, 
    Class.new(StdLiving) { # bl $RUBY_MUD/std_living.rb
      def initialize(name)
        super(name)
      end
    }
  ) unless Object.const_defined?(class_name) # must check if const is defined.
  monster = Object.const_get(class_name).new(this_name)
  if be_verbose
    e 'A '+sfancy(monster)+' emerges, joining your forces.'
  end
  return monster
end

#intercept_monster_name(this_name) ⇒ Object

#

intercept_monster_name

Use this to assign shortcuts to monster names.

#


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/games_and_rpg_paradise/mud/monsters/monster_factory.rb', line 43

def intercept_monster_name(
    this_name
  )
  if this_name.is_a? Array
    this_name = this_name.first
  end
  case this_name
  when 'gobbo','gob','g' then this_name = 'goblin'
  when 'ogr'             then this_name = 'ogre'
  end
  return this_name
end