private int DeckNewLimit(long did, InJsonOutInt fn = null) { if (fn == null) { fn = this.DeckNewLimitSingle; } List <JsonObject> decks = collection.Deck.Parents(did); decks.Add(collection.Deck.Get(did)); int lim = -1; // for the deck and each of its parents int rem = 0; foreach (JsonObject g in decks) { rem = (int)fn(g); if (lim == -1) { lim = rem; } else { lim = Math.Min(rem, lim); } } return(lim); }
private int WalkingCount(InJsonOutInt GetIndividualDeckLimit, InLongIntOutInt cntFn) { int tot = 0; Dictionary <long, int> pcounts = new Dictionary <long, int>(); foreach (long did in collection.Deck.Active()) { int lim = GetIndividualDeckLimit(collection.Deck.Get(did)); if (lim == 0) { continue; } // check the parents List <JsonObject> parents = collection.Deck.Parents(did); foreach (JsonObject p in parents) { // add if missing long id = (long)JsonHelper.GetNameNumber(p, "id"); if (!pcounts.ContainsKey(id)) { pcounts.Add(id, GetIndividualDeckLimit(p)); } // take minimum of child and parent lim = Math.Min(pcounts[id], lim); } // see how many cards we actually have int cnt = cntFn(did, lim); // if non-zero, decrement from parents counts foreach (JsonObject p in parents) { long id = (long)JsonHelper.GetNameNumber(p, "id"); pcounts[id] = pcounts[id] - cnt; } // we may also be a parent pcounts[did] = lim - cnt; // and add to running total tot += cnt; } return(tot); }