Merge branch 'main' into simpler-item-previews
This commit is contained in:
commit
e0f9a27adc
2 changed files with 3 additions and 59 deletions
|
@ -25,8 +25,6 @@ class Item < ApplicationRecord
|
||||||
|
|
||||||
NCRarities = [0, 500]
|
NCRarities = [0, 500]
|
||||||
PAINTBRUSH_SET_DESCRIPTION = 'This item is part of a deluxe paint brush set!'
|
PAINTBRUSH_SET_DESCRIPTION = 'This item is part of a deluxe paint brush set!'
|
||||||
SPECIAL_COLOR_DESCRIPTION_REGEX =
|
|
||||||
/This item is only wearable by [a-zA-Z]+ painted ([a-zA-Z]+)\.|WARNING: This [a-zA-Z]+ can be worn by ([a-zA-Z]+) [a-zA-Z]+ ONLY!|If your Neopet is not painted ([a-zA-Z]+), it will not be able to wear this item\./
|
|
||||||
|
|
||||||
scope :newest, -> {
|
scope :newest, -> {
|
||||||
order(arel_table[:created_at].desc) if arel_table[:created_at]
|
order(arel_table[:created_at].desc) if arel_table[:created_at]
|
||||||
|
@ -292,55 +290,6 @@ class Item < ApplicationRecord
|
||||||
restricted_zones + occupied_zones
|
restricted_zones + occupied_zones
|
||||||
end
|
end
|
||||||
|
|
||||||
def special_color
|
|
||||||
@special_color ||= determine_special_color
|
|
||||||
end
|
|
||||||
|
|
||||||
def special_color_id
|
|
||||||
special_color.try(:id)
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
def determine_special_color
|
|
||||||
I18n.with_locale(I18n.default_locale) do
|
|
||||||
# Rather than go find the special description in all locales, let's just
|
|
||||||
# run this logic in English.
|
|
||||||
if description.include?(PAINTBRUSH_SET_DESCRIPTION)
|
|
||||||
name_words = name.downcase.split
|
|
||||||
Color.nonstandard.each do |color|
|
|
||||||
return color if name_words.include?(color.name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
match = description.match(SPECIAL_COLOR_DESCRIPTION_REGEX)
|
|
||||||
if match
|
|
||||||
# Since there are multiple formats in the one regex, there are multiple
|
|
||||||
# possible color name captures. So, take the first non-nil capture.
|
|
||||||
color = match.captures.detect(&:present?)
|
|
||||||
return Color.find_by_name(color.downcase)
|
|
||||||
end
|
|
||||||
|
|
||||||
# HACK: this should probably be a flag on the record instead of
|
|
||||||
# being hardcoded :P
|
|
||||||
if [71893, 76192, 76202, 77367, 77368, 77369, 77370].include?(id)
|
|
||||||
return Color.find_by_name('baby')
|
|
||||||
end
|
|
||||||
|
|
||||||
if [76198].include?(id)
|
|
||||||
return Color.find_by_name('mutant')
|
|
||||||
end
|
|
||||||
|
|
||||||
if [75372].include?(id)
|
|
||||||
return Color.find_by_name('maraquan')
|
|
||||||
end
|
|
||||||
|
|
||||||
if manual_special_color_id?
|
|
||||||
return Color.find(manual_special_color_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
public
|
|
||||||
|
|
||||||
def species_support_ids
|
def species_support_ids
|
||||||
@species_support_ids_array ||= read_attribute('species_support_ids').split(',').map(&:to_i) rescue nil
|
@species_support_ids_array ||= read_attribute('species_support_ids').split(',').map(&:to_i) rescue nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,7 @@ class PetType < ApplicationRecord
|
||||||
|
|
||||||
BasicHashes = YAML::load_file(Rails.root.join('config', 'basic_type_hashes.yml'))
|
BasicHashes = YAML::load_file(Rails.root.join('config', 'basic_type_hashes.yml'))
|
||||||
|
|
||||||
|
scope :basic, -> { joins(:color).merge(Color.basic) }
|
||||||
scope :matching_name, ->(color_name, species_name) {
|
scope :matching_name, ->(color_name, species_name) {
|
||||||
color = Color.find_by_name!(color_name)
|
color = Color.find_by_name!(color_name)
|
||||||
species = Species.find_by_name!(species_name)
|
species = Species.find_by_name!(species_name)
|
||||||
|
@ -28,17 +29,11 @@ class PetType < ApplicationRecord
|
||||||
merge(Color.order(basic: :desc, standard: :desc, name: :asc))
|
merge(Color.order(basic: :desc, standard: :desc, name: :asc))
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.special_color_or_basic(special_color)
|
|
||||||
color_ids = special_color ? [special_color.id] : Color.basic.select([:id]).map(&:id)
|
|
||||||
where(color_id: color_ids)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.random_basic_per_species(species_ids)
|
def self.random_basic_per_species(species_ids)
|
||||||
random_pet_types = []
|
random_pet_types = []
|
||||||
# TODO: omg so lame :P
|
basics_by_species_id = basic.group_by(&:species_id)
|
||||||
standards = special_color_or_basic(nil).group_by(&:species_id)
|
|
||||||
species_ids.each do |species_id|
|
species_ids.each do |species_id|
|
||||||
pet_types = standards[species_id]
|
pet_types = basics_by_species_id[species_id]
|
||||||
random_pet_types << pet_types[rand(pet_types.size)] if pet_types
|
random_pet_types << pet_types[rand(pet_types.size)] if pet_types
|
||||||
end
|
end
|
||||||
random_pet_types
|
random_pet_types
|
||||||
|
|
Loading…
Reference in a new issue