private static bool GetChoicesByCost(CostRequirement costRequirement, int numChoicesRequired, RDM_Deck currentDeck, Map <int, List <RDMDeckEntry> > deckCardsByManaCost, ref RandomDeckChoices returnChoices) { int costFilterValue = costRequirement.m_costFilterValue; List <RDMDeckEntry> list = !deckCardsByManaCost.ContainsKey(costFilterValue) ? null : deckCardsByManaCost[costFilterValue]; int num2 = (list != null) ? list.Count : 0; if (num2 < costRequirement.m_minNumCards) { returnChoices.Clear(); returnChoices.displayString = GameStrings.Get(costRequirement.m_displayStringKey); CollectionFilterSet cardsIOwnFilterSet = GetCardsIOwnFilterSet(); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.COST, costFilterValue, costRequirement.m_costFilterFunc); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.CARDTYPE, TAG_CARDTYPE.HERO, CollectionFilterFunc.NOT_EQUAL); List <FilteredArtStack> newChoiceOptions = cardsIOwnFilterSet.GenerateList(); for (int i = 0; i < numChoicesRequired; i++) { RDMDeckEntry item = GetValidChoiceForDeck(newChoiceOptions, returnChoices.choices, currentDeck); if (item != null) { returnChoices.choices.Add(item); } } if (returnChoices.choices.Count >= numChoicesRequired) { return(true); } returnChoices.Clear(); } return(false); }
private void OnCardDefLoaded(string cardID, CardDef cardDef, object userData) { RDMDeckEntry entry = (RDMDeckEntry)userData; ActorLoadCallback callbackData = new ActorLoadCallback { choice = entry, cardDef = cardDef }; AssetLoader.Get().LoadActor(ActorNames.GetHandActor(entry.EntityDef, entry.Flair.Premium), new AssetLoader.GameObjectCallback(this.OnActorLoaded), callbackData, false); }
public static RDM_Deck ConvertCollectionDeckToRDMDeck(CollectionDeck deck) { RDM_Deck deck2 = new RDM_Deck(DefLoader.Get().GetEntityDef(deck.HeroCardID)); foreach (CollectionDeckSlot slot in deck.GetSlots()) { EntityDef entityDef = DefLoader.Get().GetEntityDef(slot.CardID); CardFlair cardFlair = new CardFlair(slot.Premium); for (int i = 0; i < slot.Count; i++) { RDMDeckEntry item = new RDMDeckEntry(entityDef, cardFlair); deck2.deckList.Add(item); } } return(deck2); }
public RDM_Deck CreateRDMFromDeckString(string deckString) { RDM_Deck deck = new RDM_Deck(); char[] separator = new char[] { '\n' }; foreach (string str in deckString.Split(separator)) { string str2 = str.Trim(); if (!str2.StartsWith("#")) { try { char[] chArray2 = new char[] { ';' }; foreach (string str3 in str2.Split(chArray2)) { try { int num3; char[] chArray3 = new char[] { ',' }; string[] strArray4 = str3.Split(chArray3); if ((int.TryParse(strArray4[0], out num3) && (num3 >= 0)) && (num3 <= 10)) { string cardId = strArray4[1]; EntityDef entityDef = DefLoader.Get().GetEntityDef(cardId); if (entityDef != null) { CardFlair cardFlair = new CardFlair(TAG_PREMIUM.NORMAL); for (int i = 0; i < num3; i++) { RDMDeckEntry item = new RDMDeckEntry(entityDef, cardFlair); deck.deckList.Add(item); } } } } catch { } } } catch { } } } return(deck); }
private void OnActorLoaded(string name, GameObject go, object callbackData) { if (go == null) { UnityEngine.Debug.LogWarning(string.Format("DeckHelper.OnActorLoaded() - FAILED to load actor \"{0}\"", name)); } else { Actor component = go.GetComponent <Actor>(); if (component == null) { UnityEngine.Debug.LogWarning(string.Format("DeckHelper.OnActorLoaded() - ERROR actor \"{0}\" has no Actor component", name)); } else { component.transform.parent = base.transform; SceneUtils.SetLayer(component, base.gameObject.layer); ActorLoadCallback callback = (ActorLoadCallback)callbackData; RDMDeckEntry choice = callback.choice; EntityDef entityDef = choice.EntityDef; CardDef cardDef = callback.cardDef; CardFlair cardFlair = choice.Flair; component.SetEntityDef(entityDef); component.SetCardDef(cardDef); component.SetCardFlair(cardFlair); component.UpdateAllComponents(); component.gameObject.name = cardDef.name + "_actor"; component.GetCollider().gameObject.AddComponent <DeckHelperVisual>().SetActor(component); this.m_actors.Add(component); if (this.HaveActorsForAllChoices()) { this.PositionAndShowChoices(); } else { component.Hide(); } } } }
public static RDM_Deck FinishMyDeck(RDM_Deck currentDeck) { Log.Ben.Print("Finishing the Current Deck.", new object[0]); int num = 30 - currentDeck.deckList.Count; if (num > 0) { for (int i = 0; i < num; i++) { RandomDeckChoices choices = GetChoices(currentDeck, 1); if (choices.choices.Count <= 0) { Debug.LogError("Tried to Finish this deck, but Brode's algorithm broke and couldn't do it."); return(currentDeck); } RDMDeckEntry entry = choices.choices[0]; Log.Ben.Print(string.Format("{0} - {1} (flair {2})", choices.displayString, entry.EntityDef.GetDebugName(), entry.Flair), new object[0]); currentDeck.deckList.Add(choices.choices[0]); } } return(currentDeck); }
public static RandomDeckChoices GetChoices(RDM_Deck currentDeck, int numChoicesRequired) { if (currentDeck.deckList.Count >= 30) { Debug.LogWarning("RandomDeckMaker.GetChoices(): Tried to get choices for a full deck!"); return(null); } int num = 0; foreach (RDMDeckEntry entry in currentDeck.deckList) { if (entry.EntityDef.GetClass() == currentDeck.classType) { num++; } } CollectionFilterSet cardsIOwnFilterSet = GetCardsIOwnFilterSet(); RandomDeckChoices returnChoices = new RandomDeckChoices(); returnChoices.Clear(); if (num < 12) { cardsIOwnFilterSet.RemoveAllGameFilters(); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.CLASS, currentDeck.classType, CollectionFilterFunc.EQUAL); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.CARDTYPE, TAG_CARDTYPE.HERO, CollectionFilterFunc.NOT_EQUAL); List <FilteredArtStack> newChoiceOptions = cardsIOwnFilterSet.GenerateList(); returnChoices.displayString = GameStrings.Get(GAME_STRING_CLASS_SPECIFIC); for (int k = 0; k < numChoicesRequired; k++) { RDMDeckEntry item = GetValidChoiceForDeck(newChoiceOptions, returnChoices.choices, currentDeck); if (item != null) { returnChoices.choices.Add(item); } } if (returnChoices.choices.Count == numChoicesRequired) { return(returnChoices); } } returnChoices.Clear(); Map <int, List <RDMDeckEntry> > deckCardsByManaCost = new Map <int, List <RDMDeckEntry> >(); foreach (RDMDeckEntry entry3 in currentDeck.deckList) { int key = Mathf.Clamp(entry3.EntityDef.GetCost(), 1, 7); if (!deckCardsByManaCost.ContainsKey(key)) { deckCardsByManaCost.Add(key, new List <RDMDeckEntry>()); } deckCardsByManaCost[key].Add(entry3); } for (int i = 0; i < COST_REQUIREMENTS.Length; i++) { if (GetChoicesByCost(COST_REQUIREMENTS[i], numChoicesRequired, currentDeck, deckCardsByManaCost, ref returnChoices)) { return(returnChoices); } } int num5 = 0; int num6 = 0; foreach (RDMDeckEntry entry4 in currentDeck.deckList) { if (entry4.EntityDef.IsSpell()) { num5++; } if (entry4.EntityDef.IsMinion()) { num6++; } } returnChoices.Clear(); if (num5 < 8) { cardsIOwnFilterSet.RemoveAllGameFilters(); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.CARDTYPE, TAG_CARDTYPE.SPELL, CollectionFilterFunc.EQUAL); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.CARDTYPE, TAG_CARDTYPE.HERO, CollectionFilterFunc.NOT_EQUAL); List <FilteredArtStack> list2 = cardsIOwnFilterSet.GenerateList(); returnChoices.displayString = GameStrings.Get(GAME_STRING_MORE_SPELLS); for (int m = 0; m < numChoicesRequired; m++) { RDMDeckEntry entry5 = GetValidChoiceForDeck(list2, returnChoices.choices, currentDeck); if (entry5 != null) { returnChoices.choices.Add(entry5); } } if (returnChoices.choices.Count == numChoicesRequired) { return(returnChoices); } } returnChoices.Clear(); if (num6 < 15) { cardsIOwnFilterSet.RemoveAllGameFilters(); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.CARDTYPE, TAG_CARDTYPE.MINION, CollectionFilterFunc.EQUAL); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.CARDTYPE, TAG_CARDTYPE.HERO, CollectionFilterFunc.NOT_EQUAL); List <FilteredArtStack> list3 = cardsIOwnFilterSet.GenerateList(); returnChoices.displayString = GameStrings.Get(GAME_STRING_MORE_MINIONS); for (int n = 0; n < numChoicesRequired; n++) { RDMDeckEntry entry6 = GetValidChoiceForDeck(list3, returnChoices.choices, currentDeck); if (entry6 != null) { returnChoices.choices.Add(entry6); } } if (returnChoices.choices.Count == numChoicesRequired) { return(returnChoices); } } returnChoices.Clear(); returnChoices.displayString = GameStrings.Get(GAME_STRING_NO_SPECIFICS); for (int j = 0; j < numChoicesRequired; j++) { cardsIOwnFilterSet.RemoveAllGameFilters(); cardsIOwnFilterSet.AddGameFilter(GAME_TAG.CARDTYPE, TAG_CARDTYPE.HERO, CollectionFilterFunc.NOT_EQUAL); RDMDeckEntry entry7 = GetValidChoiceForDeck(cardsIOwnFilterSet.GenerateList(), returnChoices.choices, currentDeck); if (entry7 != null) { returnChoices.choices.Add(entry7); } } return(returnChoices); }