예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Prepares the hologram ship for display.
        /// </summary>
        private void ActivateHologram()
        {
            //this.Physics.Enabled = false;
            //this.Physics.LinearVelocity = Vector3.Zero;

            MyEntity owner = OwnerEntity;

            if (owner != null)
            {
                var ownerShipBuilder = (owner.GetObjectBuilder(false) as MyMwcObjectBuilder_SmallShip);
                Debug.Assert(ownerShipBuilder != null, "ownerShipBuilder != null");

                m_hologramBuilder.ShipType                = ownerShipBuilder.ShipType;
                m_hologramBuilder.ShipMaxHealth           = ownerShipBuilder.ShipMaxHealth;
                m_hologramBuilder.ShipHealthRatio         = ownerShipBuilder.ShipHealthRatio;
                m_hologramBuilder.ArmorHealth             = ownerShipBuilder.ArmorHealth;
                m_hologramBuilder.Oxygen                  = ownerShipBuilder.Oxygen;
                m_hologramBuilder.Fuel                    = ownerShipBuilder.Fuel;
                m_hologramBuilder.ReflectorLight          = ownerShipBuilder.ReflectorLight;
                m_hologramBuilder.ReflectorLongRange      = ownerShipBuilder.ReflectorLongRange;
                m_hologramBuilder.ReflectorShadowDistance = ownerShipBuilder.ReflectorShadowDistance;
                m_hologramBuilder.PositionAndOrientation  = ownerShipBuilder.PositionAndOrientation;
                m_hologramBuilder.Faction                 = ownerShipBuilder.Faction;

                string displayName = ownerShipBuilder.DisplayName;
                if (MyFactions.GetFactionsRelation(m_hologramBuilder.Faction, MySession.Static.Player.Faction) == MyFactionRelationEnum.Friend || MySession.PlayerShip == owner)
                {
                    displayName = "Hologram";
                }

                m_hologramShip            = MyHologramShips.Add(displayName, m_hologramBuilder);
                m_hologramShip.AIPriority = 1;
                m_hologramShip.IsHologram = true;
                if (m_hologramShip != null)
                {
                    m_hologramBaseMatrix = this.WorldMatrix;

                    m_scale         = new Vector3(0, 1, 1);
                    m_hologramState = HologramState.Activating;

                    foreach (var bot in m_awareBots)
                    {
                        bot.SpoilHologram(m_hologramShip);
                    }
                }
            }
        }
예제 #3
0
        protected void InternalAddEntity( )
        {
            try
            {
                if (AddEntityQueue.Count == 0)
                {
                    return;
                }

                BaseEntity entityToAdd = AddEntityQueue.Dequeue( );

                if (ExtenderOptions.IsDebugging)
                {
                    ApplicationLog.BaseLog.Debug(String.Format("{0} '{1}': Adding to scene...", entityToAdd.GetType().Name, entityToAdd.DisplayName));
                }

                //Create the backing object
                Type entityType   = entityToAdd.GetType( );
                Type internalType = (Type)BaseEntity.InvokeStaticMethod(entityType, "get_InternalType");
                if (internalType == null)
                {
                    throw new Exception("Could not get internal type of entity");
                }
                entityToAdd.BackingObject = Activator.CreateInstance(internalType);

                //Add the backing object to the main game object manager
                //I don't think this is actually used anywhere?
                MyEntity backingObject = (MyEntity)entityToAdd.BackingObject;

                MyEntity newEntity = MyEntities.CreateFromObjectBuilderAndAdd(entityToAdd.ObjectBuilder);


                if (entityToAdd is FloatingObject)
                {
                    try
                    {
                        //Broadcast the new entity to the clients
                        MyObjectBuilder_EntityBase baseEntity = backingObject.GetObjectBuilder( );
                        //TODO - Do stuff

                        entityToAdd.ObjectBuilder = baseEntity;
                    }
                    catch (Exception ex)
                    {
                        ApplicationLog.BaseLog.Error("Failed to broadcast new floating object");
                        ApplicationLog.BaseLog.Error(ex);
                    }
                }
                else
                {
                    try
                    {
                        //Broadcast the new entity to the clients
                        ApplicationLog.BaseLog.Info("Broadcasted entity to clients.");
                        MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(newEntity));
                        //the misspelling in this function name is driving me  i n s a n e
                    }
                    catch (Exception ex)
                    {
                        ApplicationLog.BaseLog.Error("Failed to broadcast new entity");
                        ApplicationLog.BaseLog.Error(ex);
                    }
                }

                if (ExtenderOptions.IsDebugging)
                {
                    Type type = entityToAdd.GetType( );
                    ApplicationLog.BaseLog.Debug(String.Format("{0} '{1}': Finished adding to scene", entityToAdd.GetType().Name, entityToAdd.DisplayName));
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
        }
예제 #4
0
        protected void InternalAddEntity( )
        {
            try
            {
                if (AddEntityQueue.Count == 0)
                {
                    return;
                }

                BaseEntity entityToAdd = AddEntityQueue.Dequeue( );

                if (ExtenderOptions.IsDebugging)
                {
                    ApplicationLog.BaseLog.Debug(entityToAdd.GetType( ).Name + " '" + entityToAdd.GetType( ).Name + "': Adding to scene ...");
                }

                //Create the backing object
                Type entityType   = entityToAdd.GetType( );
                Type internalType = (Type)BaseEntity.InvokeStaticMethod(entityType, "get_InternalType");
                if (internalType == null)
                {
                    throw new Exception("Could not get internal type of entity");
                }
                entityToAdd.BackingObject = Activator.CreateInstance(internalType);

                //Add the backing object to the main game object manager
                MyEntity backingObject = (MyEntity)entityToAdd.BackingObject;
                backingObject.Init(entityToAdd.ObjectBuilder);
                MyEntities.Add(backingObject);

                if (entityToAdd is FloatingObject)
                {
                    try
                    {
                        //Broadcast the new entity to the clients
                        MyObjectBuilder_EntityBase baseEntity = backingObject.GetObjectBuilder( );
                        //TODO - Do stuff

                        entityToAdd.ObjectBuilder = baseEntity;
                    }
                    catch (Exception ex)
                    {
                        ApplicationLog.BaseLog.Error("Failed to broadcast new floating object");
                        ApplicationLog.BaseLog.Error(ex);
                    }
                }
                else
                {
                    try
                    {
                        //Broadcast the new entity to the clients
                        MyObjectBuilder_EntityBase baseEntity = backingObject.GetObjectBuilder( );
                        MySyncCreate.SendEntityCreated(baseEntity);

                        entityToAdd.ObjectBuilder = baseEntity;
                    }
                    catch (Exception ex)
                    {
                        ApplicationLog.BaseLog.Error("Failed to broadcast new entity");
                        ApplicationLog.BaseLog.Error(ex);
                    }
                }

                if (ExtenderOptions.IsDebugging)
                {
                    Type type = entityToAdd.GetType( );
                    ApplicationLog.BaseLog.Debug(type.Name + " '" + entityToAdd.Name + "': Finished adding to scene");
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
        }
 public ObjectBuilderCreate(MyEntity entity, bool getExactCopy = false)
 {
     Matrix        = entity.WorldMatrix;
     ObjectBuilder = entity.GetObjectBuilder(getExactCopy);
 }
        //protected MyGuiControlEntityUse(IMyGuiControlsParent parent, Vector2 size, MyEntity entity)
        //    : base(parent, Vector2.Zero, size, Vector4.One, new StringBuilder(entity.DisplayName), MyGuiManager.GetHubItemBackground())
        //{
        //    m_entity = entity;
        //    m_topLeftPosition = -m_size.Value / 2f + new Vector2(0.025f, 0.025f);
        //    Controls.Add(new MyGuiControlLabel(this, m_topLeftPosition + new Vector2(0.063f, 0.0f), null, GetEntityName(entity), MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, MyGuiManager.GetFontMinerWarsBlue()));
        //    LoadControls();
        //}

        //protected MyGuiControlEntityUse(IMyGuiControlsParent parent, Vector2 size, MyEntity entity, MyTexture2D texture):this(parent,size,entity)
        //{
        //    m_texture = texture;
        //}

        protected MyGuiControlEntityUse(IMyGuiControlsParent parent, Vector2 size, MyEntity entity)
            : this(parent, size, entity, MyGuiObjectBuilderHelpers.GetGuiHelper(entity.GetObjectBuilder(true)).Icon)
        {
        }