summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-06-05 20:04:30 -0400
committerDavid Gay <david@davidgay.org>2021-06-05 20:12:33 -0400
commitfe644bfc268b92daedbb16e00fd46b19ae082487 (patch)
treef21eedff7de4a729d7f06b78f1adb41d4080ca06 /app/models
parent771a7672876ff2c9649c919395a4d23f2a66f16f (diff)
Add resistance stats and rejigger character sheet layout
Diffstat (limited to 'app/models')
-rw-r--r--app/models/character.rb7
-rw-r--r--app/models/monster.rb10
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