summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-06-15 21:52:49 -0400
committerDavid Gay <david@davidgay.org>2021-06-15 21:54:32 -0400
commit637adf2963f174c3e3e3d6cf9efbff314e306f3e (patch)
tree4e4812f66848a751b12adda81f7c500c0a689116
parentf637f622af2d9b891271344ef23402c41419b3fe (diff)
MonsterKills and bestiary view
-rw-r--r--CHANGELOG.md5
-rw-r--r--app/controllers/characters/bestiary_controller.rb12
-rw-r--r--app/lib/activity_processor.rb5
-rw-r--r--app/models/character.rb1
-rw-r--r--app/models/monster_kill.rb7
-rw-r--r--app/views/characters/bestiary/index.html.erb22
-rw-r--r--app/views/characters/show.html.erb1
-rw-r--r--config/routes.rb1
-rw-r--r--db/migrate/20210616014044_create_monster_kills.rb11
-rw-r--r--db/schema.rb14
-rw-r--r--test/fixtures/monster_kills.yml11
-rw-r--r--test/models/monster_kill_test.rb7
12 files changed, 95 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index acc3268..22ebaf8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,9 @@ All notable changes to this project will be documented in this file.
When performing a skill, all omens infixed in that skill have the same chance to fade away.
- Havencast has been implemented. Spells can be cast from a new "Spells" view, accessible with the navigation. Spells
typically require that a certain amount of mana is available. Mana can be made available by infixing certain omens.
+- Characters now each have a bestiary where monster kills are recorded. For leviathans, only the character who actually
+ slays the leviathan by dealing the final damage gets credit for the kill in their bestiary. The bestiary can be viewed
+ via a link on the Character view. (Hopefully) obviously, kills before this release were not counted.
### Activities
- Planequarry XP award changes
@@ -34,7 +37,7 @@ All notable changes to this project will be documented in this file.
- New amenity: binding array (level 1, level 2)
### UI
-- Character skills were moved to their own view, which features a new interface with XP bars.
+- Character skills were moved from the Character view to their own view, which features a new interface with XP bars.
## [0.1.10.3] - 2021-06-14
diff --git a/app/controllers/characters/bestiary_controller.rb b/app/controllers/characters/bestiary_controller.rb
new file mode 100644
index 0000000..7e37d9c
--- /dev/null
+++ b/app/controllers/characters/bestiary_controller.rb
@@ -0,0 +1,12 @@
+class Characters::BestiaryController < ApplicationController
+ before_action :set_character
+
+ def index
+ @monster_kills = @character.monster_kills.all
+ end
+
+ private
+ def set_character
+ @character = Character.find(params[:character_id])
+ end
+end
diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb
index e211db4..79c8f3e 100644
--- a/app/lib/activity_processor.rb
+++ b/app/lib/activity_processor.rb
@@ -323,6 +323,11 @@ class ActivityProcessor
end
else
@results.push({ type: "message", body: "You slew the #{mon.name}." })
+
+ monster_kills = character.monster_kills.find_or_initialize_by(monster: mon)
+ monster_kills.quantity ? monster_kills.quantity += 1 : monster_kills.quantity = 1
+ monster_kills.save
+
if monster_spawn
char.stop_activity
return
diff --git a/app/models/character.rb b/app/models/character.rb
index 0f2c5b3..7f26ad4 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -14,6 +14,7 @@ class Character < ApplicationRecord
has_many :conditions, through: :states
has_many :states
has_many :chat_messages
+ has_many :monster_kills
has_many :bazaar_orders
validates :name, presence: true
# TODO: Make defaults better. This has to allow nil so the `attribute` default works, and I don't like that.
diff --git a/app/models/monster_kill.rb b/app/models/monster_kill.rb
new file mode 100644
index 0000000..4096e8e
--- /dev/null
+++ b/app/models/monster_kill.rb
@@ -0,0 +1,7 @@
+class MonsterKill < ApplicationRecord
+ belongs_to :monster
+ belongs_to :character
+
+ validates :quantity, numericality: { greater_than_or_equal_to: 0, only_integer: true }
+ scope :ordered_by_monster_name, -> { includes(:monster).order("monsters.name") }
+end
diff --git a/app/views/characters/bestiary/index.html.erb b/app/views/characters/bestiary/index.html.erb
new file mode 100644
index 0000000..f7376e9
--- /dev/null
+++ b/app/views/characters/bestiary/index.html.erb
@@ -0,0 +1,22 @@
+<h1 class="text-3xl mb-4">Bestiary</h1>
+
+<% if @monster_kills.any? %>
+ <table class="table-auto">
+ <thead>
+ <tr>
+ <th class="table-header-padded">Monster</th>
+ <th class="table-header-padded">Kills</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @monster_kills.ordered_by_monster_name.each do |mk| %>
+ <tr>
+ <td class="table-cell-padded"><%= mk.monster.name %></td>
+ <td class="table-cell-padded"><%= mk.quantity %></td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+<% else %>
+ <p>You haven't killed any monsters yet.</p>
+<% end %>
diff --git a/app/views/characters/show.html.erb b/app/views/characters/show.html.erb
index 02f2f55..96a87f8 100644
--- a/app/views/characters/show.html.erb
+++ b/app/views/characters/show.html.erb
@@ -5,6 +5,7 @@
<div class="text-lg text-display mb-4">
<ul class="flex flex-row">
<li class="mr-2"><%= link_to "Titles", character_titles_path(@character) %></li>
+ <li class="mr-2"><%= link_to "Bestiary", character_bestiary_path(@character) %></li>
<li class="mr-2"><%= link_to "Rankings", character_rankings_path(@character) %></li>
</ul>
</div>
diff --git a/config/routes.rb b/config/routes.rb
index af608e5..fefd12f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -27,6 +27,7 @@ Rails.application.routes.draw do
post "/combat_styles", to: "characters#set_combat_styles"
scope module: :characters do
get "/rankings", to: "rankings#index"
+ get :bestiary, to: "bestiary#index"
post "/items/unequip/:slot", to: "items#unequip", as: :item_unequip
resources :item_infixes, only: [:create, :destroy]
resources :items, only: [:index] do
diff --git a/db/migrate/20210616014044_create_monster_kills.rb b/db/migrate/20210616014044_create_monster_kills.rb
new file mode 100644
index 0000000..b61908d
--- /dev/null
+++ b/db/migrate/20210616014044_create_monster_kills.rb
@@ -0,0 +1,11 @@
+class CreateMonsterKills < ActiveRecord::Migration[6.1]
+ def change
+ create_table :monster_kills do |t|
+ t.references :monster, null: false, foreign_key: true
+ t.references :character, null: false, foreign_key: true
+ t.bigint :quantity
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f3992ee..6c503fd 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_14_004827) do
+ActiveRecord::Schema.define(version: 2021_06_16_014044) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -207,6 +207,16 @@ ActiveRecord::Schema.define(version: 2021_06_14_004827) do
t.index ["sender_id"], name: "index_messages_on_sender_id"
end
+ create_table "monster_kills", force: :cascade do |t|
+ t.bigint "monster_id", null: false
+ t.bigint "character_id", null: false
+ t.bigint "quantity"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["character_id"], name: "index_monster_kills_on_character_id"
+ t.index ["monster_id"], name: "index_monster_kills_on_monster_id"
+ end
+
create_table "monster_spawn_combats", force: :cascade do |t|
t.bigint "monster_spawn_id", null: false
t.bigint "character_id", null: false
@@ -326,6 +336,8 @@ ActiveRecord::Schema.define(version: 2021_06_14_004827) do
add_foreign_key "learned_activities", "characters"
add_foreign_key "messages", "characters", column: "recipient_id"
add_foreign_key "messages", "characters", column: "sender_id"
+ add_foreign_key "monster_kills", "characters"
+ add_foreign_key "monster_kills", "monsters"
add_foreign_key "monster_spawn_combats", "characters"
add_foreign_key "monster_spawn_combats", "monster_spawns"
add_foreign_key "monster_spawns", "locations"
diff --git a/test/fixtures/monster_kills.yml b/test/fixtures/monster_kills.yml
new file mode 100644
index 0000000..776b079
--- /dev/null
+++ b/test/fixtures/monster_kills.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ monster: one
+ character: one
+ quantity:
+
+two:
+ monster: two
+ character: two
+ quantity:
diff --git a/test/models/monster_kill_test.rb b/test/models/monster_kill_test.rb
new file mode 100644
index 0000000..aef80ac
--- /dev/null
+++ b/test/models/monster_kill_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class MonsterKillTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end