mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-23 10:53:10 +00:00
02420d3e93
* Handle some nullable cases Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data) Make some classes have explicit constructors instead of { } initialization * Handle bits more obviously without null * Make SaveFile.BAK explicitly readonly again * merge constructor methods to have readonly fields * Inline some properties * More nullable handling * Rearrange box actions define straightforward classes to not have any null properties * Make extrabyte reference array immutable * Move tooltip creation to designer * Rearrange some logic to reduce nesting * Cache generated fonts * Split mystery gift album purpose * Handle more tooltips * Disallow null setters * Don't capture RNG object, only type enum * Unify learnset objects Now have readonly properties which are never null don't new() empty learnsets (>800 Learnset objects no longer created, total of 2400 objects since we also new() a move & level array) optimize g1/2 reader for early abort case * Access rewrite Initialize blocks in a separate object, and get via that object removes a couple hundred "might be null" warnings since blocks are now readonly getters some block references have been relocated, but interfaces should expose all that's needed put HoF6 controls in a groupbox, and disable * Readonly personal data * IVs non nullable for mystery gift * Explicitly initialize forced encounter moves * Make shadow objects readonly & non-null Put murkrow fix in binary data resource, instead of on startup * Assign dex form fetch on constructor Fixes legality parsing edge cases also handle cxd parse for valid; exit before exception is thrown in FrameGenerator * Remove unnecessary null checks * Keep empty value until init SetPouch sets the value to an actual one during load, but whatever * Readonly team lock data * Readonly locks Put locked encounters at bottom (favor unlocked) * Mail readonly data / offset Rearrange some call flow and pass defaults Add fake classes for SaveDataEditor mocking Always party size, no need to check twice in stat editor use a fake save file as initial data for savedata editor, and for gamedata (wow i found a usage) constrain eventwork editor to struct variable types (uint, int, etc), thus preventing null assignment errors
103 lines
3.4 KiB
C#
103 lines
3.4 KiB
C#
using System;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
public interface IHyperTrain
|
|
{
|
|
int HyperTrainFlags { get; set; }
|
|
bool HT_HP { get; set; }
|
|
bool HT_ATK { get; set; }
|
|
bool HT_DEF { get; set; }
|
|
bool HT_SPA { get; set; }
|
|
bool HT_SPD { get; set; }
|
|
bool HT_SPE { get; set; }
|
|
}
|
|
|
|
public static partial class Extensions
|
|
{
|
|
/// <summary>
|
|
/// Toggles the Hyper Training flag for a given stat.
|
|
/// </summary>
|
|
/// <param name="t">Hyper Trainable object</param>
|
|
/// <param name="index">Battle Stat (H/A/B/S/C/D)</param>
|
|
/// <returns>Final Hyper Training Flag value</returns>
|
|
public static bool HyperTrainInvert(this IHyperTrain t, int index)
|
|
{
|
|
return index switch
|
|
{
|
|
0 => (t.HT_HP ^= true),
|
|
1 => (t.HT_ATK ^= true),
|
|
2 => (t.HT_DEF ^= true),
|
|
3 => (t.HT_SPE ^= true),
|
|
4 => (t.HT_SPA ^= true),
|
|
5 => (t.HT_SPD ^= true),
|
|
_ => false
|
|
};
|
|
}
|
|
|
|
public static bool IsHyperTrainedAll(this IHyperTrain t) => t.HyperTrainFlags == 0x3F;
|
|
public static void HyperTrainClear(this IHyperTrain t) => t.HyperTrainFlags = 0;
|
|
public static bool IsHyperTrained(this IHyperTrain t) => t.HyperTrainFlags != 0;
|
|
|
|
public static bool IsHyperTrained(this IHyperTrain t, int index)
|
|
{
|
|
return index switch
|
|
{
|
|
0 => t.HT_HP,
|
|
1 => t.HT_ATK,
|
|
2 => t.HT_DEF,
|
|
3 => t.HT_SPE,
|
|
4 => t.HT_SPA,
|
|
5 => t.HT_SPD,
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index))
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets one of the <see cref="IHyperTrain"/> values based on its index within the array.
|
|
/// </summary>
|
|
/// <param name="pk">Pokémon to check.</param>
|
|
/// <param name="index">Index to get</param>
|
|
public static bool GetHT(this IHyperTrain pk, int index)
|
|
{
|
|
return index switch
|
|
{
|
|
0 => pk.HT_HP,
|
|
1 => pk.HT_ATK,
|
|
2 => pk.HT_DEF,
|
|
3 => pk.HT_SPE,
|
|
4 => pk.HT_SPA,
|
|
5 => pk.HT_SPD,
|
|
_ => throw new ArgumentOutOfRangeException(nameof(index))
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets <see cref="IHyperTrain.HyperTrainFlags"/> to valid values which may best enhance the <see cref="PKM"/> stats.
|
|
/// </summary>
|
|
/// <param name="pkm"></param>
|
|
/// <param name="IVs"><see cref="PKM.IVs"/> to use (if already known). Will fetch the current <see cref="PKM.IVs"/> if not provided.</param>
|
|
public static void SetSuggestedHyperTrainingData(this PKM pkm, int[]? IVs = null)
|
|
{
|
|
if (!(pkm is IHyperTrain t))
|
|
return;
|
|
if (pkm.CurrentLevel < 100)
|
|
{
|
|
t.HyperTrainFlags = 0;
|
|
return;
|
|
}
|
|
if (IVs == null)
|
|
IVs = pkm.IVs;
|
|
|
|
t.HT_HP = IVs[0] != 31;
|
|
t.HT_ATK = IVs[1] != 31 && IVs[1] > 2;
|
|
t.HT_DEF = IVs[2] != 31;
|
|
t.HT_SPE = IVs[3] != 31 && IVs[3] > 2;
|
|
t.HT_SPA = IVs[4] != 31;
|
|
t.HT_SPD = IVs[5] != 31;
|
|
|
|
if (pkm is PB7 pb)
|
|
pb.ResetCP();
|
|
}
|
|
}
|
|
}
|