2016-11-13 21:11:53 +00:00
using System ;
using System.Linq ;
2016-06-20 04:22:43 +00:00
2017-01-08 07:54:09 +00:00
namespace PKHeX.Core
2016-06-20 04:22:43 +00:00
{
2017-10-23 22:45:58 +00:00
/// <summary>
/// Mystery Gift Template File
/// </summary>
2017-12-19 00:17:21 +00:00
public abstract class MysteryGift : IEncounterable , IMoveset , IGeneration
2016-06-20 04:22:43 +00:00
{
2016-10-06 04:06:24 +00:00
/// <summary>
/// Determines whether or not the given length of bytes is valid for a mystery gift.
/// </summary>
/// <param name="len">Length, in bytes, of the data of which to determine validity.</param>
/// <returns>A boolean indicating whether or not the given length is valid for a mystery gift.</returns>
2017-06-18 01:37:19 +00:00
public static bool IsMysteryGift ( long len )
2016-08-06 19:57:53 +00:00
{
return new [ ] { WC6 . SizeFull , WC6 . Size , PGF . Size , PGT . Size , PCD . Size } . Contains ( ( int ) len ) ;
}
2016-10-06 04:06:24 +00:00
/// <summary>
/// Converts the given data to a <see cref="MysteryGift"/>.
/// </summary>
/// <param name="data">Raw data of the mystery gift.</param>
/// <param name="ext">Extension of the file from which the <paramref name="data"/> was retrieved.</param>
/// <returns>An instance of <see cref="MysteryGift"/> representing the given data, or null if <paramref name="data"/> or <paramref name="ext"/> is invalid.</returns>
2017-06-18 01:37:19 +00:00
/// <remarks>This overload differs from <see cref="GetMysteryGift(byte[])"/> by checking the <paramref name="data"/>/<paramref name="ext"/> combo for validity. If either is invalid, a null reference is returned.</remarks>
public static MysteryGift GetMysteryGift ( byte [ ] data , string ext )
2016-06-20 04:22:43 +00:00
{
2017-10-23 22:45:58 +00:00
if ( ext = = null )
return GetMysteryGift ( data ) ;
2016-11-13 21:11:53 +00:00
2017-10-23 22:45:58 +00:00
switch ( data . Length )
{
case WC7 . SizeFull when ext = = ".wc7full" :
case WC7 . Size when ext = = ".wc7" :
return new WC7 ( data ) ;
case WC6 . SizeFull when ext = = ".wc6full" :
case WC6 . Size when ext = = ".wc6" :
return new WC6 ( data ) ;
2016-11-13 21:11:53 +00:00
2017-10-23 22:45:58 +00:00
case PGF . Size when ext = = ".pgf" :
return new PGF ( data ) ;
case PGT . Size when ext = = ".pgt" :
return new PGT ( data ) ;
2017-11-07 00:26:34 +00:00
case PCD . Size when ext = = ".pcd" | | ext = = ".wc4" :
2017-10-23 22:45:58 +00:00
return new PCD ( data ) ;
}
2016-11-13 21:11:53 +00:00
2016-06-20 04:22:43 +00:00
return null ;
}
2016-10-06 04:06:24 +00:00
/// <summary>
/// Converts the given data to a <see cref="MysteryGift"/>.
/// </summary>
/// <param name="data">Raw data of the mystery gift.</param>
/// <returns>An instance of <see cref="MysteryGift"/> representing the given data, or null if <paramref name="data"/> is invalid.</returns>
2017-06-18 01:37:19 +00:00
public static MysteryGift GetMysteryGift ( byte [ ] data )
2016-07-24 22:44:44 +00:00
{
switch ( data . Length )
{
case WC6 . SizeFull :
2016-11-13 23:51:28 +00:00
// Check WC7 size collision
if ( data [ 0x205 ] = = 0 ) // 3 * 0x46 for gen6, now only 2.
2016-11-13 21:11:53 +00:00
return new WC7 ( data ) ;
return new WC6 ( data ) ;
2016-07-24 22:44:44 +00:00
case WC6 . Size :
2016-11-13 21:11:53 +00:00
// Check year for WC7 size collision
if ( BitConverter . ToUInt32 ( data , 0x4C ) / 10000 < 2000 )
return new WC7 ( data ) ;
2016-07-24 22:44:44 +00:00
return new WC6 ( data ) ;
2017-10-23 22:45:58 +00:00
case PGF . Size : return new PGF ( data ) ;
case PGT . Size : return new PGT ( data ) ;
case PCD . Size : return new PCD ( data ) ;
default : return null ;
2016-07-24 22:44:44 +00:00
}
}
2016-06-20 04:22:43 +00:00
2017-01-07 17:54:31 +00:00
public string Extension = > GetType ( ) . Name . ToLower ( ) ;
2017-09-30 05:58:25 +00:00
public string FileName = > $"{CardHeader}.{Extension}" ;
2017-04-19 10:15:50 +00:00
public byte [ ] Data { get ; set ; }
2017-06-18 01:37:19 +00:00
public abstract PKM ConvertToPKM ( SaveFile SAV ) ;
2016-09-04 17:38:53 +00:00
public abstract int Format { get ; }
2016-06-20 04:22:43 +00:00
2017-11-07 06:44:51 +00:00
/// <summary>
/// Creates a deep copy of the <see cref="MysteryGift"/> object data.
/// </summary>
/// <returns></returns>
2016-08-16 03:47:34 +00:00
public MysteryGift Clone ( )
{
byte [ ] data = ( byte [ ] ) Data . Clone ( ) ;
2017-06-18 01:37:19 +00:00
return GetMysteryGift ( data ) ;
2016-08-16 03:47:34 +00:00
}
2017-11-07 06:44:51 +00:00
/// <summary>
/// Gets a friendly name for the underlying <see cref="MysteryGift"/> type.
/// </summary>
2016-08-16 03:47:34 +00:00
public string Type = > GetType ( ) . Name ;
2017-11-07 06:44:51 +00:00
/// <summary>
/// Gets a friendly name for the underlying <see cref="MysteryGift"/> type for the <see cref="IEncounterable"/> interface.
/// </summary>
2017-01-05 06:25:45 +00:00
public string Name = > $"Event Gift ({Type})" ;
2016-08-16 03:47:34 +00:00
2016-06-20 04:22:43 +00:00
// Properties
2017-05-13 03:32:36 +00:00
public virtual int Species { get = > - 1 ; set { } }
2016-06-20 04:22:43 +00:00
public abstract bool GiftUsed { get ; set ; }
public abstract string CardTitle { get ; set ; }
public abstract int CardID { get ; set ; }
public abstract bool IsItem { get ; set ; }
2017-06-18 01:37:19 +00:00
public abstract int ItemID { get ; set ; }
2016-06-20 04:22:43 +00:00
public abstract bool IsPokémon { get ; set ; }
2017-05-13 03:32:36 +00:00
public virtual int Quantity { get = > 1 ; set { } }
2017-07-16 01:36:55 +00:00
public virtual bool Empty = > Data . All ( z = > z = = 0 ) ;
2016-06-20 04:22:43 +00:00
2017-05-13 03:32:36 +00:00
public virtual bool IsBP { get = > false ; set { } }
public virtual int BP { get = > 0 ; set { } }
public virtual bool IsBean { get = > false ; set { } }
public virtual int Bean { get = > 0 ; set { } }
public virtual int BeanCount { get = > 0 ; set { } }
2017-01-27 17:09:28 +00:00
2017-06-18 01:37:19 +00:00
public virtual string CardHeader = > ( CardID > 0 ? $"Card #: {CardID:0000}" : "N/A" ) + $" - {CardTitle.Replace('\u3000',' ').Trim()}" ;
2016-09-04 17:38:53 +00:00
2017-04-19 10:15:50 +00:00
public override int GetHashCode ( )
{
int hash = 17 ;
foreach ( var b in Data )
hash = hash * 31 + b ;
return hash ;
}
2016-09-04 17:38:53 +00:00
// Search Properties
2017-05-13 03:32:36 +00:00
public virtual int [ ] Moves { get = > new int [ 4 ] ; set { } }
public virtual int [ ] RelearnMoves { get = > new int [ 4 ] ; set { } }
2016-09-04 17:38:53 +00:00
public virtual bool IsShiny = > false ;
2017-05-13 03:32:36 +00:00
public virtual bool IsEgg { get = > false ; set { } }
public virtual int HeldItem { get = > - 1 ; set { } }
2016-10-23 19:48:49 +00:00
public virtual object Content = > this ;
2017-11-18 19:34:23 +00:00
public abstract int Gender { get ; set ; }
public abstract int Form { get ; set ; }
public abstract int TID { get ; set ; }
public abstract int SID { get ; set ; }
public abstract string OT_Name { get ; set ; }
2016-10-23 19:48:49 +00:00
public abstract int Level { get ; set ; }
2017-04-12 03:55:34 +00:00
public int LevelMin = > Level ;
public int LevelMax = > Level ;
2016-10-23 19:48:49 +00:00
public abstract int Ball { get ; set ; }
2016-09-04 17:38:53 +00:00
public bool Gen7 = > Format = = 7 ;
public bool Gen6 = > Format = = 6 ;
public bool Gen5 = > Format = = 5 ;
public bool Gen4 = > Format = = 4 ;
public bool Gen3 = > Format = = 3 ;
Gen 1 move analysis improvement. Adapted the valid moves to take into account that move deleter and move reminder do not exits in generation 1 (#1037)
* Fix getMoves with min level, when SkipWhile and TakeWhile is used together the index i in TakeWhile is calculated from the enumerator that results of the SkipWhile function, not the index of the initial array, those giving an incorrect index to check Levels array in the TakeWhile
* Fix getMoves when levelmin or levelmax is above max level in the levels array, TakeWhile and SkipWhile return empty list if the while goes beyond the last element of the array
* Include player hatched egg in the list of possible encounters for parseMoves only if the pokemon was an egg
Also change the valur of WasEgg for gen1,2,3 pokemon if the encounter analyzed is not an egg
add the non egg encounters to the list instead of checking the non-egg encounter inside parseMovesWasEggPreRelearn
* Fix for gen3 egg encounters
Remove non-egg encounters without special moves if there is an egg encounter because egg encounter already cover every possible move combination
Do not add daycare egg encounter for gen3 unhatched egg if there is another encounter, that means is an event or gift egg, not a daycare egg
Remove duplicate encounters
* Gift egg should not allow inherited moves even it they dont have special moves
Those gift eggs are hatched only with the species base moves
* Added getEncounterMoves functions, to be used for generation 1 encounters to find what moves have a pokemon at the moment of being caught because there is no move reminder in generation 1
* Added GBEncounterData, structure for refactor the tuples used in generation 1 and 2 encounters
* Add LevelMin and LevelMax to IEncounterable to get the encounter moves by the min level of the generation 1 EncounterLink
Add iGeneration to difference generation 1 and generation 2 encounters for GB Era pokemon
* Mark generation in gen 1 and 2 encounters
There is no need to mark the generation in gen 3 to 7 encounters because in that generations it match the pokemon generation number
* Add min level for generation 1 moves in getMoves functions
Add function to return the default moves for a GB encounters, for generation 1 games that included both moves from level up table and level 1 moves from personal table
Fix getMoves with min level when the moves list is empty, like Raichu generation 1
* Add maxSpecies to getBaseSpecies function for gen1 pokemon with a gen2 egg encounter
Refactor VC Encounter changing Tuples for GBData class
* Fixed for gen 2 Checks
Also do not search for generation1 encounter if the gen2 pokemon have met location from crystal
* Fix VC wild encounters, should be stored as array or else other verifyEncounter functions wont work
* Add generation 1 parse moves function including default moves
* Clean-up get encounters
* Verify empty moves for generation 1 encounters, in generation 1 does not exits move deleter
That means when a move slot have been used by a level up move or a TM/HM/Tutor move it cant be empty again
Does not apply if generation 2 tradeback is allowed, in generation 2 there is a move deleter
* Added two edge cases for pokemon that learn in red/blue and yellow different moves at the same level, this combinations can not exits until a later level when they learn again one of the levels in the other game, only happen for flareon and vaporeon
* Check incompatible moves between evolution species, it is for species that learn a move in a level as an evolved species and a move at a upper level as a preevolution
Also added most edge cases for the min slots used for generation 1 games, i think every weird combination is already covered
* Fix gen 1 eevee and evolutions move checks
* Cleanup
* Move the code to change valid moves for generation 1 to a function
* Fix getMoveMinLevelGBEncounter
* getUsedMoveSlots, removed wild Butterfree edge case, it is not possible
* Filter the min level of the encounter by the possible games the pokemon could be originated, yellow pikachu and kadabra can be detected
2017-04-09 00:17:20 +00:00
public virtual bool EggEncounter = > IsEgg ;
2017-12-19 00:17:21 +00:00
public int Generation { get = > Format ; set { } }
2016-06-20 04:22:43 +00:00
}
}