Example #1
0
 public IList <IItemMoveInfo> Fill(IItemsData item, IStructureData structure, StructureTankType type, int?maxLimit = null) => ConveyorHelpers.Fill(ScriptRoot, item, structure, type, maxLimit ?? 100);
Example #2
0
 public StructureTank(IStructureTank tank, StructureTankType type)
 {
     this.tank = tank;
     this.type = type;
 }
        public static IList <IItemMoveInfo> Fill(IScriptRootData root, IItemsData item, IStructureData structure, StructureTankType type, int maxLimit)
        {
            if (!root.DeviceLockAllowed)
            {
                Log($"Fill: NoLockAllowed({root.ScriptId}): {root.CycleCounter} % {EmpyrionScripting.Configuration.Current.DeviceLockOnlyAllowedEveryXCycles}", LogLevel.Debug);
                return(ItemMoveInfo.Empty);
            }

            var specialTransfer = type switch
            {
                StructureTankType.Oxygen => structure.OxygenTank,
                StructureTankType.Fuel => structure.FuelTank,
                StructureTankType.Pentaxid => structure.PentaxidTank,
                _ => null,
            };

            if (specialTransfer == null || !specialTransfer.AllowedItem(item.Id))
            {
                return(ItemMoveInfo.Empty);
            }

            Log($"Fill Total: #{item.Source.Count}", LogLevel.Debug);

            var moveInfos = new List <IItemMoveInfo>();

            lock (moveLock) item.Source
                .ForEach(S => {
                    using var locked = WeakCreateDeviceLock(root, root.GetCurrentPlayfield(), S.E?.S.GetCurrent(), S.Position);
                    if (!locked.Success)
                    {
                        Log($"DeviceIsLocked (Source): {S.Id} #{S.Count} => {S.CustomName}", LogLevel.Debug);
                        return;
                    }

                    var count = specialTransfer.ItemsNeededForFill(S.Id, maxLimit);
                    if (count > 0)
                    {
                        count -= S.Container.RemoveItems(S.Id, count);
                        Log($"Move(RemoveItems): {S.CustomName} {S.Id} #{S.Count}->{count}", LogLevel.Debug);
                    }

                    ItemMoveInfo currentMoveInfo = null;

                    if (count > 0)
                    {
                        var startCount = count;
                        count          = specialTransfer.AddItems(S.Id, count);
                        if (startCount != count)
                        {
                            moveInfos.Add(currentMoveInfo = new ItemMoveInfo()
                            {
                                Id           = S.Id,
                                Count        = startCount - count,
                                SourceE      = S.E,
                                Source       = S.CustomName,
                                DestinationE = structure.E,
                                Destination  = type.ToString(),
                            });
                        }
                    }
                    ;

                    if (count > 0)
                    {
                        count = S.Container.AddItems(S.Id, count);
                    }
                    if (count > 0 && currentMoveInfo != null)
                    {
                        root.GetPlayfieldScriptData().MoveLostItems.Enqueue(new ItemMoveInfo()
                        {
                            Id      = S.Id,
                            Count   = count,
                            SourceE = S.E,
                            Source  = S.CustomName,
                        });
                        currentMoveInfo.Error = $"{{fill}} error lost #{count} of item {S.Id} in container {S.CustomName} -> add to retry list";
                    }
                }, () => root.TimeLimitReached);

            return(moveInfos);
        }