summaryrefslogtreecommitdiff
path: root/app/models/monster_spawn.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/monster_spawn.rb')
-rw-r--r--app/models/monster_spawn.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/monster_spawn.rb b/app/models/monster_spawn.rb
index 5162cc6..42db98a 100644
--- a/app/models/monster_spawn.rb
+++ b/app/models/monster_spawn.rb
@@ -7,6 +7,7 @@ class MonsterSpawn < ApplicationRecord
after_create :send_chat_message
validates :starting_hp, presence: true, numericality: { greater_than_or_equal_to: 1, only_integer: true }
+ validate :one_living_leviathan_per_location, on: :create
def alive?
self.remaining_hp > 0
@@ -28,4 +29,11 @@ class MonsterSpawn < ApplicationRecord
ChatRoomChannel.broadcast_chat_message(chat_message)
end
end
+
+ def one_living_leviathan_per_location
+ # TODO: Don't load into memory
+ if location.monster_spawns.find { |ms| ms.alive? && ms != self }
+ errors.add(:chat, "A location can only have one monster spawn at a time.")
+ end
+ end
end