public void ShowCards(IEnumerable<DominionBase.Cards.Card> cards, DominionBase.Piles.Visibility visibility) { int index = 0; Cards = new ObservableCollection<CardViewModel>(); foreach (DominionBase.Cards.Card card in cards) Cards.Add(new CardViewModel { CardName = card.Name, ICard = card, Visibility = visibility, OriginalIndex = index++ }); }
public static Brush GetForegroundBrush(DominionBase.Cards.Category cardType) { if ((cardType & DominionBase.Cards.Category.Attack) == DominionBase.Cards.Category.Attack) return Brushes.Firebrick; if ((cardType & DominionBase.Cards.Category.Curse) == DominionBase.Cards.Category.Curse) return Brushes.Snow; return Brushes.Black; }
public void Add(DominionBase.Game game, DominionBase.Players.Player player) { // Make sure it exists if (!_GlobalStatistics.ContainsKey(game.Players.Count)) _GlobalStatistics[game.Players.Count] = new NPlayersStatistics(game.Players.Count); // Add the game to the correct Statistics section _GlobalStatistics[game.Players.Count].Add(game, player); }
private void StartGame(DominionBase.GameSettings settings) { _StartingNewGame = false; ReleaseGame(); wMain.Settings = Settings.Load(); // Clean out the Image Repository before starting a new game -- // so we don't allocate too much memory for cards we're not even using Caching.ImageRepository.Reset(); dpGameInfo.Visibility = System.Windows.Visibility.Visible; glMain.TearDown(); glMain.Clear(); LayoutSupplyPiles(); while (tcAreas.Items.Count > 2) tcAreas.Items.RemoveAt(tcAreas.Items.Count - 1); dpMatsandPiles.Children.Clear(); dpGameStuff.Children.Clear(); _TradeRouteLabel = null; // Try to force garbage collection to save some memory GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); try { game = new DominionBase.Game( _Settings.NumberOfHumanPlayers, _Settings.PlayerSettings.Take(_Settings.NumberOfPlayers).Select(ps => ps.Name), _Settings.PlayerSettings.Take(_Settings.NumberOfPlayers).Select(ps => ps.AIClassType), settings); game.SelectCards(); if (game.Settings.Preset != null || Settings.AutomaticallyAcceptKingdomCards) this.AcceptGame(); else { wCardSelection selector = new wCardSelection(); selector.Owner = this; if (selector.ShowDialog() == true) { Settings.AutomaticallyAcceptKingdomCards = (selector.cbAutoAccept.IsChecked == true); Settings.Save(); this.AcceptGame(); } else game = null; } } catch (DominionBase.Cards.ConstraintException ce) { wMessageBox.Show(ce.Message, "Constraint exception!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } catch (DominionBase.GameCreationException gce) { wMessageBox.Show(gce.Message, "Game creation exception!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } }
public virtual void Log(DominionBase.Visual.VisualPlayer player, List<Brush> playerBrushes, params Object[] items) { }
private Tuple<List<UIElement>, String> GenerateElements(DominionBase.ICard item, SolidColorBrush background, SolidColorBrush foreground) { List<UIElement> elements = new List<UIElement>(); ucCardIcon icon = CardIconUtilities.CreateCardIcon((DominionBase.ICard)item); icon.Background = background; DockPanel.SetDock(icon, Dock.Left); elements.Add(icon); return new Tuple<List<UIElement>, String>(elements, item.Name); }
public ucPlayerTurn GetChild(DominionBase.Players.Player player) { return this.spArea.Children.OfType<ucPlayerTurn>().First(pt => pt.Player.PlayerUniqueId == player.UniqueId); }
void _Supply_TokensChanged(object sender, DominionBase.Piles.TokensChangedEventArgs e) { if (this.Dispatcher.CheckAccess()) { spExtraStuff.Children.Clear(); var tokenGroups = (sender as DominionBase.Piles.Supply).Tokens.GroupBy(t => t.GetType()); foreach (var tokenGroup in tokenGroups) { if (tokenGroup.Count() > 2) { spExtraStuff.Children.Add(new Controls.ucTokenIcon { Token = tokenGroup.ElementAt(0) }); spExtraStuff.Children.Add(new TextBlock() { Margin = new Thickness(3, 0, 3, 0), Text = String.Format("{0}x", tokenGroup.Count()) }); } else { foreach (DominionBase.Token token in tokenGroup) spExtraStuff.Children.Add(new Controls.ucTokenIcon { Token = token }); } } } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.Piles.TokensChangedEventArgs>(_Supply_TokensChanged), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
private void SetToolTip(FrameworkElement element, DominionBase.ICard card) { ToolTip tt = new System.Windows.Controls.ToolTip(); ToolTipCard ttc = new ToolTipCard(); tt.Content = ttc; ToolTipService.SetShowOnDisabled(element, true); ToolTipService.SetHasDropShadow(element, true); if (wMain.Settings != null) { if (wMain.Settings.ToolTipShowDuration == ToolTipShowDuration.Off) ToolTipService.SetIsEnabled(element, false); else { ToolTipService.SetIsEnabled(element, true); ToolTipService.SetShowDuration(element, (int)wMain.Settings.ToolTipShowDuration); } } ToolTipService.SetInitialShowDelay(element, 2000); ToolTipService.SetBetweenShowDelay(element, 250); ttc.ICard = card; element.ToolTip = tt; }
void player_CardsDiscarded(object sender, DominionBase.Players.CardsDiscardEventArgs e) { if (this.Dispatcher.CheckAccess()) { if (e.Cards.Count == 0 || e.HandledBy.Contains(this)) return; e.HandledBy.Add(this); String location = String.Empty; switch (e.FromLocation) { case DominionBase.Players.DeckLocation.InPlay: case DominionBase.Players.DeckLocation.SetAside: case DominionBase.Players.DeckLocation.InPlayAndSetAside: return; case DominionBase.Players.DeckLocation.Hand: case DominionBase.Players.DeckLocation.Deck: location = String.Format(" from {0} {1}", sender == _Player ? "your" : "their", e.FromLocation.ToString().ToLower()); break; } Object name = (sender == _Player ? (Object)"You" : (Object)sender); String verb = String.Format(" discard{0} ", sender == _Player ? "" : "s"); if (e.Cards.Count == 1) glMain.Log(sender as DominionBase.Players.Player, name, verb, e.Cards.Select(c => c.PhysicalCard), location); else glMain.Log(sender as DominionBase.Players.Player, name, verb, String.Format("{0}{1}", StringUtility.Plural("card", e.Cards.Count), location)); } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.Players.CardsDiscardEventArgs>(player_CardsDiscarded), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
void player_CardsAddedToHand(object sender, DominionBase.Players.CardsAddedToHandEventArgs e) { if (this.Dispatcher.CheckAccess()) { if (e.Cards.Count == 0) return; if (sender == _Player) glMain.Log( sender as DominionBase.Players.Player, "You put ", e.Cards.Select(c => c.PhysicalCard), " into your hand"); else glMain.Log(sender as DominionBase.Players.Player, sender, String.Format(" puts {0} into their hand", StringUtility.Plural("card", e.Cards.Count))); } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.Players.CardsAddedToHandEventArgs>(player_CardsAddedToHand), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
void player_CardsAddedToDeck(object sender, DominionBase.Players.CardsAddedToDeckEventArgs e) { if (this.Dispatcher.CheckAccess()) { String locationMod = String.Empty; if (e.DeckPosition == DominionBase.Piles.DeckPosition.Bottom) locationMod = "the "; if (e.Cards.Count == 0) return; if (sender == _Player) glMain.Log( sender as DominionBase.Players.Player, "You put ", e.Cards.Select(c => c.PhysicalCard), String.Format(" on {0}{1} of your deck", locationMod, e.DeckPosition.ToString().ToLower()) ); else glMain.Log( sender as DominionBase.Players.Player, sender, String.Format(" puts {0} on {2}{1} of their deck", StringUtility.Plural("card", e.Cards.Count), e.DeckPosition.ToString().ToLower(), locationMod )); } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.Players.CardsAddedToDeckEventArgs>(player_CardsAddedToDeck), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
void PlayerMats_DecksChanged(object sender, DominionBase.Piles.CardMatsChangedEventArgs e) { if (this.Dispatcher.CheckAccess()) { if (e.CardMat.GetType() == DominionBase.Cards.Seaside.TypeClass.IslandMat) { if (e.OperationPerformed == DominionBase.Piles.CardMatsChangedEventArgs.Operation.Added) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" set{0} aside ", e.Player == _Player ? "" : "s"), e.AddedCards.Select(c => c.PhysicalCard), " on Island Mat"); } } else if (e.CardMat.GetType() == DominionBase.Cards.Seaside.TypeClass.NativeVillageMat) { if (e.OperationPerformed == DominionBase.Piles.CardMatsChangedEventArgs.Operation.Added) { if (e.Player == _Player) glMain.Log(e.Player, "You put ", e.AddedCards.Select(c => c.PhysicalCard), " on Native Village Mat"); else glMain.Log( e.Player, e.Player, String.Format(" puts {0} on Native Village Mat", DominionBase.Utilities.StringUtility.Plural("card", e.AddedCards.Count) )); } else if (e.OperationPerformed == DominionBase.Piles.CardMatsChangedEventArgs.Operation.Removed && e.Player.Phase != DominionBase.Players.PhaseEnum.Endgame) { if (e.Player == _Player) { IEnumerable<DominionBase.Cards.Card> nvTakenCards = e.RemovedCards.Select(c => c.PhysicalCard); glMain.Log(e.Player, "You take ", nvTakenCards.Count() == 0 ? (object)"nothing" : (object)nvTakenCards, " from Native Village Mat"); } else glMain.Log( e.Player, e.Player, String.Format(" takes {0} from Native Village Mat", DominionBase.Utilities.StringUtility.Plural("card", e.RemovedCards.Count) )); } } else if (e.CardMat.GetType() == DominionBase.Cards.Promotional.TypeClass.PrinceSetAside) { if (e.OperationPerformed == DominionBase.Piles.CardMatsChangedEventArgs.Operation.Added) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" set{0} aside ", e.Player == _Player ? "" : "s"), e.AddedCards.Select(c => c.PhysicalCard)); } } } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.Piles.CardMatsChangedEventArgs>(PlayerMats_DecksChanged), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
void PlayerTokenPiles_TokenCollectionsChanged(object sender, DominionBase.TokenCollectionsChangedEventArgs e) { if (this.Dispatcher.CheckAccess()) { if (e.OperationPerformed == DominionBase.TokenCollectionsChangedEventArgs.Operation.Added) { if (e.AddedTokens[0].GetType() == DominionBase.Cards.Seaside.TypeClass.PirateShipToken) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" gain{0} a Pirate Ship token", e.Player == _Player ? "" : "s") ); } if (e.AddedTokens[0].GetType() == DominionBase.Cards.Guilds.TypeClass.CoinToken) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" gain{0} a Coin token", e.Player == _Player ? "" : "s") ); } } } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.TokenCollectionsChangedEventArgs>(PlayerTokenPiles_TokenCollectionsChanged), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
void game_GameMessage(object sender, DominionBase.GameMessageEventArgs e) { if (this.Dispatcher.CheckAccess()) { Type cardType = e.SourceCard.CardType; if (cardType == DominionBase.Cards.Base.TypeClass.Chancellor || cardType == DominionBase.Cards.Cornucopia.TypeClass.TrustySteed || cardType == DominionBase.Cards.DarkAges.TypeClass.Scavenger) { glMain.Log( e.Player, e.Player.PlayerType == DominionBase.Players.PlayerType.Human ? (Object)"You" : (Object)e.Player, String.Format(" put{0} deck into discard pile", e.Player.PlayerType == DominionBase.Players.PlayerType.Human ? "" : "s") ); } else if (cardType == DominionBase.Cards.Intrigue.TypeClass.Bridge || cardType == DominionBase.Cards.Prosperity.TypeClass.Quarry || cardType == DominionBase.Cards.Cornucopia.TypeClass.Princess || cardType == DominionBase.Cards.Hinterlands.TypeClass.Highway) { String cardTypes = String.Empty; if (cardType == DominionBase.Cards.Prosperity.TypeClass.Quarry) cardTypes = "Action "; glMain.Log(e.Player, e.SourceCard, " reduces the cost of all ", cardTypes, "cards by ", new DominionBase.Currencies.Coin(e.Count)); } else if (cardType == DominionBase.Cards.Intrigue.TypeClass.Masquerade) { String postText = String.Format(" to the left ({0})", e.AffectedPlayer); if (e.Player.PlayerType == DominionBase.Players.PlayerType.Human) glMain.Log(e.Player, "You pass ", e.Card1, postText); else glMain.Log(e.Player, e.Player, " passes a card", postText); } else if ((cardType == DominionBase.Cards.Intrigue.TypeClass.WishingWell || cardType == DominionBase.Cards.DarkAges.TypeClass.Mystic || cardType == DominionBase.Cards.DarkAges.TypeClass.Rebuild || cardType == DominionBase.Cards.Guilds.TypeClass.Doctor || cardType == DominionBase.Cards.Guilds.TypeClass.Journeyman) && e.Card1 != null) { glMain.Log( e.Player, e.Player.PlayerType == DominionBase.Players.PlayerType.Human ? (Object)"You" : (Object)e.Player, String.Format(" name{0} ", e.Player.PlayerType == DominionBase.Players.PlayerType.Human ? "" : "s"), e.Card1); } else if (cardType == DominionBase.Cards.Seaside.TypeClass.Ambassador) { glMain.Log( e.Player, e.Player.PlayerType == DominionBase.Players.PlayerType.Human ? (Object)"You" : (Object)e.Player, String.Format(" return{0} {1} to the ", e.Player.PlayerType == DominionBase.Players.PlayerType.Human ? "" : "s", StringUtility.Plural("card", e.Count)), e.Card1, " supply pile"); } else if (cardType == DominionBase.Cards.Seaside.TypeClass.Embargo) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" put{0} {1} token on ", e.Player == _Player ? "" : "s", e.SourceCard.Name), e.Card1); } else if (cardType == DominionBase.Cards.Seaside.TypeClass.Haven) { if (e.Player == _Player) glMain.Log(e.Player, "You set aside ", e.Card1); else glMain.Log(e.Player, e.Player, " sets aside a card"); } else if (cardType == DominionBase.Cards.Promotional.TypeClass.Prince) { if (e.Player == _Player) glMain.Log(e.Player, "You set aside ", e.Card1, " on ", e.SourceCard); else glMain.Log(e.Player, e.Player, " sets aside ", e.Card1, " on ", e.SourceCard); } else if (cardType == DominionBase.Cards.Seaside.TypeClass.Lighthouse) { glMain.Log( e.Player, e.Player == _Player ? (Object)"Your" : (Object)e.Player, e.Player == _Player ? " " : "'s ", e.SourceCard.PhysicalCard, " provides immunity to the attack."); } else if (cardType == DominionBase.Cards.Prosperity.TypeClass.Contraband || cardType == DominionBase.Cards.DarkAges.TypeClass.BandOfMisfits) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" name{0} ", e.Player == _Player ? "" : "s"), e.Card1 != null ? (Object)e.Card1 : (Object)"nothing"); } else if (cardType == DominionBase.Cards.Hinterlands.TypeClass.Trader) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" gain{0} ", e.Player == _Player ? "" : "s"), e.Card2, " instead of ", e.Card1); } else if (cardType == DominionBase.Cards.DarkAges.TypeClass.Madman || cardType == DominionBase.Cards.DarkAges.TypeClass.Spoils) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, " return ", e.Card1, " to the ", e.Card1, " pile"); } else if ((cardType == DominionBase.Cards.Guilds.TypeClass.Doctor || cardType == DominionBase.Cards.Guilds.TypeClass.Herald || cardType == DominionBase.Cards.Guilds.TypeClass.Masterpiece || cardType == DominionBase.Cards.Guilds.TypeClass.Stonemason) && e.Card1 == null) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" overpay{0} by ", e.Player == _Player ? "" : "s"), e.Currency); } else if (cardType == DominionBase.Cards.Guilds.TypeClass.Butcher) { glMain.Log( e.Player, e.Player == _Player ? (Object)"You" : (Object)e.Player, String.Format(" spends {0}", StringUtility.Plural("Coin token", e.Count))); } } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.GameMessageEventArgs>(game_GameMessage), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
void GamePile_PileChanged(object sender, DominionBase.Piles.PileChangedEventArgs e) { if (this.Dispatcher.CheckAccess()) { DominionBase.Piles.Supply supply = sender as DominionBase.Piles.Supply; String wpName = String.Format("wp{0}", supply.SupplyCardType.Name); String cccName = String.Format("card{0}", supply.SupplyCardType.Name); String cccPileName = supply.SupplyCardType.Name; if (supply.SupplyCardType == DominionBase.Cards.Promotional.TypeClass.BlackMarketSupply) { cccPileName = "Black Market cards"; } else if (supply.SupplyCardType == DominionBase.Cards.Cornucopia.TypeClass.PrizeSupply) { cccPileName = "Prizes"; } WrapPanel wpSpecialPile = dpMatsandPiles.Children.OfType<WrapPanel>().SingleOrDefault(wp => wp.Name == wpName); CardCollectionControl cccSpecialPile = null; if (wpSpecialPile == null) { if (dpMatsandPiles.Children.Count > 0) { Border bDiv = new Border(); bDiv.BorderThickness = new Thickness(2); bDiv.BorderBrush = Brushes.Black; DockPanel.SetDock(bDiv, Dock.Top); dpMatsandPiles.Children.Add(bDiv); } wpSpecialPile = new WrapPanel(); wpSpecialPile.Name = wpName; wpSpecialPile.Orientation = Orientation.Horizontal; DockPanel.SetDock(wpSpecialPile, Dock.Top); cccSpecialPile = new CardCollectionControl(); cccSpecialPile.Name = cccName; cccSpecialPile.Padding = new Thickness(0); cccSpecialPile.PileName = cccPileName; cccSpecialPile.CardSize = CardSize.Text; cccSpecialPile.ExactCount = true; cccSpecialPile.IsCardsVisible = true; cccSpecialPile.IsDisplaySorted = true; cccSpecialPile.Phase = DominionBase.Players.PhaseEnum.Action; cccSpecialPile.PlayerMode = DominionBase.Players.PlayerMode.Waiting; wpSpecialPile.Children.Add(cccSpecialPile); dpMatsandPiles.Children.Add(wpSpecialPile); } else cccSpecialPile = wpSpecialPile.Children.OfType<CardCollectionControl>().FirstOrDefault(); cccSpecialPile.Pile = supply; } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.Piles.PileChangedEventArgs>(GamePile_PileChanged), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
public static Brush GetBackgroundBrush(DominionBase.Cards.Category cardType) { if (!_BGBrushCache.ContainsKey(cardType)) { Color topColor = Colors.Transparent; Color bottomColor = Colors.Transparent; List<String> cardTypes = new List<String>(); if ((cardType & DominionBase.Cards.Category.Action) == DominionBase.Cards.Category.Action) topColor = Color.FromRgb(231, 231, 231); if ((cardType & DominionBase.Cards.Category.Curse) == DominionBase.Cards.Category.Curse) topColor = Color.FromRgb(129, 0, 127); if ((cardType & DominionBase.Cards.Category.Duration) == DominionBase.Cards.Category.Duration) topColor = Color.FromRgb(248, 119, 35); if ((cardType & DominionBase.Cards.Category.Ruins) == DominionBase.Cards.Category.Ruins) topColor = Color.FromRgb(162, 123, 23); if ((cardType & DominionBase.Cards.Category.Shelter) == DominionBase.Cards.Category.Shelter) { if (topColor == Colors.Transparent) topColor = Color.FromRgb(232, 98, 87); else bottomColor = Color.FromRgb(232, 98, 87); } if ((cardType & DominionBase.Cards.Category.Treasure) == DominionBase.Cards.Category.Treasure) { if (topColor == Colors.Transparent) topColor = Color.FromRgb(247, 214, 98); else bottomColor = Color.FromRgb(247, 214, 98); } if ((cardType & DominionBase.Cards.Category.Victory) == DominionBase.Cards.Category.Victory) { if (topColor == Colors.Transparent) topColor = Color.FromRgb(144, 238, 144); else bottomColor = Color.FromRgb(144, 238, 144); } if ((cardType & DominionBase.Cards.Category.Reaction) == DominionBase.Cards.Category.Reaction) { if (topColor == Colors.Transparent || (topColor.R == 231 && topColor.G == 231 && topColor.B == 231)) topColor = Color.FromRgb(64, 103, 224); else bottomColor = Color.FromRgb(64, 103, 224); } if (topColor == Colors.Transparent) topColor = bottomColor; if (bottomColor == Colors.Transparent) bottomColor = topColor; GradientStop gs1 = new GradientStop(topColor, 0.0); GradientStop gs2 = new GradientStop(topColor, 0.35); GradientStop gs3 = new GradientStop(bottomColor, 0.65); GradientStop gs4 = new GradientStop(bottomColor, 1.0); _BGBrushCache[cardType] = new LinearGradientBrush(new GradientStopCollection() { gs1, gs2, gs3, gs4 }, 90.0); } if (_BGBrushCache[cardType].CanFreeze) _BGBrushCache[cardType].Freeze(); return _BGBrushCache[cardType]; }
public void NewTurn(DominionBase.Players.Player player, DominionBase.Cards.Card grantedBy) { Utilities.Log(this.LogFile, "-------------------------------------------------------"); if (_CurrentPlayerTurn != null) _CurrentPlayerTurn.End(); _CurrentPlayerTurn = new ucPlayerTurn(); _CurrentPlayerTurn.LogFile = this.LogFile; if (player != null) _CurrentPlayerTurn.New(player, this.PlayerBrushes[player.Name], grantedBy); if (_CurrentGameTurn != null) { (_CurrentGameTurn as ucGameTurn).Add(_CurrentPlayerTurn as ucPlayerTurn); if (wMain.Settings.AutoCollapseOldTurns) { IEnumerable<ucGameTurn> gameTurns = spArea.Children.OfType<ucGameTurn>(); if (gameTurns.Count() > 1) { ucGameTurn gtOld = gameTurns.ElementAt(gameTurns.Count() - 2); foreach (ucPlayerTurn pt in gtOld.GetChildren(player)) pt.IsExpanded = false; if (!gtOld.IsAnyExpanded) { gtOld.IsAllExpanded = true; gtOld.IsExpanded = false; } } } } else { spArea.Children.Add(_CurrentPlayerTurn); } svArea.ScrollToBottom(); svArea.ScrollToLeftEnd(); }
public static ucCardIcon CreateCardIcon(DominionBase.ICard card) { ucCardIcon icon = new ucCardIcon(); icon.Card = card; icon.Count = 1; return icon; }
public void Log(DominionBase.Visual.VisualPlayer player, params Object[] items) { if (_CurrentPlayerTurn == null) this.NewTurn(null, null); _CurrentPlayerTurn.Log(player, this.PlayerBrushes[player.Name], items); svArea.ScrollToBottom(); svArea.ScrollToLeftEnd(); }
void _Supply_PileChanged(object sender, DominionBase.Piles.PileChangedEventArgs e) { if (this.Dispatcher.CheckAccess()) { DominionBase.Piles.Supply supply = sender as DominionBase.Piles.Supply; if ((wMain.Settings.DisplaySupplyPileNames && supply.Location == DominionBase.Cards.Location.Kingdom) || (wMain.Settings.DisplayBasicSupplyPileNames && supply.Location == DominionBase.Cards.Location.General)) { lName.Visibility = System.Windows.Visibility.Visible; tbName.Text = supply.Randomizer.Name; lName.Background = Caching.BrushRepository.GetBackgroundBrush(supply.Randomizer.Category); lName.Foreground = Caching.BrushRepository.GetForegroundBrush(supply.Randomizer.Category); if ((supply.Randomizer.Category & DominionBase.Cards.Category.Reaction) == DominionBase.Cards.Category.Reaction) tbName.Effect = Caching.DropShadowRepository.GetDSE(8, Colors.White, 1d); } else { lName.Visibility = System.Windows.Visibility.Collapsed; tbName.Text = String.Empty; } Caching.ImageRepository repo = Caching.ImageRepository.Acquire(); if (supply.TopCard != null) { imCardIcon.Source = repo.GetBitmapImage(supply.TopCard.Name.Replace(" ", "").Replace("'", ""), "small"); ttcCard.ICard = supply.TopCard; } else { imCardIcon.Source = repo.GetBitmapImage(supply.Name.Replace(" ", "").Replace("'", ""), "small"); ttcCard.ICard = supply.Randomizer; } Caching.ImageRepository.Release(); this.InvalidateVisual(); } else { this.Dispatcher.BeginInvoke(new EventHandler<DominionBase.Piles.PileChangedEventArgs>(_Supply_PileChanged), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
public void Add(DominionBase.Game game, DominionBase.Players.Player player) { if (game.Players.Count != _NumberOfPlayers) throw new Exception("Incorrect number of players in game!"); if (player != null) { if (!game.Players.Contains(player)) throw new Exception("Player not found in game!"); // One more game played! this.GamesPlayed++; // If the game actually finished properly, instead of being aborted if (game.State == DominionBase.GameState.Ended) { // Player won (or at least tied in winning) if (game.Winners.Contains(player)) this.GamesWon++; if (player.VictoryPoints < this.LowestScore) this.LowestScore = player.VictoryPoints; if (player.VictoryPoints > this.HighestScore) this.HighestScore = player.VictoryPoints; _TotalScore += player.VictoryPoints; } } if (game.State == DominionBase.GameState.Ended) { foreach (DominionBase.Players.Player winner in game.Winners) { // Since properly-used cards like Feast, Mining Village, & Embargo never end up in a player's hand, // we need to count how many of the cards were played during the game and add them to the player's // total as well as the total number of cards in the player's hand IEnumerable<DominionBase.Cards.Card> trashedCards = game.TurnsTaken.Where(t => t.Player == winner). SelectMany<DominionBase.Turn, DominionBase.Cards.Card>( t => t.CardsPlayed.Where(c => c.CardType == DominionBase.Cards.Base.TypeClass.Feast || c.CardType == DominionBase.Cards.Seaside.TypeClass.Embargo || (c.CardType == DominionBase.Cards.Intrigue.TypeClass.MiningVillage && t.CardsTrashed.Contains(c)) || (c.CardType == DominionBase.Cards.Cornucopia.TypeClass.HornOfPlenty && t.CardsTrashed.Contains(c)) ) ); int handCount = winner.Hand.Count + trashedCards.Count(); foreach (DominionBase.Piles.Supply supply in game.Table.Supplies.Values) { Type cardType = supply.CardType; String cardTypeKey = cardType.AssemblyQualifiedName; int cardTypeCount = winner.Hand.Count(c => c.CardType == cardType) + trashedCards.Count(c => c.CardType == cardType); if (!_WinningCardCounts.ContainsKey(cardTypeKey)) _WinningCardCounts[cardTypeKey] = new CardStatistics(cardType); _WinningCardCounts[cardTypeKey].Add(cardTypeCount, handCount); if (winner.PlayerType == DominionBase.Players.PlayerType.Human) { if (!_WinningHumanCardCounts.ContainsKey(cardTypeKey)) _WinningHumanCardCounts[cardTypeKey] = new CardStatistics(cardType); _WinningHumanCardCounts[cardTypeKey].Add(cardTypeCount, handCount); } } } } }
public IEnumerable<ucPlayerTurn> GetChildren(DominionBase.Players.Player player) { return this.spArea.Children.OfType<ucPlayerTurn>().Where(pt => pt.Player.PlayerUniqueId == player.UniqueId); }
public void Add(DominionBase.Game game) { Add(game, null); }
private Tuple<List<UIElement>, String> GenerateElements(DominionBase.Visual.VisualPlayer item, SolidColorBrush background, SolidColorBrush foreground) { List<UIElement> elements = new List<UIElement>(); TextBlock tbLine = new TextBlock(); tbLine.Text = ((DominionBase.Visual.VisualPlayer)item).Name; tbLine.Background = background; tbLine.Foreground = foreground.Color.A == 0 ? Brushes.Black : foreground; tbLine.FontWeight = FontWeights.Bold; DockPanel.SetDock(tbLine, Dock.Left); elements.Add(tbLine); return new Tuple<List<UIElement>, String>(elements, item.Name); }
public override void Log(DominionBase.Visual.VisualPlayer player, List<Brush> playerBrushes, params Object[] items) { StringBuilder sbFullLine = new StringBuilder(); TreeViewItem tvi = new TreeViewItem() { Margin = new Thickness(0), Padding = new Thickness(0) }; DockPanel dp = new DockPanel(); dp.LastChildFill = true; sbFullLine.Append(this.DepthPrefix); TreeView tvActive = tvArea; DominionBase.Visual.VisualPlayer lineVisualPlayer = null; foreach (Object item in items) { if (item is String) { foreach (UIElement elem in Utilities.RenderText((String)item, NET_WPF.RenderSize.Tiny, true)) { if (elem is TextBlock) ((TextBlock)elem).VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(elem, Dock.Left); dp.Children.Add(elem); } sbFullLine.Append(item); } else if (item is DominionBase.Currency) { foreach (UIElement elem in Utilities.RenderText(((DominionBase.Currency)item).ToStringInline(), NET_WPF.RenderSize.Tiny, true)) { if (elem is TextBlock) ((TextBlock)elem).VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(elem, Dock.Left); dp.Children.Add(elem); } sbFullLine.Append(Utilities.RenderText(((DominionBase.Currency)item).ToStringInline())); } else if (item is DominionBase.Currencies.CurrencyBase) { foreach (UIElement elem in Utilities.RenderText(((DominionBase.Currencies.CurrencyBase)item).ToString(), NET_WPF.RenderSize.Tiny, true)) { if (elem is TextBlock) ((TextBlock)elem).VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(elem, Dock.Left); dp.Children.Add(elem); } sbFullLine.Append(Utilities.RenderText(((DominionBase.Currencies.CurrencyBase)item).ToString())); } else if (item is DominionBase.Players.Player) { lineVisualPlayer = new DominionBase.Visual.VisualPlayer((DominionBase.Players.Player)item); TextBlock tbLine = new TextBlock(); tbLine.Text = lineVisualPlayer.Name; tbLine.VerticalAlignment = System.Windows.VerticalAlignment.Center; if (lineVisualPlayer.PlayerUniqueId != this.Player.PlayerUniqueId) tbLine.FontWeight = FontWeights.Bold; DockPanel.SetDock(tbLine, Dock.Left); dp.Children.Add(tbLine); sbFullLine.Append(lineVisualPlayer.Name); } else if (item is DominionBase.Visual.VisualPlayer) { lineVisualPlayer = (DominionBase.Visual.VisualPlayer)item; TextBlock tbLine = new TextBlock(); tbLine.Text = lineVisualPlayer.Name; tbLine.VerticalAlignment = System.Windows.VerticalAlignment.Center; if (lineVisualPlayer.PlayerUniqueId != this.Player.PlayerUniqueId) tbLine.FontWeight = FontWeights.Bold; DockPanel.SetDock(tbLine, Dock.Left); dp.Children.Add(tbLine); sbFullLine.Append(lineVisualPlayer.Name); } else if (item is DominionBase.ICard) { ucCardIcon icon = CardIconUtilities.CreateCardIcon((DominionBase.ICard)item); icon.VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(icon, Dock.Left); dp.Children.Add(icon); sbFullLine.Append(((DominionBase.ICard)item).Name); } else if (item is IEnumerable<DominionBase.ICard>) { foreach (ucCardIcon icon in CardIconUtilities.CreateCardIcons((IEnumerable<DominionBase.ICard>)item)) { icon.VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(icon, Dock.Left); dp.Children.Add(icon); if (icon.Count == 1) sbFullLine.Append(icon.Card.Name); else sbFullLine.AppendFormat("{0}x {1}", icon.Count, icon.Card.Name); TextBlock tbLine = new TextBlock(); tbLine.Text = ", "; tbLine.VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(tbLine, Dock.Left); dp.Children.Add(tbLine); sbFullLine.Append(", "); } if (((IEnumerable<DominionBase.ICard>)item).Count() > 0) { dp.Children.RemoveAt(dp.Children.Count - 1); sbFullLine = sbFullLine.Remove(sbFullLine.Length - 2, 2); } } else if (item is IEnumerable<DominionBase.Token>) { int count = ((IEnumerable<DominionBase.Token>)item).Count(); String displayString = ((IEnumerable<DominionBase.Token>)item).First().LongDisplayString; if (count != 1) displayString = String.Format("{0}x {1}", count, displayString); TextBlock tbLine = new TextBlock(); tbLine.Text = displayString; tbLine.VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(tbLine, Dock.Left); dp.Children.Add(tbLine); sbFullLine.Append(displayString); } } if (tvi.Background != null && dp.Children.Count > 0) { if (dp.Children.Count == 1) { if (dp.Children[0] is TextBlock) ((TextBlock)dp.Children[0]).Padding = new Thickness(2, 1, 2, 1); else if (dp.Children[0] is ucCardIcon) ((ucCardIcon)dp.Children[0]).Padding = new Thickness(2, 1, 2, 1); } else { if (dp.Children[0] is TextBlock) ((TextBlock)dp.Children[0]).Padding = new Thickness(2, 1, 0, 1); else if (dp.Children[0] is ucCardIcon) ((ucCardIcon)dp.Children[0]).Padding = new Thickness(2, 1, 0, 1); if (dp.Children[dp.Children.Count - 1] is TextBlock) ((TextBlock)dp.Children[dp.Children.Count - 1]).Padding = new Thickness(0, 1, 2, 1); else if (dp.Children[dp.Children.Count - 1] is ucCardIcon) ((ucCardIcon)dp.Children[dp.Children.Count - 1]).Padding = new Thickness(0, 1, 2, 1); } } // Need something to fill the remaining gap Grid g = new Grid(); g.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; dp.Children.Add(g); Utilities.Log(this.LogFile, sbFullLine.ToString()); int level = this._CurrentInset; ItemCollection lItems = tvArea.Items; TreeViewItem tviParent = null; while (level > 0) { if (lItems[lItems.Count - 1] is TreeViewItem) tviParent = (TreeViewItem)lItems[lItems.Count - 1]; else if (lItems[lItems.Count - 1] is TreeView) tviParent = (TreeViewItem)((TreeView)lItems[lItems.Count - 1]).Items[((TreeView)lItems[lItems.Count - 1]).Items.Count - 1]; tviParent.IsExpanded = true; lItems = tviParent.Items; level--; } if (player.PlayerUniqueId == this.Player.PlayerUniqueId) { lItems.Add(tvi); tvi.Header = dp; tvi.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } else { if (lItems.Count == 0 || !(lItems[lItems.Count - 1] is TreeView) || (lItems[lItems.Count - 1] is TreeView && ((TreeView)lItems[lItems.Count - 1]).Background != playerBrushes[0])) { // This is pretty mess at the moment -- this is to detect nested Player stuff // (e.g. discarding Market Square when trashing a card and then revealing Watchtower to put the gained Gold on top of your deck) if (tviParent is TreeViewItem && (((TreeViewItem)tviParent).Parent is TreeView && ((TreeView)((TreeViewItem)tviParent).Parent).Background == playerBrushes[0] || ((TreeViewItem)tviParent).Parent is TreeViewItem && ((TreeViewItem)((TreeViewItem)tviParent).Parent).Parent is TreeView && ((TreeView)((TreeViewItem)((TreeViewItem)tviParent).Parent).Parent).Background == playerBrushes[0])) lItems.Add(tvi); else { TreeView tvNewPlayer = new TreeView(); tvNewPlayer.Background = playerBrushes[0]; tvNewPlayer.Margin = new Thickness(-19, 0, 0, 0); tvNewPlayer.Items.Add(tvi); lItems.Add(tvNewPlayer); } } else if (lItems[lItems.Count - 1] is TreeView) { ((TreeView)lItems[lItems.Count - 1]).Items.Add(tvi); } else lItems.Add(tvi); tvi.Header = dp; tvi.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } dp.BringIntoView(); _PreviousLinePlayer = lineVisualPlayer; }
public virtual void New(DominionBase.Players.Player player, List<Brush> playerBrushes, DominionBase.Cards.Card grantedBy) { }
public override void New(DominionBase.Players.Player player, List<Brush> playerBrushes, DominionBase.Cards.Card grantedBy) { this.Player = new DominionBase.Visual.VisualPlayer(player); _CurrentInset = 0; if (playerBrushes[0] != Brushes.Transparent) { this.Background = playerBrushes[1]; this.BorderBrush = playerBrushes[2]; } Utilities.Log(this.LogFile, String.Format("{0} starting turn{1}", player, grantedBy == null ? "" : String.Format(" from {0}", grantedBy.Name))); DockPanel dp = new DockPanel(); TextBlock tbPlayerName = new TextBlock(); tbPlayerName.Text = player.Name; tbPlayerName.FontWeight = FontWeights.Bold; DockPanel.SetDock(tbPlayerName, Dock.Left); dp.Children.Add(tbPlayerName); tbPlayerName = new TextBlock(); tbPlayerName.Text = " starting turn"; DockPanel.SetDock(tbPlayerName, Dock.Left); dp.Children.Add(tbPlayerName); if (grantedBy != null) { TextBlock tbGrantedBy = new TextBlock(); tbGrantedBy.Text = " granted by "; DockPanel.SetDock(tbGrantedBy, Dock.Left); dp.Children.Add(tbGrantedBy); ucCardIcon icon = CardIconUtilities.CreateCardIcon(grantedBy); DockPanel.SetDock(icon, Dock.Left); dp.Children.Add(icon); TextBlock tbBlank = new TextBlock(); DockPanel.SetDock(tbBlank, Dock.Left); dp.Children.Add(tbBlank); } expTurn.Header = dp; }
private void _Player_TurnStarted(object sender, DominionBase.Players.TurnStartedEventArgs e) { if (cardHand.Dispatcher.CheckAccess()) { if (this.IsUIPlayer) { cardHand.IsClickable = true; } else cardHand.IsClickable = false; } else { cardHand.Dispatcher.BeginInvoke(new EventHandler<DominionBase.Players.TurnStartedEventArgs>(_Player_TurnStarted), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } }
private void UpdateDisplayPlayer(DominionBase.Players.Player player) { bPlayTreasures.IsEnabled = false; bPlayCoinTokens.IsEnabled = false; bBuyPhase.IsEnabled = false; bTurnDone.IsEnabled = false; bUndo.IsEnabled = false; bPlayTreasures.Text = "Play basic _Treasures"; if (player == null) { return; } if (player.PlayerType == DominionBase.Players.PlayerType.Human) { DominionBase.Cards.CardCollection treasures; DominionBase.Currency totalCurrency; String currency = String.Empty; switch (player.Phase) { case DominionBase.Players.PhaseEnum.Action: if (player.PlayerMode == DominionBase.Players.PlayerMode.Normal) { treasures = player.Hand[c => (c.Category & DominionBase.Cards.Category.Treasure) == DominionBase.Cards.Category.Treasure && (c.Location == DominionBase.Cards.Location.General || c.CardType.GetMethod("Play", new Type[] { typeof(DominionBase.Players.Player) }).DeclaringType == typeof(DominionBase.Cards.Card))]; bPlayTreasures.IsEnabled = treasures.Count > 0; totalCurrency = new DominionBase.Currency(); foreach (DominionBase.Currency c in treasures.Select(t => t.Benefit.Currency)) totalCurrency += c; currency = totalCurrency.ToStringInline(); bPlayCoinTokens.IsEnabled = player.TokenPiles.ContainsKey(DominionBase.Cards.Guilds.TypeClass.CoinToken) && player.TokenPiles[DominionBase.Cards.Guilds.TypeClass.CoinToken].Count > 0 && player.CurrentTurn.CardsBought.Count == 0; bBuyPhase.IsEnabled = true; bTurnDone.IsEnabled = true; } break; case DominionBase.Players.PhaseEnum.ActionTreasure: case DominionBase.Players.PhaseEnum.BuyTreasure: if (player.PlayerMode == DominionBase.Players.PlayerMode.Normal) { treasures = player.Hand[c => (c.Category & DominionBase.Cards.Category.Treasure) == DominionBase.Cards.Category.Treasure && (c.Location == DominionBase.Cards.Location.General || c.CardType.GetMethod("Play", new Type[] { typeof(DominionBase.Players.Player) }).DeclaringType == typeof(DominionBase.Cards.Card))]; bPlayTreasures.IsEnabled = treasures.Count > 0; totalCurrency = new DominionBase.Currency(); foreach (DominionBase.Currency c in treasures.Select(t => t.Benefit.Currency)) totalCurrency += c; currency = totalCurrency.ToStringInline(); bPlayCoinTokens.IsEnabled = player.TokenPiles.ContainsKey(DominionBase.Cards.Guilds.TypeClass.CoinToken) && player.TokenPiles[DominionBase.Cards.Guilds.TypeClass.CoinToken].Count > 0 && player.CurrentTurn.CardsBought.Count == 0; bBuyPhase.IsEnabled = true; bTurnDone.IsEnabled = true; } break; case DominionBase.Players.PhaseEnum.Buy: if (player.PlayerMode == DominionBase.Players.PlayerMode.Normal) { bTurnDone.IsEnabled = true; } break; case DominionBase.Players.PhaseEnum.Cleanup: case DominionBase.Players.PhaseEnum.Endgame: break; } bUndo.IsEnabled = player.CurrentTurn.CardsPlayed.Count > 0 && player.CurrentTurn.CardsPlayed[player.CurrentTurn.CardsPlayed.Count - 1].CanUndo && player.CurrentTurn.CardsBought.Count == 0; if (bPlayTreasures.IsEnabled) bPlayTreasures.Text = String.Format("Play basic _Treasures for: {0}", currency); } }