Class: Zarta::Weapon
- Inherits:
-
Object
- Object
- Zarta::Weapon
- Defined in:
- lib/zarta/weapon.rb
Overview
A weapon that can be wielded by the player or an enemey
Instance Attribute Summary collapse
-
#damage ⇒ Object
The base damage that the weapon deals.
-
#dungeon ⇒ Object
The dungeon whis weapon dropped in.
-
#name ⇒ Object
The name of the weapon.
-
#player ⇒ Object
The player or monster wielding this weapon.
Instance Method Summary collapse
- #chance ⇒ Object
-
#initialize(dungeon) ⇒ Weapon
constructor
A new instance of Weapon.
- #inspect_weapon ⇒ Object
- #random_drop ⇒ Object
- #table ⇒ Object
- #title_table ⇒ Object
Constructor Details
#initialize(dungeon) ⇒ Weapon
Returns a new instance of Weapon.
17 18 19 20 21 22 23 |
# File 'lib/zarta/weapon.rb', line 17 def initialize(dungeon) @dungeon = dungeon @player = @dungeon.player @pastel = Pastel.new random_drop end |
Instance Attribute Details
#damage ⇒ Object
The base damage that the weapon deals
15 16 17 |
# File 'lib/zarta/weapon.rb', line 15 def damage @damage end |
#dungeon ⇒ Object
The dungeon whis weapon dropped in
6 7 8 |
# File 'lib/zarta/weapon.rb', line 6 def dungeon @dungeon end |
#name ⇒ Object
The name of the weapon
12 13 14 |
# File 'lib/zarta/weapon.rb', line 12 def name @name end |
#player ⇒ Object
The player or monster wielding this weapon
9 10 11 |
# File 'lib/zarta/weapon.rb', line 9 def player @player end |
Instance Method Details
#chance ⇒ Object
39 40 41 42 |
# File 'lib/zarta/weapon.rb', line 39 def chance rand((@dungeon.level - WEAPON_MIN_MOD).. (@dungeon.level + WEAPON_MAX_MOD)).round end |
#inspect_weapon ⇒ Object
44 45 46 47 48 |
# File 'lib/zarta/weapon.rb', line 44 def inspect_weapon title_table table gets end |
#random_drop ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zarta/weapon.rb', line 25 def random_drop drop_list = [] @dungeon.weapon_list.each do |weapon| drop_list << weapon if weapon[:rarity] <= chance end drop = drop_list[rand(0...drop_list.length)] @name = drop[:name] @description = drop[:description] @damage = drop[:damage] @rarity = drop[:rarity] end |
#table ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/zarta/weapon.rb', line 59 def table table = Terminal::Table.new table.style = { width: 40, padding_left: 1 } table.add_row ['Damage:', @damage] table.add_row ['Rarity:', @rarity] puts table end |
#title_table ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/zarta/weapon.rb', line 50 def title_table table_title = Terminal::Table.new table_title.title = @pastel.cyan.bold(@name) table_title.style = { width: 40, padding_left: 1 } table_title.align_column(0, :center) table_title.add_row [@description] puts table_title end |