Beispiel #1
0
        public DeckSectionItemModel(IdeCollection <IdeBaseItem> source) : base(source) // new item
        {
            _deckSection  = new DeckSection();
            SelectedGroup = (GroupItemModel)Groups.First();
            Name          = "New Section";

            //    Messenger.Default.Register<GroupChangedMessage>(this, action => UpdateDeckSectionDef(action));
        }
Beispiel #2
0
 public IList <IPrintedCard> EnsureSection(DeckSection s)
 {
     if (!sections.TryGetValue(s, out List <IPrintedCard> container))
     {
         sections.Add(s, container = new List <IPrintedCard>());
     }
     return(container);
 }
Beispiel #3
0
 public DeckSectionItemModel(DeckSectionItemModel d, IdeCollection <IdeBaseItem> source) : base(source) // copy item
 {
     _deckSection = new DeckSection()
     {
         Shared = d._deckSection.Shared,
         Group  = d._deckSection.Group
     };
     Name = d.Name;
 }
Beispiel #4
0
 public bool HasSection(DeckSection section) => sections.ContainsKey(section);
Beispiel #5
0
 public IList <IPrintedCard> this[DeckSection s] => sections.TryGetValue(s, out List <IPrintedCard> list) ? list : EmptySection;
Beispiel #6
0
        //Temporarily store group visibility information for LoadDeck. //bug (google) #20

        public void LoadDeck(IDeck deck, bool limited)
        {
            var def    = Program.GameEngine.Definition;
            int nCards = deck.CardCount();
            var ids    = new int[nCards];
            var keys   = new Guid[nCards];
            var cards  = new Card[nCards];
            var groups = new Play.Group[nCards];
            var sizes  = new string[nCards];
            var gtmps  = new List <GrpTmp>(); //for temp groups visibility
            int j      = 0;

            foreach (var section in deck.Sections)
            {
                { // Add cards to LoadedCards deck
                    if (!LoadedCards.Sections.Any(x => x.Name == section.Name))
                    {
                        // Add section
                        ((ObservableCollection <ObservableSection>)LoadedCards.Sections).Add(new ObservableSection()
                        {
                            Name   = section.Name,
                            Shared = section.Shared,
                            Cards  = new ObservableCollection <ObservableMultiCard>()
                        });
                    }

                    var loadedCardsSection = LoadedCards.Sections.Single(x => x.Name == section.Name);

                    foreach (var card in section.Cards)
                    {
                        var existingCard = loadedCardsSection.Cards.FirstOrDefault(x => x.Id == card.Id);
                        if (existingCard != null)
                        {
                            existingCard.Quantity += card.Quantity;
                        }
                        else
                        {
                            var newCard = new ObservableMultiCard(card);
                            loadedCardsSection.Cards.AddCard(newCard);
                        }
                    }
                }

                DeckSection sectionDef = null;
                sectionDef = section.Shared ? def.SharedDeckSections[section.Name] : def.DeckSections[section.Name];
                if (sectionDef == null)
                {
                    throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file.");
                }
                var        player = section.Shared ? Player.GlobalPlayer : Player.LocalPlayer;
                Play.Group group  = player.Groups.First(x => x.Name == sectionDef.Group.Name); //TODO: match directly to SectionDef Group instead of name matching

                //In order to make the clients know what the card is (if visibility is set so that they can see it),
                //we have to set the visibility to Nobody, and then after the cards are sent, set the visibility back
                //to what it was. //bug (google) #20
                var gt = new GrpTmp(group, group.Visibility, group.Viewers.ToList());
                if (!gtmps.Contains(gt))
                {
                    gtmps.Add(gt);
                    group.SetVisibility(false, false);
                }

                foreach (IMultiCard element in section.Cards)
                {
                    //DataNew.Entities.Card mod = Definition.GetCardById(element.Id);
                    for (int i = 0; i < element.Quantity; i++)
                    {
                        //for every card in the deck, generate a unique key for it, ID for it
                        var id   = element.GenerateCardId();
                        var card = new Card(player, id, new DataNew.Entities.Card(element), true, element.Size.Name);
                        //   var card = element.ToPlayCard(player);
                        ids[j]  = card.Id;
                        keys[j] = card.Type.Model.Id;
                        //keys[j] = card.GetEncryptedKey();
                        groups[j]  = group;
                        sizes[j]   = card.Size.Name;
                        cards[j++] = card;
                        group.AddAt(card, group.Count);

                        DeckStats.AddCard(card);
                    }

                    // Load images in the background
                    string pictureUri = element.GetPicture();
                    Dispatcher.CurrentDispatcher.BeginInvoke(
                        new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap),
                        DispatcherPriority.Background, pictureUri);
                }
            }

            string sleeveString = null;

            if (deck.Sleeve != null)
            {
                try {
                    var loadSleeve = true;

                    if (!IsLocal)
                    {
                        var isSubscriber = SubscriptionModule.Get().IsSubscribed;

                        if (isSubscriber == null)
                        {
                            loadSleeve = false;

                            Log.Warn("Can't set deck sleeve, unable to determin if user is a subscriber.");

                            Program.GameMess.Warning($"Deck sleeve can not be loaded, subscriber status is unknown.");
                        }
                        else if (isSubscriber == false)
                        {
                            loadSleeve = false;

                            Log.Warn("Not authorized to use deck sleeve.");

                            Program.GameMess.Warning($"Deck sleeve can not be used, you're not a subscriber.");
                        }
                    }

                    if (loadSleeve)
                    {
                        Player.LocalPlayer.SetSleeve(deck.Sleeve);

                        sleeveString = Sleeve.ToString(deck.Sleeve);
                    }
                    else
                    {
                        Log.Info("Sleeve will not be loaded.");
                    }
                } catch (Exception ex) {
                    Log.Warn(ex.Message, ex);

                    Program.GameMess.Warning($"There was an error loading the decks sleeve.");
                }
            }

            Program.Client.Rpc.LoadDeck(ids, keys, groups, sizes, sleeveString ?? string.Empty, limited);
            //reset the visibility to what it was before pushing the deck to everybody. //bug (google) #20
            foreach (GrpTmp g in gtmps)
            {
                switch (g.Visibility)
                {
                case GroupVisibility.Everybody:
                    g.Group.SetVisibility(true, false);
                    break;

                case GroupVisibility.Nobody:
                    g.Group.SetVisibility(false, false);
                    break;

                default:
                    foreach (Player p in g.Viewers)
                    {
                        g.Group.AddViewer(p, false);
                    }
                    break;
                }
            }
            gtmps.Clear();
            gtmps.TrimExcess();
        }
Beispiel #7
0
        //Temporarily store group visibility information for LoadDeck. //bug (google) #20

        public void LoadDeck(IDeck deck)
        {
            var def    = Program.GameEngine.Definition;
            int nCards = deck.CardCount();
            var ids    = new int[nCards];
            var keys   = new ulong[nCards];
            var cards  = new Card[nCards];
            var groups = new Play.Group[nCards];
            var gtmps  = new List <GrpTmp>(); //for temp groups visibility
            int j      = 0;

            foreach (ISection section in deck.Sections)
            {
                DeckSection sectionDef = null;
                sectionDef = section.Shared ? def.SharedDeckSections[section.Name] : def.DeckSections[section.Name];
                if (sectionDef == null)
                {
                    throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file.");
                }
                var        player = section.Shared ? Player.GlobalPlayer : Player.LocalPlayer;
                Play.Group group  = player.Groups.First(x => x.Name == sectionDef.Group);

                //In order to make the clients know what the card is (if visibility is set so that they can see it),
                //we have to set the visibility to Nobody, and then after the cards are sent, set the visibility back
                //to what it was. //bug (google) #20
                var gt = new GrpTmp(group, group.Visibility, group.Viewers.ToList());
                if (!gtmps.Contains(gt))
                {
                    gtmps.Add(gt);
                    group.SetVisibility(false, false);
                }
                foreach (IMultiCard element in section.Cards)
                {
                    DataNew.Entities.Card mod = Definition.GetCardById(element.Id);
                    for (int i = 0; i < element.Quantity; i++)
                    { //for every card in the deck, generate a unique key for it, ID for it
                        ulong key = ((ulong)Crypto.PositiveRandom()) << 32 | element.Id.Condense();
                        int   id  = GenerateCardId();
                        ids[j]    = id;
                        keys[j]   = Crypto.ModExp(key);
                        groups[j] = group;
                        var card = new Card(player, id, key, mod, true);
                        cards[j++] = card;
                        group.AddAt(card, group.Count);
                    }

                    // Load images in the background
                    string pictureUri = element.GetPicture();
                    Dispatcher.CurrentDispatcher.BeginInvoke(
                        new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap),
                        DispatcherPriority.ApplicationIdle, pictureUri);
                }
            }
            Program.Client.Rpc.LoadDeck(ids, keys, groups);

            //reset the visibility to what it was before pushing the deck to everybody. //bug (google) #20
            foreach (GrpTmp g in gtmps)
            {
                switch (g.Visibility)
                {
                case GroupVisibility.Everybody:
                    g.Group.SetVisibility(true, false);
                    break;

                case GroupVisibility.Nobody:
                    g.Group.SetVisibility(false, false);
                    break;

                default:
                    foreach (Player p in g.Viewers)
                    {
                        g.Group.AddViewer(p, false);
                    }
                    break;
                }
            }
            gtmps.Clear();
            gtmps.TrimExcess();
        }
Beispiel #8
0
        //Temporarily store group visibility information for LoadDeck. //bug (google) #20

        public void LoadDeck(IDeck deck, bool limited)
        {
            LastLoadedDeck = deck;
            var def    = Program.GameEngine.Definition;
            int nCards = LastLoadedDeck.CardCount();
            var ids    = new int[nCards];
            var keys   = new Guid[nCards];
            var cards  = new Card[nCards];
            var groups = new Play.Group[nCards];
            var sizes  = new string[nCards];
            var gtmps  = new List <GrpTmp>(); //for temp groups visibility
            int j      = 0;

            foreach (ISection section in LastLoadedDeck.Sections)
            {
                DeckSection sectionDef = null;
                sectionDef = section.Shared ? def.SharedDeckSections[section.Name] : def.DeckSections[section.Name];
                if (sectionDef == null)
                {
                    throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file.");
                }
                var        player = section.Shared ? Player.GlobalPlayer : Player.LocalPlayer;
                Play.Group group  = player.Groups.First(x => x.Name == sectionDef.Group);

                //In order to make the clients know what the card is (if visibility is set so that they can see it),
                //we have to set the visibility to Nobody, and then after the cards are sent, set the visibility back
                //to what it was. //bug (google) #20
                var gt = new GrpTmp(group, group.Visibility, group.Viewers.ToList());
                if (!gtmps.Contains(gt))
                {
                    gtmps.Add(gt);
                    group.SetVisibility(false, false);
                }
                foreach (IMultiCard element in section.Cards)
                {
                    //DataNew.Entities.Card mod = Definition.GetCardById(element.Id);
                    for (int i = 0; i < element.Quantity; i++)
                    {
                        //for every card in the deck, generate a unique key for it, ID for it
                        var card = element.ToPlayCard(player);
                        card.SetSleeve(LastLoadedDeck.SleeveId);
                        ids[j]  = card.Id;
                        keys[j] = card.Type.Model.Id;
                        //keys[j] = card.GetEncryptedKey();
                        groups[j]  = group;
                        sizes[j]   = card.Size.Name;
                        cards[j++] = card;
                        group.AddAt(card, group.Count);
                    }

                    // Load images in the background
                    string pictureUri = element.GetPicture();
                    Dispatcher.CurrentDispatcher.BeginInvoke(
                        new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap),
                        DispatcherPriority.Background, pictureUri);
                }
            }
            Program.Client.Rpc.LoadDeck(ids, keys, groups, sizes, SleeveManager.Instance.GetSleeveString(LastLoadedDeck.SleeveId), limited);
            //reset the visibility to what it was before pushing the deck to everybody. //bug (google) #20
            foreach (GrpTmp g in gtmps)
            {
                switch (g.Visibility)
                {
                case GroupVisibility.Everybody:
                    g.Group.SetVisibility(true, false);
                    break;

                case GroupVisibility.Nobody:
                    g.Group.SetVisibility(false, false);
                    break;

                default:
                    foreach (Player p in g.Viewers)
                    {
                        g.Group.AddViewer(p, false);
                    }
                    break;
                }
            }
            gtmps.Clear();
            gtmps.TrimExcess();
        }
Beispiel #9
0
 public DeckSectionItemModel(DeckSection d, IdeCollection <IdeBaseItem> source) : base(source) // load item
 {
     _deckSection = d;
 }