Exemplo n.º 1
0
    protected virtual bool AttemptGiveItem()
    {
        if (items.Count == 0 || getDropOffSize() == 0)
        {
            return(false);
        }

        ItemBase item  = ItemBaseUtil.newInstance(items[0]);
        int      count = getDropOffSize();

        if (ItemBaseUtil.isStack(items[0]))
        {
            // We have a stacked item, make sure to carry only what we need
            ItemBaseUtil.decrementStack(items[0], count);
            if (ItemBaseUtil.getAmount(items[0]) == 0)
            {
                // Stack no longer exists, remove it.
                // Don't need to set the amount on the item since it already had a =< batch size amount
                items.RemoveAt(0);
            }
            else
            {
                // Stack still exists, so we need to set the amount that we removed
                ItemBaseUtil.setAmount(item, count);
            }
        }
        else
        {
            // No stack, no problem!
            items.RemoveAt(0);
        }

        carriedItems.Add(item);
        return(true);
    }
Exemplo n.º 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);
    }