Add probabilities to Dyeworks items in Item Getting Guide

I'm gonna better explain the gacha nature, I'm doing this part first!
This commit is contained in:
Emi Matchu 2024-06-20 12:54:39 -07:00
parent b6bd539fed
commit 97abd6e438
4 changed files with 25 additions and 2 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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 " +