summaryrefslogtreecommitdiff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/activity_processor.rb26
1 files changed, 23 insertions, 3 deletions
diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb
index 72aa85d..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
@@ -111,6 +114,19 @@ class ActivityProcessor
end
end
end
+ when "hearth_location"
+ location = @character.hearth&.location || Location.find_by_gid("floret")
+ @character.update(location: location)
+ @results.push({ type: type, location: location })
+ when "create_monster_spawn"
+ next if rand > (result[:chance] || 1)
+ monster = Monster.find_by_gid(result[:gid])
+ monster_spawn = MonsterSpawn.new(monster: monster, location: @character.location)
+ if monster_spawn.save
+ @results.push({ type: type, monster: monster })
+ else
+ @results.push({ type: "message", body: "A leviathan did not appear since there is already a leviathan at #{@character.location.name}." })
+ end
else
raise "Invalid result type (#{type})" # TODO: Improve this.
end
@@ -173,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