From b43c0a475b29a26e0c425328ee28d8dcfc64bff6 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 14 Jul 2021 18:26:20 -0400 Subject: Prevent characters from starting or finishing an activity that might result in combat if the character is at max wounds --- app/models/activity.rb | 4 ++++ app/models/character.rb | 3 +++ 2 files changed, 7 insertions(+) (limited to 'app/models') diff --git a/app/models/activity.rb b/app/models/activity.rb index 9910295..d66b758 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -5,4 +5,8 @@ class Activity < ApplicationRecord validates :gid, :name, :description, presence: true attribute :innate, :boolean, default: true + + def can_result_in_combat? + self.whatnot[:results].select { |r| %w[monster monster_spawn].include?(r[:type]) }.any? + end end diff --git a/app/models/character.rb b/app/models/character.rb index b3d8c25..4fd524b 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -279,6 +279,9 @@ class Character < ApplicationRecord def can_do_activity?(activity, ignore_cost: false, ignore_requirements: false) return false unless activity.innate? || self.learned_activities.exists?(activity: activity) + + return false if activity.can_result_in_combat? && !can_fight? + unless ignore_cost activity.whatnot[:cost]&.each do |cost| case cost[:type] -- cgit v1.2.3