From b8aa0a69cbdc8b145592ac142c397e0520021fdd Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 14 Jul 2021 17:27:26 -0400 Subject: Only allow a character to hunt up to two different leviathans in a 24 hour period --- app/lib/activity_processor.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'app/lib') diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb index d3bf5cb..d14282e 100644 --- a/app/lib/activity_processor.rb +++ b/app/lib/activity_processor.rb @@ -40,14 +40,17 @@ class ActivityProcessor puts "Result: #{result}" handle_xp_result(result) when "monster_spawn" + monster_spawn = MonsterSpawn.where(location: Location.find_by_gid(result[:location])).select(&:alive?).first + raise MonsterSpawnError unless monster_spawn + raise TooManyWoundsError unless @character.can_fight? + unless @character.monster_spawns_attacked_in_past_24_hours.count < 2 || @character.monster_spawns_attacked_in_past_24_hours.include?(monster_spawn) + raise TooManyMonsterSpawnCombatsError + end next if rand > (result[:chance] || 1) @results.push({ type: "br" }) - monster_spawn = MonsterSpawn.where(location: Location.find_by_gid(result[:location])).select(&:alive?).first - raise MonsterSpawnError unless monster_spawn - @results.push({ type: type, monster_spawn: monster_spawn }) resolve_combat_with(monster_spawn) break @@ -186,6 +189,10 @@ class ActivityProcessor @character.stop_activity @results.replace([{ type: "error", message: "There are no living leviathans here." }]) + rescue TooManyMonsterSpawnCombatsError + @character.stop_activity + @results.replace([{ type: "error", + message: "You're too worn out to hunt any more leviathans right now. You can only hunt two different leviathans in a 24 hour period." }]) end private -- cgit v1.2.3