2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-07-03 03:24:17 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stat/misc data for individual species or their associated alternate forme data.
|
|
|
|
|
/// </summary>
|
2016-07-03 03:24:17 +00:00
|
|
|
|
public abstract class PersonalInfo
|
|
|
|
|
{
|
|
|
|
|
protected byte[] Data;
|
2016-07-07 12:44:43 +00:00
|
|
|
|
public abstract byte[] Write();
|
2016-07-03 03:24:17 +00:00
|
|
|
|
public abstract int HP { get; set; }
|
|
|
|
|
public abstract int ATK { get; set; }
|
|
|
|
|
public abstract int DEF { get; set; }
|
|
|
|
|
public abstract int SPE { get; set; }
|
|
|
|
|
public abstract int SPA { get; set; }
|
|
|
|
|
public abstract int SPD { get; set; }
|
2016-08-28 10:18:22 +00:00
|
|
|
|
|
|
|
|
|
public int[] Stats => new[] { HP, ATK, DEF, SPE, SPA, SPD };
|
|
|
|
|
|
2016-07-03 03:24:17 +00:00
|
|
|
|
public abstract int EV_HP { get; set; }
|
|
|
|
|
public abstract int EV_ATK { get; set; }
|
|
|
|
|
public abstract int EV_DEF { get; set; }
|
|
|
|
|
public abstract int EV_SPE { get; set; }
|
|
|
|
|
public abstract int EV_SPA { get; set; }
|
|
|
|
|
public abstract int EV_SPD { get; set; }
|
2017-12-27 02:54:03 +00:00
|
|
|
|
public abstract int Type1 { get; set; }
|
|
|
|
|
public abstract int Type2 { get; set; }
|
|
|
|
|
public abstract int EggGroup1 { get; set; }
|
|
|
|
|
public abstract int EggGroup2 { get; set; }
|
2016-07-03 03:24:17 +00:00
|
|
|
|
public abstract int CatchRate { get; set; }
|
|
|
|
|
public virtual int EvoStage { get; set; }
|
|
|
|
|
public abstract int[] Items { get; set; }
|
|
|
|
|
public abstract int Gender { get; set; }
|
|
|
|
|
public abstract int HatchCycles { get; set; }
|
|
|
|
|
public abstract int BaseFriendship { get; set; }
|
|
|
|
|
public abstract int EXPGrowth { get; set; }
|
|
|
|
|
public abstract int [] Abilities { get; set; }
|
|
|
|
|
public abstract int EscapeRate { get; set; }
|
2017-11-20 16:08:48 +00:00
|
|
|
|
public virtual int FormeCount { get; set; } = 1;
|
2016-11-12 18:19:17 +00:00
|
|
|
|
protected internal virtual int FormStatsIndex { get; set; }
|
2016-07-03 03:24:17 +00:00
|
|
|
|
public virtual int FormeSprite { get; set; }
|
|
|
|
|
public abstract int BaseEXP { get; set; }
|
|
|
|
|
public abstract int Color { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual int Height { get; set; } = 0;
|
|
|
|
|
public virtual int Weight { get; set; } = 0;
|
|
|
|
|
|
2017-12-27 02:54:03 +00:00
|
|
|
|
public int[] Types
|
|
|
|
|
{
|
|
|
|
|
get => new[] { Type1, Type2 };
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value?.Length != 2) return;
|
|
|
|
|
Type1 = value[0];
|
|
|
|
|
Type2 = value[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int[] EggGroups
|
|
|
|
|
{
|
|
|
|
|
get => new[] { EggGroup1, EggGroup2 };
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value?.Length != 2) return;
|
|
|
|
|
EggGroup1 = (byte)value[0];
|
|
|
|
|
EggGroup2 = (byte)value[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 06:44:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// TM/HM learn compatibility flags for individual moves.
|
|
|
|
|
/// </summary>
|
2017-01-08 08:14:34 +00:00
|
|
|
|
public bool[] TMHM { get; protected set; }
|
2017-11-07 06:44:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Grass-Fire-Water-Etc typed learn compatibility flags for individual moves.
|
|
|
|
|
/// </summary>
|
2017-01-08 08:14:34 +00:00
|
|
|
|
public bool[] TypeTutors { get; protected set; }
|
2017-11-07 06:44:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Special tutor learn compatibility flags for individual moves.
|
|
|
|
|
/// </summary>
|
2017-01-08 08:14:34 +00:00
|
|
|
|
public bool[][] SpecialTutors { get; protected set; } = new bool[0][];
|
2016-07-03 03:24:17 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected static bool[] GetBits(byte[] data)
|
2016-07-03 03:24:17 +00:00
|
|
|
|
{
|
2017-03-18 23:50:34 +00:00
|
|
|
|
bool[] r = new bool[data.Length<<3];
|
2016-07-03 03:24:17 +00:00
|
|
|
|
for (int i = 0; i < r.Length; i++)
|
2017-03-18 23:50:34 +00:00
|
|
|
|
r[i] = (data[i>>3] >> (i&7) & 0x1) == 1;
|
2016-07-03 03:24:17 +00:00
|
|
|
|
return r;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected static byte[] SetBits(bool[] bits)
|
2016-07-03 03:24:17 +00:00
|
|
|
|
{
|
2017-03-18 23:50:34 +00:00
|
|
|
|
byte[] data = new byte[bits.Length>>3];
|
2016-07-03 03:24:17 +00:00
|
|
|
|
for (int i = 0; i < bits.Length; i++)
|
2017-03-18 23:50:34 +00:00
|
|
|
|
data[i>>3] |= (byte)(bits[i] ? 1 << (i&0x7) : 0);
|
2016-07-03 03:24:17 +00:00
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
2017-11-07 06:44:51 +00:00
|
|
|
|
/// Injects supplementary TM/HM compatibility which is not present in the generation specific <see cref="PersonalInfo"/> format.
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
internal void AddTMHM(byte[] data) => TMHM = GetBits(data);
|
|
|
|
|
/// <summary>
|
2017-11-07 06:44:51 +00:00
|
|
|
|
/// Injects supplementary Type Tutor compatibility which is not present in the generation specific <see cref="PersonalInfo"/> format.
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
internal void AddTypeTutors(byte[] data) => TypeTutors = GetBits(data);
|
2017-03-18 23:50:34 +00:00
|
|
|
|
|
2017-11-07 06:44:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the <see cref="PersonalTable"/> <see cref="PKM.AltForm"/> entry index for the input criteria, with fallback for the original species entry.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="species"><see cref="PKM.Species"/> to retrieve for</param>
|
|
|
|
|
/// <param name="forme"><see cref="PKM.AltForm"/> to retrieve for</param>
|
|
|
|
|
/// <returns>Index the <see cref="PKM.AltForm"/> exists as in the <see cref="PersonalTable"/>.</returns>
|
2016-07-03 03:24:17 +00:00
|
|
|
|
public int FormeIndex(int species, int forme)
|
|
|
|
|
{
|
2016-07-05 06:53:15 +00:00
|
|
|
|
if (forme <= 0) // no forme requested
|
2016-07-03 20:04:07 +00:00
|
|
|
|
return species;
|
2016-07-05 06:53:15 +00:00
|
|
|
|
if (FormStatsIndex <= 0) // no formes present
|
2016-07-03 20:04:07 +00:00
|
|
|
|
return species;
|
2017-11-11 03:53:11 +00:00
|
|
|
|
if (forme >= FormeCount) // beyond range of species' formes
|
2016-07-03 20:04:07 +00:00
|
|
|
|
return species;
|
|
|
|
|
|
|
|
|
|
return FormStatsIndex + forme - 1;
|
2016-07-03 03:24:17 +00:00
|
|
|
|
}
|
|
|
|
|
public int RandomGender
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (Gender)
|
|
|
|
|
{
|
|
|
|
|
case 255: // Genderless
|
|
|
|
|
return 2;
|
|
|
|
|
case 254: // Female
|
|
|
|
|
return 1;
|
|
|
|
|
case 0: // Male
|
|
|
|
|
return 0;
|
|
|
|
|
default:
|
2017-10-24 06:12:58 +00:00
|
|
|
|
return (int)(Util.Rand32() & 1);
|
2016-07-03 03:24:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public bool HasFormes => FormeCount > 1;
|
|
|
|
|
public int BST => HP + ATK + DEF + SPE + SPA + SPD;
|
2017-11-22 02:31:24 +00:00
|
|
|
|
|
|
|
|
|
public bool IsFormeWithinRange(int forme)
|
|
|
|
|
{
|
|
|
|
|
if (forme == 0)
|
|
|
|
|
return true;
|
|
|
|
|
return forme < FormeCount;
|
|
|
|
|
}
|
2016-07-03 03:24:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|