/// <summary> /// Returns the card combo with the highest possible value from the given 'HandCards'. /// </summary> /// <param name="HandCards">The cards in the player's hand</param> /// <param name="broadcastCombos">Whether to broadcast all possible combos for UI output</param> /// <returns>The combo with the highest value or an empty one, if none was found</returns> private CardCombo GetBestCardCombo(List <Card> HandCards, bool broadcastCombos) { var possibleCombos = CardUtil.GetAllPossibleCombos(HandCards, Tb.I.GameMaster.GetAllCardSpotCards(), false); if (broadcastCombos) { PossibleCardCombosChanged.Invoke(possibleCombos); } return(possibleCombos.Count > 0 ? possibleCombos[0] : new CardCombo()); }
private void DrawCardFinished(Card card, bool isServingCard) { card.MoveFinished.RemoveAllListeners(); HandCardSpot.AddCard(card); card.SetTurned(false); if (isServingCard) { State = PlayerState.IDLE; return; } var combos = CardUtil.GetAllPossibleCombos(HandCardSpot.Objects, Tb.I.GameMaster.GetAllCardSpotCards(), false); PossibleCardCombosChanged.Invoke(combos); laydownCards = combos.Count > 0 ? combos[0] : new CardCombo(); singleLayDownCards = PlayerUtil.UpdateSingleLaydownCards(HandCardSpot.Objects, laydownCards); PossibleSinglesChanged.Invoke(singleLayDownCards); if (Tb.I.GameMaster.LayingAllowed()) { var usedJokers = false; // If the player has not laid down card packs yet, check if their sum would be enough to do so if (!HasLaidDown) { HasLaidDown = laydownCards.Value >= Tb.I.GameMaster.MinimumLaySum; /// Try to reach <see cref="GameMaster.MinimumLaySum"/> by appending jokers to any possible cardcombo var jokers = HandCardSpot.Objects.Where(c => c.IsJoker()).ToList(); if (!HasLaidDown && jokers.Count() > 0) { for (int i = 0; i < combos.Count; i++) { var combo = new CardCombo(combos[i]); var jokersInUse = combo.GetCards().Where(c => c.IsJoker()).ToList(); var remainingJokers = jokers.Except(jokersInUse).ToList(); if (remainingJokers.Count == 0) { continue; } var canLayCombo = combo.TryAddJoker(remainingJokers); if (canLayCombo && combo.CardCount < HandCardCount) { usedJokers = true; laydownCards = combo; combos.Insert(0, combo); PossibleCardCombosChanged.Invoke(combos); NewThought.Invoke("Use jokers to lay down"); HasLaidDown = true; break; } } if (!HasLaidDown) { NewThought.Invoke("Cannot reach " + Tb.I.GameMaster.MinimumLaySum + " using jokers"); } } } // At least one card must remain when laying down if (!usedJokers && HasLaidDown && laydownCards.CardCount == HandCardCount) { KeepOneSingleCard(); } } State = PlayerState.WAITING; waitStartTime = Time.time; }