Class: Zarta::Weapon

Inherits:
Object
  • Object
show all
Defined in:
lib/zarta/weapon.rb

Overview

A weapon that can be wielded by the player or an enemey

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#damageObject

The base damage that the weapon deals



15
16
17
# File 'lib/zarta/weapon.rb', line 15

def damage
  @damage
end

#dungeonObject

The dungeon whis weapon dropped in



6
7
8
# File 'lib/zarta/weapon.rb', line 6

def dungeon
  @dungeon
end

#nameObject

The name of the weapon



12
13
14
# File 'lib/zarta/weapon.rb', line 12

def name
  @name
end

#playerObject

The player or monster wielding this weapon



9
10
11
# File 'lib/zarta/weapon.rb', line 9

def player
  @player
end

Instance Method Details

#chanceObject



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_weaponObject



44
45
46
47
48
# File 'lib/zarta/weapon.rb', line 44

def inspect_weapon
  title_table
  table
  gets
end

#random_dropObject



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

#tableObject



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_tableObject



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