public List <Object> GetEntities() { String selectorString = CastString(selector.GetValue()).GetStringValue(); List <object> entities = isGroup ? BlockHandlerRegistry.GROUP_BLOCK_PROVIDER(blockType, selectorString) : BlockHandlerRegistry.BLOCK_PROVIDER(blockType, selectorString); return(entities); }
public override bool Execute() { BlockHandler handler = BlockHandlerRegistry.GetBlockHandler(entityProvider.GetBlockType()); entityProvider.GetEntities().ForEach(e => blockAction(handler, e)); return(true); }
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 List <Object> GetEntities() { String selectorString = CastString(selector.GetValue()).GetTypedValue(); bool resolvedIsGroup = false; Block bt = blockType.HasValue ? blockType.Value : ResolveType(selectorString, out resolvedIsGroup); bool useGroup = isGroup || resolvedIsGroup; List <object> entities = useGroup ? BlockHandlerRegistry.GetBlocksInGroup(bt, selectorString) : BlockHandlerRegistry.GetBlocks(bt, block => block.CustomName.Equals(selectorString)); return(entities); }
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); }
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)); } }
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 List <object> GetEntities() { return(BlockHandlerRegistry.GetBlocks(blockType, block => true)); }
public List <object> GetEntities() { return(BlockHandlerRegistry.GetBlocks(blockType, (b) => b.CustomName.Equals(PROGRAM.Me.CustomName))); }