Exemplo n.º 1
0
        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));
        }
Exemplo n.º 3
0
 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));
                }
            }
        }
Exemplo n.º 5
0
 public IBlockData Block(IStructureData structure, int x, int y, int z) => new BlockData(structure.GetCurrent(), new Eleon.Modding.VectorInt3(x, y, z));
Exemplo n.º 6
0
 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();
         }
     }
 }
Exemplo n.º 7
0
 public bool IsLocked(IStructureData structure, IBlockData block) => ScriptRoot.GetCurrentPlayfield().IsStructureDeviceLocked(structure.GetCurrent().Id, block.Position);