From 97abd6e43824a42c01eebc90b1d89190a27987df Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 20 Jun 2024 12:54:39 -0700 Subject: [PATCH] Add probabilities to Dyeworks items in Item Getting Guide I'm gonna better explain the gacha nature, I'm doing this part first! --- app/helpers/items_helper.rb | 11 +++++++++++ app/models/item.rb | 2 ++ app/models/item/dyeworks.rb | 10 ++++++++++ app/views/items/sources.html.haml | 4 ++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index ac714d7d..b92b5ad6 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -240,6 +240,17 @@ module ItemsHelper {nc_total:, summary:} end + def probability(p) + case p + when 1 + "100%" + when 0 + "0%" + else + "#{p.numerator} in #{p.denominator}" + end + end + private def build_on_pet_types(species, special_color=nil, &block) diff --git a/app/models/item.rb b/app/models/item.rb index 83bdbe34..e6a19bd3 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -17,6 +17,8 @@ class Item < ApplicationRecord has_many :swf_assets, :through => :parent_swf_asset_relationships belongs_to :dyeworks_base_item, class_name: "Item", default: -> { inferred_dyeworks_base_item }, optional: true + has_many :dyeworks_variants, class_name: "Item", + inverse_of: :dyeworks_base_item attr_writer :current_body_id, :owned, :wanted diff --git a/app/models/item/dyeworks.rb b/app/models/item/dyeworks.rb index 5a458580..8d281f58 100644 --- a/app/models/item/dyeworks.rb +++ b/app/models/item/dyeworks.rb @@ -83,6 +83,16 @@ class Item date end + # The probability of getting this item when dyeing the base item. + def dyeworks_odds + return nil unless dyeworks? + + num_variants = dyeworks_base_item.dyeworks_variants.count + raise "Item's Dyeworks base has *no* variants??" if num_variants < 1 + + Rational(1, num_variants) + end + # Infer what base item this Dyeworks item probably relates to, based on # their names. We only use this when a new item is modeled to initialize # the `dyeworks_base_item` relationship in the database; after that, we diff --git a/app/views/items/sources.html.haml b/app/views/items/sources.html.haml index a583cf10..4b2a56b3 100644 --- a/app/views/items/sources.html.haml +++ b/app/views/items/sources.html.haml @@ -70,8 +70,8 @@ - base_item = item.dyeworks_base_item - content_for :subtitle, flush: true do - = link_to base_item.name, base_item, target: "_blank" - + 1 potion + #{link_to base_item.name, base_item, target: "_blank"}, + #{probability item.dyeworks_odds} chance - if item.dyeworks_permanent? %span.dyeworks-timeframe{ title: "This recipe is NOT currently scheduled to be removed " +