Exemplo n.º 1
0
        public override bool ShiftClickSlot(Item[] inventory, int context, int slot)
        {
            if ((context != ItemSlot.Context.InventoryItem && context != ItemSlot.Context.InventoryCoin && context != ItemSlot.Context.InventoryAmmo) || slot == 58)
            {
                return(false);
            }
            if (GenericBagUI.visible)
            {
                GenericHoldingBag bag = GenericBagUI.openBag;
                if (bag != null)
                {
                    Item selected = inventory[slot];
                    int  oldStack = selected.stack;
                    bag.addItem(selected);

                    if (selected.stack <= 0)
                    {
                        inventory[slot] = new Item();
                    }
                    if (oldStack != selected.stack)
                    {
                        GenericBagUI.buildItem();
                    }
                    return(true);
                }
            }
            return(base.ShiftClickSlot(inventory, context, slot));
        }
Exemplo n.º 2
0
        private bool withdrawItem(Item itm, ref bool rebuild)
        {
            /*if(itm.type > 70 && itm.type < 75){
             *                  long money = mergeAllCoins();
             *                  for(int i = 0; i < 50; i++){
             *
             *                  }
             *          }*/
            string itmTag = GenericHoldingBag.ItemToTag(itm);

            int  total = (int)Math.Min(openBag.items.GetAsLong(itmTag), itm.maxStack);
            Item t     = itm.Clone();

            t.stack = total;

            t      = player.GetItem(player.whoAmI, t, false, true);
            total -= t.stack;

            long l = openBag.items.GetAsLong(itmTag) - total;

            openBag.items.Remove(itmTag);
            if (l > 0)
            {
                openBag.items[itmTag] = l;
            }
            else
            {
                openBag.items[itmTag] = 0L;
                itm.SetDefaults(0);
                rebuild = true;
            }

            return(true);
        }
Exemplo n.º 3
0
        public static void buildItem()
        {
            presentItem.Clear();
            presentItemItem.Clear();

            if (openBag.order == null || openBag.order.Count <= 0)
            {
                return;
            }
            for (int i = 0; i < openBag.order.Count; i++)
            {
                string key = openBag.order[i];
                if (openBag.items.ContainsKey(key) && openBag.items.GetAsLong(key) > 0L)
                {
                    Item itm = GenericHoldingBag.getItemFromTag(key);
                    if (itm.type != 0)
                    {
                        presentItem.Add(key);
                        presentItemItem.Add(itm);
                    }
                    else
                    {
                        openBag.items.Remove(key);
                    }
                }
            }
        }
Exemplo n.º 4
0
 public void close(bool silent)
 {
     visible = false;
     openBag = null;
     useSlot = -1;
     if (!silent)
     {
         Main.PlaySound(Terraria.ID.SoundID.MenuClose);
     }
 }
Exemplo n.º 5
0
        public void open(Player p, GenericHoldingBag bag, bool silent)
        {
            visible = true;
            player  = p;
            Main.playerInventory = true;
            Main.recBigList      = false;

            if (player.chest != -1)
            {
                player.chest = -1;
            }

            openBag = bag;
            useSlot = player.selectedItem;

            buildItem();
            if (!silent)
            {
                Main.PlaySound(Terraria.ID.SoundID.MenuOpen);
            }
        }
Exemplo n.º 6
0
        public void sendBagOrder(int player, GenericHoldingBag bg)
        {
            ModPacket pk = GetPacket();

            pk.Write((byte)5);
            pk.Write((byte)bg.bagID);
            pk.Send(player);
            for (int i = 0; i < bg.order.Count; i++)
            {
                pk = GetPacket();
                pk.Write((byte)6);
                pk.Write((byte)bg.bagID);
                pk.Write(bg.order[i]);
                pk.Send(player);
            }
            for (int i = 0; i < bg.preventPickup.Count; i++)
            {
                pk = GetPacket();
                pk.Write((byte)7);
                pk.Write((byte)bg.bagID);
                pk.Write(bg.preventPickup[i]);
                pk.Send(player);
            }
        }
Exemplo n.º 7
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            int type = reader.ReadByte();

            if (type == 1)
            {
                int         playerID    = reader.ReadByte();
                int         slot        = reader.ReadByte();
                int         chest       = reader.ReadInt32();
                int         x           = reader.ReadInt32();
                int         y           = reader.ReadInt32();
                TagCompound bagContents = TagIO.Read(reader);
                if (Main.netMode == NetmodeID.Server)
                {
                    GenericHoldingBag bag = Main.player[playerID].inventory[slot].modItem as GenericHoldingBag;
                    if (bag == null)
                    {
                        bag = new TrueOmniBag();
                    }

                    bag.items = bagContents;
                    if (chest > -1)
                    {
                        int trueChest = GenericHoldingBag.getChestAtTarget(x, y);
                        if (Main.chest[trueChest] != null && !GenericHoldingBag.IsPlayerInChest(trueChest) && !Chest.isLocked(Main.chest[trueChest].x, Main.chest[trueChest].y))
                        {
                            bag.emptyBagOnInventory(Main.player[playerID], Main.chest[trueChest].item, trueChest);
                        }
                    }
                    else
                    {
                        bag.emptyBagOnMagicStorage(Main.player[playerID], x, y);
                    }

                    bagContents = bag.items;
                }
                ModPacket p = GetPacket();
                p.Write((byte)2);
                p.Write((byte)playerID);
                p.Write((byte)slot);
                TagIO.Write(bagContents, p);
                p.Send(playerID);
                return;
            }

            if (type == 2)
            {
                int               playerID    = reader.ReadByte();
                int               slot        = reader.ReadByte();
                TagCompound       bagContents = TagIO.Read(reader);
                GenericHoldingBag bag         = Main.player[playerID].inventory[slot].modItem as GenericHoldingBag;
                if (bag != null)
                {
                    bag.items.Clear();
                    foreach (KeyValuePair <string, object> k in bagContents)
                    {
                        bag.items.Add(k);
                    }
                }
            }

            if (type == 3)
            {
                if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    int       flags = reader.ReadByte();
                    BagPlayer pl    = Main.player[Main.myPlayer].GetModPlayer <BagPlayer>();
                    pl.checkAccessories = (flags & 1) == 1;
                    pl.checkVanity      = (flags & 2) == 2;
                    pl.checkHotbar      = (flags & 4) == 4;
                    pl.checkInventory   = (flags & 8) == 1;
                    pl.tryPlace         = (flags & 16) == 1;
                }
            }

            /*
             * if(type == 4) // check Order lists with server
             * {
             *  if (Main.netMode == NetmodeID.Server) {
             *      int player = reader.ReadByte();
             *
             *      ulong dirtBagHash = reader.ReadUInt64();
             *      ulong oreBagHash = reader.ReadUInt64();
             *      ulong gemBagHash = reader.ReadUInt64();
             *
             *      GenericHoldingBag bg = new DirtBag();
             *      bool anyBag = false;
             *      if (dirtBagHash != bg.getOrderHashCode())
             *      {
             *          sendBagOrder(player, bg);
             *          anyBag = true;
             *      }
             *      bg = new OreBag();
             *      if(oreBagHash != bg.getOrderHashCode())
             *      {
             *          sendBagOrder(player, bg);
             *          anyBag = true;
             *      }
             *      bg = new GemBag();
             *      if (gemBagHash != bg.getOrderHashCode())
             *      {
             *          sendBagOrder(player, bg);
             *          anyBag = true;
             *      }
             *
             *      if (anyBag)
             *      {
             *          ModPacket pk = GetPacket();
             *          pk.Write((byte)5);
             *          pk.Write((byte)new OmniBag().bagID);
             *          pk.Send(player);
             *      }
             *
             *  }
             *
             *
             *
             * }
             *
             * if(type == 5) // Clear order and not pickup list for this bag
             * {
             *  if(Main.netMode == NetmodeID.MultiplayerClient)
             *  {
             *      GenericHoldingBag bg = getBagFromID(reader.ReadByte());
             *      bg.order.Clear();
             *      bg.preventPickup.Clear();
             *  }
             * }
             * if(type == 6) // add String to order list;
             * {
             *
             * }
             * if(type == 7) // add String to not pickup
             * {
             *
             * }
             */
        }
Exemplo n.º 8
0
 private void resetBagConfig(GenericHoldingBag bg)
 {
     bg.config.Put("order", new String[0]);
     bg.config.Save();
 }
Exemplo n.º 9
0
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            if (args.Length != 1)
            {
                BagsOfHoldingMod.sendChat("Use with \"reloadOrder\" with a held bag to reload its order, \"reloadOmnibag\" to reload omnibag's content list and \"remakeBags\" to remake all bag orders into the configs.");
                return;
            }
            if ((args[0].Equals("reloadOrder") || args[0].Equals("\"reloadOrder\"")) && caller.Player.HeldItem.modItem != null && caller.Player.HeldItem.modItem is GenericHoldingBag)
            {
                GenericHoldingBag bag = caller.Player.HeldItem.modItem as GenericHoldingBag;
                bag.setupItemList();
                BagsOfHoldingMod.sendChat("Reloaded bag order");
                return;
            }
            if (args[0].Equals("reloadOmnibag") || args[0].Equals("\"reloadOmnibag\""))
            {
                TrueOmniBag.contents2 = null;
                BagPlayer.reloadOmnibag();
                BagsOfHoldingMod.sendChat("Recreated Omnibag order.");
                return;
            }

            if (args[0].Equals("remakeBags") || args[0].Equals("\"remakeBags\""))
            {
                GenericHoldingBag bg = new BaitBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new ChunkBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new CoinBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new CrateBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new DirtBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new DyeMaterialBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new FishBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new GemBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new MushroomBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new OreBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new PlantBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new WoodBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();

                FishingBag.resetContents();
                NatureBag.resetContents();
                OmniBag.resetContents();

                BagsOfHoldingMod.sendChat("Reset all bag orders to the original order list.");
            }
        }
Exemplo n.º 10
0
        private void ItemSlotHandle(Item itm, ref bool rebuild)
        {
            string itmTag = GenericHoldingBag.ItemToTag(itm);

            if (Main.mouseLeftRelease && Main.mouseLeft)
            {
                if (Main.mouseItem != null && Main.mouseItem.type != 0)
                {
                    Item t = Main.mouseItem;
                    openBag.addItem(t);
                    if (t.stack == 0)
                    {
                        Main.mouseItem = new Item();
                    }
                    rebuild = true;
                }
                else
                {
                    if (itm != null && itm.type != 0 && openBag.items.ContainsKey(itmTag))
                    {
                        if (ItemSlot.ShiftInUse)
                        {
                            if (withdrawItem(itm, ref rebuild))
                            {
                                Recipe.FindRecipes();
                            }
                        }
                        else
                        {
                            int total = (int)Math.Min((long)(openBag.items[itmTag]), itm.maxStack);
                            Main.mouseItem       = itm.Clone();
                            Main.mouseItem.stack = total;

                            long l = (long)(openBag.items[itmTag]) - total;

                            openBag.items.Remove(itmTag);
                            if (l > 0)
                            {
                                openBag.items[itmTag] = l;
                            }
                            else
                            {
                                openBag.items[itmTag] = 0L;
                                itm.SetDefaults(0);
                                rebuild = true;
                            }
                        }
                    }
                }
            }
            else if (Main.stackSplit <= 1 && Main.mouseRight && (itm != null && itm.type != 0 && openBag.items.ContainsKey(itmTag)))
            {
                if (itm.maxStack >= 1 && (Main.mouseItem.IsTheSameAs(itm) || Main.mouseItem.type == 0) && (Main.mouseItem.stack < Main.mouseItem.maxStack || Main.mouseItem.type == 0))
                {
                    if (Main.mouseItem.type == 0)
                    {
                        Main.mouseItem       = itm.Clone();
                        Main.mouseItem.stack = 0;
                    }
                    Main.mouseItem.stack++;


                    long l = (long)(openBag.items[itmTag]) - 1;

                    openBag.items.Remove(itmTag);
                    if (l > 0)
                    {
                        openBag.items[itmTag] = l;
                    }
                    else
                    {
                        openBag.items[itmTag] = 0L;
                        itm.SetDefaults(0);
                        rebuild = true;
                    }
                    Recipe.FindRecipes();
                    Main.soundInstanceMenuTick.Stop();
                    Main.soundInstanceMenuTick = Main.soundMenuTick.CreateInstance();
                    Main.PlaySound(12, -1, -1, 1, 1f, 0f);
                    if (Main.stackSplit == 0)
                    {
                        Main.stackSplit = 15;
                    }
                    else
                    {
                        Main.stackSplit = Main.stackDelay;
                    }
                }
            }



            if (itm != null && itm.type != 0 && openBag.items.ContainsKey(itmTag))
            {
                Main.hoverItemName = itm.HoverName;
                object hoverItemName = Main.hoverItemName;
                Main.hoverItemName = string.Concat(new object[]
                {
                    hoverItemName,
                    " (",
                    "" + (openBag.items[itmTag]) + " left in the bag",
                    ")"
                });
            }
            else
            {
            }
        }