public static IBlockData[] Devices(IStructureData structure, string names) { var uniqueNames = structure.AllCustomDeviceNames.GetUniqueNames(names); return uniqueNames .SelectMany(N => structure.GetCurrent().GetDevicePositions(N) .Select(V => new BlockData(structure.GetCurrent(), V))) .ToArray(); }
private static int MoveItem(IScriptRootData root, IItemsSource S, string N, IStructureData targetStructure, int count, int?maxLimit) { var target = targetStructure?.GetCurrent()?.GetDevice <Eleon.Modding.IContainer>(N); if (target == null) { Log($"TargetNoFound: {S.Id} #{S.Count} => {N}", LogLevel.Debug); return(count); } if (!targetStructure.ContainerSource.TryGetValue(N, out var targetData)) { Log($"TargetDataNoFound: {S.Id} #{S.Count} => {N}", LogLevel.Debug); return(count); } var tryMoveCount = maxLimit.HasValue ? Math.Max(0, Math.Min(count, maxLimit.Value - target.GetTotalItems(S.Id))) : count; using var locked = WeakCreateDeviceLock(root, root.GetCurrentPlayfield(), targetStructure.GetCurrent(), targetData.Position); if (!locked.Success) { Log($"DeviceIsLocked (Target): {S.Id} #{S.Count} => {targetData.CustomName}", LogLevel.Debug); return(count); } return(maxLimit.HasValue ? target.AddItems(S.Id, tryMoveCount) + (count - tryMoveCount) : target.AddItems(S.Id, tryMoveCount)); }
public static IBlockData[] DevicesOfType(IStructureData structure, DeviceTypeName deviceType) { return structure?.GetCurrent() .GetDevices(deviceType)? .Values() .Select(V => new BlockData(structure.GetCurrent(), V)) .ToArray(); }
private static int MoveItem(ItemsSource S, string N, IStructureData targetStructure, int count, int?maxLimit) { var target = targetStructure?.GetCurrent()?.GetDevice <Eleon.Modding.IContainer>(N); if (target == null) { Log($"TargetNoFound: {S.Id} #{S.Count} => {N}", LogLevel.Debug); return(count); } if (!targetStructure.ContainerSource.TryGetValue(N, out var targetData)) { Log($"TargetDataNoFound: {S.Id} #{S.Count} => {N}", LogLevel.Debug); return(count); } using (var locked = CreateDeviceLock(EmpyrionScripting.ModApi?.Playfield, targetStructure.GetCurrent(), targetData.Position)) { if (!locked.Success) { Log($"DeviceIsLocked (Target): {S.Id} #{S.Count} => {targetData.CustomName}", LogLevel.Debug); return(count); } if (maxLimit.HasValue) { var stock = target.GetTotalItems(S.Id); var transfer = Math.Max(0, Math.Min(count, maxLimit.Value - stock)); return(target.AddItems(S.Id, transfer) + (count - transfer)); } else { return(target.AddItems(S.Id, count)); } } }
public IBlockData Block(IStructureData structure, int x, int y, int z) => new BlockData(structure.GetCurrent(), new Eleon.Modding.VectorInt3(x, y, z));
public void WithLockedDevice(IStructureData structure, IBlockData block, Action action, Action lockFailed = null) { using (var locked = ConveyorHelpers.CreateDeviceLock(ScriptRoot, ScriptRoot.GetCurrentPlayfield(), structure.GetCurrent(), block.Position)) { if (locked.Success) { action(); } else { lockFailed?.Invoke(); } } }
public bool IsLocked(IStructureData structure, IBlockData block) => ScriptRoot.GetCurrentPlayfield().IsStructureDeviceLocked(structure.GetCurrent().Id, block.Position);