/// <summary>Provide input to the machine.</summary> /// <param name="input">The available items.</param> /// <returns>Returns whether the machine started processing an item.</returns> public override bool SetInput(IStorage input) { // get next item ITrackedStack tracker = input.GetItems().FirstOrDefault(p => p.Sample is SObject obj && obj.canBeShipped()); if (tracker == null) { return(false); } // ship item SObject item = (SObject)tracker.Take(tracker.Count); var binList = (this.Location as Farm ?? Game1.getFarm()).getShippingBin(Game1.MasterPlayer); Utility.addItemToThisInventoryList(item, binList, listMaxSpace: int.MaxValue); // play animation/sound if (this.Bin != null) { this.Bin.showShipment(item, false); } else if (this.Location is IslandWest islandFarm) { islandFarm.showShipment(item, false); } else if (this.Location is Farm farm) { farm.showShipment(item, false); } return(true); }
/// <summary>Store an item stack.</summary> /// <param name="stack">The item stack to store.</param> /// <remarks>If the storage can't hold the entire stack, it should reduce the tracked stack accordingly.</remarks> public void Store(ITrackedStack stack) { if (stack.Count <= 0 || this.Chest.SpecialChestType == Chest.SpecialChestTypes.AutoLoader) { return; } IList <Item> inventory = this.GetInventory(); // try stack into existing slot foreach (Item slot in inventory) { if (slot != null && stack.Sample.canStackWith(slot)) { Item sample = stack.Sample.getOne(); sample.Stack = stack.Count; int added = stack.Count - slot.addToStack(sample); stack.Reduce(added); if (stack.Count <= 0) { return; } } } // try add to empty slot int capacity = this.Chest.GetActualCapacity(); for (int i = 0; i < capacity && i < inventory.Count; i++) { if (inventory[i] == null) { inventory[i] = stack.Take(stack.Count); return; } } // try add new slot if (inventory.Count < capacity) { inventory.Add(stack.Take(stack.Count)); } }
/// <summary>Store an item stack.</summary> /// <param name="stack">The item stack to store.</param> /// <remarks>If the storage can't hold the entire stack, it should reduce the tracked stack accordingly.</remarks> public void Store(ITrackedStack stack) { if (stack.Count <= 0) { return; } IList <Item> inventory = this.Chest.items; // try stack into existing slot foreach (Item slot in inventory) { if (slot != null && stack.Sample.canStackWith(slot)) { int added = stack.Count - slot.addToStack(stack.Count); stack.Reduce(added); if (stack.Count <= 0) { return; } } } // try add to empty slot for (int i = 0; i < Chest.capacity && i < inventory.Count; i++) { if (inventory[i] == null) { inventory[i] = stack.Take(stack.Count); return; } } // try add new slot if (inventory.Count < Chest.capacity) { inventory.Add(stack.Take(stack.Count)); } }
/// <summary>Pull items from the connected pipes.</summary> /// <param name="pipes">The connected IO pipes.</param> /// <returns>Returns whether the machine started processing an item.</returns> public bool Pull(IPipe[] pipes) { ITrackedStack tracker = pipes.GetItems(p => p.Sample is SObject obj && obj.canBeShipped()).Take(1).FirstOrDefault(); if (tracker != null) { SObject item = (SObject)tracker.Take(tracker.Count); this.Farm.shippingBin.Add(item); this.Farm.lastItemShipped = item; this.Farm.showShipment(item, false); return(true); } return(false); }
/// <summary>Provide input to the machine.</summary> /// <param name="input">The available items.</param> /// <returns>Returns whether the machine started processing an item.</returns> public override bool SetInput(IStorage input) { ITrackedStack tracker = input.GetItems().Where(p => p.Sample is SObject obj && obj.canBeShipped()).Take(1).FirstOrDefault(); if (tracker != null) { SObject item = (SObject)tracker.Take(tracker.Count); this.Farm.getShippingBin(Game1.MasterPlayer).Add(item); this.Farm.lastItemShipped = item; this.Farm.showShipment(item, false); return(true); } return(false); }
/********* ** Private methods *********/ /// <summary>Try to add an item to the input queue, and adjust its stack size accordingly.</summary> /// <param name="item">The item stack to add.</param> /// <returns>Returns whether any items were taken from the stack.</returns> private bool TryAddInput(ITrackedStack item) { // nothing to add if (item.Count <= 0) { return(false); } // clean up input bin this.Input.clearNulls(); // try adding to input int originalSize = item.Count; IList <Item> slots = this.Input.items; int maxStackSize = this.GetMaxInputStackSize(item.Sample); for (int i = 0; i < Chest.capacity; i++) { // done if (item.Count <= 0) { break; } // add to existing slot if (slots.Count > i) { Item slot = slots[i]; if (item.Sample.canStackWith(slot) && slot.Stack < maxStackSize) { var sample = item.Sample.getOne(); sample.Stack = Math.Min(item.Count, maxStackSize - slot.Stack); // the most items we can add to the stack (in theory) int actualAdded = sample.Stack - slot.addToStack(sample); // how many items were actually added to the stack item.Reduce(actualAdded); } continue; } // add to new slot slots.Add(item.Take(Math.Min(item.Count, maxStackSize))); } return(item.Count < originalSize); }