Minor clean

expand some expressions, extract some methods, add comments
This commit is contained in:
Kurt 2021-06-08 20:14:55 -07:00
parent 71fd8b36e9
commit 2abf95cdf8
4 changed files with 41 additions and 26 deletions

View File

@ -8,7 +8,6 @@ internal static partial class Encounters8Nest
/// </summary>
internal static readonly EncounterStatic8ND[] Dist_DLC2 =
{
new(17,01,1) { Species = 002, Ability = A4, Moves = new[]{ 075, 077, 033, 079 }, Index = 71 }, // Ivysaur
new(17,01,1) { Species = 060, Ability = A4, Moves = new[]{ 055, 095, 001, 341 }, Index = 71 }, // Poliwag
new(17,01,1) { Species = 453, Ability = A4, Moves = new[]{ 040, 279, 189, 372 }, Index = 71 }, // Croagunk

View File

@ -9,6 +9,8 @@ public record EncounterStatic1 : EncounterStatic
public override int Generation => 1;
public sealed override int Level { get; init; }
private const int LightBallPikachuCatchRate = 0xA3; // 163
public EncounterStatic1(int species, int level, GameVersion game) : base(game)
{
Species = species;
@ -22,7 +24,7 @@ protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteri
var pk1 = (PK1) pk;
if (Species == (int) Core.Species.Pikachu && Version == GameVersion.YW && Level == 5 && Moves.Count == 0)
{
pk1.Catch_Rate = 0xA3; // Light Ball
pk1.Catch_Rate = LightBallPikachuCatchRate; // Light Ball
return;
}
@ -33,11 +35,14 @@ protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteri
protected override bool IsMatchLevel(PKM pkm, DexLevel evo)
{
// Met Level is not stored in the PK1 format.
// Check if it is at or above the encounter level.
return Level <= evo.Level;
}
protected override bool IsMatchLocation(PKM pkm)
{
// Met Location is not stored in the PK1 format.
return true;
}
@ -53,14 +58,12 @@ protected override bool IsMatchPartial(PKM pkm)
private bool IsCatchRateValid(PK1 pk1)
{
var catch_rate = pk1.Catch_Rate;
if (Species == (int)Core.Species.Pikachu)
{
if (catch_rate == 190) // Red Blue Pikachu is not a static encounter
return false;
if (catch_rate == 163 && Level == 5) // Light Ball (Yellow) starter
return true;
}
// Light Ball (Yellow) starter
if (Version == GameVersion.YW && Species == (int)Core.Species.Pikachu && Level == 5)
{
return catch_rate == LightBallPikachuCatchRate;
}
if (Version == GameVersion.Stadium)
{
// Amnesia Psyduck has different catch rates depending on language

View File

@ -34,23 +34,11 @@ private static List<string> GetLegalityReportLines(LegalityAnalysis l)
{
var lines = new List<string>();
var info = l.Info;
var vMoves = info.Moves;
var pkm = l.pkm;
for (int i = 0; i < 4; i++)
{
if (!vMoves[i].Valid)
lines.Add(vMoves[i].Format(L_F0_M_1_2, i + 1));
}
AddMoves(info.Moves, lines);
if (pkm.Format >= 6)
{
var vRelearn = info.Relearn;
for (int i = 0; i < 4; i++)
{
if (!vRelearn[i].Valid)
lines.Add(vRelearn[i].Format(L_F0_RM_1_2, i + 1));
}
}
AddRelearn(info.Relearn, lines);
// Build result string...
var outputLines = l.Results.Where(chk => !chk.Valid);
@ -58,6 +46,26 @@ private static List<string> GetLegalityReportLines(LegalityAnalysis l)
return lines;
}
private static void AddMoves(CheckMoveResult[] moves, List<string> lines)
{
for (int i = 0; i < moves.Length; i++)
{
var move = moves[i];
if (!move.Valid)
lines.Add(move.Format(L_F0_M_1_2, i + 1));
}
}
private static void AddRelearn(CheckResult[] relearn, List<string> lines)
{
for (int i = 0; i < relearn.Length; i++)
{
var move = relearn[i];
if (!move.Valid)
lines.Add(move.Format(L_F0_RM_1_2, i + 1));
}
}
private static IReadOnlyList<string> GetVerboseLegalityReportLines(LegalityAnalysis l)
{
var lines = l.Valid ? new List<string> {L_ALegal} : GetLegalityReportLines(l);

View File

@ -260,11 +260,16 @@ private void Menu_Export_Click(object sender, EventArgs e)
if (DialogResult.OK != fbd.ShowDialog())
return;
string path = fbd.SelectedPath;
Directory.CreateDirectory(path);
string folder = fbd.SelectedPath;
Directory.CreateDirectory(folder);
foreach (var gift in Results.OfType<DataMysteryGift>()) // WC3 have no data
File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(gift.FileName)), gift.Write());
{
var fileName = Util.CleanFileName(gift.FileName);
var path = Path.Combine(folder, fileName);
var data = gift.Write();
File.WriteAllBytes(path, data);
}
}
// View Updates