Exemplo n.º 1
0
        public static StackableItem CanItemBeStacked(CustomItem item, ServerInventory.InventSlotItem inventoryItem)
        {
            // return false if not the same item
            if (item.GroundItem.Path != inventoryItem.Item.Path)
            {
                return(StackableItem.Cannot);
            }

            // return false if the items dont have the Stack component
            // probably only need to do it on one item but for smoll brain reasons...here we go
            if (!item.GroundItem.HasComponent <Stack>() || !inventoryItem.Item.HasComponent <Stack>())
            {
                return(StackableItem.Cannot);
            }

            var itemStackComp          = item.GroundItem.GetComponent <Stack>();
            var inventoryItemStackComp = inventoryItem.Item.GetComponent <Stack>();

            if (inventoryItemStackComp.Size == inventoryItemStackComp.Info.MaxStackSize)
            {
                return(StackableItem.Cannot);
            }

            return(StackableItem.Can);
        }
Exemplo n.º 2
0
        private IEnumerator PopAStack(ServerInventory.InventSlotItem item)
        {
            //DebugWindow.LogError("Test in PopAStack", 5);
            var invSlot        = item.InventoryPosition; //initial invslot
            var openSlotPos    = Point.Zero;
            var stacksize      = item.Item.GetComponent <Stack>()?.Size ?? 0;
            var slotRectCenter = item.GetClientRect().Center;
            var cursorInv      = GameController.Game.IngameState.ServerData.PlayerInventories[12].Inventory;
            int latency        = (int)GameController.IngameState.ServerData.Latency;
            int maxWaitTime    = Settings.MaxWatitTime.Value;

            while (stacksize > 0)
            {
                //check profile requirements
                if (!Settings.DropToGround && !Settings.DropToDivTab && !_InventoryLayout.GetNextOpenSlot(ref openSlotPos))
                {
                    DebugWindow.LogError(
                        "UnstackDecks => Inventory doesn't have space to place the next div card.");
                    StopCoroutine(Name);
                    yield break;
                }
                else if (!areRequirementsMet())
                {
                    LogError("Requirements not met!");
                    StopCoroutine(Name);
                    yield break;
                }
                //click the stackdeck stack
                yield return(Input.SetCursorPositionAndClick(slotRectCenter, Settings.ReverseMouseButtons ? MouseButtons.Left : MouseButtons.Right, Settings.TimeBetweenClicks));

                //check if MouseInventory contains an item and waits for it
                yield return(new WaitFunctionTimed(() => cursorInv.CountItems > 0, true, maxWaitTime));

                if (cursorInv.TotalItemsCounts == 0)
                {
                    //LogError("Cursorinventory not filled");
                    //StopCoroutine();
                    yield break;
                }

                //click at the dropoff location
                yield return(Input.SetCursorPositionAndClick(chooseDestination(openSlotPos), Settings.ReverseMouseButtons ? MouseButtons.Right : MouseButtons.Left, Settings.TimeBetweenClicks));

                //wait for item on cursor to be dropped off
                yield return(new WaitFunctionTimed(() => cursorInv.CountItems == 0, true, maxWaitTime));

                if (cursorInv.TotalItemsCounts != 0)
                {
                    //LogError("Cursorinventory not empty");
                    //StopCoroutine();
                    yield break;
                }
                if (!Settings.DropToGround && !Settings.DropToDivTab)
                {
                    yield return(MarkSlotUsed(openSlotPos));
                }
                //update item and the stacksize more safely
                //find the item by invslot
                item = GameController.IngameState.ServerData.PlayerInventories[0].Inventory.InventorySlotItems.ToList().Find(x => x.InventoryPosition == invSlot); //the item object is rebuilt completely by the game after removing a card from the stack
                yield return(new WaitFunctionTimed(() => item.Item.HasComponent <Stack>(), true, maxWaitTime));                                                    //the game doesnt seem to like it when you unstack too fast and gives ingame chat error messages. The caching of the stacksize and simply decrementing brought other problems

                if (!item.Item.HasComponent <Stack>())
                {
                    //LogError("No Stack component of current item found");
                    //StopCoroutine();
                    yield break;
                }
                stacksize = item.Item.GetComponent <Stack>().Size;
            }
        }