summaryrefslogtreecommitdiff
path: root/app/models/hearth.rb
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-06-02 22:15:02 -0400
committerDavid Gay <david@davidgay.org>2021-06-02 22:15:02 -0400
commit4c96893a114059dc4e748307c6d046ec1faa778f (patch)
tree10e3af95e7a3749e6bd0d1ab63fffebf5b567258 /app/models/hearth.rb
parent6ec57509c6f1d44fb80a1cb2ae020b8a033dd370 (diff)
Magiculture
Diffstat (limited to 'app/models/hearth.rb')
-rw-r--r--app/models/hearth.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/hearth.rb b/app/models/hearth.rb
index 1bd54a5..ee00c0c 100644
--- a/app/models/hearth.rb
+++ b/app/models/hearth.rb
@@ -2,6 +2,7 @@ class Hearth < ApplicationRecord
belongs_to :character
has_many :built_hearth_amenities
has_many :hearth_amenities, through: :built_hearth_amenities
+ has_many :hearth_plantings
def has_amenity?(hearth_amenity, level = 1)
hearth_amenity = HearthAmenity.find_by_gid(hearth_amenity) if hearth_amenity.is_a? String
@@ -15,4 +16,14 @@ class Hearth < ApplicationRecord
bhi = self.built_hearth_amenities.find_by(hearth_amenity: hearth_amenity)
bhi ? bhi.level : 0
end
+
+ def available_planting_spots
+ character.planting_spots - hearth_plantings.count
+ end
+
+ def ripe_hearth_plantings_of(item)
+ item = Item.find_by_gid(item) if item.is_a? String
+ # TODO: Proper querey instead of loading all into memory.
+ hearth_plantings.all.select { |hp| hp.item == item && hp.ripens_at < Time.now }
+ end
end