From 23d07f8badb2b2ce8139ee421157a96fb61455dc Mon Sep 17 00:00:00 2001 From: David Gay Date: Tue, 15 Jun 2021 22:30:47 -0400 Subject: Add 7 new titles, awarded for MonsterKill quantity --- app/models/monster_kill.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app/models') diff --git a/app/models/monster_kill.rb b/app/models/monster_kill.rb index 4096e8e..24519b1 100644 --- a/app/models/monster_kill.rb +++ b/app/models/monster_kill.rb @@ -4,4 +4,19 @@ class MonsterKill < ApplicationRecord validates :quantity, numericality: { greater_than_or_equal_to: 0, only_integer: true } scope :ordered_by_monster_name, -> { includes(:monster).order("monsters.name") } + + after_save :award_titles + + private + def award_titles + character.award_title("spiteful") if quantity >= 1000 + character.award_title("hateful") if quantity >= 10_000 + character.award_title("vicious") if quantity >= 100_000 + + all_kills_quantity = character.monster_kills.sum(:quantity) + character.award_title("slayer") if all_kills_quantity >= 1_000 + character.award_title("butcher") if all_kills_quantity >= 10_000 + character.award_title("slaughterer") if all_kills_quantity >= 100_000 + character.award_title("massacrer") if all_kills_quantity >= 1_000_000 + end end -- cgit v1.2.3