예제 #1
0
        public List <int> Create(string modelId, int groupId, int quantity)
        {
            var ret = new List <int>();

            Guid modelGuid;

            if (!Guid.TryParse(modelId, out modelGuid))
            {
                return(ret);
            }

            var model = Database.GetCardById(modelGuid);

            if (model == null)
            {
                return(ret);
            }

            var group = Group.Find(groupId);

            if (group == null)
            {
                return(ret);
            }

            _engine.Invoke(
                () =>
            {
                var gt = new Game.GrpTmp(group, group.Visibility, group.Viewers.ToList());
                group.SetVisibility(false, false);


                var ids  = new int[quantity];
                var keys = new ulong[quantity];
                for (int i = 0; i < quantity; ++i)
                {
                    ulong key = (ulong)Crypto.PositiveRandom() << 32 | model.Id.Condense();
                    int id    = Program.Game.GenerateCardId();
                    ids[i]    = id;
                    keys[i]   = Crypto.ModExp(key);
                    ret.Add(id);
                    var card = new Card(Player.LocalPlayer, id, key, Program.Game.Definition.CardDefinition, model, true);
                    group.AddAt(card, group.Count);
                }

                string pictureUri = model.Picture;
                Dispatcher.CurrentDispatcher.BeginInvoke(
                    new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap),
                    DispatcherPriority.ApplicationIdle, pictureUri);

                Program.Client.Rpc.CreateCard(ids, keys, group);

                switch (gt.Visibility)
                {
                case GroupVisibility.Everybody:
                    group.SetVisibility(true, false);
                    break;

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

                default:
                    foreach (Player p in gt.Viewers)
                    {
                        group.AddViewer(p, false);
                    }
                    break;
                }
            });
            return(ret);
            // Comment for a test.
        }
예제 #2
0
        public List<int> Create(string modelId, int groupId, int quantity)
        {
            var ret = new List<int>();

            Guid modelGuid;
            if (!Guid.TryParse(modelId, out modelGuid)) return ret;

            var model = Database.GetCardById(modelGuid);
            if (model == null) return ret;

            var group = Group.Find(groupId);
            if (group == null) return ret;

            _engine.Invoke(
                () =>
                    {
                        var gt = new Game.GrpTmp(group, group.Visibility, group.Viewers.ToList());
                        group.SetVisibility(false, false);

                        var ids = new int[quantity];
                        var keys = new ulong[quantity];
                        for (int i = 0; i < quantity; ++i)
                        {
                            ulong key = (ulong)Crypto.PositiveRandom() << 32 | model.Id.Condense();
                            int id = Program.Game.GenerateCardId();
                            ids[i] = id;
                            keys[i] = Crypto.ModExp(key);
                            ret.Add(id);
                            var card = new Card(Player.LocalPlayer, id, key, Program.Game.Definition.CardDefinition, model, true);
                            group.AddAt(card, group.Count);
                        }

                        string pictureUri = model.GetPicture();
                        Dispatcher.CurrentDispatcher.BeginInvoke(
                            new Func<string, BitmapImage>(ImageUtils.CreateFrozenBitmap),
                            DispatcherPriority.ApplicationIdle, pictureUri);

                        Program.Client.Rpc.CreateCard(ids, keys, group);

                        switch (gt.Visibility)
                        {
                            case GroupVisibility.Everybody:
                                group.SetVisibility(true, false);
                                break;
                            case GroupVisibility.Nobody:
                                group.SetVisibility(false, false);
                                break;
                            default:
                                foreach (Player p in gt.Viewers)
                                {
                                    group.AddViewer(p, false);
                                }
                                break;
                        }
                    });
            return ret;
            // Comment for a test.
        }