From fe644bfc268b92daedbb16e00fd46b19ae082487 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sat, 5 Jun 2021 20:04:30 -0400 Subject: Add resistance stats and rejigger character sheet layout --- app/models/character.rb | 7 +++++++ app/models/monster.rb | 10 ++++++++++ 2 files changed, 17 insertions(+) (limited to 'app/models') 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 -- cgit v1.2.3