private static void LogDiscardingCard(QuadMistCard card) { String cardName = FF9TextTool.CardName(card.id); String displayInfo = card.ToString(); Int32 arrowCount = MathEx.BitCount(card.arrow); Log.Message($"Discard the card: {cardName} ({displayInfo}, {arrowCount} arrows) [Id: {card.id}, Type: {card.type}, Attack: {card.atk}, P.Def: {card.pdef}, M.Def: {card.mdef}]"); }
public static void DiscardUnnecessaryCards() { List <QuadMistCard> cards = FF9StateSystem.MiniGame.SavedData.MiniGameCard; Int32 minDeckSize = Configuration.TetraMaster.DiscardMinDeckSize; if (cards.Count <= minDeckSize) { Log.Warning($"You don't have enough cards to discard. You can change a minimum deck size via Mememoria.ini: [{nameof(Configuration.TetraMaster)}].{nameof(Configuration.TetraMaster.DiscardMinDeckSize)}"); return; } Dictionary <Byte, List <QuadMistCard> > cardsById = new Dictionary <Byte, List <QuadMistCard> >(); Dictionary <Byte, List <QuadMistCard> > cardsByArrow = new Dictionary <Byte, List <QuadMistCard> >(); foreach (QuadMistCard card in cards) { List <QuadMistCard> list; if (!cardsById.TryGetValue(card.id, out list)) { list = new List <QuadMistCard>(); cardsById.Add(card.id, list); } list.Add(card); if (!cardsByArrow.TryGetValue(card.arrow, out list)) { list = new List <QuadMistCard>(); cardsByArrow.Add(card.arrow, list); } list.Add(card); } foreach (List <QuadMistCard> list in cardsById.Values) { list.Sort(CompareCard); } foreach (List <QuadMistCard> list in cardsByArrow.Values) { list.Sort(CompareCard); } Int32 maxSameArrows = Configuration.TetraMaster.DiscardKeepSameArrow; Int32 maxSameType = Configuration.TetraMaster.DiscardKeepSameType; Log.Message("-------------------"); Log.Message("Discarding cards..."); foreach (KeyValuePair <Byte, List <QuadMistCard> > pair in cardsByArrow.OrderByDescending(p => MathEx.BitCount(p.Key))) { Int32 sameArrows = maxSameArrows; List <QuadMistCard> list = pair.Value; for (Int32 i = 0; (i < list.Count && i < list.Count - sameArrows); i++) { QuadMistCard card = list[i]; if (!CanDiscard(card)) { sameArrows--; continue; } List <QuadMistCard> sameCards = cardsById[card.id]; if (sameCards.Count <= maxSameType) { sameArrows--; continue; } list.RemoveAt(i); sameCards.Remove(card); cards.Remove(card); i--; LogDiscardingCard(card); if (cards.Count <= minDeckSize) { break; } } if (cards.Count <= minDeckSize) { break; } } foreach (KeyValuePair <Byte, List <QuadMistCard> > pair in cardsById.OrderBy(p => p.Key)) { Int32 sameType = maxSameType; List <QuadMistCard> list = pair.Value; for (Int32 i = 0; (i < list.Count && i < list.Count - sameType); i++) { QuadMistCard card = list[i]; if (!CanDiscard(card)) { sameType--; continue; } List <QuadMistCard> arrowCards = cardsByArrow[card.arrow]; if (arrowCards.Count <= maxSameArrows) { sameType--; continue; } list.RemoveAt(i); arrowCards.Remove(card); cards.Remove(card); i--; LogDiscardingCard(card); if (cards.Count <= minDeckSize) { break; } } if (cards.Count <= minDeckSize) { break; } } Log.Message("-------------------"); }