private bool VerifyCard(Pox.Rune rune, List <string> factions, CardRandomizerFlags flags) { // limited cards not allowed if (rune.Rarity == "LIMITED") { return(false); } // check if its a split card if ((rune.Faction.Count > 1) && (!flags.AllowSplitCards)) { return(false); } // check if its banned card if ((!rune.AllowRanked) && (!flags.AllowBannedCards)) { return(false); } // check if its forgeable if ((rune.Expansion == "Planar Disturbances") && (!flags.AllowUnforgeableCards)) { return(false); } // check if factions match bool faction_match = false; foreach (string f in factions) { if (rune.Faction.Contains(f)) { faction_match = true; break; } } if (!faction_match) { return(false); } return(true); }
public void LoadCardsFromDatabase(List <string> factions, CardRandomizerFlags flags) { if (!Program.database.ready) { return; } // load champions foreach (var kv in Program.database.Champions) { if (!VerifyCard(kv.Value, factions, flags)) { continue; } bool is_valid_hero = true; // check if this rune is a hero or a split-hero foreach (var ab in kv.Value.BaseAbilities_refs) { if ((ab.Name == "Hero") && (factions.Count > 1)) { is_valid_hero = false; break; } if ((ab.Name == "Split Hero") && (factions.Count == 1)) { is_valid_hero = false; break; } } if (!is_valid_hero) { continue; } // add champion to the pool if (flags.IsHighlander) { Champions.Add(kv.Key); } else { for (int i = 0; i < kv.Value.DeckLimit; i++) { Champions.Add(kv.Key); } } } // add spells foreach (var kv in Program.database.Spells) { if (!VerifyCard(kv.Value, factions, flags)) { continue; } // add spell to the pool if (flags.IsHighlander) { Spells.Add(kv.Key); } else { for (int i = 0; i < kv.Value.DeckLimit; i++) { Spells.Add(kv.Key); } } } // add relics foreach (var kv in Program.database.Relics) { if (!VerifyCard(kv.Value, factions, flags)) { continue; } // add relic to the pool if (flags.IsHighlander) { Relics.Add(kv.Key); } else { for (int i = 0; i < kv.Value.DeckLimit; i++) { Relics.Add(kv.Key); } } } // add equips foreach (var kv in Program.database.Equipments) { if (!VerifyCard(kv.Value, factions, flags)) { continue; } // add equip to the pool if (flags.IsHighlander) { Equips.Add(kv.Key); } else { for (int i = 0; i < kv.Value.DeckLimit; i++) { Equips.Add(kv.Key); } } } }
private void ButtonGenerateCards_Click(object sender, EventArgs e) { if (!Program.database.ready) { SetStatus("Database is not ready"); return; } // stage 1: generate settings if (!ValidateSettings()) { return; } string MainFaction = ComboMainFaction.SelectedItem.ToString(); string SecondaryFaction = ComboSecondaryFaction.SelectedItem.ToString(); CardRandomizerCardNumber mfcn = new CardRandomizerCardNumber(); CardRandomizerCardNumber sfcn = new CardRandomizerCardNumber(); CardRandomizerFlags crf = new CardRandomizerFlags(); uint.TryParse(MFCChampions.Text, out mfcn.Champions); uint.TryParse(MFCSpells.Text, out mfcn.Spells); uint.TryParse(MFCRelics.Text, out mfcn.Relics); uint.TryParse(MFCEquips.Text, out mfcn.Equips); uint.TryParse(SFCChampions.Text, out sfcn.Champions); uint.TryParse(SFCSpells.Text, out sfcn.Spells); uint.TryParse(SFCRelics.Text, out sfcn.Relics); uint.TryParse(SFCEquips.Text, out sfcn.Equips); crf.IsHighlander = CheckHighlander.Checked; crf.AllowUnforgeableCards = CheckAllowUnforgeableCards.Checked; crf.AllowBannedCards = CheckboxAllowBannedCards.Checked; crf.AllowSplitCards = CheckAllowSplitCards.Checked; // stage 2: add runes to the pool, according to the settings SetStatus("Loading cards to the pool..."); List <string> factions = new List <string>(); factions.Add(MainFaction); if (SecondaryFaction != "None") { factions.Add(SecondaryFaction); } CardRandomizerCardPool pool = new CardRandomizerCardPool(); pool.LoadCardsFromDatabase(factions, crf); // stage 3: extract runes from the pool, according to the settings SetStatus("Generating result..."); CardRandomizerFactionResultList mfresult = new CardRandomizerFactionResultList(); CardRandomizerFactionResultList sfresult = new CardRandomizerFactionResultList(); if (!mfresult.ExtractCards(MainFaction, pool, mfcn)) { SetStatus("Failed to generate result for main faction"); return; } if (SecondaryFaction != "None") { if (!sfresult.ExtractCards(SecondaryFaction, pool, sfcn)) { SetStatus("Failed to generate result for secondary faction"); return; } } Clipboard.SetText(mfresult.ToString() + (SecondaryFaction == "None" ? "" : "\n" + sfresult.ToString())); SetStatus("Copied to clipboard"); }