From 943e08a1c6ea36dece0cf64f4a3256dc251c9e58 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sat, 5 Jun 2021 20:49:46 -0400 Subject: Expand resistances code to have meta resistances: physical and energy --- app/models/character.rb | 11 +++++++++-- app/models/monster.rb | 17 +++++++++++++---- app/views/characters/show.html.erb | 20 ++++++++++---------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app/models/character.rb b/app/models/character.rb index 74dbe9f..0f434cf 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -321,10 +321,17 @@ class Character < ApplicationRecord end def resistance(damage_type) - unless %w[slash pierce bash arcane fire frost lightning acid thunder radiant necrotic poison bleed].include?(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 - [total_stat_change("#{damage_type}_resistance"), 0].max + res = total_stat_change("#{damage_type}_resistance") + 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, 0].max end def max_wounds diff --git a/app/models/monster.rb b/app/models/monster.rb index 523afa7..f4ae7a7 100644 --- a/app/models/monster.rb +++ b/app/models/monster.rb @@ -30,12 +30,21 @@ class Monster < ApplicationRecord end def resistance(damage_type) - unless %w[slash pierce bash arcane fire frost lightning acid thunder radiant necrotic poison bleed].include?(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 - self.whatnot&.each do |resistance| - return resistance[:base] if resistance[:gid] == damage_type + res = 0 + whatnot[:resistances]&.each do |data| + if data[:gid] == damage_type + res += data[:base] + end end - 0 + 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 diff --git a/app/views/characters/show.html.erb b/app/views/characters/show.html.erb index 09e2400..7875a24 100644 --- a/app/views/characters/show.html.erb +++ b/app/views/characters/show.html.erb @@ -103,19 +103,19 @@ Bash <%= @character.resistance("bash") %> - + Arcane <%= @character.resistance("arcane") %> - + Fire <%= @character.resistance("fire") %> - + Frost <%= @character.resistance("frost") %> - + Lightning <%= @character.resistance("lightning") %> @@ -125,27 +125,27 @@
- + - + - + - + - + - + -- cgit v1.2.3
Acid <%= @character.resistance("acid") %>
Thunder <%= @character.resistance("thunder")%>
Radiant <%= @character.resistance("radiant") %>
Necrotic <%= @character.resistance("necrotic") %>
Poison <%= @character.resistance("poison") %>
Bleed <%= @character.resistance("bleed") %>