diff options
author | David Gay <david@davidgay.org> | 2021-06-03 20:16:22 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-06-03 20:16:22 -0400 |
commit | de2cd93ebcacb37af501b46a60d11b25913dfa1f (patch) | |
tree | c4eeb36baa38af63b0d180b9aefc768cd4377229 /app | |
parent | 94418789939af680ed72bf31c62762046da33dfd (diff) |
New title: Aspirant
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/game_controller.rb | 5 | ||||
-rw-r--r-- | app/models/character_skill.rb | 10 | ||||
-rw-r--r-- | app/views/application/components/text/_title.html.erb | 2 |
3 files changed, 16 insertions, 1 deletions
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index c506aa6..f8b9973 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -179,6 +179,11 @@ class GameController < ApplicationController unless @results.any? @results.push({ type: "message", body: "You come up empty." }) end + + # HACK: To display any titles that were gained indirectly (not as part of the activity results). + current_char.title_awards.where(created_at: 5.seconds.ago..).each do |title_award| + @results.push({ type: "title", title: title_award.title }) + end end rescue ItemQuantityError current_char.stop_activity diff --git a/app/models/character_skill.rb b/app/models/character_skill.rb index 722a371..84c538e 100644 --- a/app/models/character_skill.rb +++ b/app/models/character_skill.rb @@ -4,7 +4,7 @@ class CharacterSkill < ApplicationRecord validates :skill_id, uniqueness: { scope: :character_id } validates :xp, numericality: { greater_than_or_equal_to: 0, only_integer: true } - before_update :send_chat_message_if_leveled_up + before_update :send_chat_message_if_leveled_up, :award_titles scope :ordered_by_skill_name, -> { includes(:skill).order("skills.name") } @@ -72,4 +72,12 @@ class CharacterSkill < ApplicationRecord end end end + + def award_titles + if CharacterSkill.level_for_xp(self.xp_was) < CharacterSkill.level_for_xp(xp) + if character.character_skills.to_a.sum(&:level) >= 100 + character.award_title("aspirant") + end + end + end end diff --git a/app/views/application/components/text/_title.html.erb b/app/views/application/components/text/_title.html.erb index ea00777..2576ff8 100644 --- a/app/views/application/components/text/_title.html.erb +++ b/app/views/application/components/text/_title.html.erb @@ -6,6 +6,8 @@ <span class="text-yellow-400">Beryly</span> <% when "retributor" %> <span class="text-gray-500">Retribut</span><span class="text-yellow-200">o</span><span class="text-gray-500">r</span> + <% when "aspirant" %> + <span class="text-purple-200">Aspirant</span> <% else %> <%= title.name %> <% end %> |