2021-05-27 19:20:00 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Modifications using <see cref="BatchInfo"/> legality.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static class BatchModifications
|
|
|
|
|
{
|
|
|
|
|
private static bool IsAll(string p) => p.EndsWith("All", true, CultureInfo.CurrentCulture);
|
|
|
|
|
private static bool IsNone(string p) => p.EndsWith("None", true, CultureInfo.CurrentCulture);
|
|
|
|
|
|
|
|
|
|
public static ModifyResult SetSuggestedRelearnData(BatchInfo info, string propValue)
|
|
|
|
|
{
|
|
|
|
|
var pk = info.Entity;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
if (pk is ITechRecord8 t)
|
2021-05-27 19:20:00 +00:00
|
|
|
|
{
|
2022-02-05 01:35:15 +00:00
|
|
|
|
t.ClearRecordFlags();
|
2021-05-27 19:20:00 +00:00
|
|
|
|
if (IsAll(propValue))
|
2022-02-05 01:35:15 +00:00
|
|
|
|
t.SetRecordFlags(); // all
|
2021-05-27 19:20:00 +00:00
|
|
|
|
else if (!IsNone(propValue))
|
2022-02-05 01:35:15 +00:00
|
|
|
|
t.SetRecordFlags(pk.Moves); // whatever fit the current moves
|
2021-05-27 19:20:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pk.SetRelearnMoves(info.SuggestedRelearn);
|
|
|
|
|
return ModifyResult.Modified;
|
|
|
|
|
}
|
2022-02-05 04:04:57 +00:00
|
|
|
|
|
|
|
|
|
public static ModifyResult SetSuggestedMasteryData(BatchInfo info, string propValue)
|
|
|
|
|
{
|
|
|
|
|
var pk = info.Entity;
|
2022-05-03 06:48:25 +00:00
|
|
|
|
if (pk is not IMoveShop8Mastery t)
|
|
|
|
|
return ModifyResult.Invalid;
|
|
|
|
|
|
2022-05-08 17:28:22 +00:00
|
|
|
|
t.ClearMoveShopFlags();
|
|
|
|
|
if (IsNone(propValue))
|
|
|
|
|
return ModifyResult.Modified;
|
|
|
|
|
|
|
|
|
|
var e = info.Legality.EncounterMatch;
|
|
|
|
|
if (e is IMasteryInitialMoveShop8 enc)
|
|
|
|
|
enc.SetInitialMastery(pk);
|
2022-05-03 06:48:25 +00:00
|
|
|
|
if (IsAll(propValue))
|
2022-05-08 04:21:29 +00:00
|
|
|
|
t.SetMoveShopFlagsAll(pk);
|
2022-05-03 06:48:25 +00:00
|
|
|
|
else
|
2022-05-08 17:28:22 +00:00
|
|
|
|
t.SetMoveShopFlags(pk);
|
2022-05-03 06:48:25 +00:00
|
|
|
|
return ModifyResult.Modified;
|
2022-02-05 04:04:57 +00:00
|
|
|
|
}
|
2021-05-27 19:20:00 +00:00
|
|
|
|
|
|
|
|
|
public static ModifyResult SetSuggestedRibbons(BatchInfo info, string value)
|
|
|
|
|
{
|
|
|
|
|
var pk = info.Entity;
|
|
|
|
|
if (IsNone(value))
|
|
|
|
|
RibbonApplicator.RemoveAllValidRibbons(pk);
|
|
|
|
|
else // All
|
|
|
|
|
RibbonApplicator.SetAllValidRibbons(pk);
|
|
|
|
|
return ModifyResult.Modified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ModifyResult SetSuggestedMetData(BatchInfo info)
|
|
|
|
|
{
|
|
|
|
|
var pk = info.Entity;
|
|
|
|
|
var encounter = EncounterSuggestion.GetSuggestedMetInfo(pk);
|
|
|
|
|
if (encounter == null)
|
|
|
|
|
return ModifyResult.Error;
|
|
|
|
|
|
|
|
|
|
int level = encounter.LevelMin;
|
|
|
|
|
int location = encounter.Location;
|
|
|
|
|
int minimumLevel = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin);
|
|
|
|
|
|
|
|
|
|
pk.Met_Level = level;
|
|
|
|
|
pk.Met_Location = location;
|
|
|
|
|
pk.CurrentLevel = Math.Max(minimumLevel, level);
|
|
|
|
|
|
|
|
|
|
return ModifyResult.Modified;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 06:33:53 +00:00
|
|
|
|
public static ModifyResult SetMinimumCurrentLevel(BatchInfo info)
|
|
|
|
|
{
|
|
|
|
|
var result = EncounterSuggestion.IterateMinimumCurrentLevel(info.Entity, info.Legal);
|
|
|
|
|
return result ? ModifyResult.Modified : ModifyResult.Filtered;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 19:20:00 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the provided moves in a random order.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">Pokémon to modify.</param>
|
|
|
|
|
/// <param name="moves">Moves to apply.</param>
|
2022-06-13 07:04:20 +00:00
|
|
|
|
public static ModifyResult SetMoves(PKM pk, ReadOnlySpan<int> moves)
|
2021-05-27 19:20:00 +00:00
|
|
|
|
{
|
|
|
|
|
pk.SetMoves(moves);
|
|
|
|
|
pk.HealPP();
|
|
|
|
|
return ModifyResult.Modified;
|
|
|
|
|
}
|
2021-12-21 03:16:23 +00:00
|
|
|
|
|
2022-05-06 22:47:54 +00:00
|
|
|
|
public static ModifyResult SetEVs(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
Span<int> evs = stackalloc int[6];
|
|
|
|
|
EffortValues.SetMax(evs, pk);
|
|
|
|
|
pk.SetEVs(evs);
|
|
|
|
|
return ModifyResult.Modified;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 03:16:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the contests stats as requested.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">Pokémon to modify.</param>
|
2022-05-31 04:43:52 +00:00
|
|
|
|
/// <param name="la">Legality Information matched to.</param>
|
2021-12-21 03:16:23 +00:00
|
|
|
|
/// <param name="option">Option to apply with</param>
|
2022-05-31 04:43:52 +00:00
|
|
|
|
public static ModifyResult SetContestStats(PKM pk, LegalityAnalysis la, string option)
|
2021-12-21 03:16:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (option.Length != 0 && option[BatchEditing.CONST_SUGGEST.Length..] is not "0")
|
2022-05-31 04:43:52 +00:00
|
|
|
|
pk.SetMaxContestStats(la.EncounterMatch, la.Info.EvoChainsAllGens);
|
2021-12-21 03:16:23 +00:00
|
|
|
|
else
|
2022-05-31 04:43:52 +00:00
|
|
|
|
pk.SetSuggestedContestStats(la.EncounterMatch, la.Info.EvoChainsAllGens);
|
2021-12-21 03:16:23 +00:00
|
|
|
|
return ModifyResult.Modified;
|
|
|
|
|
}
|
2021-05-27 19:20:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|