mirror of
https://github.com/kwsch/PKHeX
synced 2024-09-21 14:51:55 +00:00
Update showdownset handling for gen2/3
Closes #1913 by detecting any required pkm format related to the item.
This commit is contained in:
parent
3f6b1acc93
commit
f5c9873348
5 changed files with 127 additions and 13 deletions
|
@ -60,6 +60,8 @@ namespace PKHeX.Core
|
|||
/// <param name="abil">Desired <see cref="PKM.Ability"/> to set.</param>
|
||||
public static void SetAbility(this PKM pk, int abil)
|
||||
{
|
||||
if (abil < 0)
|
||||
return;
|
||||
var abilities = pk.PersonalInfo.Abilities;
|
||||
int abilIndex = Array.IndexOf(abilities, abil);
|
||||
abilIndex = Math.Max(0, abilIndex);
|
||||
|
@ -309,7 +311,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
pk.Species = Set.Species;
|
||||
pk.Moves = Set.Moves;
|
||||
pk.HeldItem = Set.HeldItem < 0 ? 0 : Set.HeldItem;
|
||||
pk.ApplyHeldItem(Set.HeldItem, Set.Format);
|
||||
pk.CurrentLevel = Set.Level;
|
||||
pk.CurrentFriendship = Set.Friendship;
|
||||
pk.IVs = Set.IVs;
|
||||
|
@ -334,6 +336,54 @@ namespace PKHeX.Core
|
|||
pk.RefreshChecksum();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM.HeldItem"/> value depending on the current format and the provided item index & format.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="item">Held Item to apply</param>
|
||||
/// <param name="format">Format required for importing</param>
|
||||
public static void ApplyHeldItem(this PKM pk, int item, int format)
|
||||
{
|
||||
if (item <= 0)
|
||||
{
|
||||
pk.HeldItem = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (format <= 3 && pk.Format != format)
|
||||
{
|
||||
if (pk.Format > 3) // try remapping
|
||||
{
|
||||
item = format == 2 ? ItemConverter.GetG4Item((byte) item) : ItemConverter.GetG4Item((ushort) item);
|
||||
pk.ApplyHeldItem(item, pk.Format);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pk.Format > format) // can't set past gen items
|
||||
{
|
||||
pk.HeldItem = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// ShowdownSet checks gen3 then gen2. For gen2 collisions (if any?) remap 3->4->2.
|
||||
item = ItemConverter.GetG4Item((ushort) item);
|
||||
item = ItemConverter.GetG2Item((ushort) item);
|
||||
if (item == 0 || item < 0)
|
||||
{
|
||||
pk.HeldItem = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch (pk.Format)
|
||||
{
|
||||
case 3: pk.HeldItem = ItemConverter.GetG3Item((ushort)item); break;
|
||||
case 2: pk.HeldItem = ItemConverter.GetG2Item((ushort)item); break;
|
||||
case 1: pk.HeldItem = 0; break;
|
||||
default: pk.HeldItem = item; break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets all Memory related data to the default value (zero).
|
||||
/// </summary>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
namespace PKHeX.Core
|
||||
using System;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Logic for converting Item IDs between the generation specific value sets.
|
||||
|
@ -29,6 +31,32 @@
|
|||
/// <returns>Generation 4+ Item ID.</returns>
|
||||
public static ushort GetG4Item(byte g2val) => g2val > arr2.Length ? NaN : arr2[g2val];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Generation 4+ Item ID to Generation 3 Item ID.
|
||||
/// </summary>
|
||||
/// <param name="g4val">Generation 4+ Item ID.</param>
|
||||
/// <returns>Generation 3 Item ID.</returns>
|
||||
public static ushort GetG3Item(ushort g4val)
|
||||
{
|
||||
if (g4val == NaN)
|
||||
return 0;
|
||||
int index = Array.IndexOf(arr3, g4val);
|
||||
return (ushort)Math.Max(0, index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Generation 4+ Item ID to Generation 2 Item ID.
|
||||
/// </summary>
|
||||
/// <param name="g4val">Generation 4+ Item ID.</param>
|
||||
/// <returns>Generation 2 Item ID.</returns>
|
||||
public static byte GetG2Item(ushort g4val)
|
||||
{
|
||||
if (g4val == NaN)
|
||||
return 0;
|
||||
int index = Array.IndexOf(arr2, g4val);
|
||||
return (byte)Math.Max(0, index);
|
||||
}
|
||||
|
||||
#region Item Mapping Tables
|
||||
/// <summary> Gen2 items (index) and their corresponding Gen4 item ID (value) </summary>
|
||||
private static readonly ushort[] arr2 =
|
||||
|
|
|
@ -273,7 +273,7 @@ namespace PKHeX.Core
|
|||
public override int Characteristic => -1;
|
||||
public override int MarkValue { get => 0; protected set { } }
|
||||
public override int CurrentFriendship { get => 0; set { } }
|
||||
public override int Ability { get => 0; set { } }
|
||||
public override int Ability { get => -1; set { } }
|
||||
public override int CurrentHandler { get => 0; set { } }
|
||||
public override int Met_Location { get => 0; set { } }
|
||||
public override int Egg_Location { get => 0; set { } }
|
||||
|
|
|
@ -346,7 +346,7 @@ namespace PKHeX.Core
|
|||
public override int PSV => 0xFFFF;
|
||||
public override int Characteristic => -1;
|
||||
public override int MarkValue { get => 0; protected set { } }
|
||||
public override int Ability { get => 0; set { } }
|
||||
public override int Ability { get => -1; set { } }
|
||||
public override int CurrentHandler { get => 0; set { } }
|
||||
public override int Egg_Location { get => 0; set { } }
|
||||
public override int OT_Friendship { get => 0; set { } }
|
||||
|
|
|
@ -14,10 +14,13 @@ namespace PKHeX.Core
|
|||
private static readonly string[] genders = {"M", "F", ""};
|
||||
private static readonly string[] genderForms = {"", "F", ""};
|
||||
private const string Language = "en";
|
||||
private const int LanguageID = 2;
|
||||
private static readonly string[] types = Util.GetTypesList(Language);
|
||||
private static readonly string[] forms = Util.GetFormsList(Language);
|
||||
private static readonly string[] species = Util.GetSpeciesList(Language);
|
||||
private static readonly string[] items = Util.GetItemsList(Language);
|
||||
private static readonly string[] g2items = Util.GetStringList("ItemsG2", Language);
|
||||
private static readonly string[] g3items = Util.GetStringList("ItemsG3", Language);
|
||||
private static readonly string[] natures = Util.GetNaturesList(Language);
|
||||
private static readonly string[] moves = Util.GetMovesList(Language);
|
||||
private static readonly string[] abilities = Util.GetAbilitiesList(Language);
|
||||
|
@ -27,10 +30,11 @@ namespace PKHeX.Core
|
|||
// Default Set Data
|
||||
public string Nickname { get; set; }
|
||||
public int Species { get; private set; } = -1;
|
||||
public int Format { get; private set; } = PKX.Generation;
|
||||
public string Form { get; private set; }
|
||||
public string Gender { get; private set; }
|
||||
public int HeldItem { get; private set; }
|
||||
public int Ability { get; private set; }
|
||||
public int Ability { get; private set; } = -1;
|
||||
public int Level { get; private set; } = 100;
|
||||
public bool Shiny { get; private set; }
|
||||
public int Friendship { get; private set; } = 255;
|
||||
|
@ -116,12 +120,8 @@ namespace PKHeX.Core
|
|||
{
|
||||
string[] pieces = line.Split(new[] {" @ "}, StringSplitOptions.None);
|
||||
string itemstr = pieces.Last().Trim();
|
||||
int item = Array.IndexOf(items, itemstr);
|
||||
if (item < 0)
|
||||
InvalidLines.Add($"Unknown Item: {itemstr}");
|
||||
else
|
||||
HeldItem = item;
|
||||
|
||||
ParseItemStr(itemstr);
|
||||
ParseFirstLine(pieces[0]);
|
||||
}
|
||||
else if (brokenline[0].Contains("Nature"))
|
||||
|
@ -143,6 +143,28 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private void ParseItemStr(string itemstr)
|
||||
{
|
||||
int item = Array.IndexOf(items, itemstr);
|
||||
if (item >= 0)
|
||||
{
|
||||
HeldItem = item;
|
||||
return;
|
||||
}
|
||||
if ((item = Array.IndexOf(g3items, itemstr)) >= 0)
|
||||
{
|
||||
HeldItem = item;
|
||||
Format = 3;
|
||||
}
|
||||
if ((item = Array.IndexOf(g2items, itemstr)) >= 0)
|
||||
{
|
||||
HeldItem = item;
|
||||
Format = 2;
|
||||
}
|
||||
else
|
||||
InvalidLines.Add($"Unknown Item: {itemstr}");
|
||||
}
|
||||
|
||||
public string Text => GetText();
|
||||
private string GetText()
|
||||
{
|
||||
|
@ -184,11 +206,24 @@ namespace PKHeX.Core
|
|||
if (!string.IsNullOrWhiteSpace(form))
|
||||
specForm += $"-{form.Replace("Mega ", "Mega-")}";
|
||||
|
||||
string result = Nickname != null && species[Species] != Nickname ? $"{Nickname} ({specForm})" : $"{specForm}";
|
||||
string result = Nickname != null && PKX.GetSpeciesNameGeneration(Species, LanguageID, Format) != Nickname ? $"{Nickname} ({specForm})" : $"{specForm}";
|
||||
if (!string.IsNullOrEmpty(Gender))
|
||||
result += $" ({Gender})";
|
||||
if (HeldItem > 0 && HeldItem < items.Length)
|
||||
result += $" @ {items[HeldItem]}";
|
||||
if (HeldItem > 0)
|
||||
{
|
||||
switch (Format)
|
||||
{
|
||||
case 2: if (HeldItem < g2items.Length)
|
||||
result += $" @ {g2items[HeldItem]}";
|
||||
break;
|
||||
case 3: if (HeldItem < g3items.Length)
|
||||
result += $" @ {g3items[HeldItem]}";
|
||||
break;
|
||||
default: if (HeldItem < items.Length)
|
||||
result += $" @ {items[HeldItem]}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private static bool GetStringStats(out IEnumerable<string> result, int[] stats, int ignore)
|
||||
|
@ -240,6 +275,7 @@ namespace PKHeX.Core
|
|||
Shiny = pkm.IsShiny,
|
||||
FormIndex = pkm.AltForm,
|
||||
Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : string.Empty,
|
||||
Format = pkm.Format,
|
||||
};
|
||||
|
||||
if (Set.Form == "F")
|
||||
|
|
Loading…
Reference in a new issue