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 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); }
public List <object> GetEntities() { List <object> entities = provider.GetEntities(); List <object> selectedEntities = new List <Object>(); //Return empty list if index > Count int i = (int)CastNumber(index.GetValue()).GetNumericValue(); if (i < entities.Count) { selectedEntities.Add(entities[i]); } return(selectedEntities); }
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)); }
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"); } }
public List <object> GetEntities() { return(provider.GetEntities().Where(b => condition.evaluate(b, provider.GetBlockType())).ToList()); }
public Primitive GetValue() { var blocks = entityProvider.GetEntities(); return(new BooleanPrimitive(Evaluate(blocks.Count, blocks.Count(block => blockCondition.evaluate(block, entityProvider.GetBlockType())), aggregationMode))); }
public void Execute() { e.GetEntities().ForEach(entity => handle(entity)); }