/// <summary>
        /// Returns objectbuilder of inventory
        /// </summary>
        /// <returns></returns>
        public MyMwcObjectBuilder_Inventory GetObjectBuilder(bool getExactCopy)
        {
            List <MyMwcObjectBuilder_InventoryItem> inventoryItemsObjectBuilders = new List <MyMwcObjectBuilder_InventoryItem>();

            foreach (MyInventoryItem item in m_inventoryItems)
            {
                //MyMwcObjectBuilder_InventoryItem inventoryItemBuilder = new MyMwcObjectBuilder_InventoryItem(item.GetInventoryItemObjectBuilder(getExactCopy), item.Amount);
                MyMwcObjectBuilder_InventoryItem inventoryItemBuilder = item.GetObjectBuilder();
                if (inventoryItemBuilder.ItemObjectBuilder is MyMwcObjectBuilder_PrefabBase)
                {
                    MyMwcObjectBuilder_PrefabBase prefabBuilder = inventoryItemBuilder.ItemObjectBuilder as MyMwcObjectBuilder_PrefabBase;
                    if (prefabBuilder.PrefabHealthRatio == 0f)
                    {
                        prefabBuilder.PrefabHealthRatio = MyGameplayConstants.HEALTH_RATIO_MAX;
                    }
                    if (prefabBuilder.PrefabMaxHealth == 0f)
                    {
                        prefabBuilder.PrefabMaxHealth = MyGameplayConstants.MAXHEALTH_PREFAB;
                    }
                }
                inventoryItemsObjectBuilders.Add(inventoryItemBuilder);
            }
            MyMwcObjectBuilder_Inventory inventoryBuilder = new MyMwcObjectBuilder_Inventory(inventoryItemsObjectBuilders, MaxItems, TemplateType, PriceCoeficient);

            inventoryBuilder.UnlimitedCapacity = UnlimitedCapacity;
            return(inventoryBuilder);
        }
        protected override MyMwcObjectBuilder_Base GetObjectBuilderInternal(bool getExactCopy)
        {
            List <MyMwcObjectBuilder_PrefabBase> prefabs   = new List <MyMwcObjectBuilder_PrefabBase>(m_prefabs.Count);
            MyMwcObjectBuilder_Inventory         inventory = null;

            if (Inventory != null)
            {
                inventory = Inventory.GetObjectBuilder(getExactCopy);
            }
            foreach (MyPrefabBase prefab in m_prefabs)
            {
                MyEntity entity = prefab;
                if (MyEntities.IsMarkedForClose(entity))
                {
                    continue;
                }

                MyMwcObjectBuilder_PrefabBase prefabOld = entity.GetObjectBuilder(getExactCopy) as MyMwcObjectBuilder_PrefabBase;
                prefabs.Add(prefabOld);
            }

            MyMwcObjectBuilder_PrefabContainer objectBuilder
                = new MyMwcObjectBuilder_PrefabContainer(null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, prefabs,
                                                         GetUserID(), Faction, inventory);

            objectBuilder.PositionAndOrientation.Position = this.GetPosition();
            objectBuilder.PositionAndOrientation.Forward  = this.GetOrientation().Forward;
            objectBuilder.PositionAndOrientation.Up       = this.GetOrientation().Up;
            objectBuilder.DisplayName   = DisplayName;
            objectBuilder.UseProperties = UseProperties.GetObjectBuilder();
            objectBuilder.AlarmOn       = AlarmOn;
            objectBuilder.RefillTime    = RefillTime;
            return(objectBuilder);
        }
Exemple #3
0
 private List <MyInventoryItem> GetInventoryItems(MyMwcObjectBuilder_Base objectBuilder)
 {
     m_helperInventoryItems.Clear();
     if (!(objectBuilder is MyMwcObjectBuilder_PrefabBase))
     {
         MyEditor.Static.FoundationFactory.PrefabContainer.Inventory.GetInventoryItems(ref m_helperInventoryItems, objectBuilder);
         //return MyEditor.Static.FoundationFactory.PrefabContainer.Inventory.GetInventoryItems(objectBuilder);
         //return m_helperInventoryItems;
     }
     else
     {
         MyMwcObjectBuilder_PrefabBase prefabBuilder = objectBuilder as MyMwcObjectBuilder_PrefabBase;
         //List<MyInventoryItem> inventoryItems = new List<MyInventoryItem>();
         foreach (MyInventoryItem inventoryItem in MyEditor.Static.FoundationFactory.PrefabContainer.Inventory.GetInventoryItems())
         {
             MyMwcObjectBuilder_Base inventoryItemBuilder = inventoryItem.GetInventoryItemObjectBuilder(false);
             if (inventoryItemBuilder is MyMwcObjectBuilder_PrefabBase)
             {
                 MyMwcObjectBuilder_PrefabBase inventoryPrefabBuilder = inventoryItemBuilder as MyMwcObjectBuilder_PrefabBase;
                 if (inventoryPrefabBuilder.GetObjectBuilderType() == prefabBuilder.GetObjectBuilderType() &&
                     inventoryPrefabBuilder.GetObjectBuilderId() == prefabBuilder.GetObjectBuilderId() &&
                     inventoryPrefabBuilder.FactionAppearance == prefabBuilder.FactionAppearance)
                 {
                     //inventoryItems.Add(inventoryItem);
                     m_helperInventoryItems.Add(inventoryItem);
                 }
             }
         }
         //return inventoryItems;
     }
     return(m_helperInventoryItems);
 }
Exemple #4
0
        protected override void AddPrefabItems(MyTreeViewItem parentItem, MyMwcObjectBuilder_Prefab_AppearanceEnum appearanceTextureEnum, BuildTypesEnum buildType, CategoryTypesEnum categoryType)
        {
            MyMwcLog.WriteLine("GAME AddPrefabItems - START");

            Vector2 itemSize = MyGuiConstants.CHECKBOX_SIZE * 3;

            foreach (MyMwcObjectBuilderTypeEnum enumValue in MyGuiPrefabHelpers.MyMwcPrefabTypesEnumValues)
            {
                foreach (int prefabId in MyMwcObjectBuilder_Base.GetObjectBuilderIDs(enumValue))
                {
                    MyPrefabConfiguration config             = MyPrefabConstants.GetPrefabConfiguration(enumValue, prefabId);
                    MyGuiPrefabHelper     prefabModuleHelper = MyGuiObjectBuilderHelpers.GetGuiHelper(enumValue, prefabId) as MyGuiPrefabHelper;

                    if (config == null)
                    {
                        continue;
                    }

                    if (config.FactionSpecific.HasValue && config.FactionSpecific.Value != appearanceTextureEnum)
                    {
                        continue;
                    }

                    if (config.BuildType == buildType && config.CategoryType == categoryType && config.EnabledInEditor)
                    {
                        MyMwcObjectBuilder_PrefabBase prefabObjectBuilder   = MyPrefabFactory.GetInstance().CreatePrefabObjectBuilder(enumValue, prefabId, appearanceTextureEnum);
                        MyBuildingSpecification       buildingSpecification = MyBuildingSpecifications.GetBuildingSpecification(prefabObjectBuilder);
                        MyTexture2D previewTexture = MyGuiManager.GetPrefabPreviewTexture(enumValue, prefabId, appearanceTextureEnum);
                        AddTreeViewItem(parentItem, prefabModuleHelper.Description, previewTexture, itemSize, MyGuiManager.GetBlankTexture(), MyGuiManager.GetBlankTexture(), MyGuiConstants.CHECKBOX_SIZE, prefabObjectBuilder, buildingSpecification);
                    }
                }
            }

            MyMwcLog.WriteLine("GAME AddPrefabItems - END");
        }
        /// <summary>
        /// Initialize inventory from objectbuilder
        /// </summary>
        /// <param name="inventoryObjectBuilder">Inventory objectbuilder</param>
        public void Init(MyMwcObjectBuilder_Inventory inventoryObjectBuilder, float defaultPriceCoeficient = DEFAULT_PRICE_COEFICIENT)
        {
            Debug.Assert(inventoryObjectBuilder != null);

            if (inventoryObjectBuilder.MaxItems == 0)
            {
                MaxItems = MyInventory.DEFAULT_MAX_ITEMS;
            }
            else
            {
                MaxItems = inventoryObjectBuilder.MaxItems;
            }

            PriceCoeficient   = inventoryObjectBuilder.PriceCoeficient != null ? inventoryObjectBuilder.PriceCoeficient.Value : defaultPriceCoeficient;
            TemplateType      = inventoryObjectBuilder.TemplateType;
            UnlimitedCapacity = inventoryObjectBuilder.UnlimitedCapacity;

            if (inventoryObjectBuilder.InventoryItems != null && inventoryObjectBuilder.InventoryItems.Count > 0)
            {
                RemoveAllInventoryItemsPrivate(true);
                List <MyInventoryItem> inventoryItemsToAdd = new List <MyInventoryItem>();
                foreach (MyMwcObjectBuilder_InventoryItem inventoryItemObjectBuilder in inventoryObjectBuilder.InventoryItems)
                {
                    if (inventoryItemsToAdd.Count >= MaxItems && !UnlimitedCapacity)
                    {
                        break;
                    }
                    // if old foundation factory is in inventory, we replace it with new prefab foundation factory
                    if (inventoryItemObjectBuilder.ItemObjectBuilder is MyMwcObjectBuilder_FoundationFactory)
                    {
                        inventoryItemObjectBuilder.ItemObjectBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT);
                    }

                    // hack: we need set default prefab health and max health to prefab object builder
                    if (inventoryItemObjectBuilder.ItemObjectBuilder is MyMwcObjectBuilder_PrefabBase)
                    {
                        MyMwcObjectBuilder_PrefabBase prefabBuilder = inventoryItemObjectBuilder.ItemObjectBuilder as MyMwcObjectBuilder_PrefabBase;
                        if (prefabBuilder.PrefabHealthRatio == 0f)
                        {
                            prefabBuilder.PrefabHealthRatio = MyGameplayConstants.HEALTH_RATIO_MAX;
                        }
                        if (prefabBuilder.PrefabMaxHealth == 0f)
                        {
                            prefabBuilder.PrefabMaxHealth = MyGameplayConstants.MAXHEALTH_PREFAB;
                        }
                    }

                    MyInventoryItem inventoryItem = CreateInventoryItemFromObjectBuilder(inventoryItemObjectBuilder.ItemObjectBuilder, inventoryItemObjectBuilder.Amount);
                    inventoryItem.TemporaryFlags = inventoryItemObjectBuilder.TemporaryFlags;
                    inventoryItemsToAdd.Add(inventoryItem);
                }
                AddInventoryItems(inventoryItemsToAdd);
            }
            else
            {
                ClearInventoryItems(true);
            }
        }
        //public void AssignToFoundationFactory(MyFoundationFactory foundationFactory)
        //{
        //    Debug.Assert(m_prefabTypeSingleFlagsCount[(int) PrefabTypesFlagEnum.FoundationFactory] == 0);

        //    m_prefabTypesFlag = m_prefabTypesFlag | PrefabTypesFlagEnum.FoundationFactory;
        //    m_prefabTypeSingleFlagsCount[(int)PrefabTypesFlagEnum.FoundationFactory]++;
        //    if (MyEntities.Exist(this))
        //    {
        //        MyEntities.Remove(this);
        //    }

        //    foundationFactory.AddChild(this, true);
        //}

        //  This method is responsible for adding new prefab modules into container
        public MyEntity CreateAndAddPrefab(string hudLabelText, MyMwcObjectBuilder_PrefabBase prefabBuilder)
        {
            if (m_prefabs.Count + 1 >= m_prefabs.Capacity)
            {
                return(null);
            }

            MyPrefabBase prefab = MyPrefabFactory.GetInstance().CreatePrefab(hudLabelText, this, prefabBuilder);

            this.AddPrefab(prefab);
            return((MyEntity)prefab);
        }
        /// <summary>
        /// CreatePrefabObjectBuilder
        /// </summary>
        /// <param name="prefabCategory"></param>
        /// <returns></returns>
        public MyMwcObjectBuilder_PrefabBase CreatePrefabObjectBuilder(MyMwcObjectBuilderTypeEnum prefabType, int prefabId, MyMwcObjectBuilder_Prefab_AppearanceEnum textureEnum)
        {
            MyGameplayProperties  gameplayProperties = MyGameplayConstants.GetGameplayProperties(prefabType, prefabId, MyMwcObjectBuilder_FactionEnum.Euroamerican);
            MyPrefabConfiguration prefabConfig       = MyPrefabConstants.GetPrefabConfiguration(prefabType, prefabId);
            MyMwcVector3Short     pos = new MyMwcVector3Short(0, 0, 0);

            MyMwcObjectBuilder_PrefabBase objBuilder = MyMwcObjectBuilder_Base.CreateNewObject(prefabType, prefabId) as MyMwcObjectBuilder_PrefabBase;

            objBuilder.PositionInContainer = pos;
            objBuilder.AnglesInContainer   = Vector3.Zero;
            objBuilder.PrefabHealthRatio   = MyGameplayConstants.HEALTH_RATIO_MAX;
            objBuilder.PrefabMaxHealth     = null;
            objBuilder.FactionAppearance   = textureEnum;
            objBuilder.IsDestructible      = gameplayProperties.IsDestructible;
            if (prefabConfig.DisplayHud)
            {
                objBuilder.PersistentFlags |= MyPersistentEntityFlags.DisplayOnHud;
            }

            return(objBuilder);
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyMwcObjectBuilder_PrefabAlarm objectBuilderAlarm = objectBuilder as MyMwcObjectBuilder_PrefabAlarm;
            MyPrefabConfigurationAlarm     alarmConfig        = prefabConfig as MyPrefabConfigurationAlarm;

            m_modelLod0On = MyModels.GetModelOnlyData(alarmConfig.ModelLod0EnumOn);
            if (alarmConfig.ModelLod1EnumOn != null)
            {
                m_modelLod1On = MyModels.GetModelOnlyData(alarmConfig.ModelLod1EnumOn.Value);
            }
            m_modelLod0Off = m_modelLod0;
            m_modelLod1Off = m_modelLod1;

            Flags |= EntityFlags.EditableInEditor;
            InitLight();
        }
Exemple #9
0
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            //Physics.RemoveAllElements();

            //float raidus = ModelLod0.BoundingSphere.Radius;
            //Vector3 min = new Vector3(-raidus, -raidus, -raidus);
            //Vector3 max = new Vector3(raidus, raidus, raidus);
            //m_localBoundingBox = new BoundingBox(min, max);

            UseProperties = new MyUseProperties(MyUseType.None, MyUseType.Solo);
            if (objectBuilder.UseProperties == null)
            {
                UseProperties.Init(MyUseType.None, MyUseType.None, 3, 8000, false);
            }
            else
            {
                UseProperties.Init(objectBuilder.UseProperties);
            }
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            m_prefabLightConfig = prefabConfig as MyPrefabConfigurationLight;
            MyMwcObjectBuilder_PrefabLight objectBuilderLight = objectBuilder as MyMwcObjectBuilder_PrefabLight;

            m_light = MyLights.AddLight();

            m_light.LightType = (MyLight.LightTypeEnum)objectBuilderLight.LightType;

            m_light.Start(m_light.LightType, 1);
            m_light.UseInForwardRender = true;


            //grab first dummy and set it as point source
            //since we dont support yet more lights in one prefab. add just the first one
            MyModel model = MyModels.GetModelOnlyDummies(m_prefabLightConfig.ModelLod0Enum);

            m_pointLocalMatrix = Matrix.Identity;
            bool dummyFound = false;

            foreach (KeyValuePair <string, MyModelDummy> pair in model.Dummies)
            {
                if (pair.Key.StartsWith("Dummy", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_pointLocalMatrix = pair.Value.Matrix;
                    dummyFound         = true;
                    break;
                }
            }
            Debug.Assert(dummyFound, "Dummy 'POINT_LIGHT_POS' not found in light prefab model: " + model.AssetName);

            m_light.Color              = objectBuilderLight.PointColor;
            m_light.ReflectorColor     = objectBuilderLight.SpotColor;
            m_light.Falloff            = objectBuilderLight.PointFalloff;
            m_light.ReflectorFalloff   = objectBuilderLight.SpotFalloff;
            m_IntensityMax             = m_light.Intensity = objectBuilderLight.PointIntensity;
            m_light.ReflectorIntensity = ReflectorIntensityMax = objectBuilderLight.SpotIntensity;
            m_light.ReflectorRange     = MathHelper.Clamp(objectBuilderLight.SpotRange, 1, MyLightsConstants.MAX_SPOTLIGHT_RANGE);
            m_light.Range              = MathHelper.Clamp(objectBuilderLight.PointRange, 1, MyLightsConstants.MAX_POINTLIGHT_RADIUS);
            m_light.PointLightOffset   = objectBuilderLight.PointOffset;
            this.FlashOffset           = objectBuilderLight.FlashOffset;

            //to add reflector range to builders
            m_light.SpecularColor        = objectBuilderLight.PointSpecular;
            m_light.ReflectorConeDegrees = objectBuilderLight.SpotAgle;
            m_effect = objectBuilderLight.Effect;
            //m_light.LightOn = true;
            m_lastBlickChange = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            // here set the properties of glare for the prefab light
            m_light.GlareOn         = true;
            m_light.Glare.Type      = MyLightGlare.GlareTypeEnum.Normal;
            m_light.Glare.QuerySize = .8f;
            m_light.ShadowDistance  = objectBuilderLight.ShadowsDistance;
            m_light.Glare.Intensity = m_light.Intensity;
            UpdateEffect();

            CastShadows = false;
            UpdateLightWorldMatrix();
        }
        public override void Init(string hudLabelText, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyMwcObjectBuilder_PrefabLargeShip objectBuilderLargeShip = objectBuilder as MyMwcObjectBuilder_PrefabLargeShip;

            m_owner.Inventory.OnInventoryContentChange += OnInventoryContentChanged;

            Name = objectBuilderLargeShip.Name;

            base.Init(Name, relativePosition, localOrientation, objectBuilder, prefabConfig);
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyMwcObjectBuilder_PrefabScanner objectBuilderScanner = objectBuilder as MyMwcObjectBuilder_PrefabScanner;

            UseProperties = new MyUseProperties(MyUseType.FromHUB, MyUseType.FromHUB | MyUseType.Solo);
            if (objectBuilderScanner.UseProperties == null)
            {
                UseProperties.Init(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB | MyUseType.Solo, 3, 4000, false);
            }
            else
            {
                UseProperties.Init(objectBuilderScanner.UseProperties);
            }

            Size          = objectBuilderScanner.Size;
            Color         = objectBuilderScanner.Color;
            ScanningSpeed = objectBuilderScanner.ScanningSpeed;
            InitScanningPart();

            Flags |= EntityFlags.EditableInEditor;
        }
        //public void AssignToFoundationFactory(MyFoundationFactory foundationFactory)
        //{
        //    Debug.Assert(m_prefabTypeSingleFlagsCount[(int) PrefabTypesFlagEnum.FoundationFactory] == 0);

        //    m_prefabTypesFlag = m_prefabTypesFlag | PrefabTypesFlagEnum.FoundationFactory;
        //    m_prefabTypeSingleFlagsCount[(int)PrefabTypesFlagEnum.FoundationFactory]++;
        //    if (MyEntities.Exist(this)) 
        //    {
        //        MyEntities.Remove(this);
        //    }

        //    foundationFactory.AddChild(this, true);                        
        //}

        //  This method is responsible for adding new prefab modules into container
        public MyEntity CreateAndAddPrefab(string hudLabelText, MyMwcObjectBuilder_PrefabBase prefabBuilder)
        {
            if (m_prefabs.Count + 1 >= m_prefabs.Capacity)
                return null;

            MyPrefabBase prefab = MyPrefabFactory.GetInstance().CreatePrefab(hudLabelText, this, prefabBuilder);

            this.AddPrefab(prefab);
            return (MyEntity) prefab;
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            UseProperties = new MyUseProperties(MyUseType.FromHUB | MyUseType.Solo, MyUseType.None);
            if (objectBuilder.UseProperties == null)
            {
                UseProperties.Init(MyUseType.FromHUB | MyUseType.Solo, MyUseType.None, 0, 1, false);
            }
            else
            {
                UseProperties.Init(objectBuilder.UseProperties);
            }

            Enabled = true;
        }
Exemple #15
0
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            m_prefabSoundConfig = prefabConfig as MyPrefabConfigurationSound;

            MyModel model = MyModels.GetModelOnlyDummies(m_prefabSoundConfig.ModelLod0Enum);

            m_pointLocalMatrix = Matrix.Identity;
            m_cueEnum          = m_prefabSoundConfig.Sound;
            foreach (KeyValuePair <string, MyModelDummy> pair in model.Dummies)
            {
                m_pointLocalMatrix = pair.Value.Matrix;
            }

            if (IsWorking())
            {
                PlaySound();
            }
        }
        /// <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);
        }
Exemple #17
0
 private void AddPrefab(MyMwcObjectBuilder_PrefabBase prefabBuilder)
 {
     MyEditor.Static.CreateFromObjectBuilder(prefabBuilder, Matrix.Identity, MyGuiManager.MouseCursorPosition);
 }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyPrefabConfigurationParticles prefabParticleConfig = prefabConfig as MyPrefabConfigurationParticles;

            m_lastTimeParticle = MyMinerGame.TotalGamePlayTimeInMilliseconds;
            MyModel model = MyModels.GetModelOnlyDummies(prefabParticleConfig.ModelLod0Enum);

            m_pointLocalMatrix = Matrix.Identity;
            foreach (KeyValuePair <string, MyModelDummy> pair in model.Dummies)
            {
                m_pointLocalMatrix = pair.Value.Matrix;
            }

            m_particleEffect             = MyParticlesManager.CreateParticleEffect((int)prefabParticleConfig.EffectID, true);
            m_particleEffect.AutoDelete  = false;
            m_particleEffect.WorldMatrix = WorldMatrix;
        }
 protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
 {
 }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {            
            prefabConfiguration = prefabConfig as MyPrefabConfigurationLargeWeapon;
            MyMwcObjectBuilder_PrefabLargeWeapon largeWeaponBuilder = objectBuilder as MyMwcObjectBuilder_PrefabLargeWeapon;
            weaponType = largeWeaponBuilder.PrefabLargeWeaponType;

            UseProperties = new MyUseProperties(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB);
            if (largeWeaponBuilder.UseProperties == null)
            {
                UseProperties.Init(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB, 1, 4000, false);
            }
            else
            {                
                UseProperties.Init(largeWeaponBuilder.UseProperties);
            }            

            // create & initialize weapon:
            MyLargeShipGunBase.CreateAloneWeapon(ref m_gun, displayName, Vector3.Zero, Matrix.Identity, largeWeaponBuilder, Activated);
            AddChild(m_gun);

            m_gun.PrefabParent = this;
            m_gun.Enabled = IsWorking();
            m_gun.SetRandomRotation();

           // if (largeWeaponBuilder.SearchingDistance == 2000)
             //   largeWeaponBuilder.SearchingDistance = 1000;

            this.LocalMatrix = Matrix.CreateWorld(relativePosition, localOrientation.Forward, localOrientation.Up);
            m_searchingDistance = MathHelper.Clamp(largeWeaponBuilder.SearchingDistance, MyLargeShipWeaponsConstants.MIN_SEARCHING_DISTANCE, MyLargeShipWeaponsConstants.MAX_SEARCHING_DISTANCE); 
            m_targetDetectorCriterias.Add(new MyEntityDetectorCriterium<MySmallShip>(1, IsPossibleTarget, true));
            m_targetsDetector = new MyEntityDetector(true);
            
            m_potentialTargetsDetector = new MyEntityDetector(true);
            m_potentialTargetDetectorCriterias.Add(new MyEntityDetectorCriterium<MySmallShip>(1, IsPotentialTarget, true));
            //m_targetsDetector.OnEntityEnter += OnTargetDetected;
            //m_targetsDetector.OnEntityLeave += OnTargetLost;
            m_targetsDetector.OnNearestEntityChange += OnNearestTargetChange;
            m_potentialTargetsDetector.OnNearestEntityChange += OnNearestPotentialTargetChange;
            //m_targetsDetector.OnEntityPositionChange += OnTargetPositionChanged;
            InitDetector(Activated);
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyMwcObjectBuilder_PrefabGenerator objectBuilderGenerator = objectBuilder as MyMwcObjectBuilder_PrefabGenerator;

            UseProperties = new MyUseProperties(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB | MyUseType.Solo);
            if (objectBuilder.UseProperties == null)
            {
                UseProperties.Init(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB | MyUseType.Solo, 1, 4000, false);
            }
            else
            {
                UseProperties.Init(objectBuilder.UseProperties);
            }
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyMwcObjectBuilder_PrefabSecurityControlHUB objectBuilderSecurityControlHUB = (MyMwcObjectBuilder_PrefabSecurityControlHUB)objectBuilder;

            //m_connetectedEntitiesIds.AddRange(objectBuilderSecurityControlHUB.ConnectedEntities);

            UseProperties = new MyUseProperties(MyUseType.Solo, MyUseType.Solo);
            if (objectBuilderSecurityControlHUB.UseProperties == null)
            {
                UseProperties.Init(MyUseType.Solo, MyUseType.Solo, 1, 4000, false);
            }
            else
            {
                UseProperties.Init(objectBuilderSecurityControlHUB.UseProperties);
            }

            UpdateSound();

            m_needsUpdate = true;
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyMwcObjectBuilder_PrefabFoundationFactory objectBuilderFF = objectBuilder as MyMwcObjectBuilder_PrefabFoundationFactory;

            IsBuilding = objectBuilderFF.IsBuilding;
            m_buildingTimeFromStart = objectBuilderFF.BuildingTimeFromStart;
            if (objectBuilderFF.BuildingObject != null)
            {
                BuildingObject = MyObjectToBuild.CreateFromObjectBuilder(objectBuilderFF.BuildingObject.ObjectBuilder, objectBuilderFF.BuildingObject.Amount);
            }
            if (objectBuilderFF.BuildingQueue != null)
            {
                foreach (MyMwcObjectBuilder_ObjectToBuild buildingQueue in objectBuilderFF.BuildingQueue)
                {
                    BuildingQueue.Add(MyObjectToBuild.CreateFromObjectBuilder(buildingQueue.ObjectBuilder, buildingQueue.Amount));
                }
            }
        }
Exemple #24
0
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            prefabConfiguration = prefabConfig as MyPrefabConfigurationLargeWeapon;
            MyMwcObjectBuilder_PrefabLargeWeapon largeWeaponBuilder = objectBuilder as MyMwcObjectBuilder_PrefabLargeWeapon;

            weaponType = largeWeaponBuilder.PrefabLargeWeaponType;

            UseProperties = new MyUseProperties(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB);
            if (largeWeaponBuilder.UseProperties == null)
            {
                UseProperties.Init(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB, 1, 4000, false);
            }
            else
            {
                UseProperties.Init(largeWeaponBuilder.UseProperties);
            }

            // create & initialize weapon:
            MyLargeShipGunBase.CreateAloneWeapon(ref m_gun, displayName, Vector3.Zero, Matrix.Identity, largeWeaponBuilder, Activated);
            AddChild(m_gun);

            m_gun.PrefabParent = this;
            m_gun.Enabled      = IsWorking();
            m_gun.SetRandomRotation();

            // if (largeWeaponBuilder.SearchingDistance == 2000)
            //   largeWeaponBuilder.SearchingDistance = 1000;

            this.LocalMatrix    = Matrix.CreateWorld(relativePosition, localOrientation.Forward, localOrientation.Up);
            m_searchingDistance = MathHelper.Clamp(largeWeaponBuilder.SearchingDistance, MyLargeShipWeaponsConstants.MIN_SEARCHING_DISTANCE, MyLargeShipWeaponsConstants.MAX_SEARCHING_DISTANCE);
            m_targetDetectorCriterias.Add(new MyEntityDetectorCriterium <MySmallShip>(1, IsPossibleTarget, true));
            m_targetsDetector = new MyEntityDetector(true);

            m_potentialTargetsDetector = new MyEntityDetector(true);
            m_potentialTargetDetectorCriterias.Add(new MyEntityDetectorCriterium <MySmallShip>(1, IsPotentialTarget, true));
            //m_targetsDetector.OnEntityEnter += OnTargetDetected;
            //m_targetsDetector.OnEntityLeave += OnTargetLost;
            m_targetsDetector.OnNearestEntityChange          += OnNearestTargetChange;
            m_potentialTargetsDetector.OnNearestEntityChange += OnNearestPotentialTargetChange;
            //m_targetsDetector.OnEntityPositionChange += OnTargetPositionChanged;
            InitDetector(Activated);
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyPrefabConfigurationKinematic     prefabKinematicConfig = (MyPrefabConfigurationKinematic)prefabConfig;
            MyMwcObjectBuilder_PrefabKinematic kinematicBuilder      = objectBuilder as MyMwcObjectBuilder_PrefabKinematic;

            MyModel model = MyModels.GetModelOnlyDummies(m_config.ModelLod0Enum);

            for (int i = 0; i < prefabKinematicConfig.KinematicParts.Count; i++)
            {
                MyPrefabConfigurationKinematicPart kinematicPart = prefabKinematicConfig.KinematicParts[i];
                MyModelDummy open, close;
                if (model.Dummies.TryGetValue(kinematicPart.m_open, out open) && model.Dummies.TryGetValue(kinematicPart.m_close, out close))
                {
                    float?kinematicPartHealth    = kinematicBuilder.KinematicPartsHealth[i];
                    float?kinematicPartMaxHealth = kinematicBuilder.KinematicPartsMaxHealth[i];
                    uint? kinematicPartEntityId  = kinematicBuilder.KinematicPartsEntityId[i];

                    // if health is not set or not destroyed, then create part
                    if (kinematicPartHealth == null || kinematicPartHealth != 0)
                    {
                        MyPrefabKinematicPart newPart = new MyPrefabKinematicPart(m_owner);
                        if (kinematicPartEntityId.HasValue)
                        {
                            newPart.EntityId = new MyEntityIdentifier(kinematicPartEntityId.Value);
                        }
                        Parts[i] = newPart;
                        newPart.Init(this, kinematicPart, prefabKinematicConfig.m_openTime, prefabKinematicConfig.m_closeTime, (MyModelsEnum)kinematicPart.m_modelMovingEnum, open.Matrix, close.Matrix, prefabKinematicConfig.MaterialType, prefabKinematicConfig.m_soundLooping, prefabKinematicConfig.m_soundOpening, prefabKinematicConfig.m_soundClosing /*, m_groupMask*/, kinematicPartHealth, kinematicPartMaxHealth, Activated);
                    }
                }
            }

            //make handler
            m_sensorHandler = new MyPrefabKinematicSensor(this);
            MySphereSensorElement sensorEl = new MySphereSensorElement();

            sensorEl.Radius                = DETECT_RADIUS;
            sensorEl.LocalPosition         = new Vector3(0, 0, 0);
            sensorEl.DetectRigidBodyTypes  = MyConstants.RIGIDBODY_TYPE_SHIP;
            sensorEl.SpecialDetectingAngle = DETECTION_ANGLE;
            MySensorDesc senDesc = new MySensorDesc();

            senDesc.m_Element            = sensorEl;
            senDesc.m_Matrix             = WorldMatrix;
            senDesc.m_SensorEventHandler = m_sensorHandler;
            m_sensor = new MySensor();
            m_sensor.LoadFromDesc(senDesc);
            MyPhysics.physicsSystem.GetSensorModule().AddSensor(m_sensor);

            GetOwner().UpdateAABB();

            UseProperties = new MyUseProperties(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB);
            if (kinematicBuilder.UseProperties == null)
            {
                UseProperties.Init(MyUseType.FromHUB, MyUseType.FromHUB, 3, 4000, false);
            }
            else
            {
                UseProperties.Init(kinematicBuilder.UseProperties);
            }
            UpdateHudAndCloseStatus();
        }
Exemple #26
0
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyMwcObjectBuilder_PrefabBankNode objectBuilderBankNode = objectBuilder as MyMwcObjectBuilder_PrefabBankNode;

            Cash          = objectBuilderBankNode.Cash;
            UseProperties = new MyUseProperties(MyUseType.None, MyUseType.Solo);
            if (objectBuilderBankNode.UseProperties == null)
            {
                UseProperties.Init(MyUseType.None, MyUseType.Solo, 3, 4000, false);
            }
            else
            {
                UseProperties.Init(objectBuilderBankNode.UseProperties);
            }
            // some default cash for testing
            if (!UseProperties.IsHacked)
            {
                Cash = 8000f;
            }
        }
Exemple #27
0
        //  Read this object from message-in
        internal override bool Read(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion)
        {
            if (base.Read(binaryReader, senderEndPoint, gameVersion) == false)
            {
                return(NetworkError());
            }

            //  TemplateId
            bool?isTemplateId = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (isTemplateId == null)
            {
                return(NetworkError());
            }
            if (isTemplateId.Value)
            {
                TemplateId = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            }
            else
            {
                TemplateId = null;
            }

            //  Container Type
            MyMwcObjectBuilder_PrefabContainer_TypesEnum?containerType = MyMwcMessageIn.ReadObjectBuilderPrefabContainerTypesEnumEx(binaryReader, senderEndPoint);

            if (containerType == null)
            {
                return(NetworkError());
            }
            ContainerType = containerType.Value;
            MyMwcLog.IfNetVerbose_AddToLog("ContainerType: " + ContainerType);

            // Faction
            Faction = (MyMwcObjectBuilder_FactionEnum)MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            // Faction must be defined
            System.Diagnostics.Debug.Assert(Enum.IsDefined(typeof(MyMwcObjectBuilder_FactionEnum), Faction));

            //  Prefabs
            int?countPrefabs = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);

            if (countPrefabs == null)
            {
                return(NetworkError());
            }
            MyMwcLog.IfNetVerbose_AddToLog("countPrefabs: " + countPrefabs);
            Prefabs = new List <MyMwcObjectBuilder_PrefabBase>(countPrefabs.Value);
            for (int i = 0; i < countPrefabs; i++)
            {
                MyMwcObjectBuilder_PrefabBase prefab = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_PrefabBase;
                if (prefab == null)
                {
                    return(NetworkError());
                }
                if (prefab.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
                Prefabs.Add(prefab);
            }

            //  Inventory
            bool?isInventory = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (isInventory == null)
            {
                return(NetworkError());
            }
            if (isInventory.Value)
            {
                Inventory = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_Inventory;
                if (Inventory == null)
                {
                    return(NetworkError());
                }
                if (Inventory.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
            }
            else
            {
                Inventory = null;
            }


            bool?hasDisplayName = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (!hasDisplayName.HasValue)
            {
                return(NetworkError());
            }
            if (hasDisplayName.Value)
            {
                string displayName = MyMwcMessageIn.ReadStringEx(binaryReader, senderEndPoint);
                if (displayName == null)
                {
                    return(NetworkError());
                }
                MyMwcLog.IfNetVerbose_AddToLog("DisplayName: " + displayName);
                DisplayName = displayName;
            }
            else
            {
                MyMwcLog.IfNetVerbose_AddToLog("DisplayName: " + "null");
                DisplayName = null;
            }

            //  Use Properties
            bool?hasUseProperties = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (hasUseProperties == null)
            {
                return(NetworkError());
            }
            if (hasUseProperties.Value)
            {
                UseProperties = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_EntityUseProperties;
                if (UseProperties == null)
                {
                    return(NetworkError());
                }
                if (UseProperties.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
            }
            else
            {
                UseProperties = null;
            }

            //  Alarm On
            bool?alarmOn = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (alarmOn == null)
            {
                return(NetworkError());
            }
            AlarmOn = alarmOn.Value;
            MyMwcLog.IfNetVerbose_AddToLog("AlarmOn: " + AlarmOn);

            //  Refill time
            bool?refillTime = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (refillTime == null)
            {
                return(NetworkError());
            }
            if (refillTime.Value)
            {
                RefillTime = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            }
            else
            {
                RefillTime = null;
            }

            return(true);
        }
Exemple #28
0
        public override void Init(string displayName, Microsoft.Xna.Framework.Vector3 relativePosition, Microsoft.Xna.Framework.Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            m_config = prefabConfig;
            MyPrefabConfigurationKinematicRotating config = (MyPrefabConfigurationKinematicRotating)prefabConfig;

            base.Init(displayName, relativePosition, localOrientation, objectBuilder, prefabConfig);
            Physics.RemoveAllElements();

            // create the box
            MyPhysicsObjects            physobj          = MyPhysics.physicsSystem.GetPhysicsObjects();
            MyRBTriangleMeshElementDesc trianglemeshDesc = physobj.GetRBTriangleMeshElementDesc();

            trianglemeshDesc.SetToDefault();
            trianglemeshDesc.m_Model      = ModelLod0;
            trianglemeshDesc.m_RBMaterial = MyMaterialsConstants.GetMaterialProperties(config.MaterialType).PhysicsMaterial;;


            MyRBTriangleMeshElement trEl = (MyRBTriangleMeshElement)physobj.CreateRBElement(trianglemeshDesc);

            this.Physics = new MyPhysicsBody(this, 1.0f, RigidBodyFlag.RBF_RBO_STATIC)
            {
                MaterialType = config.MaterialType
            };
            this.Physics.Enabled        = true;
            this.Physics.CollisionLayer = MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC;
            this.Physics.AddElement(trEl, true);

            MyModel model = MyModels.GetModelOnlyDummies(m_config.ModelLod0Enum);

            foreach (var dummyKVP in model.Dummies)
            {
                if (dummyKVP.Key.StartsWith("Dummy"))
                {
                    MyModelDummy dummy                         = dummyKVP.Value;
                    MyModelsEnum rotatingPartModel             = MyModels.GetModelEnumByAssetName(dummy.CustomData["LINKEDMODEL"].ToString());
                    MyPrefabKinematicRotatingPart rotatingPart = new MyPrefabKinematicRotatingPart(this.GetOwner());
                    rotatingPart.Init(this, rotatingPartModel, config.MaterialType, dummy.Matrix, config.RotatingVelocity, true, config.SoundLooping, config.SoundOpening, config.SoundClosing);
                    m_parts.Add(rotatingPart);
                }
            }

            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_MISSILE, true);
            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_ALL, true);
            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_MODEL_DEBRIS, true);
            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_VOXEL_DEBRIS, true);
            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC_PART, false);

            NeedsUpdate = false;
            EnabledChanged();
            //Enabled = true;
        }