2018-09-02 18:31:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-02-19 01:00:16 +00:00
|
|
|
|
using PKHeX.Core.Searching;
|
2018-09-02 18:31:34 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2019-02-19 01:19:25 +00:00
|
|
|
|
public class BoxManipClear : IBoxManip
|
2018-09-02 18:31:34 +00:00
|
|
|
|
{
|
2019-02-19 01:19:25 +00:00
|
|
|
|
public BoxManipType Type { get; protected set; }
|
2018-09-02 18:31:34 +00:00
|
|
|
|
public Func<SaveFile, bool> Usable { get; set; }
|
|
|
|
|
|
|
|
|
|
public string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxClearAll : MessageStrings.MsgSaveBoxClearCurrent;
|
|
|
|
|
public string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
|
|
|
|
|
public string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
|
|
|
|
|
|
2019-02-19 01:19:25 +00:00
|
|
|
|
protected Func<PKM, bool> CriteriaSimple { private get; set; }
|
|
|
|
|
protected Func<PKM, SaveFile, bool> CriteriaSAV { private get; set; }
|
2018-09-02 18:31:34 +00:00
|
|
|
|
|
2019-02-21 01:59:54 +00:00
|
|
|
|
public virtual int Execute(SaveFile SAV, BoxManipParam param)
|
2018-09-02 18:31:34 +00:00
|
|
|
|
{
|
|
|
|
|
bool Method(PKM p) => param.Reverse ^ (CriteriaSAV?.Invoke(p, SAV) ?? CriteriaSimple?.Invoke(p) ?? true);
|
2019-02-21 01:59:54 +00:00
|
|
|
|
return SAV.ClearBoxes(param.Start, param.Stop, Method);
|
2018-09-02 18:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 01:19:25 +00:00
|
|
|
|
protected BoxManipClear() { }
|
|
|
|
|
|
2018-09-02 18:31:34 +00:00
|
|
|
|
private BoxManipClear(BoxManipType type, Func<PKM, bool> criteria, Func<SaveFile, bool> usable = null)
|
|
|
|
|
{
|
|
|
|
|
Type = type;
|
|
|
|
|
CriteriaSimple = criteria;
|
|
|
|
|
Usable = usable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BoxManipClear(BoxManipType type, Func<PKM, SaveFile, bool> criteria, Func<SaveFile, bool> usable = null)
|
|
|
|
|
{
|
|
|
|
|
Type = type;
|
|
|
|
|
CriteriaSAV = criteria;
|
|
|
|
|
Usable = usable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly IReadOnlyList<BoxManipClear> Common = new List<BoxManipClear>
|
|
|
|
|
{
|
|
|
|
|
new BoxManipClear(BoxManipType.DeleteAll, _ => true),
|
|
|
|
|
new BoxManipClear(BoxManipType.DeleteEggs, pk => pk.IsEgg, s => s.Generation >= 2),
|
|
|
|
|
new BoxManipClear(BoxManipType.DeletePastGen, (pk, sav) => pk.GenNumber != sav.Generation, s => s.Generation >= 4),
|
|
|
|
|
new BoxManipClear(BoxManipType.DeleteForeign, (pk, sav) => !sav.IsOriginalHandler(pk, pk.Format > 2)),
|
|
|
|
|
new BoxManipClear(BoxManipType.DeleteUntrained, pk => pk.EVTotal == 0),
|
|
|
|
|
new BoxManipClear(BoxManipType.DeleteItemless, pk => pk.HeldItem == 0),
|
|
|
|
|
new BoxManipClear(BoxManipType.DeleteIllegal, pk => !new LegalityAnalysis(pk).Valid),
|
2019-02-19 01:19:25 +00:00
|
|
|
|
new BoxManipClearDuplicate<string>(BoxManipType.DeleteClones, pk => SearchUtil.GetCloneDetectMethod(CloneDetectionMethod.HashDetails)(pk)),
|
2018-09-02 18:31:34 +00:00
|
|
|
|
};
|
2019-02-19 01:19:25 +00:00
|
|
|
|
}
|
2019-02-19 01:00:16 +00:00
|
|
|
|
|
2019-02-19 01:19:25 +00:00
|
|
|
|
public sealed class BoxManipClearDuplicate<T> : BoxManipClear
|
|
|
|
|
{
|
|
|
|
|
private readonly HashSet<T> HashSet = new HashSet<T>();
|
|
|
|
|
|
2019-02-21 01:59:54 +00:00
|
|
|
|
public override int Execute(SaveFile SAV, BoxManipParam param)
|
2019-02-19 01:00:16 +00:00
|
|
|
|
{
|
2019-02-19 01:19:25 +00:00
|
|
|
|
HashSet.Clear();
|
|
|
|
|
return base.Execute(SAV, param);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BoxManipClearDuplicate(BoxManipType type, Func<PKM, T> criteria, Func<SaveFile, bool> usable = null)
|
|
|
|
|
{
|
|
|
|
|
Type = type;
|
|
|
|
|
Usable = usable;
|
|
|
|
|
CriteriaSimple = pk =>
|
|
|
|
|
{
|
|
|
|
|
var result = criteria(pk);
|
|
|
|
|
if (HashSet.Contains(result))
|
|
|
|
|
return true;
|
|
|
|
|
HashSet.Add(result);
|
|
|
|
|
return false;
|
|
|
|
|
};
|
2019-02-19 01:00:16 +00:00
|
|
|
|
}
|
2018-09-02 18:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|