From de2cd93ebcacb37af501b46a60d11b25913dfa1f Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 3 Jun 2021 20:16:22 -0400 Subject: New title: Aspirant --- app/controllers/game_controller.rb | 5 +++++ app/models/character_skill.rb | 10 +++++++++- app/views/application/components/text/_title.html.erb | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'app') 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 @@ Beryly <% when "retributor" %> Retributor + <% when "aspirant" %> + Aspirant <% else %> <%= title.name %> <% end %> -- cgit v1.2.3