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); }
protected virtual bool addItem(ItemBase item) { if (getStoredItemsCount() >= maxItems) { return(false); } if (item.mType == ItemType.ItemCubeStack || item.mType == ItemType.ItemStack) { for (int j = 0; j < items.Count; ++j) { // Check if we already have this type of stack if (item.mnItemID == items[j].mnItemID && ItemBaseUtil.compareBaseDeep(item, items[j])) { if (item.mType == ItemType.ItemCubeStack) { ++(items[j] as ItemCubeStack).mnAmount; } else { ++(items[j] as ItemStack).mnAmount; } return(true); } } } items.Add(item); return(true); }
protected virtual int getDropOffSize() { if (items.Count == 0) { return(0); } return(Math.Min(batch, ItemBaseUtil.getAmount(items[0]))); }
public void BuildInventoryList() { List <KeyValuePair <ItemBase, int> > items = new List <KeyValuePair <ItemBase, int> >(); for (int index = 0; index <= this.MassStorage.mConnectedCrates.Count; index++) { MassStorageCrate crate; ItemBase item; if (index == this.MassStorage.mConnectedCrates.Count) { crate = this.MassStorage; } else { crate = this.MassStorage.mConnectedCrates[index]; } if (crate.mMode == MassStorageCrate.CrateMode.SingleStack) { item = crate.mItem; if (item != null) { int loc = items.FindIndex(x => x.Key.Compare(item)); if (loc != -1) { items[loc] = new KeyValuePair <ItemBase, int>(items[loc].Key, items[loc].Value + item.GetAmount()); } else { items.Add(new KeyValuePair <ItemBase, int>(ItemBaseUtil.NewInstance(item), item.GetAmount())); } } } else { for (int n = 0; n < crate.STORAGE_CRATE_SIZE; n++) { item = crate.mItems[n]; if (item != null) { int loc = items.FindIndex(x => x.Key.Compare(item)); if (loc != -1) { items[loc] = new KeyValuePair <ItemBase, int>(items[loc].Key, items[loc].Value + item.GetAmount()); } else { items.Add(new KeyValuePair <ItemBase, int>(ItemBaseUtil.NewInstance(item), item.GetAmount())); } item = null; } } } } this.Inventory = items; }
// 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); }
// 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); } bool itemIsStack = item.isStack(); for (int i = 0; i < items.Count; ++i) { if (itemIsStack && items[i].isStackAndSame(item)) { VicisMod.log(getPrefix(), "Found a CubeStack " + items[i].GetDisplayString() + ", which is storing " + items[i].getAmount() + " blocks"); int amntTaken = Math.Min(amount, items[i].getAmount()); ItemBase ret = ItemBaseUtil.newInstance(items[i]); ret.setAmount(amntTaken); if (actuallyGiveItem) { VicisMod.log(getPrefix(), "Taking Away"); items[i].decrementStack(amntTaken); if (items[i].getAmount() == 0) { VicisMod.log(getPrefix(), "There are " + items[i].getAmount() + " items for " + items[i].GetDisplayString() + ", removing it from items"); items.RemoveAt(i); } MarkDirtyDelayed(); } return(ret); } else if (!item.isStack() && items[i].compareBase(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); }
public int getNumItems() { return(ItemBaseUtil.getItemCount(items)); }
// 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); }
protected virtual float getReqPower() { return(ItemBaseUtil.getItemCount(items) / ippps * powerConsumptionFreq); }
protected virtual int getItemCount(List <ItemBase> items) { return(ItemBaseUtil.getItemCount(items)); }
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"); } } }