Ejemplo n.º 1
0
        public static void DoDepositAll(Player player)
        {
            //this shouldn't happen if method is called correctly
            if (player.chest == -1)
            {
                return;
            }
            bool sendNetMsg = player.chest > -1;

            if (IHPlayer.ActionLocked(TIH.DepositAll))
            {
                for (int i = R_START; i >= R_END; i--)
                {
                    if (IHPlayer.SlotLocked(i) || player.inventory[i].IsBlank())
                    {
                        continue;
                    }
                    MoveItemToChest(i, sendNetMsg);
                }
                Recipe.FindRecipes(); // !ref:Main:#22640.36#
                return;
            }

            for (int i = R_START; i >= R_END; i--)
            {
                if (!player.inventory[i].IsBlank())
                {
                    MoveItemToChest(i, sendNetMsg);
                }
            }
            Recipe.FindRecipes(); // !ref:Main:#22640.36#
        } //\DoDepositAll()
Ejemplo n.º 2
0
 public override void PostDrawItemSlotBackground(SpriteBatch sb, ItemSlot slot)
 {
     if (IHBase.ModOptions["LockingEnabled"] && slot.type == "Inventory" && IHPlayer.SlotLocked(slot.index))
     {
         sb.Draw(IHBase.LockedIcon,      // the texture to draw
                 slot.pos,               // (Vector2) location in screen coords to draw sprite
                 null,                   // Rectangle to specifies source texels from texture; null draws whole texture
                 Color.Firebrick,        // color to tint sprite; color.white=full color, no tint
                 0f,                     // angle in radians to rotate sprite around its center
                 default(Vector2),       // (Vector2) sprite origin, default=(0,0) i.e. upper left corner
                 slot.scale,             // (Vector2) scale factor
                 SpriteEffects.None,     // effects to apply
                 0f                      // layer depth; 0=front layer, 1=backlayer; SpriteSortMode can sort sprites
                 );
     }
 }
Ejemplo n.º 3
0
        public static void DoQuickStack(Player player)
        {
            if (player.chest == -1)
            {
                return;
            }

            var  inventory   = player.inventory;
            var  container   = player.chestItems;
            bool sendMessage = player.chest > -1;
            var  checkLocks  = IHPlayer.ActionLocked(TIH.QuickStack); //boolean


            for (int iC = 0; iC < Chest.maxItems; iC++)                                         // go through entire chest inventory.
            {                                                                                   //if chest item is not blank && not a full stack, then
                if (!container[iC].IsBlank() && container[iC].stack < container[iC].maxStack)
                {                                                                               //for each item in inventory (including coins, ammo, hotbar),
                    for (int iP = 0; iP < 58; iP++)
                    {
                        if (checkLocks && IHPlayer.SlotLocked(iP))
                        {
                            continue;                                                           // if we're checking locks ignore the locked ones
                        }
                        if (container[iC].IsTheSameAs(inventory[iP]))                           //if chest item matches inv. item...
                        {
                            // RingBell();                                                       //...play "item-moved" sound and...
                            Sound.ItemMoved.Play();
                            // ...merge inv. item stack to chest item stack
                            if (StackMerge(ref inventory[iP], container, iC))
                            {                                                                   // do merge & check return (inv stack empty) status
                                inventory[iP] = new Item();                                     // reset slot if all inv stack moved
                            }
                            else if (container[iC].IsBlank())
                            {                                                                   // else, inv stack not empty after merge, but (because of DoCoins() call),
                                                                                                // chest stack could be.
                                container[iC] = inventory[iP].Clone();                          // move inv item to chest slot
                                inventory[iP] = new Item();                                     // and reset inv slot
                            }
                            // if (sendMessage) SendNetMessage(iC);                             //send net message if regular chest
                        }
                    }
                }
            }
            Recipe.FindRecipes(); // !ref:Main:#22640.36#
        }
Ejemplo n.º 4
0
        /****************************************************
         *   This will compare the categories of items in the player's
         *  inventory to those of items in the open container and
         *  deposit any items of matching categories.
         */
        public static void SmartDeposit()
        {
            if (Main.localPlayer.chest == -1)
            {
                return;
            }

            var pInventory = Main.localPlayer.inventory;  //Item[]
            var chestItems = Main.localPlayer.chestItems; //Item[]
            var sendNetMsg = Main.localPlayer.chest > -1; //bool

            // define a query that creates category groups for the items in the chests,
            // then pulls out the category keys into a distinct list (List<ItemCat>)
            var catList =
                (from item in chestItems
                 where !item.IsBlank()
                 group item by item.GetCategory() into catGroup
                 from cat in catGroup
                 select catGroup.Key).Distinct()     //no duplicates
                .ToList();                           //store the query results

            if (IHBase.ModOptions["LockingEnabled"]) //slot locking on
            {
                for (int i = 49; i >= 10; i--)       // reverse through player inv
                {
                    if (!pInventory[i].IsBlank() && !IHPlayer.SlotLocked(i) &&
                        catList.Contains(pInventory[i].GetCategory()))
                    {
                        IHUtils.MoveItemToChest(i, sendNetMsg);
                    }
                }
            }
            else //no locking
            {
                for (int i = 49; i >= 10; i--)
                {
                    // if chest contains a matching category
                    if (!pInventory[i].IsBlank() && catList.Contains(pInventory[i].GetCategory()))
                    {
                        IHUtils.MoveItemToChest(i, sendNetMsg);
                    }
                }
            }
            Recipe.FindRecipes();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Construct a list containing cloned copies of items in the given
        /// container, skipping blank (and optionally locked) slots.
        /// </summary>
        /// <param name="source_container">The Item[] array of the container</param>
        /// <param name="source_is_chest">Is the source container a chest? </param>
        /// <param name="range">Starting and ending indices defining the subset of the
        /// source's slots to be searched for items.</param>
        /// <returns> The new list of copied items, or null if no items were
        /// applicable to be copied (NOT an empty list!).</returns>
        public static List <Item> GetItemCopies(Item[] source_container, bool source_is_chest, Tuple <int, int> range = null)
        {
            if (range == null)
            {
                range = new Tuple <int, int>(0, source_container.Length - 1);
            }

            // initialize the list that will hold the copied items
            var itemList = new List <Item>();

            int count = 0; //having trouble with empty lists...

            // get copies of viable items from container.
            // will need a different list if locking is enabled
            if (!source_is_chest && IHBase.ModOptions["LockingEnabled"])
            {
                for (int i = range.Item1; i <= range.Item2; i++)
                {
                    if (IHPlayer.SlotLocked(i) || source_container[i].IsBlank())
                    {
                        continue;
                    }

                    itemList.Add(source_container[i].Clone());
                    count++;
                }
            }
            else //only skip blank slots
            {
                for (int i = range.Item1; i <= range.Item2; i++)
                {
                    if (!source_container[i].IsBlank())
                    {
                        itemList.Add(source_container[i].Clone());
                    }
                    count++;
                }
            }
            // return null if no items were copied to new list
            return(count > 0 ? itemList : null);
        }
Ejemplo n.º 6
0
        public static void Sort(Item[] container, bool chest, bool reverse, Tuple <int, int> range = null)
        {
            // if range param not specified, set it to whole container
            if (range == null)
            {
                range = new Tuple <int, int>(0, container.Length - 1);
            }

            // for clarity
            var checkLocks = IHBase.ModOptions["LockingEnabled"]; //boolean

            // get copies of the items and send them off to be sorted
            var sortedItemList = OrganizeItems(GetItemCopies(container, chest, range));

            if (sortedItemList == null)
            {
                return;
            }

            if (reverse)
            {
                sortedItemList.Reverse();          //reverse on user request
            }
            // depending on user settings, decide if we copy items to end or beginning of container
            var fillFromEnd = chest ? IHBase.ModOptions["RearSortChest"] : IHBase.ModOptions["RearSortPlayer"]; //boolean

            // set up the functions that will be used in the iterators ahead
            Func <int, int>  getIndex, getIter;
            Func <int, bool> getCond, getWhileCond;

            if (fillFromEnd)    // use decrementing iterators
            {
                getIndex     = x => range.Item2 - x;
                getIter      = x => x - 1;
                getCond      = x => x >= range.Item1;
                getWhileCond = x => x > range.Item1 && IHPlayer.SlotLocked(x);
            }
            else        // use incrementing iterators
            {
                getIndex     = y => range.Item1 + y;
                getIter      = y => y + 1;
                getCond      = y => y <= range.Item2;
                getWhileCond = y => y < range.Item2 && IHPlayer.SlotLocked(y);
            }

            int filled = 0;           // num of slots filled (or locked) so far

            if (!chest && checkLocks) // player inv with locking enabled
            {
                // copy the sorted items back to the original container
                // (overwriting the current, unsorted contents)
                foreach (var item in sortedItemList)
                {
                    // find the first unlocked slot. this would throw an
                    // exception if range.Item1+filled somehow went over 49, but
                    // if the categorizer and slot-locker are functioning
                    // correctly, that _shouldn't_ be possible. Shouldn't.
                    // Probably.
                    while (IHPlayer.SlotLocked(getIndex(filled)))
                    {
                        filled++;
                    }

                    // now that we've found an unlocked slot, clone
                    // the next sorted item into it.
                    container[getIndex(filled++)] = item.Clone();
                    Sound.ItemMoved.Play();
                }
                // and the rest of the slots should be empty
                for (int i = getIndex(filled); getCond(i); i = getIter(i))
                {
                    // find the first unlocked slot.
                    if (IHPlayer.SlotLocked(i))
                    {
                        continue;
                    }

                    container[i] = new Item();
                }
            }
            else // just run through 'em all
            {
                foreach (var item in sortedItemList)
                {
                    container[getIndex(filled++)] = item.Clone();
                    Sound.ItemMoved.Play();
                }
                // and the rest of the slots should be empty
                for (int i = getIndex(filled); getCond(i); i = getIter(i))
                {
                    container[i] = new Item();
                }
            }
        } // sort()