Beispiel #1
0
    // This will check if the food item actually exists in the container, before making the trip to it.
    public static ItemValue CheckContents(TileEntityLootContainer tileLootContainer, List <String> lstContents, String strSearchType)
    {
        DisplayLog(" Check Contents of Container: " + tileLootContainer.ToString());
        DisplayLog(" TileEntity: " + tileLootContainer.items.Length);
        ItemValue myItem = null;

        if (tileLootContainer.items != null)
        {
            ItemStack[] array = tileLootContainer.GetItems();
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].IsEmpty())
                {
                    continue;
                }

                DisplayLog(" Not Empty: " + array[i].itemValue.ItemClass.Name);
                // The animals will only eat the food they like best.
                if (lstContents.Contains(array[i].itemValue.ItemClass.Name))
                {
                    if (IsConsumable(array[i].itemValue, strSearchType) != null)
                    {
                        myItem = array[i].itemValue;
                    }
                }
                else if (lstContents.Count == 0)
                {
                    DisplayLog(" No Filtered list. Checking if its edible.");
                    if (IsConsumable(array[i].itemValue, strSearchType) != null)
                    {
                        myItem = array[i].itemValue;
                    }
                }

                if (myItem != null)
                {
                    if (IsConsumable(myItem, strSearchType) != null)
                    {
                        DisplayLog(" My Item is consumable: " + myItem.ItemClass.GetItemName());
                        // if there's only one left, remove the entire item; otherwise, decrease it.
                        if (array[i].count == 1)
                        {
                            tileLootContainer.RemoveItem(array[i].itemValue);
                        }
                        else
                        {
                            array[i].count--;
                        }

                        tileLootContainer.UpdateSlot(i, array[i]);

                        return(myItem);
                    }
                }
            }
        }

        DisplayLog("CheckContents(): No Items found.");
        return(null);
    }
    // Grab a single item from the storage box, and remmove it.
    public ItemValue GetItemFromContainer(TileEntityLootContainer tileLootContainer, List <String> lstContents, String strSearchType)
    {
        ItemValue item = CheckContents(tileLootContainer, lstContents, strSearchType);

        if (item != null)
        {
            DisplayLog("GetItemFromContainer() Searching for item: " + item.ItemClass.Name);
            if (tileLootContainer.items != null)
            {
                ItemStack[] array = tileLootContainer.items;
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i].IsEmpty()) // nothing in the slot
                    {
                        continue;
                    }

                    // The animals will only eat the food they like best.
                    if (array[i].itemValue.ItemClass.Name == item.ItemClass.Name)
                    {
                        DisplayLog(" Found item to remove.");
                        // if there's only one left, remove the entire item; otherwise, decrease it.
                        if (array[i].count == 1)
                        {
                            tileLootContainer.RemoveItem(array[i].itemValue);
                        }
                        else
                        {
                            array[i].count--;
                        }

                        tileLootContainer.UpdateSlot(i, array[i]);
                        return(array[i].itemValue);
                    }

                    // If there's no specific food items specified, then check for all water / food sources that the player can use.
                    if (lstContents.Count == 0)
                    {
                        if (IsConsumable(array[i].itemValue, strSearchType) != null)
                        {
                            return(array[i].itemValue);
                        }
                    }
                }
            }
        }
        return(null);
    }