From aac7563767c5fbc5ef67f4d615833e7523a46df7 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sat, 29 May 2021 17:19:56 -0400 Subject: Conditions and states (boons & banes), with `quarrying_draught` --- app/models/state.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/models/state.rb (limited to 'app/models/state.rb') 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 -- cgit v1.2.3