Esempio n. 1
0
            public List <object> GetEntities()
            {
                List <object> entities         = provider.GetEntities();
                List <object> selectedEntities = new List <Object>();
                BlockHandler  b = BlockHandlerRegistry.GetBlockHandler(GetBlockType());

                var indexes = CastList(index.GetValue()).GetTypedValue().GetValues()
                              .Select(v => v.GetValue()).ToList();

                foreach (Primitive p in indexes)
                {
                    //Return empty list if index > Count
                    if (p.GetPrimitiveType() == Return.NUMERIC)
                    {
                        int i = (int)CastNumber(p).GetTypedValue();
                        if (i < entities.Count)
                        {
                            selectedEntities.Add(entities[i]);
                        }
                    }
                    if (p.GetPrimitiveType() == Return.STRING)
                    {
                        var entityName = CastString(p).GetTypedValue();
                        selectedEntities.AddRange(entities.Where(o => entityName == b.GetName(o)));
                    }
                    //Other Index types not supported
                }
                return(selectedEntities);
            }
            public override bool Execute()
            {
                BlockHandler handler = BlockHandlerRegistry.GetBlockHandler(entityProvider.GetBlockType());

                entityProvider.GetEntities().ForEach(e => blockAction(handler, e));
                return(true);
            }
            public void PreParseCommands(List <CommandParameter> commandParameters)
            {
                extract <ActionCommandParameter>(commandParameters);//Extract and ignore
                SelectorCommandParameter selector = extractFirst <SelectorCommandParameter>(commandParameters);

                if (selector == null)
                {
                    throw new Exception("SelectorCommandParameter is required for command: " + GetType());
                }
                blockHandler   = BlockHandlerRegistry.GetBlockHandler(selector.Value.GetBlockType());
                entityProvider = selector.Value;
            }
            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);
            }
Esempio n. 5
0
            public bool evaluate(Object block, Block blockType)
            {
                BlockHandler     handler = BlockHandlerRegistry.GetBlockHandler(blockType);
                Primitive        value   = comparisonValue.GetValue();
                PropertySupplier prop    = property ?? handler.GetDefaultProperty(value.GetPrimitiveType());

                if (direction.HasValue)
                {
                    return(comparator.compare(handler.GetPropertyValue(block, prop, direction.Value), value));
                }
                else
                {
                    return(comparator.compare(handler.GetPropertyValue(block, prop), value));
                }
            }
Esempio n. 6
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));
            }