summaryrefslogtreecommitdiff
path: root/app/models/state.rb
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-29 17:19:56 -0400
committerDavid Gay <david@davidgay.org>2021-05-29 17:19:56 -0400
commitaac7563767c5fbc5ef67f4d615833e7523a46df7 (patch)
tree807e708c32d6d8710bcc1b6f96862ed34b320072 /app/models/state.rb
parent8f9dcbf33d5cd3222e4d8e0cfa6f72b1596b917c (diff)
Conditions and states (boons & banes), with `quarrying_draught`
Diffstat (limited to 'app/models/state.rb')
-rw-r--r--app/models/state.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/models/state.rb b/app/models/state.rb
new file mode 100644
index 0000000..27c8741
--- /dev/null
+++ b/app/models/state.rb
@@ -0,0 +1,23 @@
+class State < ApplicationRecord
+ belongs_to :character
+ belongs_to :condition
+
+ after_create :destroy_duplicates
+
+ def expired?
+ self.expires_at < Time.now
+ end
+
+ def remaining_duration
+ (self.expires_at - Time.now).to_i
+ end
+
+ def effects
+ self.condition.whatnot[:effects]
+ end
+
+ private
+ def destroy_duplicates
+ self.character.states.where(condition: self.condition).where.not(id: self.id).destroy_all
+ end
+end