diff options
author | David Gay <david@davidgay.org> | 2021-07-14 18:26:20 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-07-14 18:26:35 -0400 |
commit | b43c0a475b29a26e0c425328ee28d8dcfc64bff6 (patch) | |
tree | 2d79d1251b13f2b89f979960bffa6966b4d55028 /app/models | |
parent | b4f643b1ce4613dcd18e71a6f31a84293ac10857 (diff) |
Prevent characters from starting or finishing an activity that might result in combat if the character is at max wounds
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/activity.rb | 4 | ||||
-rw-r--r-- | app/models/character.rb | 3 |
2 files changed, 7 insertions, 0 deletions
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] |