public override bool Execute()
            {
                BlockHandler handler = BlockHandlerRegistry.GetBlockHandler(entityProvider.GetBlockType());

                entityProvider.GetEntities().ForEach(e => blockAction(handler, e));
                return(true);
            }
            public override bool Execute()
            {
                if (from.GetBlockType() != Block.CARGO || to.GetBlockType() != Block.CARGO)
                {
                    throw new Exception("Transfers can only be executed on cargo block types");
                }

                BlockHandler blockHandler = BlockHandlerRegistry.GetBlockHandler(Block.CARGO);

                var filter = PROGRAM.AnyItem(PROGRAM.GetItemFilters(CastString((second ?? first).GetValue()).GetTypedValue()));
                var items  = new List <MyInventoryItem>();

                var toInventories   = to.GetEntities().Select(i => (IMyInventory)i).Where(i => !i.IsFull).ToList();
                var fromInventories = from.GetEntities().Select(i => (IMyInventory)i)
                                      .Where(i => toInventories.TrueForAll(to => i.Owner.EntityId != to.Owner.EntityId)) //Don't transfer to yourself
                                      .ToList();

                MyFixedPoint amountLeft = MyFixedPoint.MaxValue;

                if (second != null)
                {
                    amountLeft = (MyFixedPoint)CastNumber(first.GetValue()).GetTypedValue();
                }

                int transfers = 0;

                foreach (IMyInventory fromInventory in fromInventories)
                {
                    fromInventory.GetItems(items, filter);
                    for (int i = 0; i < toInventories.Count; i++)
                    {
                        foreach (MyInventoryItem item in items)
                        {
                            var destinationInventory = toInventories[i];
                            var startMass            = fromInventory.CurrentMass;
                            fromInventory.TransferItemTo(destinationInventory, item, amountLeft);
                            amountLeft -= (startMass - fromInventory.CurrentMass);
                            if (amountLeft <= MyFixedPoint.Zero || ++transfers >= PROGRAM.maxItemTransfers)
                            {
                                return(true);
                            }
                            if (destinationInventory.IsFull)
                            {
                                toInventories.RemoveAt(i--);
                                break;
                            }
                        }
                    }
                }
                return(true);
            }
Beispiel #3
0
            public Primitive GetValue()
            {
                List <Object> blocks = entityProvider.GetEntities();

                if (aggregationType == PropertyAggregate.COUNT)
                {
                    return(new NumberPrimitive(blocks.Count));
                }

                BlockHandler handler = BlockHandlerRegistry.GetBlockHandler(entityProvider.GetBlockType());

                PropertySupplier p = property ?? handler.GetDefaultProperty(Return.NUMERIC);

                List <Primitive> propertyValues = blocks.Select(b => {
                    return(direction.HasValue ? handler.GetPropertyValue(b, p, direction.Value) : handler.GetPropertyValue(b, p));
                }).ToList();

                return(Aggregate(propertyValues, aggregationType));
            }
Beispiel #4
0
            public bool Evaluate()
            {
                List <Object> blocks = entityProvider.GetEntities();

                if (blocks.Count == 0)
                {
                    return(false);                   //If there are no blocks, consider this not matching
                }
                int matches = blocks.Count(block => blockCondition.evaluate(block, entityProvider.GetBlockType()));

                switch (aggregationMode)
                {
                case AggregationMode.ALL: return(matches == blocks.Count);

                case AggregationMode.ANY: return(matches > 0);

                case AggregationMode.NONE: return(matches == 0);

                default: throw new Exception("Unsupported Aggregation Mode");
                }
            }
Beispiel #5
0
 public BlockType GetBlockType()
 {
     return(provider.GetBlockType());
 }
Beispiel #6
0
            public Primitive GetValue()
            {
                var blocks = entityProvider.GetEntities();

                return(new BooleanPrimitive(Evaluate(blocks.Count, blocks.Count(block => blockCondition.evaluate(block, entityProvider.GetBlockType())), aggregationMode)));
            }