summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-07-14 17:27:26 -0400
committerDavid Gay <david@davidgay.org>2021-07-14 17:27:26 -0400
commitb8aa0a69cbdc8b145592ac142c397e0520021fdd (patch)
tree3dc60a2d516fd04729cddb301e3b1ec3639e4603 /app/models
parentf02a38cfc1a38a0c1fdc4d00cc10f47bb987b7d0 (diff)
Only allow a character to hunt up to two different leviathans in a 24 hour period
Diffstat (limited to 'app/models')
-rw-r--r--app/models/character.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb
index f6ddb92..b3d8c25 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -16,6 +16,7 @@ class Character < ApplicationRecord
has_many :states
has_many :chat_messages
has_many :monster_kills
+ has_many :monster_spawn_combats
has_many :bazaar_orders
validates :name, presence: true
# TODO: Make defaults better. This has to allow nil so the `attribute` default works, and I don't like that.
@@ -459,6 +460,11 @@ class Character < ApplicationRecord
base
end
+ def monster_spawns_attacked_in_past_24_hours
+ # TODO: Don't load into memory
+ monster_spawn_combats.where(created_at: 24.hours.ago..).map { |msc| msc.monster_spawn }.uniq
+ end
+
private
def create_skills
Skill.all.each { |skill| self.character_skills.create(skill: skill, xp: 0) }