2018-05-19 19:07:50 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 3 Evolution Branch Entries
|
|
|
|
/// </summary>
|
2018-07-02 02:55:23 +00:00
|
|
|
public sealed class EvolutionSet3 : EvolutionSet
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
|
|
|
private static EvolutionMethod GetMethod(byte[] data, int offset)
|
|
|
|
{
|
|
|
|
int method = BitConverter.ToUInt16(data, offset + 0);
|
|
|
|
int arg = BitConverter.ToUInt16(data, offset + 2);
|
|
|
|
int species = SpeciesConverter.GetG4Species(BitConverter.ToUInt16(data, offset + 4));
|
|
|
|
//2 bytes padding
|
|
|
|
|
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case 1: /* Friendship*/
|
|
|
|
case 2: /* Friendship day*/
|
|
|
|
case 3: /* Friendship night*/
|
|
|
|
case 5: /* Trade */
|
|
|
|
case 6: /* Trade while holding */
|
|
|
|
return new EvolutionMethod { Method = method, Species = species, Argument = arg };
|
|
|
|
case 4: /* Level Up */
|
|
|
|
return new EvolutionMethod { Method = 4, Species = species, Level = arg, Argument = arg };
|
|
|
|
case 7: /* Use item */
|
|
|
|
case 15: /* Beauty evolution*/
|
|
|
|
return new EvolutionMethod { Method = method + 1, Species = species, Argument = arg };
|
|
|
|
case 8: /* Tyrogue -> Hitmonchan */
|
|
|
|
case 9: /* Tyrogue -> Hitmonlee */
|
|
|
|
case 10: /* Tyrogue -> Hitmontop*/
|
|
|
|
case 11: /* Wurmple -> Silcoon evolution */
|
|
|
|
case 12: /* Wurmple -> Cascoon evolution */
|
|
|
|
case 13: /* Nincada -> Ninjask evolution */
|
|
|
|
case 14: /* Shedinja spawn in Nincada -> Ninjask evolution */
|
|
|
|
return new EvolutionMethod { Method = method + 1, Species = species, Level = arg, Argument = arg };
|
2019-03-23 08:01:04 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
throw new ArgumentException(nameof(method));
|
2018-05-19 19:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2019-01-07 00:22:45 +00:00
|
|
|
private static readonly EvolutionSet Blank = new EvolutionSet3 { PossibleEvolutions = Array.Empty<EvolutionMethod>() };
|
|
|
|
|
|
|
|
public static IReadOnlyList<EvolutionSet> GetArray(byte[] data)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
2019-01-07 00:22:45 +00:00
|
|
|
var evos = new EvolutionSet[Legal.MaxSpeciesID_3 + 1];
|
|
|
|
evos[0] = Blank;
|
|
|
|
for (int i = 1; i <= Legal.MaxSpeciesIndex_3; i++)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
|
|
|
int g4species = SpeciesConverter.GetG4Species(i);
|
|
|
|
if (g4species == 0)
|
|
|
|
continue;
|
|
|
|
|
2019-01-07 00:22:45 +00:00
|
|
|
const int maxCount = 5;
|
|
|
|
const int size = 8;
|
|
|
|
|
|
|
|
int offset = i * (maxCount * size);
|
|
|
|
int count = 0;
|
|
|
|
for (; count < maxCount; count++)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
2019-01-07 00:22:45 +00:00
|
|
|
if (data[offset + (count * size)] == 0)
|
2018-05-19 19:07:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-01-07 00:22:45 +00:00
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
evos[g4species] = Blank;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var set = new EvolutionMethod[count];
|
|
|
|
for (int j = 0; j < set.Length; j++)
|
2019-01-07 06:18:14 +00:00
|
|
|
set[j] = GetMethod(data, offset + (j * size));
|
2019-01-07 00:22:45 +00:00
|
|
|
evos[g4species] = new EvolutionSet3 { PossibleEvolutions = set };
|
2018-05-19 19:07:50 +00:00
|
|
|
}
|
2019-01-07 00:22:45 +00:00
|
|
|
return evos;
|
2018-05-19 19:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|