using System; using System.Collections.Generic; using System.Globalization; using static PKHeX.Core.BatchEditing; namespace PKHeX.Core; public static class BatchMods { public static readonly List SuggestionMods = new() { // Interface Specific new TypeSuggestion(nameof(ICombatPower.Stat_CP), p => p.ResetCP()), new TypeSuggestion(nameof(IScaledSizeValue.HeightAbsolute), p => p.ResetHeight()), new TypeSuggestion(nameof(IScaledSizeValue.WeightAbsolute), p => p.ResetWeight()), new TypeSuggestion(nameof(Extensions.HyperTrainClear), p => p.HyperTrainClear()), new TypeSuggestion(nameof(Extensions.ClearGeoLocationData), p => p.ClearGeoLocationData()), new TypeSuggestion(nameof(AwakeningUtil.AwakeningClear), p => p.AwakeningClear()), new TypeSuggestion(nameof(AwakeningUtil.AwakeningMax), p => p.AwakeningMax()), new TypeSuggestion(nameof(GanbaruExtensions.ClearGanbaruValues), p => p.ClearGanbaruValues()), new TypeSuggestion(nameof(GanbaruExtensions.SetSuggestedGanbaruValues), p => p.SetSuggestedGanbaruValues((PKM)p)), // Date Copy new TypeSuggestion(nameof(PKM.EggMetDate), p => p.EggMetDate = p.MetDate), new TypeSuggestion(nameof(PKM.MetDate), p => p.MetDate = p.EggMetDate), new TypeSuggestion(nameof(PKM.Nature), p => p.Format >= 8, p => p.Nature = p.StatNature), new TypeSuggestion(nameof(PKM.StatNature), p => p.Format >= 8, p => p.StatNature = p.Nature), new TypeSuggestion(nameof(PKM.Stats), p => p.ResetPartyStats()), new TypeSuggestion(nameof(PKM.Ball), p => BallApplicator.ApplyBallLegalByColor(p)), new TypeSuggestion(nameof(PKM.Heal), p => p.Heal()), new TypeSuggestion(nameof(PKM.HealPP), p => p.HealPP()), new TypeSuggestion(nameof(IHyperTrain.HyperTrainFlags), p => p.SetSuggestedHyperTrainingData()), new TypeSuggestion(nameof(PKM.Move1_PP), p => p.SetSuggestedMovePP(0)), new TypeSuggestion(nameof(PKM.Move2_PP), p => p.SetSuggestedMovePP(1)), new TypeSuggestion(nameof(PKM.Move3_PP), p => p.SetSuggestedMovePP(2)), new TypeSuggestion(nameof(PKM.Move4_PP), p => p.SetSuggestedMovePP(3)), new ComplexSuggestion(nameof(PKM.Moves), (_, _, info) => BatchModifications.SetMoves(info.Entity, info.Legality.GetMoveSet())), new ComplexSuggestion(PROP_EVS, (_, _, info) => BatchModifications.SetEVs(info.Entity)), new ComplexSuggestion(nameof(PKM.RelearnMoves), (_, value, info) => BatchModifications.SetSuggestedRelearnData(info, value)), new ComplexSuggestion(PROP_RIBBONS, (_, value, info) => BatchModifications.SetSuggestedRibbons(info, value)), new ComplexSuggestion(nameof(PKM.Met_Location), (_, _, info) => BatchModifications.SetSuggestedMetData(info)), new ComplexSuggestion(nameof(PKM.CurrentLevel), (_, _, info) => BatchModifications.SetMinimumCurrentLevel(info)), new ComplexSuggestion(PROP_CONTESTSTATS, p => p is IContestStatsMutable, (_, value, info) => BatchModifications.SetContestStats(info.Entity, info.Legality, value)), new ComplexSuggestion(PROP_MOVEMASTERY, (_, value, info) => BatchModifications.SetSuggestedMasteryData(info, value)), }; private static DateTime ParseDate(string val) => DateTime.ParseExact(val, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); public static readonly List ComplexMods = new() { // Date new ComplexSet(nameof(PKM.MetDate), (pk, cmd) => pk.MetDate = ParseDate(cmd.PropertyValue)), new ComplexSet(nameof(PKM.EggMetDate), (pk, cmd) => pk.EggMetDate = ParseDate(cmd.PropertyValue)), // Value Swap new ComplexSet(nameof(PKM.EncryptionConstant), value => value == nameof(PKM.PID), (pk, _) => pk.EncryptionConstant = pk.PID), new ComplexSet(nameof(PKM.PID), value => value == nameof(PKM.EncryptionConstant), (pk, _) => pk.PID = pk.EncryptionConstant), // Realign to Derived Value new ComplexSet(nameof(PKM.Ability), value => value.StartsWith(CONST_SPECIAL), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)), new ComplexSet(nameof(PKM.AbilityNumber), value => value.StartsWith(CONST_SPECIAL), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)), // Random new ComplexSet(nameof(PKM.EncryptionConstant), value => value == CONST_RAND, (pk, _) => pk.EncryptionConstant = Util.Rand32()), new ComplexSet(nameof(PKM.PID), value => value == CONST_RAND, (pk, _) => pk.PID = Util.Rand32()), new ComplexSet(nameof(PKM.Gender), value => value == CONST_RAND, (pk, _) => pk.SetPIDGender(pk.Gender)), new ComplexSet(PROP_EVS, value => value == CONST_RAND, (pk, _) => SetRandomEVs(pk)), // Shiny new ComplexSet(nameof(PKM.PID), value => value.StartsWith(CONST_SHINY, true, CultureInfo.CurrentCulture), (pk, cmd) => CommonEdits.SetShiny(pk, GetRequestedShinyState(cmd.PropertyValue))), new ComplexSet(nameof(PKM.Species), value => value == "0", (pk, _) => Array.Clear(pk.Data, 0, pk.Data.Length)), new ComplexSet(nameof(PKM.IsNicknamed), value => string.Equals(value, "false", StringComparison.OrdinalIgnoreCase), (pk, _) => pk.SetDefaultNickname()), }; private static void SetRandomEVs(PKM pk) { Span evs = stackalloc int[6]; EffortValues.SetRandom(evs, pk.Format); pk.SetEVs(evs); } private static Shiny GetRequestedShinyState(string text) => text.Length == 0 ? Shiny.Random : GetRequestedShinyState(text[^1]); private static Shiny GetRequestedShinyState(char last) => last switch { '0' => Shiny.AlwaysSquare, '1' => Shiny.AlwaysStar, _ => Shiny.Random, }; }