public ScenarioService(ProductRepository productRepository, CardRepository cardRepository) { this.cardRepository = cardRepository; this.cards = cardRepository.Cards().ToList(); foreach (var card in this.cards.Where(x => !string.IsNullOrEmpty(x.EncounterSet))) { if (!cardsByEncounterSet.ContainsKey(card.EncounterSet)) { cardsByEncounterSet[card.EncounterSet] = new List <Card>(); } cardsByEncounterSet[card.EncounterSet].Add(card); } foreach (var group in productRepository.ProductGroups()) { if (group.MainProduct != null) { AddProduct(group.MainProduct, cards); } foreach (var product in group.ChildProducts) { AddProduct(product, cards); } } listViewModel = new ScenarioListViewModel(); var lookupCard = new Func <string, Card>((slug) => { return(cardRepository.FindBySlug(slug)); }); foreach (var scenarioGroup in ScenarioGroups()) { listViewModel.ScenarioGroups.Add(new ScenarioGroupViewModel(scenarioGroup, lookupCard)); } }
private void AddScenario(Scenario scenario) { var escapedTitle = scenario.Title.ToUrlSafeString(); if (scenariosByTitle.ContainsKey(escapedTitle)) { return; } scenariosByTitle.Add(escapedTitle, scenario); if (!string.IsNullOrEmpty(scenario.AlternateTitle)) { scenariosByAlternateTitle[scenario.AlternateTitle.ToUrlSafeString()] = scenario; } foreach (var set in scenario.EncounterSets()) { if (!cardsByEncounterSet.ContainsKey(set.Name)) { continue; } foreach (var card in cardsByEncounterSet[set.Name].Where(x => x.CardType != CardType.Quest)) { byte easyCount = 0; byte normalCount = 0; byte nightmareCount = 0; if (set.IsNightmare) { nightmareCount = scenario.NightmareModeCount(card.Slug, card.Quantity); } else { easyCount = scenario.EasyModeCount(card.Slug, card.Quantity); normalCount = scenario.NormalModeCount(card.Slug, card.Quantity); nightmareCount = scenario.NightmareModeCount(card.Slug, card.Quantity); } scenario.MapCardCount(card.Slug, easyCount, normalCount, nightmareCount); scenario.AddScenarioCard(card); } } foreach (var questId in scenario.QuestCardIds()) { var questCard = cardRepository.FindBySlug(questId); if (questCard != null) { var releaseQuantity = questCard.CardSet.IsNightmare ? (byte)0 : (byte)1; var easyQuantity = scenario.EasyModeCount(questId, releaseQuantity); var normalQuantity = scenario.NormalModeCount(questId, releaseQuantity); var nightmareQuantity = scenario.NightmareModeCount(questId, 1); scenario.AddQuestCard(questCard, easyQuantity, normalQuantity, nightmareQuantity); } else { //invalid quest card ID var x = questId; } } }