Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 4
0
        protected override void OnOkClick(MyGuiControlButton sender)
        {
            CloseScreen();
            var focused = m_groupList.GetFocusedItem();

            if (focused != null)
            {
                var group = focused.Tag as MyMwcObjectBuilder_ObjectGroup;

                IEnumerable <MyMwcObjectBuilder_PrefabBase> prefabs     = group.GetPrefabBuilders(m_entities);
                IEnumerable <MyMwcObjectBuilder_Base>       rootObjects = group.GetRootBuilders(m_entities);
                var objects3d = rootObjects.OfType <MyMwcObjectBuilder_Object3dBase>();

                if (objects3d.Any())
                {
                    MyEditorGizmo.ClearSelection();

                    var basePos  = MyCamera.Position + Matrix.Invert(MyCamera.ViewMatrix).Forward * 100;
                    var firstPos = objects3d.First().PositionAndOrientation.Position;
                    var offset   = basePos - firstPos;

                    foreach (var b in objects3d)
                    {
                        b.PositionAndOrientation.Position += offset;
                        b.ClearEntityId();
                        MyEntity entity = MyEntities.CreateFromObjectBuilderAndAdd(null, b, b.PositionAndOrientation.GetMatrix());
                        MyEditorGizmo.AddEntityToSelection(entity);
                    }
                }

                // Prefabs
                var editedContainer = MyEditor.Static.GetEditedPrefabContainer();
                if (editedContainer == null)
                {
                    MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer(
                        null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, new List <MyMwcObjectBuilder_PrefabBase>(), MyClientServer.LoggedPlayer.GetUserId(),
                        MyMwcObjectBuilder_FactionEnum.Euroamerican, new MyMwcObjectBuilder_Inventory(new List <MyMwcObjectBuilder_InventoryItem>(), MyInventory.DEFAULT_MAX_ITEMS));

                    editedContainer = MyEntities.CreateFromObjectBuilderAndAdd(
                        null, prefabContainerBuilder,
                        Matrix.CreateTranslation(MyCamera.Position + Matrix.Invert(MyCamera.ViewMatrix).Forward * 100)) as MyPrefabContainer;

                    MyEditor.Static.EditPrefabContainer(editedContainer);
                }

                if (editedContainer != null)
                {
                    MyEditorGizmo.ClearSelection();
                    List <MyEntity> addedEntities = new List <MyEntity>();

                    foreach (var prefabBuilder in prefabs)
                    {
                        prefabBuilder.EntityId = null;
                        var entity = editedContainer.CreateAndAddPrefab(null, prefabBuilder);
                        addedEntities.Add(entity);
                    }

                    // Select newly added objects
                    foreach (var entity in addedEntities)
                    {
                        MyEditorGizmo.AddEntityToSelection(entity);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public virtual void Init(string hudLabelText, MyMwcObjectBuilder_PrefabContainer objectBuilder, Matrix matrix)
        {
            m_intializing = true;
            StringBuilder hudLabelTextSb = (string.IsNullOrEmpty(hudLabelText) ? null : new StringBuilder(hudLabelText));

            base.Init(hudLabelTextSb, null, null, null, null, objectBuilder);

            DisplayName = objectBuilder.DisplayName;

            SetWorldMatrix(matrix);

            Flags |= EntityFlags.EditableInEditor;

            this.Faction = objectBuilder.Faction;

            //during container initialization, it is not necessary to check if prefab is outside boundaries, because it cannot be saved that way
            foreach (MyMwcObjectBuilder_PrefabBase prefabBuilder in objectBuilder.Prefabs)
            {
                CreateAndAddPrefab(null, prefabBuilder);
            }

            // we must initialize inventory after prefabs, because some prefabs are registered on OnInventoryContentChanged event
            if (objectBuilder.Inventory != null)
            {
                Inventory.Init(objectBuilder.Inventory, MyMwcUtils.GetRandomFloat(1.1f, 2f));
            }

            //Commit();

            UpdateAABBHr();

            // ----- THIS PHYSICS IS NEEDED BECAUSE ENTITY DETECTOR -----
            this.Physics = new MyPhysicsBody(this, 1.0f, UseKinematicPhysics ? RigidBodyFlag.RBF_KINEMATIC : RigidBodyFlag.RBF_RBO_STATIC)
            {
                MaterialType = MyMaterialType.METAL
            };
            MyPhysicsObjects   physobj = MyPhysics.physicsSystem.GetPhysicsObjects();
            MyRBBoxElementDesc boxDesc = physobj.GetRBBoxElementDesc();

            boxDesc.SetToDefault();
            boxDesc.m_RBMaterial     = MyMaterialsConstants.GetMaterialProperties(MyMaterialType.METAL).PhysicsMaterial;
            boxDesc.m_Size           = UseKinematicPhysics ? WorldAABBHr.Size() : Vector3.One;
            boxDesc.m_CollisionLayer = UseKinematicPhysics ? MyConstants.COLLISION_LAYER_DEFAULT : MyConstants.COLLISION_LAYER_UNCOLLIDABLE;
            MyRBBoxElement boxEl = (MyRBBoxElement)physobj.CreateRBElement(boxDesc);

            this.Physics.AddElement(boxEl, true);
            this.Physics.Enabled = true;
            this.Physics.RigidBody.KinematicLinear = false;
            // ----- THIS PHYSICS IS NEEDED BECAUSE ENTITY DETECTOR -----

            /*
             * MyRBBoxElementDesc boxDesc = physobj.GetRBBoxElementDesc();
             * MyMaterialType materialType = MyMaterialType.METAL;
             * boxDesc.SetToDefault();
             * boxDesc.m_Size = Vector3.One;
             * boxDesc.m_CollisionLayer = MyConstants.COLLISION_LAYER_UNCOLLIDABLE;
             * boxDesc.m_RBMaterial = MyMaterialsConstants.GetMaterialProperties(materialType).PhysicsMaterial;
             */
            //m_selectionBox = (MyRBBoxElement)physobj.CreateRBElement(boxDesc);
            m_selectionBox = new BoundingBox(-Vector3.One, Vector3.One);

            // to be selectable in editor
            //this.Physics.AddElement(m_selectionBox, true);

            m_userID  = objectBuilder.UserOwnerID;
            m_faction = objectBuilder.Faction;

            VisibleInGame = false;
            // set here later on user id when firstly created object inserted into scene

            //m_selectionBox = new BoundingBox(m_worldAABB.Min, m_worldAABB.Max);

            if (OnPrefabContainerInitialized != null)
            {
                OnPrefabContainerInitialized(this);
            }

            //StringBuilder displayName;
            //if (!string.IsNullOrEmpty(DisplayName))
            //{
            //    MyHud.ChangeText(this, new StringBuilder(DisplayName), null, 0, MyHudIndicatorFlagsEnum.SHOW_TEXT | MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS | MyHudIndicatorFlagsEnum.SHOW_ONLY_IF_DETECTED_BY_RADAR);
            //}
            m_intializing = false;

            UpdateGenerators();

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

            AlarmOn    = objectBuilder.AlarmOn;
            RefillTime = objectBuilder.RefillTime;

            // check possible values
            if (Inventory.TemplateType != null && RefillTime == null)
            {
                RefillTime = DEFAULT_REFILL_TIME_IN_SEC;
            }
            else if (Inventory.TemplateType == null && RefillTime != null)
            {
                RefillTime = null;
            }
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        public virtual void Init(string hudLabelText, MyMwcObjectBuilder_PrefabContainer objectBuilder, Matrix matrix)
        {
            m_intializing = true;
            StringBuilder hudLabelTextSb = (string.IsNullOrEmpty(hudLabelText) ? null : new StringBuilder(hudLabelText));

            base.Init(hudLabelTextSb, null, null, null, null, objectBuilder);

            DisplayName = objectBuilder.DisplayName;            

            SetWorldMatrix(matrix);            

            Flags |= EntityFlags.EditableInEditor;

            this.Faction = objectBuilder.Faction;

            //during container initialization, it is not necessary to check if prefab is outside boundaries, because it cannot be saved that way
            foreach (MyMwcObjectBuilder_PrefabBase prefabBuilder in objectBuilder.Prefabs)
            {
                CreateAndAddPrefab(null, prefabBuilder);
            }

            // we must initialize inventory after prefabs, because some prefabs are registered on OnInventoryContentChanged event
            if (objectBuilder.Inventory != null)
            {
                Inventory.Init(objectBuilder.Inventory, MyMwcUtils.GetRandomFloat(1.1f, 2f));                
            }

            //Commit();

            UpdateAABBHr();

            // ----- THIS PHYSICS IS NEEDED BECAUSE ENTITY DETECTOR -----                        
            this.Physics = new MyPhysicsBody(this, 1.0f, UseKinematicPhysics ? RigidBodyFlag.RBF_KINEMATIC : RigidBodyFlag.RBF_RBO_STATIC) { MaterialType = MyMaterialType.METAL };
            MyPhysicsObjects physobj = MyPhysics.physicsSystem.GetPhysicsObjects();
            MyRBBoxElementDesc boxDesc = physobj.GetRBBoxElementDesc();
            boxDesc.SetToDefault();
            boxDesc.m_RBMaterial = MyMaterialsConstants.GetMaterialProperties(MyMaterialType.METAL).PhysicsMaterial;
            boxDesc.m_Size = UseKinematicPhysics ? WorldAABBHr.Size() : Vector3.One;
            boxDesc.m_CollisionLayer = UseKinematicPhysics ? MyConstants.COLLISION_LAYER_DEFAULT : MyConstants.COLLISION_LAYER_UNCOLLIDABLE;
            MyRBBoxElement boxEl = (MyRBBoxElement)physobj.CreateRBElement(boxDesc);
            this.Physics.AddElement(boxEl, true);
            this.Physics.Enabled = true;
            this.Physics.RigidBody.KinematicLinear = false;
            // ----- THIS PHYSICS IS NEEDED BECAUSE ENTITY DETECTOR -----

                /*
            MyRBBoxElementDesc boxDesc = physobj.GetRBBoxElementDesc();
            MyMaterialType materialType = MyMaterialType.METAL;
            boxDesc.SetToDefault();
            boxDesc.m_Size = Vector3.One;
            boxDesc.m_CollisionLayer = MyConstants.COLLISION_LAYER_UNCOLLIDABLE;
            boxDesc.m_RBMaterial = MyMaterialsConstants.GetMaterialProperties(materialType).PhysicsMaterial;
              */
            //m_selectionBox = (MyRBBoxElement)physobj.CreateRBElement(boxDesc);
            m_selectionBox = new BoundingBox(-Vector3.One, Vector3.One);

            // to be selectable in editor
            //this.Physics.AddElement(m_selectionBox, true);

            m_userID = objectBuilder.UserOwnerID;
            m_faction = objectBuilder.Faction;

            VisibleInGame = false;
            // set here later on user id when firstly created object inserted into scene

            //m_selectionBox = new BoundingBox(m_worldAABB.Min, m_worldAABB.Max);

            if (OnPrefabContainerInitialized != null)
            {
                OnPrefabContainerInitialized(this);
            }
            
            //StringBuilder displayName;
            //if (!string.IsNullOrEmpty(DisplayName))
            //{
            //    MyHud.ChangeText(this, new StringBuilder(DisplayName), null, 0, MyHudIndicatorFlagsEnum.SHOW_TEXT | MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS | MyHudIndicatorFlagsEnum.SHOW_ONLY_IF_DETECTED_BY_RADAR);
            //}
            m_intializing = false;

            UpdateGenerators();

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

            AlarmOn = objectBuilder.AlarmOn;
            RefillTime = objectBuilder.RefillTime;

            // check possible values
            if (Inventory.TemplateType != null && RefillTime == null) 
            {
                RefillTime = DEFAULT_REFILL_TIME_IN_SEC;
            }
            else if (Inventory.TemplateType == null && RefillTime != null) 
            {
                RefillTime = null;
            }
        }