private static void UnpackMothership() { MyTrace.Send(TraceWindow.Saving, "Player unpacking mothership"); MyInventoryItem item = MySession.Static.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.PrefabContainer, null); if (item != null) { //place largeship //MyMwcObjectBuilder_LargeShip largeShipObjectBuilder = (MyMwcObjectBuilder_LargeShip)inventoryItems[0].GetObjectBuilder(true); MyMwcObjectBuilder_PrefabContainer containerObjectBuilder = (MyMwcObjectBuilder_PrefabContainer)item.GetInventoryItemObjectBuilder(true); // We need to remove id's because mothership container could have same entity id in different sector containerObjectBuilder.RemapEntityIds(new MyEntityIdRemapContext()); MyPrefabContainer container = new MyPrefabContainer(); container.Init(null, containerObjectBuilder, FindMothershipPosition()); MyEntities.Add(container); //CreateFromObjectBuilderAndAdd(null, largeShipObjectBuilder, Matrix.CreateTranslation(MySession.PlayerShip.GetPosition() + new Vector3(100,100,0))); MySession.Static.Inventory.RemoveInventoryItem(item); container.Link(); MyTrace.Send(TraceWindow.Saving, "Player mothership found and unpacked"); } }
/// <summary> /// Creates new foundation factory from player's inventory. When player has no foundation factory in inventory, then returns result false. /// </summary> /// <param name="result">Result of foundation factory creation</param> /// <returns>Instance of new foundation factory</returns> public static MyPrefabFoundationFactory TryCreateFoundationFactory(MyPlayer player, out bool result) { MyPrefabFoundationFactory foundationFactory = null; MyInventoryItem foundationFactoryItem = player.Ship.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT); if (foundationFactoryItem == null) { foundationFactoryItem = player.Ship.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.FoundationFactory, null); } if (foundationFactoryItem == null) { result = false; } else { MyMwcObjectBuilder_PrefabFoundationFactory foundationFactoryBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT) as MyMwcObjectBuilder_PrefabFoundationFactory; MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer( null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, new List<MyMwcObjectBuilder_PrefabBase>(), MyClientServer.LoggedPlayer.GetUserId(), player.Faction, new MyMwcObjectBuilder_Inventory(new List<MyMwcObjectBuilder_InventoryItem>(), 1000)); Matrix ffWorld = Matrix.Identity; ffWorld.Translation = player.Ship.WorldMatrix.Translation + player.Ship.WorldMatrix.Forward * 20; MyPrefabContainer prefabContainer = new MyPrefabContainer(); prefabContainer.Init(null, prefabContainerBuilder, ffWorld); MyEntities.Add(prefabContainer); MyPrefabConfiguration ffConfiguration = MyPrefabConstants.GetPrefabConfiguration(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT); foundationFactory = new MyPrefabFoundationFactory(prefabContainer); foundationFactory.Init(null, new Vector3(0f, 0f, 0f), Matrix.Identity, foundationFactoryBuilder, ffConfiguration); prefabContainer.AddPrefab(foundationFactory); player.Ship.Inventory.RemoveInventoryItemAmount(ref foundationFactoryItem, 1f); result = true; } return foundationFactory; }