diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/characters/bestiary_controller.rb | 12 | ||||
-rw-r--r-- | app/lib/activity_processor.rb | 5 | ||||
-rw-r--r-- | app/models/character.rb | 1 | ||||
-rw-r--r-- | app/models/monster_kill.rb | 7 | ||||
-rw-r--r-- | app/views/characters/bestiary/index.html.erb | 22 | ||||
-rw-r--r-- | app/views/characters/show.html.erb | 1 |
6 files changed, 48 insertions, 0 deletions
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> |