From d349eaa9ce4700f5c71f7266dbbaaceade9dd7c1 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sun, 13 Jun 2021 22:18:43 -0400 Subject: Move skills to their own page, with a new interface and XP bars --- app/models/character_skill.rb | 16 ++- app/views/application/_navbar.html.erb | 3 + app/views/characters/show.html.erb | 25 ---- app/views/characters/skills/index.html.erb | 190 +++-------------------------- 4 files changed, 33 insertions(+), 201 deletions(-) (limited to 'app') diff --git a/app/models/character_skill.rb b/app/models/character_skill.rb index 368cc28..406cade 100644 --- a/app/models/character_skill.rb +++ b/app/models/character_skill.rb @@ -39,6 +39,10 @@ class CharacterSkill < ApplicationRecord end end + def self.xp_required_for_level(level) + level <= 120 ? XP_TOTALS_PER_LEVEL[level - 1] : nil + end + def level XP_TOTALS_PER_LEVEL.each_with_index do |total, index| return index if total > self.xp @@ -46,7 +50,7 @@ class CharacterSkill < ApplicationRecord end def total_xp_for_next_level - xp_required_for_level(level + 1) + CharacterSkill.xp_required_for_level(level + 1) end def xp_to_next_level @@ -57,11 +61,13 @@ class CharacterSkill < ApplicationRecord CharacterSkill.top_xp_for(self.skill, limit: nil).map(&:character).map(&:id).index(self.character.id) + 1 end - private - def xp_required_for_level(level) - level <= 120 ? XP_TOTALS_PER_LEVEL[level - 1] : nil - end + def percentage_of_skill_level_completed + xp_gained_this_level = xp - CharacterSkill.xp_required_for_level(level) + total_xp_gain_neeeded_for_entire_level = total_xp_for_next_level - CharacterSkill.xp_required_for_level(level) + (xp_gained_this_level.to_f / total_xp_gain_neeeded_for_entire_level) * 100 + end + private def send_chat_message_if_leveled_up if CharacterSkill.level_for_xp(self.xp_was) < CharacterSkill.level_for_xp(self.xp) chat_message = ChatMessage.new(body: "reached #{self.skill.name} level #{self.level}!", diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb index be2d9f2..3436619 100644 --- a/app/views/application/_navbar.html.erb +++ b/app/views/application/_navbar.html.erb @@ -6,6 +6,9 @@
  • <%= link_to "Character", character_path(current_char) %>
  • +
  • + <%= link_to "Skills", character_skills_path(current_char) %> +
  • <%= link_to "Inventory", character_items_path(current_char) %>
  • diff --git a/app/views/characters/show.html.erb b/app/views/characters/show.html.erb index a7b7c0e..02f2f55 100644 --- a/app/views/characters/show.html.erb +++ b/app/views/characters/show.html.erb @@ -149,31 +149,6 @@ -
    -

    Skills

    - - - - - - - - - - - - <% @character.character_skills.ordered_by_skill_name.each do |cs| %> - - - - - - - <% end %> - -
    SkillLevelXPTNLTotal XP
    <%= cs.skill.name %><%= cs.level %><%= cs.xp_to_next_level %><%= cs.xp %>
    -
    - <% if @character == current_char %> <%= link_to "Manage account", edit_user_registration_path, class: "text-sm" %> <% end %> diff --git a/app/views/characters/skills/index.html.erb b/app/views/characters/skills/index.html.erb index f13e611..fd53870 100644 --- a/app/views/characters/skills/index.html.erb +++ b/app/views/characters/skills/index.html.erb @@ -1,176 +1,24 @@ -

    Skills

    -
    - -
    - -

    First entered the planes - <%= pluralize((Date.current - @character.created_at.to_date).to_i, "day") %> ago.

    - -

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

    - -
    -
    -

    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 %> - - <%= f.label :defensive_style, "Defensive" %> - <%= f.select :defensive_style, Character.defensive_styles.keys.to_a, selected: @character.defensive_style %> - - <%= 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) %>
    -
    -
    -

    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") %>
    +

    Skills

    +
    + <% @character.character_skills.ordered_by_skill_name.each do |cs| %> +
    +
    +
    +
    + <%= cs.skill.name %> +
    +
    + XP<%= cs.xp %> +
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Acid<%= @character.resistance("acid") %>
    Thunder<%= @character.resistance("thunder")%>
    Radiant<%= @character.resistance("radiant") %>
    Necrotic<%= @character.resistance("necrotic") %>
    Poison<%= @character.resistance("poison") %>
    Bleed<%= @character.resistance("bleed") %>
    +
    + <%= cs.level %> +
    +
    +
    +
    -
    -
    - -
    -

    Skills

    - - - - - - - - - - - - <% @character.character_skills.ordered_by_skill_name.each do |cs| %> - - - - - - - <% end %> - -
    SkillLevelXPTNLTotal XP
    <%= cs.skill.name %><%= cs.level %><%= cs.xp_to_next_level %><%= cs.xp %>
    + <% end %>
    - -<% if @character == current_char %> - <%= link_to "Manage account", edit_user_registration_path, class: "text-sm" %> -<% end %> -- cgit v1.2.3