示例#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);
    }
示例#2
0
 protected virtual int getDropOffSize()
 {
     if (items.Count == 0)
     {
         return(0);
     }
     return(Math.Min(batch, ItemBaseUtil.getAmount(items[0])));
 }
示例#3
0
    protected virtual void dropOffToConveyors()
    {
        bool ignore;
        List <ConveyorEntity> list = VicisMod.checkSurrounding <ConveyorEntity>(this, out ignore);

        VicisMod.log(getPrefix(), "Found " + list.Count + " ConveyorEntities");
        string msg = items.Count + ": ";

        foreach (ItemBase it in items)
        {
            msg += it.GetDisplayString() + ", ";
        }
        VicisMod.log(getPrefix(), "Currently storing " + msg);
        for (int i = 0; i < list.Count && items.Count > 0; ++i)
        {
            ConveyorEntity c = list[i] as ConveyorEntity;
            if (!isConveyorNotFacingMe(c))
            {
                VicisMod.log(getPrefix(), "Conveyor is either not facing somewhere else: " + isConveyorNotFacingMe(c));
                continue;
            }
            if (c.mbReadyToConvey && c.mrLockTimer == 0f)
            {
                VicisMod.log(getPrefix(), "Ready to convey, will be giving " + items[0].GetDisplayString() + ", a " + items[0].mType);
                if (items[0].mType == ItemType.ItemCubeStack)
                {
                    ItemCubeStack a = items[0] as ItemCubeStack;
                    c.AddCube(a.mCubeType, a.mCubeValue, 1);
                    c.mItemForwards = forwards;
                    --a.mnAmount;
                    if (a.mnAmount == 0)
                    {
                        VicisMod.log(getPrefix(), "Removing cube " + a.GetDisplayString() + " from items list");
                        items.RemoveAt(0);
                    }
                }
                else if (items[0].mType == ItemType.ItemStack)
                {
                    ItemStack a = ItemBaseUtil.newInstance(items[0]) as ItemStack;
                    a.mnAmount = 1;
                    ItemBaseUtil.decrementStack(items[0], 1);
                    c.AddItem(a);
                    c.mItemForwards = forwards;
                    if (ItemBaseUtil.getAmount(items[0]) == 0)
                    {
                        VicisMod.log(getPrefix(), "Removing item " + a.GetDisplayString() + " from items list");
                        items.RemoveAt(0);
                    }
                }
                else
                {
                    c.AddItem(items[0]);
                    c.mrCarryTimer       = 1f;
                    c.mrVisualCarryTimer = 1f;
                    c.mItemForwards      = forwards;
                    items.RemoveAt(0);
                }
            }
            else
            {
                VicisMod.log(getPrefix(), "Conveyor is not ready to convey");
            }
        }
    }