/// <summary>
 /// Returns if player can build this object
 /// </summary>
 /// <param name="foundationFactory">Foundation factory</param>
 /// <returns></returns>
 public bool CanBuild(MyPrefabFoundationFactory foundationFactory)
 {            
     foreach (IMyBuildingRequirement myBuildingRequirement in BuildingRequirements)
     {
         if (!myBuildingRequirement.Check(foundationFactory))
         {
             return false;
         }
     }
     return true;
 }
        /// <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);
        }
Esempio n. 3
0
        /// <summary>
        /// CreatePrefab
        /// </summary>
        /// <param name="hudLabelText"></param>
        /// <param name="objBuilder"></param>
        /// <returns></returns>
        public MyPrefabBase CreatePrefab(string hudLabelText, MyPrefabContainer prefabContainer, MyMwcObjectBuilder_PrefabBase prefabBuilder)
        {
            Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyPrefabFactory.CreatePrefab");

            MyPrefabConfiguration config = MyPrefabConstants.GetPrefabConfiguration(prefabBuilder.GetObjectBuilderType(), prefabBuilder.GetObjectBuilderId().Value);
            Vector3 relativePosition = MyPrefabContainer.GetRelativePositionInAbsoluteCoords(prefabBuilder.PositionInContainer);
            Matrix prefabLocalOrientation = Matrix.CreateFromYawPitchRoll(prefabBuilder.AnglesInContainer.X, prefabBuilder.AnglesInContainer.Y, prefabBuilder.AnglesInContainer.Z);

            MyPrefabBase prefab = null;
            if (config is MyPrefabConfigurationKinematic)
            {
                prefab = new MyPrefabKinematic(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationLight)
            {
                prefab = new MyPrefabLight(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationLargeWeapon)
            {
                prefab = new MyPrefabLargeWeapon(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationSound)
            {
                prefab = new MyPrefabSound(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationParticles)
            {
                prefab = new MyPrefabParticles(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationLargeShip)
            {
                prefab = new MyPrefabLargeShip(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationHangar)
            {
                prefab = new MyPrefabHangar(prefabContainer);                
            }
            else if(config is MyPrefabConfigurationFoundationFactory)
            {
                prefab = new MyPrefabFoundationFactory(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationSecurityControlHUB) 
            {
                prefab = new MyPrefabSecurityControlHUB(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationBankNode) 
            {
                prefab = new MyPrefabBankNode(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationGenerator) 
            {
                prefab = new MyPrefabGenerator(prefabContainer);                
            }
            else if (config is MyPrefabConfigurationScanner) 
            {
                prefab = new MyPrefabScanner(prefabContainer);
            }
            else if (config is MyPrefabConfigurationCamera)
            {
                prefab = new MyPrefabCamera(prefabContainer);
            }
            else if (config is MyPrefabConfigurationAlarm)
            {
                prefab = new MyPrefabAlarm(prefabContainer);
            }            
            else
            {
                prefab = new MyPrefab(prefabContainer);
                //prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config);
            }
            prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config);

            Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            return prefab;
        }
 /// <summary>
 /// Checks if player meet this requirement
 /// </summary>
 /// <param name="foundationFactory">Foundation factory</param>
 /// <returns></returns>
 public bool Check(MyPrefabFoundationFactory foundationFactory)
 {
     float requiredInventoryItemAmount = foundationFactory.Player.Ship.Inventory.GetTotalAmountOfInventoryItems(ObjectBuilderType, ObjectBuilderId);
     return requiredInventoryItemAmount >= Amount;
 }
 /// <summary>
 /// Checks if player meet this requirement
 /// </summary>
 /// <param name="foundationFactory">Foundation factory</param>
 /// <returns></returns>
 public bool Check(MyPrefabFoundationFactory foundationFactory)
 {
     return MySession.Static.Inventory.Contains(MyMwcObjectBuilderTypeEnum.Blueprint, (int) BlueprintType);
 }
        /// <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;
        }