summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-07-14 18:26:20 -0400
committerDavid Gay <david@davidgay.org>2021-07-14 18:26:35 -0400
commitb43c0a475b29a26e0c425328ee28d8dcfc64bff6 (patch)
tree2d79d1251b13f2b89f979960bffa6966b4d55028
parentb4f643b1ce4613dcd18e71a6f31a84293ac10857 (diff)
Prevent characters from starting or finishing an activity that might result in combat if the character is at max wounds
-rw-r--r--CHANGELOG.md4
-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
5 files changed, 14 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54b0d04..8ad564c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ All notable changes to this project will be documented in this file.
- Added message output when you would learn how to do a new activity (e.g. cast a new spell), but you already know how
how to do it.
- Fixed bug where multiple activities could be learned at once (e.g. multiple spells from one spellpage).
+- Characters can no longer start or finish an activity if the character is at max wounds and the activity might result
+ in combat. This means that you can no longer start a timer that won't finish due to being at max wounds.
### Monsters
- New monster: sulfur scuttler
@@ -24,7 +26,7 @@ All notable changes to this project will be documented in this file.
- Hearths now have locations, like characters do. All existing hearths are now located at Floret.
### Web
-- Favicon added (contributed by mattagarr)
+- Favicon added (contributed by mattagarr).
### Engine
- Some improvements/tweaks.
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]