mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
Handle contest ribbon deadlock scenario
Contest Star needs all 5 ribbons; all 5 ribbons require contest star. Incrementally adding will fail on the last ribbon. Try setting both at the end. When removing ribbons, attempt to remove the pair first, as the incremental removal will fail each time (contest star last). #3061
This commit is contained in:
parent
62d5375f67
commit
7e93bcfb61
1 changed files with 29 additions and 3 deletions
|
@ -90,6 +90,10 @@ namespace PKHeX.Core
|
|||
// Repeat the operation until no more ribbons are set.
|
||||
}
|
||||
|
||||
// Ribbon Deadlock
|
||||
if (pk is IRibbonSetCommon6 c6)
|
||||
InvertDeadlockContest(c6, la, true);
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
@ -121,6 +125,10 @@ namespace PKHeX.Core
|
|||
var la = new LegalityAnalysis(pk);
|
||||
var valid = new List<string>();
|
||||
|
||||
// Ribbon Deadlock
|
||||
if (pk is IRibbonSetCommon6 c6)
|
||||
InvertDeadlockContest(c6, la, false);
|
||||
|
||||
while (TryRemoveAllRibbons(pk, la, allRibbons, valid) != 0)
|
||||
{
|
||||
// Repeat the operation until no more ribbons are set.
|
||||
|
@ -182,13 +190,17 @@ namespace PKHeX.Core
|
|||
private static bool TryRemoveRibbon(PKM pk, LegalityAnalysis la, string rib)
|
||||
{
|
||||
RemoveRibbon(pk, rib);
|
||||
LegalityAnalysis.Ribbon.Verify(la);
|
||||
return la.Results.All(z => z.Valid);
|
||||
return UpdateIsValid(la);
|
||||
}
|
||||
|
||||
private static bool TryApplyRibbon(PKM pk, LegalityAnalysis la, string rib)
|
||||
{
|
||||
SetRibbonValue(pk, rib, 1);
|
||||
return UpdateIsValid(la);
|
||||
}
|
||||
|
||||
private static bool UpdateIsValid(LegalityAnalysis la)
|
||||
{
|
||||
LegalityAnalysis.Ribbon.Verify(la);
|
||||
return la.Results.All(z => z.Valid);
|
||||
}
|
||||
|
@ -211,5 +223,19 @@ namespace PKHeX.Core
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void InvertDeadlockContest(IRibbonSetCommon6 c6, LegalityAnalysis la, bool desiredState)
|
||||
{
|
||||
// RibbonContestStar depends on having all contest ribbons, and having RibbonContestStar requires all.
|
||||
// Since the above logic sets individual ribbons, we must try setting this deadlock pair manually.
|
||||
if (c6.RibbonMasterToughness == desiredState || c6.RibbonContestStar == desiredState)
|
||||
return;
|
||||
|
||||
la.ResetParse();
|
||||
c6.RibbonMasterToughness = c6.RibbonContestStar = desiredState;
|
||||
bool result = UpdateIsValid(la);
|
||||
if (!result)
|
||||
c6.RibbonMasterToughness = c6.RibbonContestStar = !desiredState;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue