summaryrefslogtreecommitdiff
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
parent771a7672876ff2c9649c919395a4d23f2a66f16f (diff)
Add resistance stats and rejigger character sheet layout
-rw-r--r--app/models/character.rb7
-rw-r--r--app/models/monster.rb10
-rw-r--r--app/views/characters/show.html.erb195
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 @@
<p class="mb-4">Learned <%= @character.learned_activities.count %> recipe(s) or technique(s).</p>
-<div class="my-4">
- <h2 class="text-xl mb-2">Boons & Banes</h2>
- <% if @character.active_states.any? %>
- <ul>
- <% @character.active_states.each do |state| %>
- <ul><%= state.condition.name %> (expires in <%= distance_of_time_in_words_to_now(state.expires_at)%>)</ul>
- <% end %>
- </ul>
- <% else %>
- <p>No boons or banes affect you.</p>
- <% end %>
-</div>
+<div class="grid grid-cols-1 xl:grid-cols-2 my-2">
+ <div class="my-2">
+ <h2 class="text-xl mb-2">Boons & Banes</h2>
+ <% if @character.active_states.any? %>
+ <ul>
+ <% @character.active_states.each do |state| %>
+ <ul><%= state.condition.name %> (expires in <%= distance_of_time_in_words_to_now(state.expires_at)%>)</ul>
+ <% end %>
+ </ul>
+ <% else %>
+ <p>No boons or banes affect you.</p>
+ <% end %>
+ </div>
+ <div class="my-2">
+ <% if @character == current_char %>
+ <h2 class="text-xl mb-2">Combat Styles</h2>
+ <%= 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 %>
- <h2 class="text-xl mb-4">Combat Styles</h2>
- <%= 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 %>
+ </div>
+</div>
- <%= f.submit "Set" %>
- <% end %>
-<% end %>
<div class="my-6">
- <h2 class="text-xl mb-4">Combat Statistics</h2>
- <table class="table-auto">
- <tbody>
- <tr>
- <th class="table-cell-padded text-right">Wounds</th>
- <td class="table-cell-padded"><%= @character.wounds %> / <%= @character.max_wounds %></td>
- </tr>
- <tr>
- <th class="table-cell-padded text-right">Max HP</th>
- <td class="table-cell-padded"><%= @character.max_hp %></td>
- </tr>
- <tr>
- <th class="table-cell-padded text-right">Speed</th>
- <td class="table-cell-padded"><%= @character.speed %></td>
- </tr>
- <tr>
- <th class="table-cell-padded text-right">Accuracy</th>
- <td class="table-cell-padded"><%= @character.accuracy(with_combat_style: true) %></td>
- </tr>
- <tr>
- <th class="table-cell-padded text-right">Power</th>
- <td class="table-cell-padded"><%= @character.power(with_combat_style: true) %></td>
- </tr>
- <tr>
- <th class="table-cell-padded text-right">Evasion</th>
- <td class="table-cell-padded"><%= @character.evasion(with_combat_style: true) %></td>
- </tr>
- <tr>
- <th class="table-cell-padded text-right">Block</th>
- <td class="table-cell-padded"><%= @character.block(with_combat_style: true) %></td>
- </tr>
- <tr>
- <th class="table-cell-padded text-right">Block Value</th>
- <td class="table-cell-padded"><%= @character.block_value %></td>
- </tr>
- </tbody>
- </table>
+ <div class="grid grid-cols-1 xl:grid-cols-2">
+ <div class="my-2">
+ <h2 class="text-xl mb-2">Combat Statistics</h2>
+ <table class="table-auto">
+ <tbody>
+ <tr>
+ <th class="table-cell-padded text-right">Wounds</th>
+ <td class="table-cell-padded"><%= @character.wounds %> / <%= @character.max_wounds %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Max HP</th>
+ <td class="table-cell-padded"><%= @character.max_hp %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Speed</th>
+ <td class="table-cell-padded"><%= @character.speed %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Accuracy</th>
+ <td class="table-cell-padded"><%= @character.accuracy(with_combat_style: true) %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Power</th>
+ <td class="table-cell-padded"><%= @character.power(with_combat_style: true) %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Evasion</th>
+ <td class="table-cell-padded"><%= @character.evasion(with_combat_style: true) %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Block</th>
+ <td class="table-cell-padded"><%= @character.block(with_combat_style: true) %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Block Value</th>
+ <td class="table-cell-padded"><%= @character.block_value %></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div>
+ <h2 class="text-xl mb-2">Resistances</h2>
+ <div class="my-2 grid grid-cols-2">
+ <div class="my-2">
+ <table class="table-auto">
+ <tbody>
+ <tr>
+ <th class="table-cell-padded text-right">Slash</th>
+ <td class="table-cell-padded"><%= @character.resistance("slash")%></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Pierce</th>
+ <td class="table-cell-padded"><%= @character.resistance("pierce") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Bash</th>
+ <td class="table-cell-padded"><%= @character.resistance("bash") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Arcane</th>
+ <td class="table-cell-padded"><%= @character.resistance("arcane") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Fire</th>
+ <td class="table-cell-padded"><%= @character.resistance("fire") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Frost</th>
+ <td class="table-cell-padded"><%= @character.resistance("frost") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Lightning</th>
+ <td class="table-cell-padded"><%= @character.resistance("lightning") %></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div class="my-2">
+ <table class="table-auto">
+ <tbody>
+ <tr>
+ <th class="table-cell-padded text-right">Acid</th>
+ <td class="table-cell-padded"><%= @character.resistance("acid") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Thunder</th>
+ <td class="table-cell-padded"><%= @character.resistance("thunder")%></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Radiant</th>
+ <td class="table-cell-padded"><%= @character.resistance("radiant") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Necrotic</th>
+ <td class="table-cell-padded"><%= @character.resistance("necrotic") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Poison</th>
+ <td class="table-cell-padded"><%= @character.resistance("poison") %></td>
+ </tr>
+ <tr>
+ <th class="table-cell-padded text-right">Bleed</th>
+ <td class="table-cell-padded"><%= @character.resistance("bleed") %></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ </div>
</div>
<div class="my-6">