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/models | |
parent | 94418789939af680ed72bf31c62762046da33dfd (diff) |
New title: Aspirant
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character_skill.rb | 10 |
1 files changed, 9 insertions, 1 deletions
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 |