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 ++ app/views/characters/show.html.erb | 195 ++++++++++++++++++++++++++----------- 3 files changed, 153 insertions(+), 59 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 diff --git a/app/views/characters/show.html.erb b/app/views/characters/show.html.erb index c507efd..09e2400 100644 --- a/app/views/characters/show.html.erb +++ b/app/views/characters/show.html.erb @@ -14,70 +14,147 @@

Learned <%= @character.learned_activities.count %> recipe(s) or technique(s).

-
-

Boons & Banes

- <% if @character.active_states.any? %> - - <% else %> -

No boons or banes affect you.

- <% end %> -
+
+
+

Boons & Banes

+ <% if @character.active_states.any? %> +
    + <% @character.active_states.each do |state| %> +
      <%= state.condition.name %> (expires in <%= distance_of_time_in_words_to_now(state.expires_at)%>)
    + <% end %> +
+ <% else %> +

No boons or banes affect you.

+ <% end %> +
+
+ <% if @character == current_char %> +

Combat Styles

+ <%= form_with url: character_combat_styles_path(character_id: @character) do |f| %> + <%= f.label :offensive_style, "Offensive" %> + <%= f.select :offensive_style, Character.offensive_styles.keys.to_a, selected: @character.offensive_style %> -<% if @character == current_char %> -

Combat Styles

- <%= form_with url: character_combat_styles_path(character_id: @character) do |f| %> - <%= f.label :offensive_style, "Offensive" %> - <%= f.select :offensive_style, Character.offensive_styles.keys.to_a, selected: @character.offensive_style %> + <%= f.label :defensive_style, "Defensive" %> + <%= f.select :defensive_style, Character.defensive_styles.keys.to_a, selected: @character.defensive_style %> - <%= f.label :defensive_style, "Defensive" %> - <%= f.select :defensive_style, Character.defensive_styles.keys.to_a, selected: @character.defensive_style %> + <%= f.submit "Set" %> + <% end %> + <% end %> +
+
- <%= f.submit "Set" %> - <% end %> -<% end %>
-

Combat Statistics

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Wounds<%= @character.wounds %> / <%= @character.max_wounds %>
Max HP<%= @character.max_hp %>
Speed<%= @character.speed %>
Accuracy<%= @character.accuracy(with_combat_style: true) %>
Power<%= @character.power(with_combat_style: true) %>
Evasion<%= @character.evasion(with_combat_style: true) %>
Block<%= @character.block(with_combat_style: true) %>
Block Value<%= @character.block_value %>
+
+
+

Combat Statistics

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Wounds<%= @character.wounds %> / <%= @character.max_wounds %>
Max HP<%= @character.max_hp %>
Speed<%= @character.speed %>
Accuracy<%= @character.accuracy(with_combat_style: true) %>
Power<%= @character.power(with_combat_style: true) %>
Evasion<%= @character.evasion(with_combat_style: true) %>
Block<%= @character.block(with_combat_style: true) %>
Block Value<%= @character.block_value %>
+
+
+

Resistances

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Slash<%= @character.resistance("slash")%>
Pierce<%= @character.resistance("pierce") %>
Bash<%= @character.resistance("bash") %>
Arcane<%= @character.resistance("arcane") %>
Fire<%= @character.resistance("fire") %>
Frost<%= @character.resistance("frost") %>
Lightning<%= @character.resistance("lightning") %>
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Acid<%= @character.resistance("acid") %>
Thunder<%= @character.resistance("thunder")%>
Radiant<%= @character.resistance("radiant") %>
Necrotic<%= @character.resistance("necrotic") %>
Poison<%= @character.resistance("poison") %>
Bleed<%= @character.resistance("bleed") %>
+
+
+
+
-- cgit v1.2.3