コード例 #1
0
        public void DuplicateSelectedSlot()
        {
            if (this.SelectedSlot == null)
            {
                return;
            }

            var copy = (IBackpackSlot)this.SelectedSlot.BackpackSlot.Clone();

            copy.UniqueId = new Random().Next(int.MinValue, int.MaxValue);
            // TODO: check other item unique IDs to prevent rare collisions

            if (copy is BackpackWeapon weapon)
            {
                weapon.QuickSlot = QuickWeaponSlot.None;
                weapon.Mark      = PlayerMark.Standard;

                var viewModel = new BackpackWeaponViewModel(weapon);
                this.Slots.Add(viewModel);
                this.SelectedSlot = viewModel;
            }
            else if (copy is BackpackItem item)
            {
                item.Equipped = false;
                item.Mark     = PlayerMark.Standard;

                var viewModel = new BackpackItemViewModel(item);
                this.Slots.Add(viewModel);
                this.SelectedSlot = viewModel;
            }
            else
            {
                throw new NotSupportedException();
            }
        }
コード例 #2
0
        public void NewItem()
        {
            var item = new BackpackItem()
            {
                UniqueId = new Random().Next(int.MinValue, int.MaxValue),
                // TODO: check other item unique IDs to prevent rare collisions
                AssetLibrarySetId = 0,
            };
            var viewModel = new BackpackItemViewModel(item);

            this.Slots.Add(viewModel);
            this.SelectedSlot = viewModel;
        }
コード例 #3
0
        public void ImportData(WillowTwoPlayerSaveGame saveGame)
        {
            this.Slots.Clear();

            foreach (var packedWeapon in saveGame.PackedWeaponData)
            {
                var weapon = (BackpackWeapon)BackpackDataHelper.Decode(packedWeapon.Data);
                var test   = BackpackDataHelper.Encode(weapon);
                if (packedWeapon.Data.SequenceEqual(test) == false)
                {
                    throw new FormatException("backpack weapon reencode mismatch");
                }

                weapon.QuickSlot = packedWeapon.QuickSlot;
                weapon.Mark      = packedWeapon.Mark;

                var viewModel = new BackpackWeaponViewModel(weapon);
                this.Slots.Add(viewModel);
            }

            foreach (var packedItem in saveGame.PackedItemData)
            {
                var item = (BackpackItem)BackpackDataHelper.Decode(packedItem.Data);
                var test = BackpackDataHelper.Encode(item);
                if (packedItem.Data.SequenceEqual(test) == false)
                {
                    throw new FormatException("backpack item reencode mismatch");
                }

                item.Quantity = packedItem.Quantity;
                item.Equipped = packedItem.Equipped;
                item.Mark     = packedItem.Mark;

                var viewModel = new BackpackItemViewModel(item);
                this.Slots.Add(viewModel);
            }
        }
コード例 #4
0
        public void ImportData(WillowTwoPlayerSaveGame saveGame, Platform platform)
        {
            this.Slots.Clear();

            this._BrokenWeapons.Clear();
            foreach (var packedWeapon in saveGame.PackedWeaponData)
            {
                BackpackWeapon weapon;
                try
                {
                    weapon = (BackpackWeapon)BackpackDataHelper.Decode(packedWeapon.InventorySerialNumber, platform);
                }
                catch (Exception e)
                {
                    this._BrokenWeapons.Add(new KeyValuePair <PackedWeaponData, Exception>(packedWeapon, e));
                    continue;
                }

                var test = BackpackDataHelper.Encode(weapon, platform);
                if (packedWeapon.InventorySerialNumber.SequenceEqual(test) == false)
                {
                    throw new FormatException("backpack weapon reencode mismatch");
                }

                weapon.QuickSlot = packedWeapon.QuickSlot;
                weapon.Mark      = packedWeapon.Mark;

                var viewModel = new BackpackWeaponViewModel(weapon);
                this.Slots.Add(viewModel);
            }

            this._ExpansionItems.Clear();
            this._BrokenItems.Clear();
            foreach (var packedItem in saveGame.PackedItemData)
            {
                if (packedItem.Quantity < 0)
                {
                    this._ExpansionItems.Add(packedItem);
                    continue;
                }

                BackpackItem item;
                try
                {
                    item = (BackpackItem)BackpackDataHelper.Decode(packedItem.InventorySerialNumber, platform);
                }
                catch (Exception e)
                {
                    this._BrokenItems.Add(new KeyValuePair <PackedItemData, Exception>(packedItem, e));
                    continue;
                }

                var test = BackpackDataHelper.Encode(item, platform);
                if (packedItem.InventorySerialNumber.SequenceEqual(test) == false)
                {
                    throw new FormatException("backpack item reencode mismatch");
                }

                item.Quantity = packedItem.Quantity;
                item.Equipped = packedItem.Equipped;
                item.Mark     = (PlayerMark)packedItem.Mark;

                // required since protobuf is no longer doing the validation for us
                if (item.Mark != PlayerMark.Trash &&
                    item.Mark != PlayerMark.Standard &&
                    item.Mark != PlayerMark.Favorite)
                {
                    throw new FormatException("invalid PlayerMark value");
                }

                var viewModel = new BackpackItemViewModel(item);
                this.Slots.Add(viewModel);
            }
        }
コード例 #5
0
        public IEnumerable <IResult> PasteCode()
        {
            bool containsUnicodeText = false;

            if (MyClipboard.ContainsText(TextDataFormat.Text, out var containsText) != MyClipboard.Result.Success ||
                MyClipboard.ContainsText(TextDataFormat.UnicodeText, out containsUnicodeText) !=
                MyClipboard.Result.Success)
            {
                yield return(new MyMessageBox("Clipboard failure.", "Error")
                             .WithIcon(MessageBoxImage.Error));
            }

            if (containsText == false &&
                containsUnicodeText == false)
            {
                yield break;
            }

            var errors     = 0;
            var viewModels = new List <IBackpackSlotViewModel>();

            yield return(new DelegateResult(
                             () =>
            {
                if (MyClipboard.GetText(out var codes) != MyClipboard.Result.Success)
                {
                    MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // strip whitespace
                codes = Regex.Replace(codes, @"\s+", "");

                foreach (var match in _CodeSignature.Matches(codes).Cast <Match>()
                         .Where(m => m.Success == true))
                {
                    var code = match.Groups["data"].Value;

                    IPackableSlot packable;

                    try
                    {
                        var data = Convert.FromBase64String(code);
                        packable = BackpackDataHelper.Decode(data, Platform.PC);
                    }
                    catch (Exception)
                    {
                        errors++;
                        continue;
                    }

                    // TODO: check other item unique IDs to prevent rare collisions
                    packable.UniqueId = new Random().Next(int.MinValue, int.MaxValue);

                    if (packable is BackpackWeapon weapon)
                    {
                        weapon.QuickSlot = QuickWeaponSlot.None;
                        weapon.Mark = PlayerMark.Standard;
                        var viewModel = new BackpackWeaponViewModel(weapon);
                        viewModels.Add(viewModel);
                    }
                    else if (packable is BackpackItem item)
                    {
                        item.Quantity = 1;
                        item.Equipped = false;
                        item.Mark = PlayerMark.Standard;
                        var viewModel = new BackpackItemViewModel(item);
                        viewModels.Add(viewModel);
                    }
                }
            }));

            if (viewModels.Count > 0)
            {
                viewModels.ForEach(vm => this.Slots.Add(vm));
                this.SelectedSlot = viewModels.First();
            }

            if (errors > 0)
            {
                yield return(new MyMessageBox($"Failed to load {errors} codes.", "Warning")
                             .WithIcon(MessageBoxImage.Warning));
            }
            else if (viewModels.Count == 0)
            {
                yield return(new MyMessageBox("Did not find any codes in clipboard.", "Warning")
                             .WithIcon(MessageBoxImage.Warning));
            }
        }
コード例 #6
0
 public void NewItem()
 {
     var item = new BackpackItem()
     {
         UniqueId = new Random().Next(int.MinValue, int.MaxValue),
         // TODO: check other item unique IDs to prevent rare collisions
         AssetLibrarySetId = 0,
     };
     var viewModel = new BackpackItemViewModel(item);
     this.Slots.Add(viewModel);
     this.SelectedSlot = viewModel;
 }
コード例 #7
0
        public void ImportData(WillowTwoPlayerSaveGame saveGame)
        {
            this.Slots.Clear();

            foreach (var packedWeapon in saveGame.PackedWeaponData)
            {
                var weapon = (BackpackWeapon)BackpackDataHelper.Decode(packedWeapon.Data);
                var test = BackpackDataHelper.Encode(weapon);
                if (packedWeapon.Data.SequenceEqual(test) == false)
                {
                    throw new FormatException("backpack weapon reencode mismatch");
                }

                weapon.QuickSlot = packedWeapon.QuickSlot;
                weapon.Mark = packedWeapon.Mark;

                var viewModel = new BackpackWeaponViewModel(weapon);
                this.Slots.Add(viewModel);
            }

            foreach (var packedItem in saveGame.PackedItemData)
            {
                var item = (BackpackItem)BackpackDataHelper.Decode(packedItem.Data);
                var test = BackpackDataHelper.Encode(item);
                if (packedItem.Data.SequenceEqual(test) == false)
                {
                    throw new FormatException("backpack item reencode mismatch");
                }

                item.Quantity = packedItem.Quantity;
                item.Equipped = packedItem.Equipped;
                item.Mark = packedItem.Mark;

                var viewModel = new BackpackItemViewModel(item);
                this.Slots.Add(viewModel);
            }
        }
コード例 #8
0
        public void DuplicateSelectedSlot()
        {
            if (this.SelectedSlot == null)
            {
                return;
            }

            var copy = (IBackpackSlot)this.SelectedSlot.BackpackSlot.Clone();
            copy.UniqueId = new Random().Next(int.MinValue, int.MaxValue);
            // TODO: check other item unique IDs to prevent rare collisions

            if (copy is BackpackWeapon)
            {
                var weapon = (BackpackWeapon)copy;
                weapon.QuickSlot = QuickWeaponSlot.None;
                weapon.Mark = PlayerMark.Standard;

                var viewModel = new BackpackWeaponViewModel(weapon);
                this.Slots.Add(viewModel);
                this.SelectedSlot = viewModel;
            }
            else if (copy is BackpackItem)
            {
                var item = (BackpackItem)copy;
                item.Equipped = false;
                item.Mark = PlayerMark.Standard;

                var viewModel = new BackpackItemViewModel(item);
                this.Slots.Add(viewModel);
                this.SelectedSlot = viewModel;
            }
            else
            {
                throw new NotSupportedException();
            }
        }
コード例 #9
0
        public IEnumerable<IResult> PasteCode()
        {
            bool containsText;
            bool containsUnicodeText = false;
            if (MyClipboard.ContainsText(TextDataFormat.Text, out containsText) != MyClipboard.Result.Success ||
                MyClipboard.ContainsText(TextDataFormat.UnicodeText, out containsUnicodeText) !=
                MyClipboard.Result.Success)
            {
                yield return new MyMessageBox("Clipboard failure.", "Error")
                    .WithIcon(MessageBoxImage.Error);
            }

            if (containsText == false &&
                containsUnicodeText == false)
            {
                yield break;
            }

            var errors = 0;
            var viewModels = new List<IBackpackSlotViewModel>();
            yield return new DelegateResult(() =>
            {
                string codes;
                if (MyClipboard.GetText(out codes) != MyClipboard.Result.Success)
                {
                    MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // strip whitespace
                codes = Regex.Replace(codes, @"\s+", "");

                foreach (var match in _CodeSignature.Matches(codes).Cast<Match>()
                    .Where(m => m.Success == true))
                {
                    var code = match.Groups["data"].Value;

                    IPackable packable;

                    try
                    {
                        var data = Convert.FromBase64String(code);
                        packable = BackpackDataHelper.Decode(data);
                    }
                    catch (Exception)
                    {
                        errors++;
                        continue;
                    }

                    // TODO: check other item unique IDs to prevent rare collisions
                    packable.UniqueId = new Random().Next(int.MinValue, int.MaxValue);

                    if (packable is BackpackWeapon)
                    {
                        var weapon = (BackpackWeapon)packable;
                        weapon.QuickSlot = QuickWeaponSlot.None;
                        weapon.Mark = PlayerMark.Standard;
                        var viewModel = new BackpackWeaponViewModel(weapon);
                        viewModels.Add(viewModel);
                    }
                    else if (packable is BackpackItem)
                    {
                        var item = (BackpackItem)packable;
                        item.Quantity = 1;
                        item.Equipped = false;
                        item.Mark = PlayerMark.Standard;
                        var viewModel = new BackpackItemViewModel(item);
                        viewModels.Add(viewModel);
                    }
                }
            });

            if (viewModels.Count > 0)
            {
                viewModels.ForEach(vm => this.Slots.Add(vm));
                this.SelectedSlot = viewModels.First();
            }

            if (errors > 0)
            {
                yield return
                    new MyMessageBox("Failed to load " + errors.ToString(CultureInfo.InvariantCulture) + " codes.",
                                     "Warning")
                        .WithIcon(MessageBoxImage.Warning);
            }
            else if (viewModels.Count == 0)
            {
                yield return
                    new MyMessageBox("Did not find any codes in clipboard.",
                                     "Warning")
                        .WithIcon(MessageBoxImage.Warning);
            }
        }