Ejemplo n.º 1
0
        private void B_Apply_Click(object sender, EventArgs e)
        {
            var type    = (SpawnType)CB_SpawnType.SelectedIndex;
            var arrange = (SpawnArrangement)CB_SpawnArrange.SelectedIndex;
            var x       = (int)NUD_SpawnX.Value;
            var y       = (int)NUD_SpawnY.Value;
            var count   = (int)NUD_SpawnCount.Value;

            IEnumerable <Item> items;
            int sizeX;
            int sizeY;

            if (type == SpawnType.SequentialDIY)
            {
                var min = (ushort)NUD_DIYStart.Value;
                var max = (ushort)NUD_DIYStop.Value;
                var diy = RecipeList.Recipes
                          .Where(z => min <= z.Key && z.Key <= max)
                          .Select(z => z.Key)
                          .Select(z => new Item(Item.DIYRecipe)
                {
                    FreeParam = z
                });

                items = Enumerable.Repeat(diy, count).SelectMany(z => z);
                sizeX = sizeY = 2;
            }
            else
            {
                var item = Editor.ItemProvider.SetItem(new Item());
                items = Enumerable.Repeat(item, count);
                var size = ItemInfo.GetItemSize(item);
                sizeX = size.GetWidth();
                sizeY = size.GetHeight();
            }

            if (sizeX % 2 == 1)
            {
                sizeX++;
            }
            if (sizeY % 2 == 1)
            {
                sizeY++;
            }

            var ctr = SpawnItems(Editor.SpawnLayer, items.ToArray(), x, y, arrange, sizeX, sizeY, true);

            if (ctr == 0)
            {
                WinFormsUtil.Alert(MessageStrings.MsgFieldItemModifyNone);
                return;
            }
            Editor.ReloadItems();
            WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemModifyCount, count));
        }
Ejemplo n.º 2
0
        private void B_Apply_Click(object sender, EventArgs e)
        {
            var type    = (SpawnType)CB_SpawnType.SelectedIndex;
            var arrange = (SpawnArrangement)CB_SpawnArrange.SelectedIndex;
            var x       = (int)NUD_SpawnX.Value;
            var y       = (int)NUD_SpawnY.Value;
            var count   = (int)NUD_SpawnCount.Value;

            IReadOnlyList <Item> items;
            int sizeX;
            int sizeY;

            if (type == SpawnType.SequentialDIY)
            {
                var min = (ushort)NUD_DIYStart.Value;
                var max = (ushort)NUD_DIYStop.Value;
                var diy = RecipeList.Recipes
                          .Where(z => min <= z.Key && z.Key <= max)
                          .Select(z => z.Key)
                          .Select(z => new Item(Item.DIYRecipe)
                {
                    FreeParam = z
                });

                items = Enumerable.Repeat(diy, count).SelectMany(z => z).ToArray();
                sizeX = sizeY = 2;
            }
            else if (type == SpawnType.ItemsFromNHI)
            {
                if (string.IsNullOrEmpty(NHIFilePath) || !File.Exists(NHIFilePath))
                {
                    WinFormsUtil.Alert(MessageStrings.MsgFieldItemNoNHI);
                    return;
                }

                // read non-empty slots into item array
                var data  = File.ReadAllBytes(this.NHIFilePath);
                var array = data.GetArray <Item>(Item.SIZE).Where(item => !item.IsNone);
                items = Enumerable.Repeat(array, count).SelectMany(z => z).ToArray();

                // set flag0 = 0x20 for each item to ensure it gets dropped
                // this also forces a 2x2 item size
                foreach (Item item in items)
                {
                    item.SystemParam = 0x20;
                }

                sizeX = sizeY = 2;
            }
            else
            {
                var item = Editor.ItemProvider.SetItem(new Item());
                items = Enumerable.Repeat(item, count).ToArray();
                var size = ItemInfo.GetItemSize(item);
                sizeX = size.GetWidth();
                sizeY = size.GetHeight();
            }

            if (sizeX % 2 == 1)
            {
                sizeX++;
            }
            if (sizeY % 2 == 1)
            {
                sizeY++;
            }

            var ctr = SpawnItems(Editor.SpawnLayer, items, x, y, arrange, sizeX, sizeY, true);

            if (ctr == 0)
            {
                WinFormsUtil.Alert(MessageStrings.MsgFieldItemModifyNone);
                return;
            }
            Editor.ReloadItems();
            WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemModifyCount, count));
        }