public void Draw(CardRepository cardRepository) { if (!cardRepository.IsLoadingComplete.Signaled || CurrentZone != Zone.SampleHand) { return; } var drawn = draw(cardRepository); if (drawn == null) { return; } TouchedCard = drawn; lock (DataSource) if (!DataSource.Contains(drawn)) { DataSource.Add(drawn); } DeckChanged?.Invoke( listChanged: SampleHand.GetCount(drawn.Id) == 1, countChanged: true, card: drawn, touchedChanged: true, changedZone: CurrentZone, changeTerminatesBatch: true); }
private void createSampleHand(int handSize, CardRepository cardRepository) { SampleHand.Clear(); Shuffle(); for (int i = 0; i < handSize; i++) { draw(cardRepository); } SampleHand.SetOrder(SampleHand.CardsIds .OrderBy(id => cardRepository.CardsById[id].Cmc) .ThenBy(id => cardRepository.CardsById[id].TypeEn) .ThenBy(id => cardRepository.CardsById[id].Color) .ToList()); lock (DataSource) { DataSource.Clear(); DataSource.AddRange(SampleHand.CardsIds.Select(id => cardRepository.CardsById[id])); } DeckChanged?.Invoke( listChanged: true, countChanged: true, card: null, touchedChanged: false, changedZone: CurrentZone, changeTerminatesBatch: true); }
public void Clear() { switch (CurrentZone) { case Zone.SampleHand: SampleHand.Clear(); break; case Zone.Side: SideDeck.Clear(); break; case Zone.Main: MainDeck.Clear(); SideDeck.Clear(); break; default: return; } lock (DataSource) DataSource.Clear(); DeckChanged?.Invoke( listChanged: true, countChanged: true, card: null, touchedChanged: false, changedZone: CurrentZone, changeTerminatesBatch: true); }
private Card draw(CardRepository cardRepository) { if (_library == null || _library.Count == 0) { return(null); } var index = _random.Next(_library.Count); var id = _library[index]; _library.RemoveAt(index); SampleHand.Add(id, SampleHand.GetCount(id) + 1); return(cardRepository.CardsById[id]); }