diff options
author | David Gay <david@davidgay.org> | 2021-05-25 20:44:53 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-25 20:48:00 -0400 |
commit | 3f079ef8a7d46d5a4864836dbbd9e37b900c0a59 (patch) | |
tree | 612089e06320cdbba5bdd5ff99b10826a1ee4519 | |
parent | 7c191c15e3a16c5c4c53f6d83c89fe6d1219b6e5 (diff) |
Award title for mining a yellow beryl
-rw-r--r-- | app/controllers/game_controller.rb | 7 | ||||
-rw-r--r-- | app/models/character.rb | 7 | ||||
-rw-r--r-- | app/views/activities/_results.html.erb | 2 | ||||
-rw-r--r-- | app/views/application/components/text/_title.html.erb | 2 | ||||
-rw-r--r-- | data/activities.yml | 2 | ||||
-rw-r--r-- | data/titles.yml | 2 |
6 files changed, 22 insertions, 0 deletions
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 4b96b49..8c1acaf 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -57,6 +57,13 @@ class GameController < ApplicationController if table_roll >= score give_item_with_xp(table_entry, quantity) + + table_entry[:titles]&.each do |title_data| + title = Title.find_by_gid(title_data[:gid]) + if current_char.award_title(title) + @results.push({ type: "title", title: title }) + end + end break end end diff --git a/app/models/character.rb b/app/models/character.rb index 970ede1..92e84c7 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -150,6 +150,13 @@ class Character < ApplicationRecord self.update(activity: nil, activity_started_at: nil, queued_actions: nil) end + def award_title(title) + title = Title.find_by_gid(title) if title.is_a? String + # TODO: Simplify these lines? + return false if self.title_awards.exists?(title: title) + self.title_awards.create(title: title) + end + def equipment_stats stats = {} self.equipment.each do |eq| diff --git a/app/views/activities/_results.html.erb b/app/views/activities/_results.html.erb index e0e54cc..49de2d5 100644 --- a/app/views/activities/_results.html.erb +++ b/app/views/activities/_results.html.erb @@ -16,6 +16,8 @@ <p class="text-xs italic"><%= result[:monster].description %></p> <% when "xp" %> <p class="text-xs">You gained <%= result[:xp] %> <%= result[:skill].name %> XP.</p> + <% when "title" %> + <p>You earned the title <%= render "application/components/text/title", title: result[:title] %>!</p> <% when "message" %> <p><%= result[:body] %></p> <% when "error" %> diff --git a/app/views/application/components/text/_title.html.erb b/app/views/application/components/text/_title.html.erb index 1cf13b7..edcf220 100644 --- a/app/views/application/components/text/_title.html.erb +++ b/app/views/application/components/text/_title.html.erb @@ -2,6 +2,8 @@ <% case title.gid %> <% when "steward" %> <span class="text-gray-200">Steward</span> + <% when "beryly" %> + <span class="text-yellow-400">Beryly</span> <% else %> <%= title.name %> <% end %> diff --git a/data/activities.yml b/data/activities.yml index c169c0f..f455017 100644 --- a/data/activities.yml +++ b/data/activities.yml @@ -213,6 +213,8 @@ quarry_floret_mines: xp: - gid: "planequarry" value: 50 + titles: + - gid: "beryly" - gid: "paraiba_tourmaline" score: 0.95 xp: diff --git a/data/titles.yml b/data/titles.yml index e5dc758..8b608be 100644 --- a/data/titles.yml +++ b/data/titles.yml @@ -1,2 +1,4 @@ steward: name: "Steward" +beryly: + name: "Beryly" |