summaryrefslogtreecommitdiff
path: root/app/models/monster.rb
blob: 523afa7c7b0906f3f1ddfc11812c1d2eae5de02d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Monster < ApplicationRecord
  include HasWhatnot

  def max_hp
    self.whatnot[:max_hp][:base]
  end

  def speed
    self.whatnot[:speed][:base]
  end

  def accuracy(with_combat_style: false)
    self.whatnot[:accuracy][:base]
  end

  def power(with_combat_style: false)
    self.whatnot[:power][:base]
  end

  def evasion(with_combat_style: false)
    self.whatnot[:evasion][:base]
  end

  def block(with_combat_style: false)
    self.whatnot[:block][:base]
  end

  def block_value
    self.whatnot[:block_value][:base]
  end

  def resistance(damage_type)
    unless %w[slash pierce bash arcane fire frost lightning acid thunder radiant necrotic poison bleed].include?(damage_type)
      raise "Invalid damage type"
    end
    self.whatnot&.each do |resistance|
      return resistance[:base] if resistance[:gid] == damage_type
    end
    0
  end
end