Delete unused roulette feature

It was a cute idea! But it's been broken for a long time now. Goodbye!
This commit is contained in:
Emi Matchu 2023-10-24 18:07:11 -07:00
parent c06cea2a3c
commit f5b45d2dc8
4 changed files with 15 additions and 101 deletions

View file

@ -4,9 +4,6 @@ class PetsController < ApplicationController
rescue_from Pet::DownloadError, :with => :pet_download_error rescue_from Pet::DownloadError, :with => :pet_download_error
def load def load
if params[:name] == '!'
redirect_to roulette_path
else
raise Pet::PetNotFound unless params[:name] raise Pet::PetNotFound unless params[:name]
@pet = Pet.load( @pet = Pet.load(
params[:name], params[:name],
@ -26,7 +23,6 @@ class PetsController < ApplicationController
end end
end end
end end
end
protected protected

View file

@ -1,6 +0,0 @@
class RoulettesController < ApplicationController
def new
@roulette = Roulette.new
redirect_to wardrobe_path(:anchor => @roulette.to_query)
end
end

View file

@ -1,74 +0,0 @@
class Roulette
attr_accessor :pet_type, :pet_state, :item_ids
def initialize
# Choose a random pet type, and get a random state
@pet_type = PetType.offset(rand(PetType.count)).first # random pet type
states = @pet_type.pet_states
@pet_state = states.offset(rand(states.count)).first
fitting_swf_assets = SwfAsset.object_assets.fitting_body_id(@pet_type.body_id)
# Keep going until we have all zones occupied. Find a random SWF asset for
# a given unoccupied zone, then look up its item to see if it affects or
# restricts zones we've already used. If so, try again. If not, add it to
# the list.
unoccupied_zone_ids = Zone.all.map(&:id)
swf_asset_count_by_zone_id = fitting_swf_assets.count(:group => :zone_id)
swf_asset_count_by_zone_id.default = 0
@item_ids = []
while !unoccupied_zone_ids.empty?
zone_id = unoccupied_zone_ids.slice!(rand(unoccupied_zone_ids.count))
swf_asset_count = swf_asset_count_by_zone_id[zone_id]
if swf_asset_count > 0
used_swf_asset_ids = []
first_asset = true
found_item = false
while !found_item && used_swf_asset_ids.size < swf_asset_count
base = fitting_swf_assets
unless first_asset
first_asset = false
base = base.where(fitting_swf_assets.arel_table[:id].not_in(used_swf_asset_ids))
end
swf_asset = base.
where(:zone_id => zone_id).
offset(rand(swf_asset_count)).
includes(:object_asset_relationships => :item).
first
used_swf_asset_ids.push(swf_asset.id)
swf_asset.object_asset_relationships.each do |rel|
item = rel.item
if item.species_support_ids.empty? || item.species_support_ids.include?(@pet_type.species_id)
pass = true
item.affected_zones.each do |zone|
checked_zone_id = zone.id
next if checked_zone_id == zone_id
if i = unoccupied_zone_ids.find_index(zone_id)
unoccupied_zone_ids.delete zone_id
else
# This zone is already occupied, so this item is no good.
pass = false
break
end
end
if pass
found_item = true
@item_ids << item.id
break
end
end
end
break if found_item
end
end
end
end
def to_query
{
:color => @pet_type.color_id,
:species => @pet_type.species_id,
:state => @pet_state.id,
:objects => @item_ids
}.to_query
end
end

View file

@ -17,8 +17,6 @@ OpenneoImpressItems::Application.routes.draw do
get '/pet_states/:pet_state_id/swf_assets.json' => 'swf_assets#index', :as => :pet_state_swf_assets get '/pet_states/:pet_state_id/swf_assets.json' => 'swf_assets#index', :as => :pet_state_swf_assets
get '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show' get '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show'
get '/roulette' => 'roulettes#new', :as => :roulette
resources :contributions, :only => [:index] resources :contributions, :only => [:index]
resources :items, :only => [:index, :show] do resources :items, :only => [:index, :show] do
collection do collection do