private static void LoadSerializers() { MyObjectBuilder_Base loaded = null; try { MyObjectBuilderSerializer.DeserializeXML(String.Empty, out loaded); } catch { } }
public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1) { var maxAmount = ComputeAmountThatFits(objectBuilder.GetId()); var restAmount = amount; if (amount <= maxAmount) { foreach (MyInventoryBase inventory in m_children.Reader) { var availableSpace = inventory.ComputeAmountThatFits(objectBuilder.GetId()); if (availableSpace > restAmount) { availableSpace = restAmount; } if (availableSpace > 0) { if (inventory.AddItems(availableSpace, objectBuilder)) { restAmount -= availableSpace; } } } } return(restAmount == 0); }
public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder) { MyFixedPoint point = this.ComputeAmountThatFits(objectBuilder.GetId(), 0f, 0f); MyFixedPoint point2 = amount; if (amount <= point) { foreach (MyInventoryBase base2 in this.m_children.Reader) { MyFixedPoint point3 = base2.ComputeAmountThatFits(objectBuilder.GetId(), 0f, 0f); if (point3 > point2) { point3 = point2; } if ((point3 > 0) && base2.AddItems(point3, objectBuilder)) { point2 -= point3; } if (point2 == 0) { break; } } } return(point2 == 0); }
public virtual void Init(MyObjectBuilder_Base objectBuilder, MyEntityStat parentStat) { m_parentStat = parentStat; var builder = objectBuilder as MyObjectBuilder_EntityStatRegenEffect; if (builder == null) { return; } Debug.Assert(builder.Interval > 0f); if (builder.Interval <= 0f) { return; } m_amount = builder.TickAmount; m_interval = builder.Interval; m_maxRegenRatio = builder.MaxRegenRatio; m_minRegenRatio = builder.MinRegenRatio; m_duration = builder.Duration - (builder.AliveTime / 1000); ResetRegenTime(); }
private static bool DeserializeXML(Stream reader, out MyObjectBuilder_Base objectBuilder, Type builderType) { Debug.Assert(typeof(MyObjectBuilder_Base).IsAssignableFrom(builderType)); Debug.Assert(reader != null); Debug.Assert(builderType != null); objectBuilder = null; try { XmlSerializer serializer = m_serializersByType[builderType]; Debug.Assert(serializer != null); objectBuilder = (MyObjectBuilder_Base)serializer.Deserialize(XmlReader.Create(reader, new XmlReaderSettings() { CheckCharacters = false })); } catch (Exception e) { MyLog.Default.WriteLine("ERROR: Exception during objectbuilder read! (xml): " + builderType.Name); MyLog.Default.WriteLine(e); if (Debugger.IsAttached) { Debugger.Break(); } return(false); } return(true); }
public virtual void Init(MyObjectBuilder_Base objectBuilder) { var builder = (MyObjectBuilder_EntityStat)objectBuilder; MyEntityStatDefinition definition; MyDefinitionManager.Static.TryGetDefinition <MyEntityStatDefinition>(new MyDefinitionId(builder.TypeId, builder.SubtypeId), out definition); Debug.Assert(definition != null); StatDefinition = definition; m_maxValue = builder.MaxValue * 100.0f; m_minValue = 0.0f; m_currentValue = builder.Value * m_maxValue; m_lastSyncValue = m_currentValue; m_statId = MyStringHash.GetOrCompute(definition.Name); if (builder.Effects != null) { foreach (var effectBuilder in builder.Effects) { AddEffect(effectBuilder); } } }
private void removePilotToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Sector sector = (MyObjectBuilder_Sector)node.Parent.Parent.Tag; Console.WriteLine("in method"); if (node.Nodes.ContainsKey("Pilot")) { Console.WriteLine("Contains Pilot"); TreeNode pilotNode = node.Nodes[node.Nodes.IndexOfKey("Pilot")]; MyObjectBuilder_Cockpit cockpit = (MyObjectBuilder_Cockpit)pilotNode.Tag; long Pilot_id = 0; if (cockpit.Pilot != null) { DialogResult dialogResult = MessageBox.Show("Overwrite \"" + SectorTree.SelectedNode.Parent.Parent.Text + "\"?", "Save", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { MyObjectBuilder_Character pilot = (MyObjectBuilder_Character)cockpit.Pilot; MyObjectBuilder_Character newPilot = (MyObjectBuilder_Character)pilot.Clone(); MyPositionAndOrientation newpos = (MyPositionAndOrientation)newPilot.PositionAndOrientation; newpos.Position.X = 0; newpos.Position.Y = 0; newpos.Position.Z = 0; newPilot.PositionAndOrientation = newpos; newPilot.AutoenableJetpackDelay = 0; newPilot.JetpackEnabled = true; newPilot.Battery.ProducerEnabled = true; cockpit.Pilot = null; sector.SectorObjects.Add(newPilot); Pilot_id = newPilot.EntityId; string file = Path.Combine(this.saves_path, SectorTree.SelectedNode.Parent.Parent.Text, "SANDBOX_0_0_0_.sbs"); string backupfile = Path.Combine(this.saves_path, SectorTree.SelectedNode.Parent.Parent.Text, "SANDBOX_0_0_0_.BAK2"); if (File.Exists(backupfile)) { File.Delete(backupfile); } File.Move(file, backupfile); label1.Text = "Saving..."; MyObjectBuilder_Sector mySector = (MyObjectBuilder_Sector)SectorTree.SelectedNode.Parent.Parent.Tag; using (FileStream sr = File.Open(file, FileMode.Create)) { MyObjectBuilder_Base.SerializeXML(sr, mySector); sr.Dispose(); } //now update the sbc file String sbcfile = Path.Combine(this.saves_path, node.Parent.Parent.Text, "Sandbox.sbc"); XDocument sbcFile = XDocument.Load(sbcfile); sbcFile.Root.SetElementValue("ControlledObject", Pilot_id); sbcFile.Save(sbcfile); this.create_tree(node.Parent.Parent, mySector); label1.Text = ""; } else { return; } } } }
public static bool SerializeXML(Stream writeTo, MyObjectBuilder_Base objectBuilder, XmlCompression compress = XmlCompression.Uncompressed, Type serializeAsType = null) { try { if (compress == XmlCompression.Gzip) { SerializeGZippedXMLInternal(writeTo, objectBuilder, serializeAsType); } else if (compress == XmlCompression.Uncompressed) { SerializeXMLInternal(writeTo, objectBuilder, serializeAsType); } else { Debug.Assert(false, "Unhandled XML compression type during object builder serialization"); } } catch (Exception e) { MyLog.Default.WriteLine("Error during serialization."); MyLog.Default.WriteLine(e.ToString()); return(false); } return(true); }
private void BTN_InventoryItem_Add_Click(object sender, EventArgs e) { if (CMB_ItemType.SelectedItem == null) { return; } if (Amount <= 0.0f) { return; } try { MyObjectBuilder_InventoryItem objectBuilder = MyObjectBuilder_Base.CreateNewObject <MyObjectBuilder_InventoryItem>(); objectBuilder.Content = MyObjectBuilder_Base.CreateNewObject(SelectedType.TypeId, SelectedType.SubtypeId); objectBuilder.Amount = Amount; InventoryItemEntity newItem = new InventoryItemEntity(objectBuilder); Container.NewEntry(newItem); this.Close(); } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); } }
//export ship private void exportToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = saveFileDialog2.ShowDialog(); if (result == DialogResult.OK) { string filename = saveFileDialog2.FileName; TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Base myBase = (MyObjectBuilder_Base)node.Tag; switch (myBase.TypeId) { case MyObjectBuilderTypeEnum.CubeGrid: using (FileStream sr = File.Open(filename, FileMode.Create)) { MyObjectBuilder_Base.SerializeXML(sr, (MyObjectBuilder_CubeGrid)SectorTree.SelectedNode.Tag); } break; case MyObjectBuilderTypeEnum.VoxelMap: using (FileStream sr = File.Open(filename, FileMode.Open)) { MyObjectBuilder_Base.SerializeXML(sr, (MyObjectBuilder_VoxelMap)SectorTree.SelectedNode.Tag); } break; } } }
public virtual void Init(MyObjectBuilder_Base objectBuilder) { MyEntityStatDefinition definition; MyObjectBuilder_EntityStat stat = (MyObjectBuilder_EntityStat)objectBuilder; MyDefinitionManager.Static.TryGetDefinition <MyEntityStatDefinition>(new MyDefinitionId(stat.TypeId, stat.SubtypeId), out definition); this.StatDefinition = definition; this.m_maxValue = definition.MaxValue; this.m_minValue = definition.MinValue; this.m_currentValue = stat.Value * this.m_maxValue; this.m_defaultValue = definition.DefaultValue; this.m_lastSyncValue = this.m_currentValue; this.m_statId = MyStringHash.GetOrCompute(definition.Name); this.m_regenAmountMultiplier = stat.StatRegenAmountMultiplier; this.m_regenAmountMultiplierDuration = stat.StatRegenAmountMultiplierDuration; this.m_regenAmountMultiplierTimeStart = MySandboxGame.TotalGamePlayTimeInMilliseconds; this.m_regenAmountMultiplierTimeAlive = 0; this.m_regenAmountMultiplierActive = this.m_regenAmountMultiplierDuration > 0f; this.ClearEffects(); if (stat.Effects != null) { foreach (MyObjectBuilder_EntityStatRegenEffect effect in stat.Effects) { this.AddEffect(effect); } } }
public static T CreateEntity <T>(MyObjectBuilder_Base builder) where T : MyEntity { T entity = m_objectFactory.CreateInstance <T>(builder.TypeId); AddScriptGameLogic(entity, builder.GetType(), builder.SubtypeName); MyEntities.RaiseEntityCreated(entity); return(entity); }
private static void SerializeGZippedXMLInternal(Stream writeTo, MyObjectBuilder_Base objectBuilder, Type serializeAsType = null) { using (GZipStream gz = new GZipStream(writeTo, CompressionMode.Compress, true)) using (BufferedStream buffer = new BufferedStream(gz, 0x8000)) { SerializeXMLInternal(buffer, objectBuilder, serializeAsType); } }
public void Init(MyLogicalEnvironmentSectorBase sector, MyObjectBuilder_Base ob) { if (ob != null) { m_disabledItems.UnionWith(((MyObjectBuilder_DummyEnvironmentModule)ob).DisabledItems); } m_sector = sector; }
public static T CreateEntity <T>(MyObjectBuilder_Base builder) where T : MyEntity { ProfilerShort.Begin("MyEntityFactory.CreateEntity(...)"); T entity = m_objectFactory.CreateInstance <T>(builder.TypeId); AddScriptGameLogic(entity, builder.GetType(), builder.SubtypeName); ProfilerShort.End(); return(entity); }
public static T CreateEntity <T>(MyObjectBuilder_Base builder, bool readyForReplication = true) where T : MyEntity { ProfilerShort.Begin("MyEntityFactory.CreateEntity(...)"); T entity = m_objectFactory.CreateInstance <T>(builder.TypeId); AddScriptGameLogic(entity, builder.GetType(), builder.SubtypeName); entity.IsReadyForReplication = readyForReplication; ProfilerShort.End(); MyEntities.RaiseEntityCreated(entity); return(entity); }
private static double GetMaxVolume(MyObjectBuilder_Base block, MyCubeSize size) { Func <MyCubeSize, MyStringHash, double> volumeFunc; Definitions.MaxInventoryVolume.TryGetValue(block.TypeId, out volumeFunc); if (volumeFunc == null) { return(0); } return(volumeFunc.Invoke(size, block.SubtypeId)); }
private void regenerateIDsToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Base myBase = (MyObjectBuilder_Base)node.Tag; if (myBase.TypeId == MyObjectBuilderTypeEnum.CubeGrid) { MyObjectBuilder_CubeGrid myGrid = (MyObjectBuilder_CubeGrid)myBase; this.regenerateIDs(myGrid); } }
public virtual void Init(MyObjectBuilder_Base objectBuilder) { var builder = objectBuilder as MyObjectBuilder_EntityStat; if (builder == null) { return; } m_minValue = builder.MinValue; m_maxValue = builder.MaxValue; m_currentValue = MathHelper.Clamp(builder.Value, m_minValue, m_maxValue); }
private void cloneToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Base myBase = (MyObjectBuilder_Base)node.Tag; if (myBase.TypeId == MyObjectBuilderTypeEnum.CubeGrid) { MyObjectBuilder_CubeGrid myGrid = this.clone_grid((MyObjectBuilder_CubeGrid)myBase); MyPositionAndOrientation myGridPos = (MyPositionAndOrientation)myGrid.PositionAndOrientation; myGridPos.Position.X = myGridPos.Position.X + 100; node.Parent.Nodes.Add(newCubeGridNode(myGrid)); } }
public override unsafe void Init(MyLogicalEnvironmentSectorBase sector, MyObjectBuilder_Base ob) { base.Init(sector, ob); var penv = (MyPlanetEnvironmentComponent)sector.Owner; if (penv.CollisionCheckEnabled) { m_boxes = penv.GetCollidedBoxes(sector.Id); if (m_boxes != null) { m_boxes = new List <MyOrientedBoundingBoxD>(m_boxes); // duplicate the list so the debug draw works } } var builder = (MyObjectBuilder_StaticEnvironmentModule)ob; if (builder != null) { var newDisabled = builder.DisabledItems; foreach (var item in newDisabled) { if (!m_disabledItems.Contains(item)) { OnItemEnable(item, false); } } m_disabledItems.UnionWith(newDisabled); if (builder.Boxes != null && builder.MinScanned > 0) { m_boxes = builder.Boxes; m_minScannedLod = builder.MinScanned; } } // Postprocess positions so they are local and simplify tests if (m_boxes != null) { var sWorldPos = sector.WorldPos; int cnt = m_boxes.Count; fixed(MyOrientedBoundingBoxD *bb = m_boxes.GetInternalArray()) for (int i = 0; i < cnt; ++i) { bb[i].Center -= sWorldPos; } } }
public static MyObjectBuilder_Base Clone(MyObjectBuilder_Base toClone) { MyObjectBuilder_Base clone = null; using (var stream = new MemoryStream()) { SerializeXMLInternal(stream, toClone); stream.Position = 0; DeserializeXML(stream, out clone, toClone.GetType()); } return(clone); }
private void moveToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Base myBase = (MyObjectBuilder_Base)node.Tag; if (myBase.TypeId == MyObjectBuilderTypeEnum.CubeGrid) { MyObjectBuilder_CubeGrid myGrid = (MyObjectBuilder_CubeGrid)myBase; Form2 newform = new Form2(this); MyPositionAndOrientation pos = (MyPositionAndOrientation)myGrid.PositionAndOrientation; newform.Show(); newform.setVals(pos.Position.X, pos.Position.Y, pos.Position.Z); } }
public static T CreateEntity <T>(MyObjectBuilder_Base builder) where T : MyEntity { ProfilerShort.Begin("MyEntityFactory.CreateEntity(...)"); T entity = m_objectFactory.CreateInstance <T>(builder.TypeId); var scriptManager = Sandbox.Game.World.MyScriptManager.Static; var builderType = builder.GetType(); if (scriptManager != null && scriptManager.EntityScripts.ContainsKey(builderType)) { entity.GameLogic = (MyGameLogicComponent)Activator.CreateInstance(scriptManager.EntityScripts[builderType]); } ProfilerShort.End(); return(entity); }
public virtual void Init(MyObjectBuilder_Base objectBuilder, MyEntityStat parentStat) { this.m_parentStat = parentStat; MyObjectBuilder_EntityStatRegenEffect effect = objectBuilder as MyObjectBuilder_EntityStatRegenEffect; if ((effect != null) && (effect.Interval > 0f)) { this.m_amount = effect.TickAmount; this.m_interval = effect.Interval; this.m_maxRegenRatio = effect.MaxRegenRatio; this.m_minRegenRatio = effect.MinRegenRatio; this.m_duration = effect.Duration - (effect.AliveTime / 1000f); this.ResetRegenTime(); } }
public static string Serialize <T>(MyObjectBuilder_Base item) where T : MyObjectBuilder_Base { using (var outStream = new MemoryStream()) { if (MyObjectBuilderSerializer.SerializeXML(outStream, item)) { outStream.Position = 0; StreamReader sw = new StreamReader(outStream); return(sw.ReadToEnd()); } } return(null); }
public T NewEntry <T>(MyObjectBuilder_Base source) where T : BaseObject { if (!IsMutable) { return(default(T)); } var newEntry = (T)Activator.CreateInstance(typeof(T), new object[] { source }); GetInternalData().Add(m_definitions.Count, newEntry); m_changed = true; return(newEntry); }
public void setPosition(float x, float y, float z) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Base myBase = (MyObjectBuilder_Base)node.Tag; if (myBase.TypeId == MyObjectBuilderTypeEnum.CubeGrid) { MyObjectBuilder_CubeGrid myGrid = (MyObjectBuilder_CubeGrid)myBase; MyPositionAndOrientation pos = (MyPositionAndOrientation)myGrid.PositionAndOrientation; pos.Position.X = x; pos.Position.Y = y; pos.Position.Z = z; myGrid.PositionAndOrientation = pos; } }
//###################################################################### new stuff below this line ######################// private MyObjectBuilder_CubeGrid clone_grid(MyObjectBuilder_CubeGrid old_grid) { using (MemoryStream input_stream = new MemoryStream()) { MyObjectBuilder_Base.SerializeXML(input_stream, old_grid); MyObjectBuilder_CubeGrid new_grid = (MyObjectBuilder_CubeGrid)MyObjectBuilder_Base.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid); using (MemoryStream output_stream = new MemoryStream()){ input_stream.CopyTo(output_stream); output_stream.Seek(0, 0); MyObjectBuilder_Base.DeserializeXML(output_stream, out new_grid); } return(new_grid); } }
public override void UpdateBeforeSimulation100() { var myEntity = Entity as MyEntity; var inv0 = myEntity.GetInventory(0); if (GuidedMissileCore.GuidedMissileTargeterAmmo.HasValue) { if (inv0.GetItemAmount(GuidedMissileCore.GuidedMissileTargeterAmmo.Value) < 10) { MyObjectBuilder_Base myObjectBuilderPhysicalObject = (MyObjectBuilder_Base)MyObjectBuilderSerializer.CreateNewObject(GuidedMissileCore.GuidedMissileTargeterAmmo.Value); inv0.AddItems(10, myObjectBuilderPhysicalObject); } } base.UpdateBeforeSimulation100(); }
public void DebugAddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder) { if (!MyFinalBuildConstants.IS_OFFICIAL) { MyMultiplayer.RaiseEvent(this, x => x.DebugAddItems_Implementation, amount, objectBuilder); } else { Trace.Fail("DebugAddItems not supported in official builds (it would be cheating)"); } }
bool IMyComponentInventory.AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index) { return AddItems(amount, objectBuilder, index); }
public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1) { var maxAmount = ComputeAmountThatFits(objectBuilder.GetId()); var restAmount = amount; if (amount <= maxAmount) { foreach (MyInventoryBase inventory in m_children.Reader) { var availableSpace = inventory.ComputeAmountThatFits(objectBuilder.GetId()); if (availableSpace > restAmount) { availableSpace = restAmount; } if (availableSpace > 0) { if (inventory.AddItems(availableSpace, objectBuilder)) { restAmount -= availableSpace; } } } } return restAmount == 0; }
private static void SaveSandbox( MyObjectBuilder_Base objectBuilder, string savePath, out ulong fileSize ) { string path = Path.Combine(savePath, "Sandbox.sbc"); MyObjectBuilderSerializer.SerializeXML(path, false, objectBuilder, out fileSize); }
void SwitchToWeaponSuccess(MyDefinitionId? weapon, MyObjectBuilder_Base weaponObjectBuilder, long weaponEntityId) { SwitchToWeaponInternal(weapon, false); }
public bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1) { Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject, "This type of inventory can't add other types than PhysicalObjects!"); MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject; if (physicalObjectBuilder == null) { return false; } if (amount == 0) return false; if (!CanItemsBeAdded(amount, physicalObjectBuilder.GetObjectId())) return false; if (Sync.IsServer) { if (MyPerGameSettings.ConstrainInventory()) AffectAddBySurvival(ref amount, physicalObjectBuilder); if (amount == 0) return false; AddItemsInternal(amount, physicalObjectBuilder, index); SyncObject.SendAddItemsAnnounce(this, amount, physicalObjectBuilder, index); } else SyncObject.SendAddItemsRequest(this, index, amount, physicalObjectBuilder); return true; }
/// <summary> /// Find the physical object of the specified name or partial name. /// </summary> /// <param name="itemName">The name of the physical object to find.</param> /// <param name="objectBuilder">The object builder of the physical object, ready for use.</param> /// <param name="options">Returns a list of potential matches if there was more than one of the same or partial name.</param> /// <returns>Returns true if a single exact match was found.</returns> public static bool FindPhysicalParts(string[] _oreNames, string[] _ingotNames, string[] _physicalItemNames, MyPhysicalItemDefinition[] _physicalItems, string itemName, out MyObjectBuilder_Base objectBuilder, out string[] options) { var itemNames = itemName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // prefix the search term with 'ore' to find this ore name. if (itemNames.Length > 1 && itemNames[0].Equals("ore", StringComparison.InvariantCultureIgnoreCase)) { var findName = itemName.Substring(4).Trim(); var exactMatchOres = _oreNames.Where(ore => ore.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToArray(); if (exactMatchOres.Length == 1) { objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = exactMatchOres[0] }; options = new string[0]; return true; } else if (exactMatchOres.Length > 1) { objectBuilder = null; options = exactMatchOres; return false; } var partialMatchOres = _oreNames.Where(ore => ore.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray(); if (partialMatchOres.Length == 1) { objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = partialMatchOres[0] }; options = new string[0]; return true; } else if (partialMatchOres.Length > 1) { objectBuilder = null; options = partialMatchOres; return false; } objectBuilder = null; options = new string[0]; return false; } // prefix the search term with 'ingot' to find this ingot name. if (itemNames.Length > 1 && itemNames[0].Equals("ingot", StringComparison.InvariantCultureIgnoreCase)) { var findName = itemName.Substring(6).Trim(); var exactMatchIngots = _ingotNames.Where(ingot => ingot.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToArray(); if (exactMatchIngots.Length == 1) { objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = exactMatchIngots[0] }; options = new string[0]; return true; } else if (exactMatchIngots.Length > 1) { objectBuilder = null; options = exactMatchIngots; return false; } var partialMatchIngots = _ingotNames.Where(ingot => ingot.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray(); if (partialMatchIngots.Length == 1) { objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = partialMatchIngots[0] }; options = new string[0]; return true; } else if (partialMatchIngots.Length > 1) { objectBuilder = null; options = partialMatchIngots; return false; } objectBuilder = null; options = new string[0]; return false; } // full name match. var res = _physicalItemNames.FirstOrDefault(s => s != null && s.Equals(itemName, StringComparison.InvariantCultureIgnoreCase)); // need a good method for finding partial name matches. if (res == null) { var matches = _physicalItemNames.Where(s => s != null && s.StartsWith(itemName, StringComparison.InvariantCultureIgnoreCase)).Distinct().ToArray(); if (matches.Length == 1) { res = matches.FirstOrDefault(); } else { matches = _physicalItemNames.Where(s => s != null && s.IndexOf(itemName, StringComparison.InvariantCultureIgnoreCase) >= 0).Distinct().ToArray(); if (matches.Length == 1) { res = matches.FirstOrDefault(); } else if (matches.Length > 1) { objectBuilder = null; options = matches; return false; } } } if (res != null) { var item = _physicalItems[Array.IndexOf(_physicalItemNames, res)]; if (item != null) { objectBuilder = MyObjectBuilderSerializer.CreateNewObject(item.Id.TypeId, item.Id.SubtypeName); options = new string[0]; return true; } } objectBuilder = null; options = new string[0]; return false; }
public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1, bool stack = true) { Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject, "This type of inventory can't add other types than PhysicalObjects!"); MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject; if (physicalObjectBuilder == null) { return false; } if (amount == 0) return false; if (!CanItemsBeAdded(amount, physicalObjectBuilder.GetObjectId())) return false; if (Sync.IsServer) { if (MyPerGameSettings.ConstrainInventory()) AffectAddBySurvival(ref amount, physicalObjectBuilder); if (amount == 0) return false; AddItemsInternal(amount, physicalObjectBuilder, index, null, stack); } return true; }
public static MyGuiControlBase CreateGuiControl(MyObjectBuilder_Base builder) { return m_objectFactory.CreateInstance(builder.TypeId); }
public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder) { return AddItems(amount, objectBuilder, null, -1); }
private bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, uint? itemId, int index = -1) { if (amount == 0) return false; Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject || (MyFakes.ENABLE_COMPONENT_BLOCKS && objectBuilder is MyObjectBuilder_CubeBlock), "This type of inventory can't add other types than PhysicalObjects!"); MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject; MyDefinitionId defId = objectBuilder.GetId(); if (MyFakes.ENABLE_COMPONENT_BLOCKS) { if (physicalObjectBuilder == null) { physicalObjectBuilder = new MyObjectBuilder_BlockItem(); (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = defId; } else { MyCubeBlockDefinition blockDef = MyDefinitionManager.Static.TryGetComponentBlockDefinition(defId); if (blockDef != null) { physicalObjectBuilder = new MyObjectBuilder_BlockItem(); (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = blockDef.Id; } } } if (physicalObjectBuilder == null) return false; defId = physicalObjectBuilder.GetObjectId(); MyFixedPoint fittingAmount = ComputeAmountThatFits(defId); if (fittingAmount < amount) return false; if (Sync.IsServer) { if (MyPerGameSettings.ConstrainInventory()) AffectAddBySurvival(ref amount, physicalObjectBuilder); if (amount == 0) return false; AddItemsInternal(amount, physicalObjectBuilder, itemId, index); } return true; }
/// <summary> /// Adds item to inventory /// </summary> /// <param name="amount"></param> /// <param name="objectBuilder"></param> /// <param name="index"></param> /// <returns>true if items were added, false if items didn't fit</returns> public abstract bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1);
/// <summary> /// Find the physical object of the specified name or partial name. /// </summary> /// <param name="itemName">The name of the physical object to find.</param> /// <param name="objectBuilder">The object builder of the physical object, ready for use.</param> /// <param name="options">Returns a list of potential matches if there was more than one of the same or partial name.</param> /// <returns>Returns true if a single exact match was found.</returns> public static bool FindPhysicalParts(string itemName, out MyObjectBuilder_Base objectBuilder, out Dictionary<string, MyPhysicalItemDefinition> options) { BuildComponentLists(); itemName = itemName.Trim(); var itemNames = itemName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // prefix the search term with 'ore' to find this ore name. if (itemNames.Length > 1 && itemNames[0].Equals("ore", StringComparison.InvariantCultureIgnoreCase)) { var findName = itemName.Substring(4).Trim(); var exactMatchOres = _oreList.Where(ore => ore.Value.Id.SubtypeName.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (exactMatchOres.Count == 1) { objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = exactMatchOres.First().Value.Id.SubtypeName }; options = new Dictionary<string, MyPhysicalItemDefinition>(); return true; } if (exactMatchOres.Count > 1) { objectBuilder = null; options = exactMatchOres; return false; } var partialMatchOres = _oreList.Where(ore => ore.Value.Id.SubtypeName.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (partialMatchOres.Count == 1) { objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = partialMatchOres.First().Value.Id.SubtypeName }; options = new Dictionary<string, MyPhysicalItemDefinition>(); return true; } if (partialMatchOres.Count > 1) { objectBuilder = null; options = partialMatchOres; return false; } objectBuilder = null; options = new Dictionary<string, MyPhysicalItemDefinition>(); return false; } // prefix the search term with 'ingot' to find this ingot name. if (itemNames.Length > 1 && itemNames[0].Equals("ingot", StringComparison.InvariantCultureIgnoreCase)) { var findName = itemName.Substring(6).Trim(); var exactMatchIngots = _ingotList.Where(ingot => ingot.Value.Id.SubtypeName.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (exactMatchIngots.Count == 1) { objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = exactMatchIngots.First().Value.Id.SubtypeName }; options = new Dictionary<string, MyPhysicalItemDefinition>(); return true; } if (exactMatchIngots.Count > 1) { objectBuilder = null; options = exactMatchIngots; return false; } var partialMatchIngots = _ingotList.Where(ingot => ingot.Value.Id.SubtypeName.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (partialMatchIngots.Count == 1) { objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = partialMatchIngots.First().Value.Id.SubtypeName }; options = new Dictionary<string, MyPhysicalItemDefinition>(); return true; } if (partialMatchIngots.Count > 1) { objectBuilder = null; options = partialMatchIngots; return false; } objectBuilder = null; options = new Dictionary<string, MyPhysicalItemDefinition>(); return false; } // full name match. var res = _physicalItemNames.FirstOrDefault(s => s.Key != null && s.Key.Equals(itemName, StringComparison.InvariantCultureIgnoreCase)); // need a good method for finding partial name matches. if (res.Key == null) { var matches = _physicalItemNames.Where(s => s.Key != null && s.Key.StartsWith(itemName, StringComparison.InvariantCultureIgnoreCase)).Distinct().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (matches.Count == 1) { res = matches.FirstOrDefault(); } else { matches = _physicalItemNames.Where(s => s.Key != null && s.Key.IndexOf(itemName, StringComparison.InvariantCultureIgnoreCase) >= 0).Distinct().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (matches.Count == 1) { res = matches.FirstOrDefault(); } else if (matches.Count > 1) { objectBuilder = null; options = matches; return false; } } } if (res.Key != null) { if (res.Value != null) { objectBuilder = MyObjectBuilderSerializer.CreateNewObject(res.Value.Id.TypeId, res.Value.Id.SubtypeName); options = new Dictionary<string, MyPhysicalItemDefinition>(); return true; } } objectBuilder = null; options = new Dictionary<string, MyPhysicalItemDefinition>(); return false; }
virtual public bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1) { var maxAmount = ComputeAmountThatFits(objectBuilder.GetId()); var restAmount = amount; if (amount <= maxAmount) { foreach (var inventory in Inventories) { var availableSpace = inventory.ComputeAmountThatFits(objectBuilder.GetId()); if (availableSpace > restAmount) { availableSpace = restAmount; } if (inventory.AddItems(availableSpace, objectBuilder)) { restAmount -= availableSpace; } } } return restAmount == 0; }
public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1, bool stack = true) { return AddItems(amount, objectBuilder, null, index, stack); }
public bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, uint? itemId, int index = -1, bool stack = true) { Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject, "This type of inventory can't add other types than PhysicalObjects!"); MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject; if (physicalObjectBuilder == null) { return false; } if (amount == 0) return false; if (!CanItemsBeAdded(amount, physicalObjectBuilder.GetObjectId())) return false; if (MyFakes.ENABLE_GATHERING_SMALL_BLOCK_FROM_GRID) { MyCubeBlockDefinition blockDef = MyDefinitionManager.Static.TryGetComponentBlockDefinition(objectBuilder.GetId()); if (blockDef != null) { physicalObjectBuilder = new MyObjectBuilder_BlockItem(); (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = blockDef.Id; } } if (Sync.IsServer) { if (MyPerGameSettings.ConstrainInventory()) AffectAddBySurvival(ref amount, physicalObjectBuilder); if (amount == 0) return false; AddItemsInternal(amount, physicalObjectBuilder, index, itemId, stack); } return true; }