blob: 4423557f34af9bc11bfbf40cbc0c0b4ec1cf7e84 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
class MonsterSpawn < ApplicationRecord
belongs_to :monster
belongs_to :location
has_many :monster_spawn_combats
after_create :send_chat_message
def alive?
self.remaining_hp > 0
end
def remaining_hp
self.monster.max_hp - MonsterSpawnCombat.where(monster_spawn: self).sum(:hp_lost)
end
private
def send_chat_message
chat_message = ChatMessage.new(body: "A leviathan has appeared in #{location.name}!",
chat_room: ChatRoom.find_by_gid("news"))
if chat_message.save
ChatRoomChannel.broadcast_chat_message(chat_message)
end
end
end
|