From fdb8214e7d5a0aac74e0fce5185363f494147438 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Sun, 25 Sep 2011 01:17:01 +0300 Subject: [PATCH] Add special encounters for RBY. Helps #22 --- pokedex/data/csv/event_pokemon.csv | 55 ++++++ .../data/csv/special_encounter_versions.csv | 95 ++++++++++ pokedex/data/csv/special_encounters.csv | 55 ++++++ pokedex/data/csv/trainer_names.csv | 1 + pokedex/data/csv/trainers.csv | 1 + scripts/events-special-encounters.csv | 52 ++++++ scripts/load-events-and-special-encounters.py | 166 ++++++++++++++++++ 7 files changed, 425 insertions(+) create mode 100644 scripts/events-special-encounters.csv create mode 100644 scripts/load-events-and-special-encounters.py diff --git a/pokedex/data/csv/event_pokemon.csv b/pokedex/data/csv/event_pokemon.csv index c4c94aa..effa783 100644 --- a/pokedex/data/csv/event_pokemon.csv +++ b/pokedex/data/csv/event_pokemon.csv @@ -1 +1,56 @@ id,nickname,pokemon_form_id,ability_id,nature_id,item_id,level,gender_id,pokeball_id,personality,is_shiny,is_egg,original_trainer_id +1,,1,,,,5,,,,,0, +2,,2,,,,5,,,,,0, +3,,3,,,,5,,,,,0, +4,,25,,,,5,,,,,0, +5,,1,,,,10,,,,,0, +6,,4,,,,10,,,,,0, +7,,7,,,,10,,,,,0, +8,,107,,,,30,,,,,0, +9,,106,,,,30,,,,,0, +10,,131,,,,15,,,,,0, +11,,133,,,,25,,,,,0, +12,,138,,,,30,,,,,0, +13,,140,,,,30,,,,,0, +14,,142,,,,30,,,,,0, +15,,143,,,,30,,,,,0, +16,,143,,,,30,,,,,0, +17,,144,,,,50,,,,,0, +18,,145,,,,50,,,,,0, +19,,146,,,,50,,,,,0, +20,,150,,,,70,,,,,0, +21,,129,,,,,,,,,0, +22,DUX,83,,,,,,,,,0,1 +23,MARC,108,,,,,,,,,0,1 +24,MARCEL,122,,,,,,,,,0,1 +25,MILES,122,,,,,,,,,0,1 +26,LOLA,124,,,,,,,,,0,1 +27,SPOT,29,,,,,,,,,0,1 +28,TERRY,30,,,,,,,,,0,1 +29,SPIKE,47,,,,,,,,,0,1 +30,GURIO,51,,,,,,,,,0,1 +31,RICKY,67,,,,,,,,,0,1 +32,SAILOR,86,,,,,,,,,0,1 +33,CEZANNE,87,,,,,,,,,0,1 +34,STICKY,89,,,,,,,,,0,1 +35,DORIS,101,,,,,,,,,0,1 +36,BUFFY,112,,,,,,,,,0,1 +37,CRINKLES,114,,,,,,,,,0,1 +38,,30,,,,17,,,,,0, +39,,33,,,,17,,,,,0, +40,,35,,,,8,,,,,0, +41,,35,,,,12,,,,,0, +42,,37,,,,18,,,,,0, +43,,40,,,,22,,,,,0, +44,,63,,,,9,,,,,0, +45,,63,,,,6,,,,,0, +46,,63,,,,15,,,,,0, +47,,123,,,,25,,,,,0, +48,,123,,,,30,,,,,0, +49,,127,,,,20,,,,,0, +50,,127,,,,30,,,,,0, +51,,137,,,,26,,,,,0, +52,,137,,,,18,,,,,0, +53,,137,,,,26,,,,,0, +54,,147,,,,18,,,,,0, +55,,147,,,,24,,,,,0, diff --git a/pokedex/data/csv/special_encounter_versions.csv b/pokedex/data/csv/special_encounter_versions.csv index 7781355..9b55a43 100644 --- a/pokedex/data/csv/special_encounter_versions.csv +++ b/pokedex/data/csv/special_encounter_versions.csv @@ -1 +1,96 @@ special_encounter_id,version_id +1,1 +1,2 +2,1 +2,2 +3,1 +3,2 +4,3 +5,3 +6,3 +7,3 +8,1 +8,2 +8,3 +9,1 +9,2 +9,3 +10,1 +10,2 +10,3 +11,1 +11,2 +11,3 +12,1 +12,2 +12,3 +13,1 +13,2 +13,3 +14,1 +14,2 +14,3 +15,1 +15,2 +15,3 +16,1 +16,2 +16,3 +17,1 +17,2 +17,3 +18,1 +18,2 +18,3 +19,1 +19,2 +19,3 +20,1 +20,2 +20,3 +21,1 +21,2 +21,3 +22,1 +22,2 +23,1 +23,2 +24,1 +24,2 +25,3 +26,1 +26,2 +27,1 +27,2 +28,1 +28,2 +29,3 +30,3 +31,3 +32,1 +32,2 +33,3 +34,3 +35,1 +35,2 +36,3 +37,1 +37,2 +38,1 +39,2 +40,1 +41,2 +42,3 +43,3 +44,1 +45,2 +46,3 +47,1 +48,3 +49,2 +50,3 +51,1 +52,2 +53,3 +54,1 +55,2 diff --git a/pokedex/data/csv/special_encounters.csv b/pokedex/data/csv/special_encounters.csv index b8542b4..e74771c 100644 --- a/pokedex/data/csv/special_encounters.csv +++ b/pokedex/data/csv/special_encounters.csv @@ -1 +1,56 @@ id,type_id,event_pokemon_id,location_area_id,roam_region_id,cost,traded_species_id,traded_gender_id +1,1,1,554,,,, +2,1,2,554,,,, +3,1,3,554,,,, +4,1,4,554,,,, +5,2,5,281,,,, +6,2,6,552,,,, +7,2,7,557,,,, +8,2,8,576,,,, +9,2,9,576,,,, +10,2,10,576,,,, +11,2,11,283,,,, +12,3,12,279,,,, +13,3,13,279,,,, +14,3,14,279,,,, +15,4,15,276,,,, +16,4,16,309,,,, +17,4,17,577,,,, +18,4,18,330,,,, +19,4,19,318,,,, +20,4,20,325,,,, +21,5,21,298,,,, +22,6,22,557,,,, +23,6,23,311,,,, +24,6,24,530,,,, +25,6,25,530,,,, +26,6,26,281,,,, +27,6,27,299,,,, +28,6,28,305,,,, +29,6,29,311,,,, +30,6,30,305,,,, +31,6,31,299,,,, +32,6,32,279,,,, +33,6,33,279,,,, +34,6,34,279,,,, +35,6,35,279,,,, +36,6,36,279,,,, +37,6,37,279,,,, +38,7,38,283,,,, +39,7,39,283,,,, +40,7,40,283,,,, +41,7,41,283,,,, +42,7,42,283,,,, +43,7,43,283,,,, +44,7,44,283,,,, +45,7,45,283,,,, +46,7,46,283,,,, +47,7,47,283,,,, +48,7,48,283,,,, +49,7,49,283,,,, +50,7,50,283,,,, +51,7,51,283,,,, +52,7,52,283,,,, +53,7,53,283,,,, +54,7,54,283,,,, +55,7,55,283,,,, diff --git a/pokedex/data/csv/trainer_names.csv b/pokedex/data/csv/trainer_names.csv index 9ad6925..50fc5f4 100644 --- a/pokedex/data/csv/trainer_names.csv +++ b/pokedex/data/csv/trainer_names.csv @@ -1 +1,2 @@ trainer_id,local_language_id,name +1,9,TRAINER diff --git a/pokedex/data/csv/trainers.csv b/pokedex/data/csv/trainers.csv index ef042a0..336cd7e 100644 --- a/pokedex/data/csv/trainers.csv +++ b/pokedex/data/csv/trainers.csv @@ -1 +1,2 @@ id,number,gender_id +1,, diff --git a/scripts/events-special-encounters.csv b/scripts/events-special-encounters.csv new file mode 100644 index 0000000..41412dc --- /dev/null +++ b/scripts/events-special-encounters.csv @@ -0,0 +1,52 @@ +For use with load-events-special-encounters.py,Versions: RBY GSC RSE-CoXd-FL DPPt BW,,,,,,,,Stat order is HP/Atk/Def/Spd/SpA/SpD. Gen. I-II genes are Atk/Def/Spd/Sp.,,,,,,,,,Real World +Method,Version,Species/Form,Lv.,Item,Move(s),♂♀,⁂,Egg,Genes,Place,Trade for,Name,OT Name,OT №,Cost,Shadow mvs,Ribbons,Location,Distribution dates,Notes,Wonder Card title,Wonder Card text +starter,RB,"bulbasaur, ivysaur, venusaur",5,,,,,,,pallet-town,,,,,,,,,,choice of 1 +starter,Y,pikachu,5,,,,,,,pallet-town,,,,,,,,,,"(Has happiness, unable to evolve, etc)" +gift,Y,bulbasaur,10,,,,,,,cerulean-city,,,,,,,,,,(Pikachu's happiness high) +gift,Y,charmander,10,,,,,,,kanto-route-24 +gift,Y,squirtle,10,,,,,,,vermillion-city,,,,,,,,,,(Thunder Badge required) +gift,RBY,"hitmonchan, hitmonlee",30,,,,,,,saffron-city,,,,,,,,,,choice of 1; Fighting Dojo +gift,RBY,lapras,15,,,,,,,saffron-city,,,,,,,,,,Silph Co. +gift,RBY,eevee,25,,,,,,,celadon-city,,,,,,,,,,Celadon Mansion +fossil,RBY,"omanyte, kabuto",30,,,,,,,cinnabar-island,,,,,,,,,,choice of 1; Pokémon Lab; fossil from Mt. Moon +fossil,RBY,aerodactyl,30,,,,,,,cinnabar-island,,,,,,,,,,Pokémon Lab; fossil from behind Pewter Museum (need Cut) +overworld,RBY,snorlax,30,,,,,,,"kanto-route-12, kanto-route-16",,,,,,,,,,Nedd to be awakened by Poké Flute +overworld,RBY,articuno,50,,,,,,,seafoam-islands +overworld,RBY,zapdos,50,,,,,,,power-plant +overworld,RBY,moltres,50,,,,,,,kanto-victory-road-1 2f +overworld,RBY,mewtwo,70,,,,,,,cerulean-cave b1f +purchase,RBY,magikarp,,,,,,,,kanto-route-4,,,,,500 +trade,RB,farfetchd,,,,,,,,vermillion-city,spearow,DUX,TRAINER +trade,RB,lickitung,,,,,,,,kanto-route-18,slowbro,MARC,TRAINER +trade,RB,mr-mime,,,,,,,,kanto-route-2,abra,MARCEL,TRAINER +trade,Y,mr-mime,,,,,,,,kanto-route-2,clefairy,MILES,TRAINER +trade,RB,jynx,,,,,,,,cerulean-city,poliwhirl,LOLA,TRAINER +trade,RB,nidoran-f,,,,,,,,kanto-route-5,nidoran-m,SPOT,TRAINER +trade,RB,nidorina,,,,,,,,kanto-route-11,nidorino,TERRY,TRAINER +trade,Y,parasect,,,,,,,,kanto-route-18,tangela,SPIKE,TRAINER +trade,Y,dugtrio,,,,,,,,kanto-route-11,lickitung,GURIO,TRAINER +trade,Y,machoke,,,,,,,,kanto-route-5,cubone,RICKY,TRAINER,,,,,,,(evolves immediately) +trade,RB,seel,,,,,,,,cinnabar-island,ponyta,SAILOR,TRAINER +trade,Y,dewgong,,,,,,,,cinnabar-island,growlithe,CEZANNE,TRAINER +trade,Y,muk,,,,,,,,cinnabar-island,kangaskhan,STICKY,TRAINER +trade,RB,electrode,,,,,,,,cinnabar-island,raichu,DORIS,TRAINER +trade,Y,rhydon,,,,,,,,cinnabar-island,golduck,BUFFY,TRAINER +trade,RB,tangela,,,,,,,,cinnabar-island,venonat,CRINKLES,TRAINER +prize,R,nidorina,17,,,,,,,celadon-city,,,,,1200 +prize,B,nidorino,17,,,,,,,celadon-city,,,,,1200 +prize,R,clefairy,8,,,,,,,celadon-city,,,,,500 +prize,B,clefairy,12,,,,,,,celadon-city,,,,,750 +prize,Y,vulpix,18,,,,,,,celadon-city,,,,,1000 +prize,Y,wigglytuff,22,,,,,,,celadon-city,,,,,2680 +prize,R,abra,9,,,,,,,celadon-city,,,,,180 +prize,B,abra,6,,,,,,,celadon-city,,,,,120 +prize,Y,abra,15,,,,,,,celadon-city,,,,,230 +prize,R,scyther,25,,,,,,,celadon-city,,,,,5500 +prize,Y,scyther,30,,,,,,,celadon-city,,,,,6500 +prize,B,pinsir,20,,,,,,,celadon-city,,,,,2500 +prize,Y,pinsir,30,,,,,,,celadon-city,,,,,6500 +prize,R,porygon,26,,,,,,,celadon-city,,,,,9999 +prize,B,porygon,18,,,,,,,celadon-city,,,,,4600 +prize,Y,porygon,26,,,,,,,celadon-city,,,,,9999 +prize,R,dratini,18,,,,,,,celadon-city,,,,,2800 +prize,B,dratini,24,,,,,,,celadon-city,,,,,4600 diff --git a/scripts/load-events-and-special-encounters.py b/scripts/load-events-and-special-encounters.py new file mode 100644 index 0000000..097bd8f --- /dev/null +++ b/scripts/load-events-and-special-encounters.py @@ -0,0 +1,166 @@ +# Encoding: UTF-8 +"""Load events and special encounters from a CSV file + +This is an unmaintained one-shot script, only included in the repo for reference. + +Loads the data from an ad-hoc spreadsheet format, because for getting this stuff +together, flat is definitely better than nested. + +""" + +from __future__ import unicode_literals + +import sys +import csv + +from sqlalchemy.sql.expression import func +from sqlalchemy.orm import subqueryload +import sqlalchemy.orm.exc + +from pokedex.db import connect, tables, util, load + +session = connect() + +reader = ([c.decode('utf-8') for c in l] for l in csv.reader(open(sys.argv[1]))) +reader.next() # discard line 1 +column_names = reader.next() +print ','.join(column_names) + +english = util.get(session, tables.Language, 'en') + +def create_with_autoid(table): + autoid = (session.query(func.max(table.id)).one()[0] or 0) + 1 + obj = table() + obj.id = autoid + return obj + +# We need location_areas for places that don't have them yet +for location in session.query(tables.Location).options(subqueryload('areas')): + if not location.areas: + print 'Creating default area for', location.identifier + area = create_with_autoid(tables.LocationArea) + area.location = location + session.add(area) + +def trainer(name, number): + if name is number is None: + return None + query = session.query(tables.Trainer).join(tables.Trainer.names) + query = query.filter(tables.Trainer.names_table.name == name) + query = query.filter(tables.Trainer.number == number) + try: + return query.one() + except sqlalchemy.orm.exc.NoResultFound: + trainer = create_with_autoid(tables.Trainer) + trainer_name = tables.Trainer.names_table() + trainer_name.local_language = english + trainer_name.foreign_id = trainer.id + trainer_name.name = name + trainer.number = number + session.add(trainer) + session.add(trainer_name) + return trainer + +version_codes = ( + # 2-letter codes first! + ('Xd', 'xd'), + ('Co', 'colosseum'), + ('Pt', 'platinum'), + ('Hg', 'heartgold'), + ('Ss', 'soulsilver'), + + ('R', 'red'), + ('B', 'blue'), + ('Y', 'yellow'), + + ('G', 'gold'), + ('S', 'silver'), + ('C', 'crystal'), + + ('R', 'ruby'), + ('S', 'sapphire'), + ('E', 'emerald'), + ('F', 'firered'), + ('L', 'leafgreen'), + + ('D', 'diamond'), + ('P', 'pearl'), + + ('B', 'black'), + ('W', 'white'), + ) + +for line in reader: + print ','.join(line) + line_dict = dict(zip(column_names, line + [''] * 100)) + all_places = line_dict.pop('Place').split(',') + for p_form_ident in line_dict.pop('Species/Form').split(','): + p_form_ident = p_form_ident.strip() + for place_ident in all_places: + place_ident = place_ident.strip() + + dct = dict(line_dict) + + encounter_type = util.get(session, tables.SpecialEncounterType, dct.pop('Method')) + species_ident, sp, form_ident = p_form_ident.partition(' ') + species = util.get(session, tables.PokemonSpecies, species_ident) + for pokemon_form in species.forms: + if pokemon_form.form_identifier == (form_ident or None): + break + else: + raise ValueError('No such pkmn form: %s' % p_form_ident) + if place_ident: + location_ident, sp, area_ident = place_ident.partition(' ') + location = util.get(session, tables.Location, location_ident) + for location_area in location.areas: + if location_area.identifier == (area_ident or None): + break + else: + raise ValueError('No such area: %s' % place_ident) + else: + location_area = None + se_pokemon = create_with_autoid(tables.EventPokemon) + se_pokemon.pokemon_form = pokemon_form + se_pokemon.is_egg = bool(dct.pop('Egg')) + se_pokemon.cost = dct.pop('Cost') or None + session.add(se_pokemon) + encounter = create_with_autoid(tables.SpecialEncounter) + encounter.event_pokemon = se_pokemon + encounter.type = encounter_type + encounter.location_area = location_area + se_pokemon.level = dct.pop('Lv.') or None + se_pokemon.nickname = dct.pop('Name') or None + session.add(encounter) + if encounter_type == 'starter': + print + dct.pop('Notes') + versions = dct.pop('Version') + trade_for = dct.pop('Trade for') + if trade_for: + encounter.trade_species = util.get(session, + tables.PokemonSpecies, trade_for) + se_pokemon.original_trainer = trainer( + dct.pop('OT Name') or None, dct.pop('OT №') or None) + for code, version_ident in version_codes: + part1, current_code, part2 = versions.partition(code) + versions = part1 + part2 + if current_code: + entry = tables.SpecialEncounterVersion() + entry.encounter = encounter + entry.version = util.get(session, tables.Version, version_ident) + session.add(entry) + assert not versions, 'Leftover versions: %s' % versions + assert not any(dct.values()), 'stuff left over: %s' % ', '.join( + '%s=%s' % (k, v) for k, v in dct.items() if v) + +print 'Dumping!' +load.dump(session, verbose=True, tables=[ + 'special_encounters', + 'event_pokemon', + 'special_encounter_versions', + 'location_areas', + 'trainers', + 'trainer_names', + ]) + +session.rollback()