Inheritance: SelectableItem
Exemplo n.º 1
0
 public TestFluidCardStack()
 {
     InitializeComponent();
     GameEngine.LoadExpansions("./");
     var model = new CardViewModel() { Card = GameEngine.CardSet.First() };
     cardView1.DataContext = model;
 }
Exemplo n.º 2
0
 public static IList<Inline> RichTranslate(CardViewModel card)
 {
     IList<Inline> list = new List<Inline>();
     string typeString = Application.Current.TryFindResource(string.Format("Card.{0}.Name", card.TypeString)) as string;
     if (typeString != null)
     {
         list.Add(new Run("【" + typeString) { Foreground = new SolidColorBrush(Colors.Yellow) });
         Run run = new Run();
         run.Foreground = Application.Current.Resources[string.Format("Card.Suit.{0}.SuitBrush", card.Suit)] as Brush;
         run.Text = string.Format("{0}{1}", Application.Current.Resources[string.Format("Card.Suit.{0}.SuitText", card.Suit)], card.RankString);
         list.Add(run);
         list.Add(new Run("】") { Foreground = new SolidColorBrush(Colors.Yellow) });
     }
     return list;
 }
Exemplo n.º 3
0
        public void NotifyWuGuStart(Prompt prompt, DeckPlace place)
        {
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                GameModel.WuGuModel = new WuGuChoiceViewModel();
                GameModel.WuGuModel.Prompt = PromptFormatter.Format(prompt);
                bool isFirstRow = true;
                int i = 0;
                int total = Game.CurrentGame.Decks[place].Count;

                foreach (var c in Game.CurrentGame.Decks[place])
                {
                    if (isFirstRow && total > 4 && i >= total / 2) isFirstRow = false;
                    var card = new CardViewModel() { Card = c, IsSelectionMode = true, IsEnabled = true };
                    if (isFirstRow) GameModel.WuGuModel.Cards1.Add(card);
                    else GameModel.WuGuModel.Cards2.Add(card);
                    card.OnSelectedChanged += new EventHandler(card_OnSelectedChanged);
                    i++;
                }

                wuGuWindow.Show();
            });
        }
Exemplo n.º 4
0
        public void NotifyTwoSidesCardPickStart(Prompt prompt, DeckPlace place, IDictionary<int, int> groupMap, int group0MaxPick, int group1MaxPick)
        {
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                var twoSidesCardChoiceModel = new TwoSidesCardChoiceViewModel();
                twoSidesCardChoiceModel.Prompt = LogFormatter.Translate(prompt);
                twoSidesCardChoiceModel.GroupOfPlayer = groupMap;

                foreach (var c in Game.CurrentGame.Decks[place])
                {
                    var card = new CardViewModel() { Card = c, IsSelectionMode = true, IsEnabled = true };
                    card.OnSelectedChanged += new EventHandler(card_OnSelectedChanged);
                    twoSidesCardChoiceModel.CardsToPick.Add(card);
                }

                int mainPlayerMaxPick, opponentMaxPick;
                if (groupMap[GameModel.MainPlayerModel.Id] == 0)
                {
                    mainPlayerMaxPick = group0MaxPick;
                    opponentMaxPick = group1MaxPick;
                }
                else
                {
                    mainPlayerMaxPick = group1MaxPick;
                    opponentMaxPick = group0MaxPick;
                }
                for (int i = 0; i < mainPlayerMaxPick; i++)
                {
                    twoSidesCardChoiceModel.CardsPicked1.Add(new CardSlotViewModel());
                }

                for (int i = 0; i < opponentMaxPick; i++)
                {
                    twoSidesCardChoiceModel.CardsPicked2.Add(new CardSlotViewModel());
                }

                GameModel.TwoSidesCardChoiceModel = twoSidesCardChoiceModel;

                if (ViewModelBase.IsDetached) return;

                twoSidesCardChoiceBox.DataContext = twoSidesCardChoiceModel;
                twoSidesCardChoiceWindow.Show();
            });
        }
Exemplo n.º 5
0
        public void NotifyWuGuStart(Prompt prompt, DeckPlace place)
        {
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                var wuguModel = new WuGuChoiceViewModel();
                wuguModel.Prompt = LogFormatter.Translate(prompt);
                bool isFirstRow = true;
                int i = 0;
                int total = Game.CurrentGame.Decks[place].Count;

                foreach (var c in Game.CurrentGame.Decks[place])
                {
                    if (isFirstRow && total > 5 && i >= (total + 1) / 2) isFirstRow = false;
                    var card = new CardViewModel() { Card = c, IsSelectionMode = true, IsEnabled = true };
                    if (isFirstRow) wuguModel.Cards1.Add(card);
                    else wuguModel.Cards2.Add(card);
                    card.OnSelectedChanged += new EventHandler(card_OnSelectedChanged);
                    i++;
                }
                GameModel.WuGuModel = wuguModel;

                if (ViewModelBase.IsDetached) return;

                wuGuBox.DataContext = wuguModel;
                wuGuWindow.Show();
            });
        }
Exemplo n.º 6
0
        private void _ConstructCardChoiceModel(List<DeckPlace> sourceDecks, List<string> resultDeckNames,
                                               List<int> resultDeckMaximums,
                                               AdditionalCardChoiceOptions options,
                                               ICardChoiceVerifier verifier,
                                               int timeOutSeconds,
                                               CardChoiceRearrangeCallback callback)
        {
            bool isSingleResult = (resultDeckMaximums.Sum() == 1);

            var choiceModel = new CardChoiceViewModel();

            int numLines = sourceDecks.Count;

            foreach (var deck in sourceDecks)
            {
                if (Game.CurrentGame.Decks[deck].Count == 0)
                {
                    continue;
                }
                CardChoiceLineViewModel line = new CardChoiceLineViewModel();
                line.DeckName = deck.DeckType.Name;
                line.IsResultDeck = false;
                int i = 0;
                int numCards = Game.CurrentGame.Decks[deck].Count;
                int maxColumns = Math.Max(numCards / 2 + 1, 5);
                bool firstRow = true;
                foreach (var card in Game.CurrentGame.Decks[deck])
                {
                    if (numLines == 1 && isSingleResult && i >= maxColumns && firstRow)
                    {
                        Trace.Assert(choiceModel.CardStacks.Count == 0);
                        choiceModel.CardStacks.Add(line);
                        line = new CardChoiceLineViewModel();
                        line.DeckName = deck.DeckType.Name;
                        line.IsResultDeck = false;
                        firstRow = false;
                    }
                    CardViewModel model = new CardViewModel()
                    {
                        Card = card,
                        IsSelectionMode = isSingleResult,
                        IsEnabled = true
                    };

                    line.Cards.Add(model);
                    i++;
                }
                choiceModel.CardStacks.Add(line);
            }

            if (!isSingleResult)
            {
                int k = 0;
                foreach (var deckName in resultDeckNames)
                {
                    CardChoiceLineViewModel line = new CardChoiceLineViewModel();
                    line.DeckName = deckName;
                    if (options != null)
                    {
                        if (options.Rearrangeable != null)
                        {
                            line.Rearrangable = options.Rearrangeable[k];
                        }
                        if (options.DefaultResult != null)
                        {
                            foreach (var card in options.DefaultResult[k])
                            {
                                line.Cards.Add(new CardViewModel() { Card = card });
                            }
                        }
                    }
                    line.Capacity = resultDeckMaximums[k++];
                    line.IsResultDeck = true;
                    choiceModel.CardStacks.Add(line);
                }
            }

            if (options != null && options.Options != null)
            {
                for (int i = 0; i < options.Options.Count; i++)
                {
                    MultiChoiceCommand command = new MultiChoiceCommand(ExecuteCardChoiceCommand)
                    {
                        CanExecuteStatus = false,
                        ChoiceKey = options.Options[i],
                        ChoiceIndex = i
                    };
                    choiceModel.MultiChoiceCommands.Add(command);
                }
            }
            else
            {
                MultiChoiceCommand command = new MultiChoiceCommand(ExecuteCardChoiceCommand)
                {
                    CanExecuteStatus = false,
                    ChoiceKey = new OptionPrompt("Confirm")
                };
                choiceModel.MultiChoiceCommands.Add(command);
            }
            if (options != null && options.IsCancellable)
            {
                MultiChoiceCommand command = new MultiChoiceCommand(CancelCardChoiceCommand)
                {
                    IsCancel = true,
                    ChoiceKey = new OptionPrompt("Cancel")
                };
                choiceModel.MultiChoiceCommands.Add(command);
            }

            choiceModel.Verifier = verifier;
            choiceModel.TimeOutSeconds = timeOutSeconds;
            CardChoiceModel = choiceModel;
        }
Exemplo n.º 7
0
        private void _UpdateCardUsageStatus()
        {
            if (_updateCardUsageRecurvieLock || currentUsageVerifier == null)
            {
                return;
            }

            _updateCardUsageRecurvieLock = true;

            List<Card> cards = _GetSelectedNonEquipCards();
            List<Player> players = _GetSelectedPlayers();
            ISkill skill = null;
            bool isEquipCommand;
            SkillCommand command = _GetSelectedSkillCommand(out isEquipCommand);

            if (currentUsageVerifier.Helper.IsActionStage)
            {
                cancelCardUsageCommand.CanExecuteStatus = (cards.Count != 0 || players.Count != 0 || command != null);
            }

            if (command != null)
            {
                skill = command.Skill;
            }

            // are we really able to use this equip as command?
            if (isEquipCommand)
            {
                Trace.Assert(skill != null);
                if (currentUsageVerifier.Verify(HostPlayer, skill, new List<Card>(), new List<Player>()) == VerifierResult.Fail)
                {
                    //nope, not really
                    isEquipCommand = false;
                    skill = null;
                }
            }

            string prompt = null;
            if (skill != null)
            {
                prompt = Application.Current.TryFindResource(string.Format("Skill.{0}.Prompt", skill.GetType().Name)) as string;
            }
            if (prompt == null)
            {
                prompt = LogFormatter.Translate(CurrentPrompt);
            }
            CurrentPromptString = prompt;

            if (!isEquipCommand)
            {
                foreach (var equipCommand in EquipCommands)
                {
                    if (equipCommand.IsSelected)
                        cards.Add(equipCommand.Card);
                }
            }

            var sc = new List<SkillCommand>(ActiveSkillCommands);

            // Handle skill down
            bool hideSpecialDeck = true;

            if (currentUsageVerifier != null && currentUsageVerifier.Helper != null &&
                currentUsageVerifier.Helper.OtherDecksUsed != null &&
                currentUsageVerifier.Helper.OtherDecksUsed.Count > 0)
            {
                hideSpecialDeck = false;
            }

            foreach (var skillCommand in sc)
            {
                // Handle kurou, luanwu and yeyan
                if (skillCommand.Skill != null && skillCommand.IsSelected)
                {
                    var helper = skillCommand.Skill.Helper;

                    // Handle KuRou, LuanWu
                    if (helper.HasNoConfirmation)
                    {
                        SubmitAnswerCommand.Execute(null);
                        _updateCardUsageRecurvieLock = false;
                        return;
                    }

                    // Handle YeYan
                    foreach (var player in _game.PlayerModels)
                    {
                        if (player.IsSelectionRepeatable == helper.IsPlayerRepeatable)
                        {
                            break;
                        }
                        player.IsSelectionRepeatable = helper.IsPlayerRepeatable;
                    }

                    // Handle JiXi, PaiYi
                    if (helper.OtherDecksUsed.Count > 0)
                    {
                        hideSpecialDeck = false;
                        if (helper.OtherDecksUsed.Count != 1)
                        {
                            _updateCardUsageRecurvieLock = false;
                            throw new NotImplementedException("Currently using more than one private decks is not supported");
                        }
                        var deck = helper.OtherDecksUsed[0];
                        var deckModel = PrivateDecks.FirstOrDefault(d => d.Name == deck.Name);
                        Trace.Assert(deckModel != null);
                        if (deckModel != CurrentSpecialDeck)
                        {
                            if (CurrentSpecialDeck != null)
                            {
                                foreach (var card in CurrentSpecialDeck.Cards)
                                {
                                    card.IsSelectionMode = false;
                                    card.OnSelectedChanged -= _OnCardSelected;
                                }
                            }
                            foreach (var card in deckModel.Cards)
                            {
                                card.IsSelectionMode = true;
                                card.OnSelectedChanged += _OnCardSelected;
                            }
                            CurrentSpecialDeck = deckModel;
                        }
                    }
                    else if (helper.OtherGlobalCardDeckUsed.Count > 0)
                    {
                        hideSpecialDeck = false;
                        if (helper.OtherGlobalCardDeckUsed.Count != 1)
                        {
                            _updateCardUsageRecurvieLock = false;
                            throw new NotImplementedException("Currently using more than one private decks is not supported");
                        }
                        var deck = helper.OtherGlobalCardDeckUsed.First().Key;
                        var numShown = helper.OtherGlobalCardDeckUsed.First().Value;

                        if (CurrentSpecialDeck == null || CurrentSpecialDeck.DeckPlace != deck ||
                            CurrentSpecialDeck.NumberOfCardsLimit != numShown)
                        {
                            var deckModel = new SpecialDeckViewModel() { DeckPlace = deck, NumberOfCardsLimit = numShown };
                            int total;
                            var deckCards = Game.CurrentGame.Decks[deck];

                            if (CurrentSpecialDeck != null)
                            {
                                foreach (var card in CurrentSpecialDeck.Cards)
                                {
                                    card.IsSelectionMode = false;
                                    card.OnSelectedChanged -= _OnCardSelected;
                                }
                            }

                            if (numShown == null)
                            {
                                total = deckCards.Count;
                            }
                            else
                            {
                                total = Math.Min((int)numShown, deckCards.Count);
                            }

                            for (int t = 0; t < total; t++)
                            {
                                var card = new CardViewModel() { Card = deckCards[t] };
                                card.IsSelectionMode = true;
                                card.OnSelectedChanged += _OnCardSelected;
                                deckModel.Cards.Add(card);
                            }

                            CurrentSpecialDeck = deckModel;
                        }
                    }
                    else
                    {
                        CurrentSpecialDeck = null;
                    }
                }

                // Handler GuHuo, QiCe
                GuHuoSkillCommand cmdGuhuo = skillCommand as GuHuoSkillCommand;
                if (cmdGuhuo != null)
                {
                    if (skillCommand.IsEnabled)
                    {
                        if (cmdGuhuo.GuHuoTypes.Count == 0 && cmdGuhuo.GuHuoChoice == null)
                        {
                            var trySkill = Activator.CreateInstance(cmdGuhuo.Skill.GetType()) as IAdditionalTypedSkill;
                            trySkill.Owner = cmdGuhuo.Skill.Owner;
                            foreach (var c in Game.CurrentGame.AvailableCards)
                            {
                                trySkill.AdditionalType = c;
                                if (currentUsageVerifier.Verify(HostPlayer, trySkill, new List<Card>(), new List<Player>()) != VerifierResult.Fail)
                                {
                                    cmdGuhuo.GuHuoTypes.Add(c);
                                }
                            }
                        }
                    }
                }
            }

            if (hideSpecialDeck) CurrentSpecialDeck = null;

            var status = currentUsageVerifier.Verify(HostPlayer, skill, cards, players);

            if (status == VerifierResult.Fail)
            {
                submitCardUsageCommand.CanExecuteStatus = false;
                foreach (var playerModel in _game.PlayerModels)
                {
                    playerModel.IsSelected = false;
                }
                players.Clear();
                _lastSelectedPlayers.Clear();
            }

            else if (status == VerifierResult.Partial)
            {
                submitCardUsageCommand.CanExecuteStatus = false;
            }
            else if (status == VerifierResult.Success)
            {
                submitCardUsageCommand.CanExecuteStatus = true;
            }

            if (skill == null || (skill is CardTransformSkill) || (skill is ActiveSkill))
            {
                // cards to be passed to verifier
                List<Card> attempt = new List<Card>(cards);
                // contains cards that doesn't pass the verifier when added to selected cards,
                // but can pass the verifier if current card selection is rejected.
                _cardsInSwitchMode.Clear();

                bool allowCardSwitch = (attempt.Count == 1);

                var cardsToTry = CurrentSpecialDeck == null ? HandCards : HandCards.Concat(CurrentSpecialDeck.Cards);

                foreach (var card in cardsToTry)
                {
                    if (card.IsSelected)
                    {
                        continue;
                    }
                    attempt.Add(card.Card);
                    bool disabled = (currentUsageVerifier.Verify(HostPlayer, skill, attempt, players) == VerifierResult.Fail);

                    if (disabled && allowCardSwitch)
                    {
                        if (currentUsageVerifier.Verify(HostPlayer, skill, new List<Card>() { card.Card }, players) != VerifierResult.Fail)
                        {
                            disabled = false;
                            _cardsInSwitchMode.Add(card);
                        }
                    }
                    else
                    {
                        allowCardSwitch = false;
                        foreach (var c in _cardsInSwitchMode)
                        {
                            c.IsEnabled = false;
                        }
                        _cardsInSwitchMode.Clear();
                    }

                    card.IsEnabled = !disabled;
                    attempt.Remove(card.Card);
                }

                foreach (var equipCommand in EquipCommands)
                {
                    bool enabledAsSkill = false;
                    if (skill == null && equipCommand.SkillCommand.Skill != null && (equipCommand.SkillCommand.Skill is CardTransformSkill || equipCommand.SkillCommand.Skill is ActiveSkill))
                    {
                        enabledAsSkill = (currentUsageVerifier.Verify(HostPlayer, equipCommand.SkillCommand.Skill, new List<Card>(), new List<Player>()) != VerifierResult.Fail);
                    }
                    if (!equipCommand.IsSelected)
                    {
                        attempt.Add(equipCommand.Card);
                        bool disabled = (currentUsageVerifier.Verify(HostPlayer, skill, attempt, players) == VerifierResult.Fail);
                        equipCommand.IsEnabled = (!disabled) | enabledAsSkill;
                    }
                    attempt.Remove(equipCommand.Card);
                }
            }

            // Invalidate target selection
            List<Player> attempt2 = new List<Player>(players);
            int validCount = 0;
            bool[] enabledMap = new bool[_game.PlayerModels.Count];
            int i = 0;
            foreach (var playerModel in _game.PlayerModels)
            {
                enabledMap[i] = false;
                if (playerModel.IsSelected && !playerModel.IsSelectionRepeatable)
                {
                    i++;
                    continue;
                }
                attempt2.Add(playerModel.Player);
                bool disabled = (currentUsageVerifier.Verify(HostPlayer, skill, cards, attempt2) == VerifierResult.Fail);
                if (!disabled)
                {
                    validCount++;
                    enabledMap[i] = true;
                }
                attempt2.RemoveAt(attempt2.Count - 1);
                i++;

            }
            i = 0;

            bool allowSelection = (cards.Count != 0 || validCount != 0 || skill != null);
            foreach (var playerModel in _game.PlayerModels)
            {
                if (playerModel.IsSelected && !playerModel.IsSelectionRepeatable)
                {
                    i++;
                    continue;
                }

                playerModel.IsSelectionMode = allowSelection;
                if (allowSelection)
                {
                    if (playerModel.IsSelected)
                    {
                        playerModel.CanBeSelectedMore = enabledMap[i];
                    }
                    else
                    {
                        playerModel.IsEnabled = enabledMap[i];
                    }
                }
                i++;
            }

            _updateCardUsageRecurvieLock = false;
        }
Exemplo n.º 8
0
        private void _ResetSkillsAndCards()
        {
            foreach (var equipCommand in EquipCommands)
            {
                equipCommand.OnSelectedChanged -= _OnCardUsageSelectionChanged;
                equipCommand.IsSelectionMode = false;
            }

            foreach (var skillCommand in ActiveSkillCommands)
            {
                skillCommand.OnSelectedChanged -= _OnSkillCommandSelected;
                skillCommand.IsSelected = false;
                skillCommand.IsEnabled = false;
            }

            foreach (CardViewModel card in HandCards)
            {
                card.OnSelectedChanged -= _OnCardSelected;
                card.IsSelectionMode = false;
            }

            foreach (var playerModel in _game.PlayerModels)
            {
                playerModel.OnSelectedChanged -= _OnCardUsageSelectionChanged;
                playerModel.IsSelectionMode = false;
            }
            _lastSelectedPlayers.Clear();
            CurrentSpecialDeck = null;
            _lastSelectedCard = null;
            _lastSelectedCommand = null;
            SubmitAnswerCommand = DisabledCommand;
            CancelAnswerCommand = DisabledCommand;
            AbortAnswerCommand = DisabledCommand;
        }
Exemplo n.º 9
0
        private void _OnCardSelected(object sender, EventArgs args)
        {
            var card = sender as CardViewModel;
            if (card.IsSelected)
            {
                /*
                if (card == _lastSelectedCard)
                {
                    Trace.Assert(false);
                }
                else*/
                if (_lastSelectedCard != null && _cardsInSwitchMode.Contains(card))
                {
                    _lastSelectedCard.OnSelectedChanged -= _OnCardSelected;
                    _lastSelectedCard.IsSelected = false;
                    _lastSelectedCard.OnSelectedChanged += _OnCardSelected;
                    // _lastSelectedCard = null;
                }

                _lastSelectedCard = card;
            }
            else if (card == _lastSelectedCard)
            {
                _lastSelectedCard = null;
            }

            if (currentUsageVerifier != null)
            {
                _UpdateCardUsageStatus();
            }
        }
Exemplo n.º 10
0
 public CardView(CardViewModel card)
     : this()
 {
     this.DataContext = card;
 }
Exemplo n.º 11
0
        public static CardView CreateCard(CardViewModel card, Panel parent = null, int width = 93, int height = 130)
        {
            if (_cardViewPool.Count == 0) _cardViewPool.Push(new CardView());

            var cardView = _cardViewPool.Pop();

            cardView.Width = width;
            cardView.Height = height;
            cardView.Opacity = 0d;
            cardView.Visibility = Visibility.Visible;
            cardView.DataContext = card;
            cardView.IsHitTestVisible = true;
            Trace.Assert(cardView.Parent == null);

            if (parent != null)
            {
                parent.Children.Add(cardView);
            }
            return cardView;
        }
Exemplo n.º 12
0
        private void _ConstructCardChoiceModel(List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, List<bool> rearrangeable, int timeOutSeconds, CardChoiceRearrangeCallback callback)
        {
            if (resultDeckMaximums.Sum() != 1)
            {
                throw new NotImplementedException();
            }

            CardChoiceModel.CardStacks.Clear();

            int numLines = sourceDecks.Count;

            foreach (var deck in sourceDecks)
            {
                if (Game.CurrentGame.Decks[deck].Count == 0)
                {
                    continue;
                }
                CardChoiceLineViewModel line = new CardChoiceLineViewModel();
                line.DeckName = deck.DeckType.Name;
                int i = 0;
                int numCards = Game.CurrentGame.Decks[deck].Count;
                int maxColumns = Math.Max(numCards / 2 + 1, 5);
                bool firstRow = true;
                foreach (var card in Game.CurrentGame.Decks[deck])
                {
                    if (numLines == 1 && i >= maxColumns && firstRow)
                    {
                        Trace.Assert(CardChoiceModel.CardStacks.Count == 0);
                        CardChoiceModel.CardStacks.Add(line);
                        line = new CardChoiceLineViewModel();
                        line.DeckName = deck.DeckType.Name;
                        firstRow = false;
                    }
                    CardViewModel model = new CardViewModel()
                    {
                        Card = card,
                        IsSelectionMode = true,
                        IsEnabled = true
                    };
                    model.OnSelectedChanged += cardChoice_OnSelectedChanged;
                    line.Cards.Add(model);
                    i++;
                }
                CardChoiceModel.CardStacks.Add(line);
            }

            CardChoiceModel.TimeOutSeconds = timeOutSeconds;
        }