diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 7 | ||||
-rw-r--r-- | app/models/monster.rb | 10 |
2 files changed, 17 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index f4c9bc2..74dbe9f 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -320,6 +320,13 @@ class Character < ApplicationRecord self.wounds < max_wounds 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 + [total_stat_change("#{damage_type}_resistance"), 0].max + end + def max_wounds [1 + total_stat_change("max_wounds"), 0].max end diff --git a/app/models/monster.rb b/app/models/monster.rb index d1e1b99..523afa7 100644 --- a/app/models/monster.rb +++ b/app/models/monster.rb @@ -28,4 +28,14 @@ class Monster < ApplicationRecord 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 |