diff options
-rw-r--r-- | CHANGELOG.md | 12 | ||||
-rw-r--r-- | app/lib/activity_processor.rb | 8 | ||||
-rw-r--r-- | app/models/monster_spawn.rb | 8 | ||||
-rw-r--r-- | app/views/look/look.html.erb | 1 |
4 files changed, 27 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e1cb47..857543e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Skills +- Worldcall has been implemented. + - New spells: Hearth Passage, Project Thought + +### Leviathans +- A location can now only have one living leviathan at a time. + +### Hearth +- Hearths now have locations, like characters do. All existing hearths are now located at Floret. + +### Engine +- Some improvements/tweaks. ## [0.1.13.3] - 2021-07-08 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 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 diff --git a/app/views/look/look.html.erb b/app/views/look/look.html.erb index 8b41e0f..ef0f6c4 100644 --- a/app/views/look/look.html.erb +++ b/app/views/look/look.html.erb @@ -3,6 +3,7 @@ <p class="italic"><%= @location.description %></p> </div> +<%# TODO: Don't load into memory %> <% @location.monster_spawns.select(&:alive?).each do |ms| %> <p class="text-yellow-400">A <%= ms.monster.name %> is ravaging this location! (<%= ms.remaining_hp %> HP)</p> <% activity = Activity.find_by_gid("beastslay_leviathan_#{@location.gid}") %> |