示例#1
0
    // An item that we'll try taking, and a flag whether we should actually take it or not (we could just be checking if we have space)
    public bool AttemptGiveItem(ItemBase item, int amount = 1, bool actuallyTakeItem = true)
    {
        VicisMod.log(getPrefix(), "Attempting to receive " + amount + " item " + item.GetDisplayString() + " with id = " + item.mnItemID + " and type = " + item.mType);
        // Can we even take this item(s)?
        if (getNumItems() + amount > maxItems)
        {
            return(false);
        }
        for (int i = 0; i < items.Count; ++i)
        {
            if (ItemBaseUtil.compareCubeStack(items[i] as ItemCubeStack, item as ItemCubeStack))
            {
                ItemCubeStack a         = items[i] as ItemCubeStack;
                int           amntTaken = Math.Min(amount, a.mnAmount);
                if (a != null && a.mnAmount < maxBinSize)
                {
                    if (actuallyTakeItem)
                    {
                        a.mnAmount += amount;
                    }
                    MarkDirtyDelayed();
                    return(true);
                }
            }
            else if (ItemBaseUtil.compareStack(items[i] as ItemStack, item as ItemStack))
            {
                ItemStack a = items[i] as ItemStack;
                if (a != null && a.mnAmount < maxBinSize)
                {
                    if (actuallyTakeItem)
                    {
                        a.mnAmount += amount;
                    }
                    MarkDirtyDelayed();
                    return(true);
                }
            }
        }

        if (items.Count < maxBins)
        {
            if (actuallyTakeItem)
            {
                items.Add(item);
            }
            MarkDirtyDelayed();
            return(true);
        }

        VicisMod.log(getPrefix(), "Did not accept item " + item.GetDisplayString());
        return(false);
    }
示例#2
0
    // An item that we're going to give, or check that we can give
    public ItemBase AttemptTakeItem(ItemBase item, int amount = 1, bool actuallyGiveItem = true)
    {
        VicisMod.log(getPrefix(), "Attempting to give " + amount + " item " + item.GetDisplayString() + " with id = " + item.mnItemID + " and type = " + item.mType);
        if (getNumItems() == 0)
        {
            return(null);
        }
        for (int i = 0; i < items.Count; ++i)
        {
            if (ItemBaseUtil.compareCubeStack(items[i] as ItemCubeStack, item as ItemCubeStack))
            {
                ItemCubeStack a = items[i] as ItemCubeStack;
                VicisMod.log(getPrefix(), "Found a CubeStack " + a.GetDisplayString() + ", which is storing " + a.mnAmount + " blocks");
                if (a != null)
                {
                    int           amntTaken = Math.Min(amount, a.mnAmount);
                    ItemCubeStack ret       = new ItemCubeStack(a.mCubeType, a.mCubeValue, amntTaken);
                    if (actuallyGiveItem)
                    {
                        VicisMod.log(getPrefix(), "Taking away");
                        a.mnAmount -= amntTaken;
                        if (a.mnAmount <= 0)
                        {
                            VicisMod.log(getPrefix(), "There are " + a.mnAmount + " items for " + a.GetDisplayString() + ", removing it from items");
                            items.RemoveAt(i);
                        }
                    }
                    MarkDirtyDelayed();
                    return(ret);
                }
                // a was null, this is bad. Clean up, hide the evidence
                VicisMod.log(getPrefix(), "Removing a null that masquaraded as an ItemCubeStack!");
                items.RemoveAt(i);
                return(null);
            }
            else if (ItemBaseUtil.compareStack(items[i] as ItemStack, item as ItemStack))
            {
                ItemStack a = items[i] as ItemStack;
                VicisMod.log(getPrefix(), "Found a Stack " + a.GetDisplayString() + ", which is storing " + a.mnAmount + " blocks");
                if (a != null)
                {
                    int       amntTaken = Math.Min(amount, a.mnAmount);
                    ItemStack ret       = new ItemStack(a.mnItemID, amntTaken);
                    if (actuallyGiveItem)
                    {
                        VicisMod.log(getPrefix(), "Taking away");
                        a.mnAmount -= amntTaken;
                        if (a.mnAmount <= 0)
                        {
                            VicisMod.log(getPrefix(), "There are " + a.mnAmount + " items for " + a.GetDisplayString() + ", removing it from items");
                            items.RemoveAt(i);
                        }
                    }
                    MarkDirtyDelayed();
                    return(ret);
                }
                // a was null, this is bad. Clean up, hide the evidence
                VicisMod.log(getPrefix(), "Removing a null that masquaraded as an ItemStack!");
                items.RemoveAt(i);
                return(null);
            }
        }

        if (ItemBaseUtil.isStack(item))
        {
            VicisMod.log(getPrefix(), "Could not find a stack or cube stack for " + item.GetDisplayString() + ", returning null");
            return(null);
        }

        // What we're looking for is not a stack, start looking at the individual items.
        for (int i = 0; i < items.Count; ++i)
        {
            if (ItemBaseUtil.compareBase(items[i], item))
            {
                ItemBase ret = items[i];
                VicisMod.log(getPrefix(), "Found a " + ret.GetDisplayString() + ", with id = " + ret.mnItemID + " and type = " + ret.mType);
                if (actuallyGiveItem)
                {
                    VicisMod.log(getPrefix(), "Removing from items");
                    items.RemoveAt(i);
                }
                MarkDirtyDelayed();
                return(ret);
            }
        }
        return(null);
    }