diff options
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | app/models/monster_spawn.rb | 9 | ||||
-rw-r--r-- | db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb | 8 | ||||
-rw-r--r-- | db/schema.rb | 3 |
4 files changed, 22 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 89647d1..4480d77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ All notable changes to this project will be documented in this file. equal to your beastslay level divided by 5, rounded up. - Equipment break check now occurs immediately once a combatant has been reduced to zero HP or less. Previously the break check could be skipped under certain conditons where the combat loop ended early. + +### Leviathans +- Leviathan starting HP is now set when the leviathan spawns. Before, it just checked the monster's max HP. This means + that if max HP was increased by a patch, the leviathan could become alive again. This is what happened this morning. ### Monsters - Stalk beast diff --git a/app/models/monster_spawn.rb b/app/models/monster_spawn.rb index 4423557..5162cc6 100644 --- a/app/models/monster_spawn.rb +++ b/app/models/monster_spawn.rb @@ -3,17 +3,24 @@ class MonsterSpawn < ApplicationRecord belongs_to :location has_many :monster_spawn_combats + after_initialize :set_starting_hp after_create :send_chat_message + validates :starting_hp, presence: true, numericality: { greater_than_or_equal_to: 1, only_integer: true } + def alive? self.remaining_hp > 0 end def remaining_hp - self.monster.max_hp - MonsterSpawnCombat.where(monster_spawn: self).sum(:hp_lost) + self.starting_hp - MonsterSpawnCombat.where(monster_spawn: self).sum(:hp_lost) end private + def set_starting_hp + self.starting_hp = monster.max_hp + end + def send_chat_message chat_message = ChatMessage.new(body: "A leviathan has appeared in #{location.name}!", chat_room: ChatRoom.find_by_gid("news")) diff --git a/db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb b/db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb new file mode 100644 index 0000000..4b89120 --- /dev/null +++ b/db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb @@ -0,0 +1,8 @@ +class AddStartingHpToMonsterSpawns < ActiveRecord::Migration[6.1] + def change + add_column :monster_spawns, :starting_hp, :integer + MonsterSpawn.all.each do |ms| + ms.update(starting_hp: ms.monster.max_hp) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e34c95..9e062cb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_06_06_215818) do +ActiveRecord::Schema.define(version: 2021_06_08_001838) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -211,6 +211,7 @@ ActiveRecord::Schema.define(version: 2021_06_06_215818) do t.bigint "location_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.integer "starting_hp" t.index ["location_id"], name: "index_monster_spawns_on_location_id" t.index ["monster_id"], name: "index_monster_spawns_on_monster_id" end |