blob: 9e3060f8b29ac81c76c279460d1c8da18e30d651 (
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
42
43
44
45
46
|
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 damage_ranges
self.whatnot[:hit_effects].filter_map { |e| { gid: e[:gid], min: e[:min], max: e[:max] } if e[:type] == "damage" && conditions_met?(e) }
end
def resistance(damage_type)
unless %w[slash pierce bash arcane fire frost lightning acid thunder radiant necrotic poison bleed
physical energy].include?(damage_type)
raise "Invalid damage type"
end
res = 0
whatnot[:resistances]&.each do |data|
if data[:gid] == damage_type
res += data[:base]
end
end
if %w[slash pierce bash].include?(damage_type)
res += resistance("physical")
elsif %w[arcane fire frost lightning acid thunder radiant necrotic].include?(damage_type)
res += resistance("energy")
end
res
end
end
|