From f02a38cfc1a38a0c1fdc4d00cc10f47bb987b7d0 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 14 Jul 2021 17:08:56 -0400 Subject: Only allow one living monster_spawn per location --- app/lib/activity_processor.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app/lib') diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb index 4ba3609..d3bf5cb 100644 --- a/app/lib/activity_processor.rb +++ b/app/lib/activity_processor.rb @@ -118,8 +118,12 @@ class ActivityProcessor when "create_monster_spawn" next if rand > (result[:chance] || 1) monster = Monster.find_by_gid(result[:gid]) - MonsterSpawn.create(monster: monster, location: @character.location) - @results.push({ type: type, monster: monster }) + 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 -- cgit v1.2.3