diff --git a/library/Pokedex/Location.cs b/library/Pokedex/Location.cs index a7b4108d..6e137a64 100644 --- a/library/Pokedex/Location.cs +++ b/library/Pokedex/Location.cs @@ -129,14 +129,30 @@ namespace PkmnFoundations.Pokedex public static LazyKeyValuePair CreatePairForGeneration(Pokedex pokedex, Func generationGetter) { return new LazyKeyValuePair( - k => k == 0 ? null : (pokedex == null ? null : pokedex.Locations(GenerationToLocationNumbering(generationGetter()))[k]), + k => + { + if (k == 0) return null; + if (pokedex == null) return null; + var locations = pokedex.Locations(GenerationToLocationNumbering(generationGetter())); + if (locations == null) return null; + if (!locations.ContainsKey(k)) return null; + return locations[k]; + }, v => v == null ? 0 : (v.Value(generationGetter()) ?? -1)); } public static LazyKeyValuePair CreatePairForLocationNumbering(Pokedex pokedex, Func generationGetter) { return new LazyKeyValuePair( - k => k == 0 ? null : (pokedex == null ? null : pokedex.Locations(generationGetter())[k]), + k => + { + if (k == 0) return null; + if (pokedex == null) return null; + var locations = pokedex.Locations(generationGetter()); + if (locations == null) return null; + if (!locations.ContainsKey(k)) return null; + return locations[k]; + }, v => v == null ? 0 : (v.Value(generationGetter()) ?? -1)); } } diff --git a/library/Structures/BattleTowerProfile4.cs b/library/Structures/BattleTowerProfile4.cs index 6c2dfd52..5343e51b 100644 --- a/library/Structures/BattleTowerProfile4.cs +++ b/library/Structures/BattleTowerProfile4.cs @@ -50,7 +50,7 @@ namespace PkmnFoundations.Structures public uint OT; public TrendyPhrase4 PhraseLeader; // Different from GTS, 0 = male, 2 = female, 1 = Plato???? - public byte Gender; // Probably trainer class. + public byte Gender; // 3: Lass // 6: Bug Catcher @@ -68,7 +68,7 @@ namespace PkmnFoundations.Structures // 57: Roughneck // 60: School Kid M // 85: Idol - public byte Unknown; + public byte Unknown; // Probably trainer class. public byte[] Save() { diff --git a/library/Structures/Format.cs b/library/Structures/Format.cs index 27cae3f5..c801e8f3 100644 --- a/library/Structures/Format.cs +++ b/library/Structures/Format.cs @@ -7,16 +7,16 @@ namespace PkmnFoundations.Structures { public static class Format { - private static String[] m_marks = new String[] { "●", "▲", "■", "♥", "★", "♦" }; + private static string[] m_marks = new string[] { "●", "▲", "■", "♥", "★", "♦" }; - public static String Markings(Markings markings, String trueFormat, String falseFormat, String delimiter) + public static string Markings(Markings markings, string trueFormat, string falseFormat, string delimiter) { StringBuilder result = new StringBuilder(); int marking = 1; for (int value = 0; value < 6; value++) { if (marking > 1) result.Append(delimiter); - String format = (((int)markings & marking) != 0) ? trueFormat : falseFormat; + string format = (((int)markings & marking) != 0) ? trueFormat : falseFormat; result.Append(String.Format(format, m_marks[value])); marking <<= 1; @@ -25,7 +25,7 @@ namespace PkmnFoundations.Structures return result.ToString(); } - public static String GenderSymbol(Genders gender) + public static string GenderSymbol(Genders gender) { switch (gender) { @@ -38,7 +38,7 @@ namespace PkmnFoundations.Structures } } - public static String ToIso639_1(Languages lang) + public static string ToIso639_1(Languages lang) { switch (lang) { @@ -61,7 +61,7 @@ namespace PkmnFoundations.Structures } } - public static Languages FromIso639_1(String lang) + public static Languages FromIso639_1(string lang) { switch (lang.ToUpperInvariant()) { diff --git a/library/Structures/Pokemon4.cs b/library/Structures/Pokemon4.cs index 2ff17ce9..4fd32425 100644 --- a/library/Structures/Pokemon4.cs +++ b/library/Structures/Pokemon4.cs @@ -307,6 +307,14 @@ namespace PkmnFoundations.Structures return pokeballId > 16; } + public override ushort HP + { + get + { + return (ushort)Stats[Structures.Stats.Hp]; + } + } + public override int Size { get { return 136; } diff --git a/library/Structures/Pokemon5.cs b/library/Structures/Pokemon5.cs index e638e1e6..23925483 100644 --- a/library/Structures/Pokemon5.cs +++ b/library/Structures/Pokemon5.cs @@ -248,7 +248,7 @@ namespace PkmnFoundations.Structures eggLocationId = (plat && EggLocationID_Plat != 0) ? EggLocationID_Plat : EggLocationID; locationId = (plat && LocationID_Plat != 0) ? LocationID_Plat : LocationID; - return new TrainerMemo(m_pokedex, LocationNumbering.Generation4, + return new TrainerMemo(m_pokedex, LocationNumbering.Generation5, TrainerMemoDateTime(EggDate), TrainerMemoDateTime(Date), eggLocationId, locationId, EncounterLevel == 0, EncounterLevel); } @@ -285,6 +285,14 @@ namespace PkmnFoundations.Structures } } + public override ushort HP + { + get + { + return (ushort)Stats[Structures.Stats.Hp]; + } + } + private bool IsBw2() { return (Version == Versions.Black2 || Version == Versions.White2); diff --git a/library/Structures/PokemonParty4.cs b/library/Structures/PokemonParty4.cs index d31260a7..90a2d665 100644 --- a/library/Structures/PokemonParty4.cs +++ b/library/Structures/PokemonParty4.cs @@ -56,7 +56,7 @@ namespace PkmnFoundations.Structures // todo: validate this against the computed level //Level = block[4]; CapsuleIndex = block[5]; - HP = BitConverter.ToUInt16(block, 6); + _HP = BitConverter.ToUInt16(block, 6); m_stats = new IntStatValues(BitConverter.ToUInt16(block, 8), BitConverter.ToUInt16(block, 10), BitConverter.ToUInt16(block, 12), @@ -77,7 +77,8 @@ namespace PkmnFoundations.Structures public byte Unknown5 { get; set; } public ushort Unknown6 { get; set; } public byte CapsuleIndex { get; set; } - public ushort HP { get; set; } // remaining hp + public override ushort HP { get { return _HP; } } // remaining hp + public ushort _HP { get; set; } public byte[] Unknown7 { get; set; } // 56 bytes public byte[] Seals { get; set; } // 24 bytes diff --git a/library/Structures/PokemonParty5.cs b/library/Structures/PokemonParty5.cs index b4379d00..925c465c 100644 --- a/library/Structures/PokemonParty5.cs +++ b/library/Structures/PokemonParty5.cs @@ -56,7 +56,7 @@ namespace PkmnFoundations.Structures // todo: validate this against the computed level //Level = block[4]; CapsuleIndex = block[5]; - HP = BitConverter.ToUInt16(block, 6); + _HP = BitConverter.ToUInt16(block, 6); // todo: validate this against computed stats m_stats = new IntStatValues(BitConverter.ToUInt16(block, 8), BitConverter.ToUInt16(block, 10), @@ -79,7 +79,8 @@ namespace PkmnFoundations.Structures public byte Unknown5 { get; set; } public ushort Unknown6 { get; set; } public byte CapsuleIndex { get; set; } - public ushort HP { get; set; } // remaining hp + public override ushort HP { get { return _HP; } } // remaining hp + public ushort _HP { get; set; } public byte[] Mail { get; set; } // 56 bytes public byte[] Unknown7 { get; set; } // 8 bytes public byte[] Padding { get; set; } // 16 bytes. Pads the length to match the gen4 structure. diff --git a/library/Structures/PokemonPartyBase.cs b/library/Structures/PokemonPartyBase.cs index 52bb6ad7..5d3ff05c 100644 --- a/library/Structures/PokemonPartyBase.cs +++ b/library/Structures/PokemonPartyBase.cs @@ -162,6 +162,8 @@ namespace PkmnFoundations.Structures } } + public abstract ushort HP { get; } + public static ushort ComputeChecksum(byte[] data) { ushort result = 0; diff --git a/web/gts/Pokemon.aspx.cs b/web/gts/Pokemon.aspx.cs index a383883d..b70c8018 100644 --- a/web/gts/Pokemon.aspx.cs +++ b/web/gts/Pokemon.aspx.cs @@ -24,7 +24,7 @@ namespace PkmnFoundations.Web.gts protected void Page_Load(object sender, EventArgs e) { Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application); - PokemonParty4 pkmn = null; + PokemonPartyBase pkmn = null; if (Request.QueryString.Count == 0 || Request.QueryString.Count > 2) throw new WebException(400); if (Request.QueryString["offer"] != null || @@ -66,7 +66,7 @@ namespace PkmnFoundations.Web.gts case "5": { GtsRecord5 record = Database.Instance.GtsGetRecord5(pokedex, tradeId, isExchanged, true); - if (record != null) pkmn = new PokemonParty4(pokedex, record.Data.ToArray()); + if (record != null) pkmn = new PokemonParty5(pokedex, record.Data.ToArray()); } break; default: @@ -86,7 +86,7 @@ namespace PkmnFoundations.Web.gts Bind(pkmn); } - private void Bind(PokemonParty4 pkmn) + private void Bind(PokemonPartyBase pkmn) { litNickname.Text = pkmn.Nickname; bool shiny = pkmn.IsShiny; @@ -103,7 +103,7 @@ namespace PkmnFoundations.Web.gts litCharacteristic.Text = pkmn.Characteristic.ToString(); litSpecies.Text = pkmn.Species.Name.ToString(); litPokedex.Text = pkmn.SpeciesID.ToString("000"); - FormStats fs = pkmn.Form.BaseStats(Generations.Generation4); + FormStats fs = pkmn.Form.BaseStats(pkmn.Generation); litType1.Text = fs.Type1 == null ? "" : WebFormat.RenderType(fs.Type1); litType2.Text = fs.Type2 == null ? "" : WebFormat.RenderType(fs.Type2); litOtName.Text = Common.HtmlEncode(pkmn.TrainerName);