public JsonResult GetItems(string category, int countOnPage, int page) { IItemsData itemsData = itemService.getItemsByCategory(WebAssembler.Assemble(category), countOnPage, page); ItemsData result = new ItemsData(itemsData.TotalCount, WebAssembler.Assemble(itemsData.Items, ViewBag.Language)); return(Json(result, JsonRequestBehavior.AllowGet)); }
public IList <IItemMoveInfo> Move(IItemsData item, IStructureData structure, string names, int?maxLimit = null) => ConveyorHelpers.Move(ScriptRoot, item, structure, names, maxLimit);
public IList <IItemMoveInfo> Fill(IItemsData item, IStructureData structure, StructureTankType type, int?maxLimit = null) => ConveyorHelpers.Fill(ScriptRoot, item, structure, type, maxLimit ?? 100);
public ItemsController(IItemsData data) => _data = data;
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); }
public static IList <IItemMoveInfo> Move(IScriptRootData root, IItemsData item, IStructureData structure, string namesSearch, int?maxLimit) { if (!root.DeviceLockAllowed) { Log($"Move: NoLockAllowed({root.ScriptId}): {root.CycleCounter} % {EmpyrionScripting.Configuration.Current.DeviceLockOnlyAllowedEveryXCycles}", LogLevel.Debug); return(ItemMoveInfo.Empty); } if (root.TimeLimitReached) { Log($"Move: TimeLimitReached({root.ScriptId})", LogLevel.Debug); return(ItemMoveInfo.Empty); } var uniqueNames = structure.AllCustomDeviceNames.GetUniqueNames(namesSearch); if (!uniqueNames.Any()) { Log($"NoDevicesFound: {namesSearch}", LogLevel.Debug); return(ItemMoveInfo.Empty); } 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 = S.Count; 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) { uniqueNames .Where(N => N != S.CustomName) .ForEach(N => { var startCount = count; count = MoveItem(root, S, N, structure, count, maxLimit); if (startCount != count) { var movedCount = startCount - count; moveInfos.Add(currentMoveInfo = new ItemMoveInfo() { Id = S.Id, Count = movedCount, SourceE = S.E, Source = S.CustomName, DestinationE = structure.E, Destination = N, }); Log($"Move(AddItems): {S.CustomName} {S.Id} #{S.Count}->{startCount - count}", LogLevel.Debug); // Für diesen Scriptdurchlauf dieses Item aus der Verarbeitung nehmen S.Count -= movedCount; } ; }, () => root.TimeLimitReached); } if (count > 0) { var retoureCount = count; count = S.Container.AddItems(S.Id, retoureCount); Log($"Move(retoure): {S.CustomName} {retoureCount} -> {count}", LogLevel.Debug); } if (count > 0) { root.GetPlayfieldScriptData().MoveLostItems.Enqueue(new ItemMoveInfo() { Id = S.Id, Count = count, SourceE = S.E, Source = S.CustomName, }); currentMoveInfo.Error = $"{{move}} error lost #{count} of item {S.Id} in container {S.CustomName} -> add to retry list"; } }, () => root.TimeLimitReached); return(moveInfos); }