Update unclaimed card filter to fallback to any card if all cards are claimed (#452)
All checks were successful
Test / build (push) Successful in 1m2s

#451

Reviewed-on: #452
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
Ethan Lane 2025-05-28 16:07:38 +01:00 committed by Vylpes
parent 7d9c1bda62
commit 434f162a01

View file

@ -39,12 +39,11 @@ export default class GetUnclaimedCardsHelper {
const allCards = CoreClient.Cards
.flatMap(x => x.cards)
.filter(x => x.type == rarity)
.filter(x => !claimedCards.find(y => y.CardNumber == x.id));
.filter(x => !claimedCards.find(y => y.CardNumber == x.id && y.Quantity > 0));
if (!allCards) {
AppLogger.LogError("CardDropHelperMetadata/GetRandomCardByRarityUnclaimed", `No cards found to randomise from, User Id: ${userId}, rarity: ${rarity}`);
return undefined;
if (!allCards || allCards.length == 0) {
// There is no card left unclaimed, fallback to any card
return GetCardsHelper.GetRandomCardByRarity(rarity);
};
const randomCardIndex = Math.floor(Math.random() * allCards.length);