public MyItem(string Code, string Name, float Price, MyItem.MyItemType Type) { this.Code = Code; this.Name = Name; this.Price = Price; this.Type = Type; }
// Arguments separated by commas // Display name // Components public BaseStatistics() { Runtime.UpdateFrequency = UpdateFrequency.Update100; baseGrid = Me.CubeGrid; List <IMyTextPanel> allPanels = new List <IMyTextPanel>(); GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(allPanels); inventoryDisplays = new Dictionary <int, IMyTextPanel>(); foreach (IMyTextPanel panel in allPanels) { if (panel.CustomName.Contains("Inventory Display")) { int panelIndex = int.Parse(panel.CustomName[panel.CustomName.Length - 1].ToString()); panel.ContentType = ContentType.TEXT_AND_IMAGE; panel.BackgroundColor = new Color(0f); inventoryDisplays.Add(panelIndex, panel); } } cargoContainers = FindCargoContainers(); refineries = FindRefineries(); assemblers = FindAssemblers(); itemTypes = new Dictionary <string, MyItemType>(); itemTypes.Add("Iron", MyItemType.MakeIngot("Iron")); itemTypes.Add("Cobalt", MyItemType.MakeIngot("Cobalt")); }
/// <summary> /// Attempts to move certain item type from one inventory to another. /// </summary> /// <param name="from">Source inventory.</param> /// <param name="to">Destination inventory.</param> /// <param name="type">Item type to move.</param> /// <param name="amount">How much to move. If not specified, attempts to move every item of set type.</param> /// <returns>The amount actually moved.</returns> public static MyFixedPoint MoveItem(IMyInventory from, IMyInventory to, MyItemType type, MyFixedPoint?amount = null) { MyFixedPoint amountmoved = new MyFixedPoint(); MyInventoryItem?item; bool moved; for (int i = from.ItemCount; i >= 0; i--) { item = from.GetItemAt(i); if (item.HasValue && item.Value.Type == type) { MyFixedPoint amounttomove = amount.HasValue ? MyFixedPoint.Min(amount.Value - amountmoved, item.Value.Amount) : item.Value.Amount; moved = to.TransferItemFrom(from, item.Value, amounttomove); if (!moved) { return(amountmoved); } amountmoved += amounttomove; if (amountmoved >= amount) { return(amountmoved); } } } return(amountmoved); }
public MyFixedPoint GetItemAmount(MyItemType itemType) => new MyFixedPoint { RawValue = Inventory.Where(i => i.Type == itemType) .DefaultIfEmpty(new MyInventoryItem(itemType, 0, Value0)) .Sum(i => i.Amount.RawValue) };
public void CheckProductionNeed(ref List <ControlObject> controlObjectList, ref FinalContainer finalContainer) { IMyGridTerminalSystem myGridTerminalSystem = null; IMyCargoContainer finalContainerUnico = null; foreach (ControlObject controlObject in controlObjectList) { MyItemType item = new MyItemType(controlObject.getComponentIDValue(), ""); for (int i = 0; i < finalContainer.getContainerName().Count(); i++) { finalContainerUnico = (IMyCargoContainer)myGridTerminalSystem.GetBlockWithName(finalContainer.getContainerName()[i]); if (finalContainerUnico != null) { MyInventoryItem myInventoryItem = (MyInventoryItem)finalContainerUnico.GetInventory().FindItem(item); if (myInventoryItem != null) { controlObject.setComponentsAmountProduced((int)myInventoryItem.Amount); controlObject.setComponentsAmountToProduce(controlObject.getComponetAmountKeepStorage() - controlObject.getComponentsAmountProduced()); } else { controlObject.setComponentsAmountProduced(controlObject.getComponetAmountKeepStorage()); controlObject.setComponentsAmountToProduce(controlObject.getComponetAmountKeepStorage()); } } } } }
void GetBlockRequestSettings(IMyTerminalBlock block) { InventoryRequests[block] = new Dictionary <MyItemType, int>(); if (iniParser.TryParse(block.CustomData) && iniParser.ContainsSection(kInventoryRequestSection)) { iniParser.GetKeys(iniKeyScratchpad); foreach (var key in iniKeyScratchpad) { if (key.Section != kInventoryRequestSection) { continue; } var count = iniParser.Get(key).ToInt32(); if (count == 0) { continue; } var type = MyItemType.Parse(key.Name); var inventory = block.GetInventory(block.InventoryCount - 1); itemTypeScratchpad.Clear(); inventory.GetAcceptedItems(itemTypeScratchpad); if (!itemTypeScratchpad.Contains(type)) { continue; } InventoryRequests[block][type] = count; } } }
public int GetItemCountFromInventory(IMyInventory inventory, string itemName) { MyDefinitionId myDefinitionId = GetMyDefinitionIdByName(itemName); MyItemType myItemType = MyItemType.MakeComponent(myDefinitionId.SubtypeId.ToString()); return((int)inventory.GetItemAmount(myItemType)); }
public static void DeserializeItem(string fileName, IFormatter formatter) { FileStream s = new FileStream(fileName, FileMode.Open); MyItemType t = (MyItemType)formatter.Deserialize(s); Console.WriteLine(t.MyProperty); }
VRage.MyFixedPoint ItemAmount(MyItemType type, float volume) { return(new VRage.MyFixedPoint { RawValue = (long)(volume / type.GetItemInfo().Volume) }); }
public Target(String t, long a, String r) { target = new MyItemType(objectType, t); recipe = new MyDefinitionId(); bool _ = MyDefinitionId.TryParse("MyObjectBuilder_BlueprintDefinition", r, out recipe); amount = fromLong(a); }
public static bool compareItemTypes(MyItemType a, MyItemType b) { if (a.SubtypeId != "" && b.SubtypeId != "") { return(a.TypeId == b.TypeId && a.SubtypeId == b.SubtypeId); } return(a.TypeId == b.TypeId); }
public TankSnapshot(IMyTerminalBlock block) { Tank = (IMyGasTank)block; Amount = 0; var sink = Tank.Components.Get <MyResourceSinkComponent>(); type = sink.AcceptedResources.Contains(Oxygen) ? Oxygen : Hydrogen; }
private long GetItemCount(MyItemType type, List <IMyInventory> inventories) { return(inventories.Sum(i => { var items = new List <MyInventoryItem>(); i.GetItems(items, item => item.Type.Equals(type)); return items.Sum(eff => (int)eff.Amount); })); }
public int countItems(EItemType itemType) { CComponentItem result = new CComponentItem(itemType); MyItemType miType = result.asMyItemType(); foreach (IMyCargoContainer container in blocks()) { result.appendAmount(container.GetInventory().GetItemAmount(miType).ToIntSafe()); } return(result.amount()); }
public bool Filter(IMyTerminalBlock block) { if (block is IMyGasGenerator) { return(true); } if (!block.HasInventory) { return(false); } return(block.AnyInventoryCanContain(MyItemType.MakeOre("Ice"))); }
public long GetItemsMängi(MyItemType type) { if (!type.TypeId.Equals("MyObjectBuilder_Ingot") && !type.TypeId.Equals("MyObjectBuilder_Ore")) { var mängi = _inventories.Sum(i => (int)i.GetItemAmount(type)); return(mängi); } var liter = _inventories.Sum(i => i.GetItemAmount(type).RawValue / 1000); //m^3 to l return(Convert.ToInt64(Math.Truncate((double)liter * type.GetItemInfo().Volume))); }
public static void SerializeItem(string fileName, IFormatter formatter) { // Create an instance of the type and serialize it. MyItemType t = new MyItemType(); t.MyProperty = "Hello World"; FileStream s = new FileStream(fileName, FileMode.Create); formatter.Serialize(s, t); s.Close(); }
public void Transfer() { Echo("###--- Transfersystem 2000 started"); List <IMyTerminalBlock> toCargoContainerList = new List <IMyTerminalBlock> (); List <IMyTerminalBlock> fromCargoContainerList = new List <IMyTerminalBlock> (); for (int nIndex = 0; nIndex < m_transferItemList.Length; nIndex++) { toCargoContainerList.Clear(); TransferItem transferItem = m_transferItemList[nIndex]; MyItemType itemType = GetItemType(transferItem.Type); GridTerminalSystem.GetBlocksOfType(toCargoContainerList, searchItem => searchItem.CustomName.Contains(transferItem.TagTo)); for (int nToContainerIndex = 0; nToContainerIndex < toCargoContainerList.Count; nToContainerIndex++) { IMyInventory toInventory = toCargoContainerList[nToContainerIndex].GetInventory(); fromCargoContainerList.Clear(); GridTerminalSystem.GetBlocksOfType(fromCargoContainerList, searchItem => searchItem.CustomName.Contains(transferItem.TagFrom)); for (int nFromContainerIndex = 0; nFromContainerIndex < fromCargoContainerList.Count; nFromContainerIndex++) { MyInventoryItem?steelPlateFoundTo = toInventory.FindItem(itemType); VRage.MyFixedPoint diffAmount = transferItem.Amount; if ((steelPlateFoundTo.HasValue)) { diffAmount = diffAmount - steelPlateFoundTo.Value.Amount; } if (0 < diffAmount) { IMyInventory fromInventory = fromCargoContainerList[nFromContainerIndex].GetInventory(); MyInventoryItem?steelPlateFound = fromInventory.FindItem(itemType); if (steelPlateFound.HasValue) { fromInventory.TransferItemTo(toInventory, steelPlateFound.Value, diffAmount); } } } } } Echo("###--- Transfersystem 2000 finished"); }
public VISItemType(string typeId, string subtypeId) { try { Type = new MyItemType(typeId, subtypeId); Valid = true; } catch (Exception) { Valid = false; Type = new MyItemType(); } }
public VISItemType(string type) { try { Type = MyItemType.Parse(type); Valid = true; } catch (Exception) { Valid = false; Type = EmptyType; } }
public bool CanTransferItemTo(IMyInventory otherInventory, MyItemType itemType) { if (!ContainItems(Value1, itemType)) { return(false); } if (!IsConnectedTo(otherInventory)) { return(false); } return(otherInventory.CanItemsBeAdded(Value1, itemType)); }
public long GetItemAmount(MyItemType itemType) { long amount = 0; GridProgramRef.Echo($"TypeId: {itemType.TypeId}, SubtypeId: {itemType.SubtypeId}"); foreach (IMyCargoContainer container in CargoContainers) { List <MyInventoryItem> _items = new List <MyInventoryItem>(); container.GetInventory().GetItems(_items, i => i.Type == itemType); _items.ForEach(new Action <MyInventoryItem>((b) => { amount += b.Amount.RawValue; })); } return(amount / 1000000); }
public bool Contains(MyItemType type) { IMyInventory inv = container.GetInventory(); List <MyInventoryItem> items = new List <MyInventoryItem>(); inv.GetItems(items); foreach (MyInventoryItem item in items) { if (item.Type == type) { return(true); } } return(false); }
public bool AddBlueprint(string name, out MyItemType type) { MyDefinitionId item; MyDefinitionId?blueprint; if (MyDefinitionId.TryParse("MyObjectBuilder_" + name, out item) && ((blueprint = CreateBlueprint(item.SubtypeName)) != null)) { Blueprints[item] = blueprint.Value; InverseBlueprints[blueprint.Value] = item; type = item; return(true); } type = default(MyItemType); return(false); }
// void BuildDictionaryFromCustomData<TKey,TValue>(ExecutionContext context, IMyTerminalBlock block, string section, Func<string, TKey> funcKeyParse, Func<MyIniValue, TValue> funcValueParse, Action<TKey,TValue> funcWrite) // Dictionary<MyIniValue, TValue> dictionary ) // { // var Parser = context.IniParser; // if (Parser.TryParse(block.CustomData) && Parser.ContainsSection(section)) // { // var TODOiniKeyScratchpad = new List<MyIniKey>(); // Parser.GetKeys(TODOiniKeyScratchpad); // foreach (var iniKey in iniKeyScratchpad) // { // if (iniKey.Section != section) // continue; // // var value = valueParse(Parser.Get(iniKey)); // if (value == null) // continue; // // var key = keyParse(iniKey.Name); // if (key == null) // continue; // // } // } // } void GetBlockRequestSettings(IMyTerminalBlock block) { InventoryRequests[block.EntityId] = new Dictionary <MyItemType, int>(); var Parser = Context.IniParser; if (Parser.TryParse(block.CustomData) && Parser.ContainsSection(InventoryRequestSection)) { // TODO: Replace with // public void GetKeys(string section, List<MyIniKey> keys); Parser.GetKeys(iniKeyScratchpad); foreach (var key in iniKeyScratchpad) { if (key.Section != InventoryRequestSection) { continue; } var count = Parser.Get(key).ToInt32(); if (count == 0) { continue; } var type = MyItemType.Parse(key.Name); var inventory = block.GetInventory(block.InventoryCount - 1); itemTypeScratchpad.Clear(); inventory.GetAcceptedItems(itemTypeScratchpad); if (!itemTypeScratchpad.Contains(type)) { continue; } InventoryRequests[block.EntityId][type] = count; if (!TotalInventoryRequests.ContainsKey(type)) { TotalInventoryRequests[type] = 0; } TotalInventoryRequests[type] += count; if (!SortedInventory.Contains(type)) { SortedInventory.Add(type); } } } }
private void ScanReactors(ref ReactorsState reactorsState) { foreach (var reactor in state.Reactors) { for (var i = 0; i < reactor.InventoryCount; i++) { var inventory = reactor.GetInventory(i); reactorsState.FuelAvailableKg += (float)inventory.GetItemAmount(MyItemType.MakeIngot("Uranium")); } reactorsState.PowerConsumedMW += reactor.CurrentOutput; reactorsState.MaxPowerDrawMW += reactor.MaxOutput; if (reactor.Enabled) { reactorsState.Enabled++; } } }
private void UICheckItem(int _index, MyItemType _type) { ClearSelected(); switch (_type) { case MyItemType.One: IntegrationPageList[_index].SetSelected(true); break; case MyItemType.Two: PlayersPageList[_index].SetSelected(true); break; case MyItemType.Three: TroopsPageList[_index].SetSelected(true); break; } }
public int this[MyItemType type] { get { return(DesiredStock[type]); } set { if (!Blueprints.ContainsKey(type)) { MyDefinitionId?bp = CreateBlueprint(type.SubtypeId); if (!bp.HasValue) { throw new ArgumentException($"Failed to create blueprint for {type.ToString()}"); } Blueprints[type] = bp.Value; InverseBlueprints[bp.Value] = type; } DesiredStock[type] = value; } }
void RequestItem(MyItemType type, float amount) { if (amount <= 0) { return; } var fixedAmt = amount * MyFixedPointOne; string targetFlag = compFlag; if (type.TypeId == "MyObjectBuilder_Ammo") { targetFlag = ammoFlag; } else if (type.TypeId == "MyObjectBuilder_Component") { targetFlag = compFlag; } var enumerator = flaggedContainers[targetFlag].GetEnumerator(); while (enumerator.MoveNext()) { var current = enumerator.Current; IMyInventory inv = current.GetInventory(); inv.GetItems(itemsScratchPad); for (int i = 0; i < itemsScratchPad.Count; i++) { if (itemsScratchPad[i].Type == type) { for (int j = 0; j < myRequesterSet.Count; j++) { fixedAmt = TransferAsMuchAsPossible(inv, myRequesterSet[j].GetInventory(), itemsScratchPad[i], fixedAmt); } } } itemsScratchPad.Clear(); } }
private string GetBlueprintName(MyItemType itemType) { switch (itemType.TypeId) { case TypeIdComponents: switch (itemType.SubtypeId) { case SubTypeIdConstructionComponent: case SubTypeIdComputer: case SubTypeIdDetector: case SubTypeIdMotor: case SubTypeIdGirder: case SubTypeIdRadioCommunication: return(string.Format("{0}Component", itemType.SubtypeId)); } break; } return(itemType.SubtypeId); }