/// <summary> /// Load expedition state from JSON string /// </summary> /// <param name="json">JSON string</param> public void LoadFromJson(Dictionary <string, JsonElement> json) { if (json != null) { IsActive = json["IsActive"].ToObject <bool>(); State = json["State"].ToString(); Record = json["Record"].ToObject <string[]>(); Cards = Utilities.DeckFromStringCodeList(json["Deck"].ToObject <string[]>()); NumberOfGames = json["Games"].ToObject <int>(); NumberOfWins = json["Wins"].ToObject <int>(); NumberOfLosses = json["Losses"].ToObject <int>(); IsEliminationGame = false; if (Record != null) { IsEliminationGame = (Array.FindLastIndex(Record, item => item.Equals("win")) < Array.FindLastIndex(Record, item => item.Equals("loss"))) || (NumberOfWins == 6); } var expeditionPicks = json["DraftPicks"].ToObject <Dictionary <string, JsonElement>[]>(); if (expeditionPicks != null) { DraftPicks = new ExpeditionPick[expeditionPicks.Length]; for (int i = 0; i < expeditionPicks.Length; i++) { DraftPicks[i] = new ExpeditionPick(expeditionPicks[i]); } } else { DraftPicks = null; } } }
private void ApplyDraftPick(ref List <CardWithCount> cards, ExpeditionPick pick) { if (pick.IsSwap) { foreach (var cardCode in pick.SwappedOut) { int index = cards.FindIndex(item => item.Code.Equals(cardCode)); if (0 == --cards[index].Count) { cards.RemoveAt(index); } } foreach (var cardCode in pick.SwappedIn) { int index = cards.FindIndex(item => item.Code.Equals(pick.SwappedOut)); if (index >= 0) { cards[index].Count++; } else { cards.Add(new CardWithCount(CardLibrary.GetCard(cardCode), 1, true)); } } } else { foreach (var cardCode in pick.DraftPicks) { int index = cards.FindIndex(item => item.Code.Equals(cardCode)); if (index >= 0) { cards[index].Count++; } else { cards.Add(new CardWithCount(CardLibrary.GetCard(cardCode), 1, true)); } } } }