summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/lib/activity_processor.rb4
-rw-r--r--app/models/activity.rb4
-rw-r--r--app/models/character.rb3
4 files changed, 11 insertions, 2 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 607fe6e..52e9baf 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -21,7 +21,7 @@ class ApplicationController < ActionController::Base
if current_char.start_activity(activity, queued_actions: queued_actions)
redirect_to character_path(current_char)
else
- message = "You can't do that. Check the costs and requirements."
+ message = "You can't do that. Check the costs and requirements. Also, you can't do anything that might result in combat if you're at max wounds."
flash[:alert] = message.strip
redirect_back(fallback_location: character_path(current_char))
end
diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb
index b8456c8..e8ca82e 100644
--- a/app/lib/activity_processor.rb
+++ b/app/lib/activity_processor.rb
@@ -25,6 +25,8 @@ class ActivityProcessor
return
end
+ raise TooManyWoundsError if @character.activity.can_result_in_combat? && !@character.can_fight?
+
Character.transaction do
if @character.rested_duration > 0
remaining_rested_duration = @character.rested_duration - @character.rested_duration_to_spend_on_activity
@@ -191,7 +193,7 @@ class ActivityProcessor
rescue TooManyWoundsError
@character.stop_activity
@results.replace([{ type: "error",
- message: "You can't fight in your condition. You'll have to heal a wound." }])
+ message: "In your condition, you can't do anything that might result in combat. You'll have to heal a wound first." }])
rescue MonsterSpawnError
@character.stop_activity
@results.replace([{ type: "error",
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]