summaryrefslogtreecommitdiff
path: root/app/models/monster_kill.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/monster_kill.rb')
-rw-r--r--app/models/monster_kill.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/models/monster_kill.rb b/app/models/monster_kill.rb
new file mode 100644
index 0000000..24519b1
--- /dev/null
+++ b/app/models/monster_kill.rb
@@ -0,0 +1,22 @@
+class MonsterKill < ApplicationRecord
+ belongs_to :monster
+ belongs_to :character
+
+ 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