Class: Gemwarrior::Location
- Defined in:
- lib/gemwarrior/entities/location.rb
Constant Summary collapse
- DANGER_LEVEL =
CONSTANTS HASHES
{:none => 0, :low => 15, :moderate => 30, :high => 55, :assured => 100}
- ERROR_LOCATION_ITEM_REMOVE_INVALID =
ERRORS
'That item cannot be removed as it does not exist here.'
Instance Attribute Summary collapse
-
#bosses_abounding ⇒ Object
Returns the value of attribute bosses_abounding.
-
#checked_for_monsters ⇒ Object
Returns the value of attribute checked_for_monsters.
-
#coords ⇒ Object
Returns the value of attribute coords.
-
#danger_level ⇒ Object
Returns the value of attribute danger_level.
-
#items ⇒ Object
Returns the value of attribute items.
-
#locs_connected ⇒ Object
Returns the value of attribute locs_connected.
-
#monsters_abounding ⇒ Object
Returns the value of attribute monsters_abounding.
Attributes inherited from Entity
Instance Method Summary collapse
- #checked_for_monsters? ⇒ Boolean
- #has_loc_to_the?(direction) ⇒ Boolean
- #has_monster? ⇒ Boolean
-
#initialize(options) ⇒ Location
constructor
A new instance of Location.
- #list_bosses ⇒ Object
- #list_items ⇒ Object
- #list_monsters ⇒ Object
- #list_paths ⇒ Object
- #monster_by_name(monster_name) ⇒ Object
- #populate_monsters(monsters_available) ⇒ Object
- #remove_item(item_name) ⇒ Object
- #remove_monster(name) ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(options) ⇒ Location
Returns a new instance of Location.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gemwarrior/entities/location.rb', line 18 def initialize() self.name = .fetch(:name) self.description = .fetch(:description) self.coords = .fetch(:coords) self.locs_connected = .fetch(:locs_connected) self.danger_level = .fetch(:danger_level) self.items = .fetch(:items) self.monsters_abounding = [] self.bosses_abounding = [:bosses_abounding] self.checked_for_monsters = false end |
Instance Attribute Details
#bosses_abounding ⇒ Object
Returns the value of attribute bosses_abounding.
15 16 17 |
# File 'lib/gemwarrior/entities/location.rb', line 15 def bosses_abounding @bosses_abounding end |
#checked_for_monsters ⇒ Object
Returns the value of attribute checked_for_monsters.
15 16 17 |
# File 'lib/gemwarrior/entities/location.rb', line 15 def checked_for_monsters @checked_for_monsters end |
#coords ⇒ Object
Returns the value of attribute coords.
15 16 17 |
# File 'lib/gemwarrior/entities/location.rb', line 15 def coords @coords end |
#danger_level ⇒ Object
Returns the value of attribute danger_level.
15 16 17 |
# File 'lib/gemwarrior/entities/location.rb', line 15 def danger_level @danger_level end |
#items ⇒ Object
Returns the value of attribute items.
15 16 17 |
# File 'lib/gemwarrior/entities/location.rb', line 15 def items @items end |
#locs_connected ⇒ Object
Returns the value of attribute locs_connected.
15 16 17 |
# File 'lib/gemwarrior/entities/location.rb', line 15 def locs_connected @locs_connected end |
#monsters_abounding ⇒ Object
Returns the value of attribute monsters_abounding.
15 16 17 |
# File 'lib/gemwarrior/entities/location.rb', line 15 def monsters_abounding @monsters_abounding end |
Instance Method Details
#checked_for_monsters? ⇒ Boolean
72 73 74 |
# File 'lib/gemwarrior/entities/location.rb', line 72 def checked_for_monsters? checked_for_monsters end |
#has_loc_to_the?(direction) ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gemwarrior/entities/location.rb', line 48 def has_loc_to_the?(direction) case direction when 'n' direction = 'north' when 'e' direction = 'east' when 's' direction = 'south' when 'w' direction = 'west' end locs_connected[direction.to_sym] end |
#has_monster? ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/gemwarrior/entities/location.rb', line 76 def has_monster? found = false unless danger_level.eql?(:none) max = DANGER_LEVEL[danger_level] trigger_values = 0..max actual_value = rand(1..100) if trigger_values.include?(actual_value) found = true end end return found end |
#list_bosses ⇒ Object
98 99 100 |
# File 'lib/gemwarrior/entities/location.rb', line 98 def list_bosses return "\n >> Boss(es) abound: #{bosses_abounding.map(&:name).join(', ')}" if bosses_abounding.length > 0 end |
#list_items ⇒ Object
90 91 92 |
# File 'lib/gemwarrior/entities/location.rb', line 90 def list_items return "\n >> Curious object(s): #{items.map(&:name).join(', ')}" if items.length > 0 end |
#list_monsters ⇒ Object
94 95 96 |
# File 'lib/gemwarrior/entities/location.rb', line 94 def list_monsters return "\n >> Monster(s) abound: #{monsters_abounding.map(&:name).join(', ')}" if monsters_abounding.length > 0 end |
#list_paths ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/gemwarrior/entities/location.rb', line 102 def list_paths valid_paths = [] locs_connected.each do |key, value| if value valid_paths.push(key.to_s) end end return "\n >> Paths: #{valid_paths.join(', ')}" end |
#monster_by_name(monster_name) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/gemwarrior/entities/location.rb', line 62 def monster_by_name(monster_name) monsters_list = monsters_abounding | bosses_abounding monsters_list.each do |m| if m.name.downcase.eql?(monster_name.downcase) return m.clone end end end |
#populate_monsters(monsters_available) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gemwarrior/entities/location.rb', line 112 def populate_monsters(monsters_available) if has_monster? self.checked_for_monsters = true self.monsters_abounding = [] random_monster = nil # get random non-boss monster loop do random_monster = monsters_available[rand(0..monsters_available.length-1)] unless random_monster.is_boss break end end monsters_abounding.push(random_monster) else return nil end end |
#remove_item(item_name) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/gemwarrior/entities/location.rb', line 36 def remove_item(item_name) if items.map(&:name).include?(item_name) items.reject! { |item| item.name == item_name } else ERROR_LOCATION_ITEM_REMOVE_INVALID end end |
#remove_monster(name) ⇒ Object
44 45 46 |
# File 'lib/gemwarrior/entities/location.rb', line 44 def remove_monster(name) monsters_abounding.reject! { |monster| monster.name == name } end |
#status ⇒ Object
30 31 32 33 34 |
# File 'lib/gemwarrior/entities/location.rb', line 30 def status status_text = name.ljust(26).upcase status_text << coords.values.to_a.to_s status_text << " #{description}\n" end |