track pet state gender/mood
This commit is contained in:
parent
4e7e98beca
commit
c2c6a800f2
5 changed files with 45 additions and 4 deletions
|
@ -31,7 +31,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/matchu/neopets.git
|
||||
revision: c00b44ab75064815c5d433f0053bbf612c8465fd
|
||||
revision: d0127de12eae650fd85c56b45bc0b52e64e34ffe
|
||||
specs:
|
||||
neopets (0.0.1)
|
||||
nokogiri (~> 1.5.2)
|
||||
|
|
|
@ -39,6 +39,7 @@ class Pet < ActiveRecord::Base
|
|||
biology = pet_data.biology_by_zone
|
||||
biology[0] = nil # remove effects if present
|
||||
@pet_state = self.pet_type.add_pet_state_from_biology! biology
|
||||
@pet_state.label_by_pet(self, pet_data.owner)
|
||||
@items = Item.collection_from_pet_type_and_registries(self.pet_type,
|
||||
contents.object_info_registry, contents.object_asset_registry)
|
||||
true
|
||||
|
|
|
@ -62,6 +62,26 @@ class PetState < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def label_by_pet(pet, username)
|
||||
# If this pet is already labeled with a gender/mood, or it's unconverted
|
||||
# and therefore has none, skip.
|
||||
return false if self.labeled? || self.unconverted?
|
||||
|
||||
# Find this pet on the owner's userlookup, where we can get both its gender
|
||||
# and its mood.
|
||||
user_pet = Neopets::User.new(username).pets.
|
||||
find { |user_pet| user_pet.name.downcase == pet.name.downcase }
|
||||
self.female = user_pet.female?
|
||||
self.mood_id = user_pet.mood.id
|
||||
self.labeled = true
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def mood
|
||||
Neopets::Pet::Mood.find(self.mood_id)
|
||||
end
|
||||
|
||||
def self.from_pet_type_and_biology_info(pet_type, info)
|
||||
swf_asset_ids = []
|
||||
info.each do |zone_id, asset_info|
|
||||
|
@ -112,6 +132,7 @@ class PetState < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
pet_state.parent_swf_asset_relationships_to_update = relationships
|
||||
pet_state.unconverted = (relationships.size == 1)
|
||||
pet_state
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class AddFemaleAndMoodAndUnconvertedAndLabeledToPetStates < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :pet_states, :female, :boolean
|
||||
add_column :pet_states, :mood_id, :integer
|
||||
add_column :pet_states, :unconverted, :boolean
|
||||
add_column :pet_states, :labeled, :boolean, :null => false, :default => false
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :pet_states, :labeled
|
||||
remove_column :pet_states, :unconverted
|
||||
remove_column :pet_states, :mood_id
|
||||
remove_column :pet_states, :female
|
||||
end
|
||||
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120321231507) do
|
||||
ActiveRecord::Schema.define(:version => 20120521164652) do
|
||||
|
||||
create_table "auth_servers", :force => true do |t|
|
||||
t.string "short_name", :limit => 10, :null => false
|
||||
|
@ -140,8 +140,12 @@ ActiveRecord::Schema.define(:version => 20120321231507) do
|
|||
end
|
||||
|
||||
create_table "pet_states", :force => true do |t|
|
||||
t.integer "pet_type_id", :limit => 3, :null => false
|
||||
t.text "swf_asset_ids", :null => false
|
||||
t.integer "pet_type_id", :limit => 3, :null => false
|
||||
t.text "swf_asset_ids", :null => false
|
||||
t.boolean "female"
|
||||
t.integer "mood_id"
|
||||
t.boolean "unconverted"
|
||||
t.boolean "labeled", :default => false, :null => false
|
||||
end
|
||||
|
||||
add_index "pet_states", ["pet_type_id"], :name => "pet_states_pet_type_id"
|
||||
|
|
Loading…
Reference in a new issue