Move more logic closer to where it's used

This commit is contained in:
Kurt
2020-11-02 14:46:26 -08:00
parent 7cb6ee0060
commit 51c872f4e1
20 changed files with 104 additions and 104 deletions

View File

@@ -73,7 +73,7 @@ private IEnumerable<EncounterSlot> GetSlotsMatching(IReadOnlyList<EvoCriteria> c
if (slot.Species != evo.Species)
continue;
if (slot.Form != evo.Form && !Legal.WildChangeFormAfter.Contains(slot.Species) && slot.Species != (int)Species.Unown)
if (slot.Form != evo.Form && !AltFormInfo.WildChangeFormAfter.Contains(slot.Species) && slot.Species != (int)Species.Unown)
break;
if (!slot.IsLevelWithinRange(lvl))
break;
@@ -93,7 +93,7 @@ private IEnumerable<EncounterSlot> GetSlotsFuzzy(IReadOnlyList<EvoCriteria> chai
if (slot.Species != evo.Species)
continue;
if (slot.Form != evo.Form && !Legal.WildChangeFormAfter.Contains(slot.Species) && slot.Species != (int)Species.Unown)
if (slot.Form != evo.Form && !AltFormInfo.WildChangeFormAfter.Contains(slot.Species) && slot.Species != (int)Species.Unown)
break;
if (slot.LevelMin > evo.Level)
break;

View File

@@ -56,7 +56,7 @@ public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyLi
if (!slot.IsLevelWithinRange(pkm.Met_Level))
break;
if (slot.Form != evo.Form && !Legal.WildChangeFormAfter.Contains(slot.Species))
if (slot.Form != evo.Form && !AltFormInfo.WildChangeFormAfter.Contains(slot.Species))
break;
yield return slot;

View File

@@ -75,7 +75,7 @@ public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyLi
if (!slot.IsLevelWithinRange(pkm.Met_Level))
break;
if (slot.Form != evo.Form && slot.Form < RandomFormVivillon && !Legal.WildChangeFormAfter.Contains(slot.Species))
if (slot.Form != evo.Form && slot.Form < RandomFormVivillon && !AltFormInfo.WildChangeFormAfter.Contains(slot.Species))
{
if (slot.Species != (int)Species.Flabébé)
break;

View File

@@ -56,7 +56,7 @@ public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyLi
if (!slot.IsLevelWithinRange(pkm.Met_Level))
break;
if (slot.Form != evo.Form && !Legal.WildChangeFormAfter.Contains(slot.Species))
if (slot.Form != evo.Form && !AltFormInfo.WildChangeFormAfter.Contains(slot.Species))
{
if (slot.Species != (int)Species.Minior) // Random Color, edge case
break;

View File

@@ -49,7 +49,7 @@ private IEnumerable<EncounterSlot> GetUnboostedMatches(IReadOnlyList<EvoCriteria
if (!slot.IsLevelWithinRange(met))
break;
if (slot.Form != evo.Form && !Legal.WildChangeFormAfter.Contains(evo.Species))
if (slot.Form != evo.Form && !AltFormInfo.WildChangeFormAfter.Contains(evo.Species))
break;
yield return slot;
@@ -69,7 +69,7 @@ private IEnumerable<EncounterSlot> GetBoostedMatches(IReadOnlyList<EvoCriteria>
// Ignore met level comparison; we already know it is permissible to boost to level 60.
if (slot.Form != evo.Form && !Legal.WildChangeFormAfter.Contains(evo.Species))
if (slot.Form != evo.Form && !AltFormInfo.WildChangeFormAfter.Contains(evo.Species))
break;
yield return slot;

View File

@@ -183,51 +183,6 @@ internal static int GetMaxLanguageID(int generation)
};
}
internal static bool IsEvolutionValid(PKM pkm, int minSpecies = -1, int minLevel = -1)
{
var curr = EvolutionChain.GetValidPreEvolutions(pkm, minLevel: minLevel);
var min = curr.FindLast(z => z.Species == minSpecies);
if (min != null && min.Level < minLevel)
return false;
var poss = EvolutionChain.GetValidPreEvolutions(pkm, maxLevel: 100, minLevel: minLevel, skipChecks: true);
if (minSpecies != -1)
{
int last = poss.FindLastIndex(z => z.Species == minSpecies);
return curr.Count >= last;
}
int gen = pkm.GenNumber;
if (gen >= 3 && GetSplitBreedGeneration(gen).Contains(EvoBase.GetBaseSpecies(poss, 1).Species))
return curr.Count >= poss.Count - 1;
return curr.Count >= poss.Count;
}
/// <summary>Checks if the form may be different than the original encounter detail.</summary>
/// <param name="species">Original species</param>
/// <param name="oldForm">Original form</param>
/// <param name="newForm">Current form</param>
/// <param name="format">Current format</param>
internal static bool IsFormChangeable(int species, int oldForm, int newForm, int format)
{
if (FormChange.Contains(species))
return true;
// Zygarde Form Changing
// Gen6: Introduced; no form changing.
// Gen7: Form changing introduced; can only change to Form 2/3 (Power Construct), never to 0/1 (Aura Break). A form-1 can be boosted to form-0.
// Gen8: Form changing improved; can pick any Form & Ability combination.
if (species == (int)Species.Zygarde)
{
return format switch
{
6 => false,
7 => newForm >= 2 || (oldForm == 1 && newForm == 0),
_ => true,
};
}
return false;
}
internal static bool GetCanInheritMoves(int species)
{
if (FixedGenderFromBiGender.Contains(species)) // Nincada -> Shedinja loses gender causing 'false', edge case
@@ -267,15 +222,6 @@ internal static bool GetCanKnowMove(PKM pkm, int move, int generation, IReadOnly
internal static bool HasVisitedUSUM(this PKM pkm, int species) => pkm.InhabitedGeneration(7, species) && (pkm.USUM || !pkm.IsUntraded);
internal static bool IsMovesetRestricted(this PKM pkm, int gen) => (pkm.GG && gen == 7) || pkm.IsUntraded;
public static bool HasMetLocationUpdatedTransfer(int originalGeneration, int currentGeneration)
{
if (originalGeneration < 3)
return currentGeneration >= 3;
if (originalGeneration <= 4)
return currentGeneration != originalGeneration;
return false;
}
public static bool IsValidMissingLanguage(PKM pkm)
{
return pkm.Format == 5 && pkm.BW;

View File

@@ -257,7 +257,7 @@ protected virtual bool IsMatchForm(PKM pkm, DexLevel evo)
{
if (SkipFormCheck)
return true;
return Form == evo.Form || Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format);
return Form == evo.Form || AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format);
}
protected virtual bool IsMatchEggLocation(PKM pkm)

View File

@@ -26,7 +26,7 @@ protected override bool IsMatchForm(PKM pkm, DexLevel evo)
return expectForm == evo.Form;
}
return Form == evo.Form || Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format);
return Form == evo.Form || AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format);
}
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)

View File

@@ -242,7 +242,7 @@ public virtual bool IsMatch(PKM pkm, DexLevel evo)
if (CurrentLevel != -1 && CurrentLevel > pkm.CurrentLevel)
return false;
if (Form != evo.Form && !Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
if (Form != evo.Form && !AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
return false;
if (OTGender != -1 && OTGender != pkm.OT_Gender)
return false;

View File

@@ -146,5 +146,24 @@ private static bool GetCanBeEgg2(PKM pkm)
return pkm.CurrentLevel >= 5;
}
private static bool IsEvolutionValid(PKM pkm, int minSpecies = -1, int minLevel = -1)
{
var curr = EvolutionChain.GetValidPreEvolutions(pkm, minLevel: minLevel);
var min = curr.FindLast(z => z.Species == minSpecies);
if (min != null && min.Level < minLevel)
return false;
var poss = EvolutionChain.GetValidPreEvolutions(pkm, maxLevel: 100, minLevel: minLevel, skipChecks: true);
if (minSpecies != -1)
{
int last = poss.FindLastIndex(z => z.Species == minSpecies);
return curr.Count >= last;
}
int gen = pkm.GenNumber;
if (gen >= 3 && GetSplitBreedGeneration(gen).Contains(EvoBase.GetBaseSpecies(poss, 1).Species))
return curr.Count >= poss.Count - 1;
return curr.Count >= poss.Count;
}
}
}

View File

@@ -136,6 +136,15 @@ private static List<EvoCriteria>[] GetChainAll(PKM pkm, IEncounterable enc, IRea
return GensEvoChains;
}
private static bool HasMetLocationUpdatedTransfer(int originalGeneration, int currentGeneration)
{
if (originalGeneration < 3)
return currentGeneration >= 3;
if (originalGeneration <= 4)
return currentGeneration != originalGeneration;
return false;
}
private static void TrimVC1Transfer(PKM pkm, IList<List<EvoCriteria>> GensEvoChains)
{
if (GensEvoChains[7].All(z => z.Species > MaxSpeciesID_1))

View File

@@ -73,6 +73,65 @@ public static bool IsFusedForm(int species, int form, int format)
};
}
/// <summary>Checks if the form may be different than the original encounter detail.</summary>
/// <param name="species">Original species</param>
/// <param name="oldForm">Original form</param>
/// <param name="newForm">Current form</param>
/// <param name="format">Current format</param>
public static bool IsFormChangeable(int species, int oldForm, int newForm, int format)
{
if (FormChange.Contains(species))
return true;
// Zygarde Form Changing
// Gen6: Introduced; no form changing.
// Gen7: Form changing introduced; can only change to Form 2/3 (Power Construct), never to 0/1 (Aura Break). A form-1 can be boosted to form-0.
// Gen8: Form changing improved; can pick any Form & Ability combination.
if (species == (int)Zygarde)
{
return format switch
{
6 => false,
7 => newForm >= 2 || (oldForm == 1 && newForm == 0),
_ => true,
};
}
return false;
}
/// <summary>
/// Species that can be captured normally in the wild and can change between their forms.
/// </summary>
public static readonly HashSet<int> WildChangeFormAfter = new HashSet<int>
{
412, // Burmy
479, // Rotom
676, // Furfrou
741, // Oricorio
};
/// <summary>
/// Species that can change between their forms, regardless of origin.
/// </summary>
/// <remarks>Excludes Zygarde as it has special conditions. Check separately.</remarks>
private static readonly HashSet<int> FormChange = new HashSet<int>(WildChangeFormAfter)
{
386, // Deoxys
487, // Giratina
492, // Shaymin
493, // Arceus
641, // Tornadus
642, // Thundurus
645, // Landorus
646, // Kyurem
647, // Keldeo
649, // Genesect
720, // Hoopa
773, // Silvally
800, // Necrozma
898, // Calyrex
};
/// <summary>
/// Species that have an alternate form that cannot exist outside of battle.
/// </summary>

View File

@@ -9,17 +9,6 @@ public static partial class Legal
/// </summary>
public static readonly HashSet<int> LightBall = new HashSet<int> { 25, 26, 172 };
/// <summary>
/// Species that can be captured normally in the wild and can change between their forms.
/// </summary>
public static readonly HashSet<int> WildChangeFormAfter = new HashSet<int>
{
412, // Burmy
479, // Rotom
676, // Furfrou
741, // Oricorio
};
/// <summary>
/// Species that can yield a different baby species when bred.
/// </summary>
@@ -37,28 +26,6 @@ public static partial class Legal
358, // Chimecho
};
/// <summary>
/// Species that can change between their forms, regardless of origin.
/// </summary>
/// <remarks>Excludes Zygarde as it has special conditions. Check separately.</remarks>
public static readonly HashSet<int> FormChange = new HashSet<int>(WildChangeFormAfter)
{
386, // Deoxys
487, // Giratina
492, // Shaymin
493, // Arceus
641, // Tornadus
642, // Thundurus
645, // Landorus
646, // Kyurem
647, // Keldeo
649, // Genesect
720, // Hoopa
773, // Silvally
800, // Necrozma
898, // Calyrex
};
/// <summary>
/// Species that can change between their forms and get access to form-specific moves.
/// </summary>

View File

@@ -157,7 +157,7 @@ protected override bool IsMatchExact(PKM pkm, DexLevel evo)
return false;
}
if (wc.AltForm != evo.Form && !Legal.IsFormChangeable(wc.Species, wc.AltForm, pkm.AltForm, pkm.Format))
if (wc.AltForm != evo.Form && !AltFormInfo.IsFormChangeable(wc.Species, wc.AltForm, pkm.AltForm, pkm.Format))
return false;
if (wc.Ball != pkm.Ball) return false;

View File

@@ -369,7 +369,7 @@ protected override bool IsMatchExact(PKM pkm, DexLevel evo)
return false;
}
if (Form != evo.Form && !Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
if (Form != evo.Form && !AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
return false;
if (Level != pkm.Met_Level) return false;

View File

@@ -471,7 +471,7 @@ protected override bool IsMatchExact(PKM pkm, DexLevel evo)
if (EncryptionConstant != 0 && EncryptionConstant != pkm.EncryptionConstant) return false;
}
if (Form != evo.Form && !Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
if (Form != evo.Form && !AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
return false;
if (IsEgg)

View File

@@ -249,7 +249,7 @@ protected override bool IsMatchExact(PKM pkm, DexLevel evo)
}
}
if (Form != evo.Form && !Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
if (Form != evo.Form && !AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
return false;
if (Language != -1 && Language != pkm.Language) return false;

View File

@@ -487,7 +487,7 @@ protected override bool IsMatchExact(PKM pkm, DexLevel evo)
if (EncryptionConstant != 0 && EncryptionConstant != pkm.EncryptionConstant) return false;
if (Language != 0 && Language != pkm.Language) return false;
}
if (Form != evo.Form && !Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
if (Form != evo.Form && !AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
return false;
if (IsEgg)

View File

@@ -518,7 +518,7 @@ protected override bool IsMatchExact(PKM pkm, DexLevel evo)
if (Language != 0 && Language != pkm.Language) return false;
}
if (Form != evo.Form && !Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
if (Form != evo.Form && !AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
return false;
if (IsEgg)

View File

@@ -561,7 +561,7 @@ protected override bool IsMatchExact(PKM pkm, DexLevel evo)
}
}
if (Form != evo.Form && !Legal.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
if (Form != evo.Form && !AltFormInfo.IsFormChangeable(Species, Form, pkm.AltForm, pkm.Format))
return false;
if (IsEgg)