From 94418789939af680ed72bf31c62762046da33dfd Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 3 Jun 2021 19:58:16 -0400 Subject: Only allow one drink condition, too --- CHANGELOG.md | 2 ++ app/models/state.rb | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea00707..b15c280 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ amenities, etc that are added unless they are special in some way. ### Added - Spicework has been implemented. You can now craft food and drugs in your hearth, once you build a spicebench. + A character can only have one food condition and one drink condition at a time. If a second food or drink condition + is gained, the old one is lost. There is no limit to the number of drug conditions a character can have at once. - New hearth amenities: spicebench level 1, spicebench level 2 - New items: bluster powder, mudtub mash, midoras spice, midoras mudtub mash diff --git a/app/models/state.rb b/app/models/state.rb index 29b3f42..52767e7 100644 --- a/app/models/state.rb +++ b/app/models/state.rb @@ -21,10 +21,12 @@ class State < ApplicationRecord # Don't allow duplicate conditions; just destroy the old one. character.states.where(condition: condition).where.not(id: id).destroy_all - # Only allow one food condition. Destroy the old one. - if condition.tags.include?("food") - character.states.each do |state| - state.destroy if state.id != id && state.condition.tags.include?("food") + # Only allow one food condition and one drink condition. Destroy any old ones. + %w[food drink].each do |tag| + if condition.tags.include?(tag) + character.states.each do |state| + state.destroy if state.id != id && state.condition.tags.include?(tag) + end end end end -- cgit v1.2.3