summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-26 20:57:47 -0400
committerDavid Gay <david@davidgay.org>2021-05-26 20:57:47 -0400
commit8cec9b3f6f277399c6da23a04d8afb0c68cf8a2b (patch)
tree749356642343c8f7ad2e20f7d3d94fe709c26725 /app/models
parent920b9a66eb2d7e7810c16f1d9b70d65a19736487 (diff)
Basic usage of hearth amenities
Diffstat (limited to 'app/models')
-rw-r--r--app/models/built_hearth_amenity.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/built_hearth_amenity.rb b/app/models/built_hearth_amenity.rb
index 5ae8a42..39b6679 100644
--- a/app/models/built_hearth_amenity.rb
+++ b/app/models/built_hearth_amenity.rb
@@ -3,4 +3,29 @@ class BuiltHearthAmenity < ApplicationRecord
belongs_to :hearth_amenity
validates :hearth_id, uniqueness: { scope: :hearth_amenity_id }
+
+ def cooldown
+ # TODO: HACK: Update this so multiple use effects will work
+ self.hearth_amenity.whatnot[:use_effects].first[:cooldown]
+ end
+
+ def usable?
+ self.hearth_amenity.whatnot[:use_effects].present?
+ end
+
+ def on_cooldown?
+ if usable? && cooldown.present?
+ # If it's never been used, it's off cooldown
+ return false unless self.last_used_at
+ seconds_until_cooled_down > 0
+ else
+ false
+ end
+ end
+
+ def seconds_until_cooled_down
+ return nil unless usable?
+ seconds_until_cooled_down = cooldown - (Time.now - self.last_used_at)
+ [0, seconds_until_cooled_down].max
+ end
end