PKHeX/PKHeX.WinForms/Controls/PKM Editor/CatchRate.cs
Kurt 6f09f7b89e Add catch rate editor control
#2132
has a 'reset' button which tries to set a legal value
has a 'clear' button which sets it to zero, similar to gen2 removing an
item
2018-09-30 10:16:45 -07:00

40 lines
1.5 KiB
C#

using System;
using System.Windows.Forms;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
public partial class CatchRate : UserControl
{
private PK1 pk1;
public CatchRate() => InitializeComponent();
public void LoadPK1(PK1 pk) => NUD_CatchRate.Value = (pk1 = pk).Catch_Rate;
private void ChangeValue(object sender, EventArgs e) => pk1.Catch_Rate = (int)NUD_CatchRate.Value;
private void Clear(object sender, EventArgs e) => NUD_CatchRate.Value = 0;
private void Reset(object sender, EventArgs e) => NUD_CatchRate.Value = GetSuggestedPKMCatchRate(pk1);
private static int GetSuggestedPKMCatchRate(PK1 pk1)
{
var la = new LegalityAnalysis(pk1);
if (la.Valid)
return pk1.Catch_Rate;
if (la.Info.Generation == 2)
return 0;
var enc = la.EncounterOriginal;
switch (enc)
{
case EncounterTradeCatchRate c:
return (int)c.Catch_Rate;
case EncounterStatic s when s.Version == GameVersion.Stadium && s.Species == 054:
return pk1.Japanese ? 167 : 168; // Amnesia Psyduck has different catch rates depending on language
case IVersion v when v.Version.Contains(GameVersion.YW):
return PersonalTable.Y[enc.Species].CatchRate;
default:
return PersonalTable.RB[enc.Species].CatchRate;
}
}
}
}