private long SpawnInventoryContainer(MyDefinitionId bagDefinition)
        {
            MyEntity builder     = Character;
            var      worldMatrix = Character.WorldMatrix;

            worldMatrix.Translation += worldMatrix.Up + worldMatrix.Forward;

            MyObjectBuilder_EntityBase bagBuilder = new MyObjectBuilder_EntityBase();

            var position = new MyPositionAndOrientation(worldMatrix);

            bagBuilder.PositionAndOrientation = position;
            bagBuilder.EntityId = MyEntityIdentifier.AllocateId();
            var entity = MyEntities.CreateAndAddFromDefinition(bagBuilder, bagDefinition);

            entity.Physics.ClearSpeed();
            entity.Physics.ForceActivate();
            entity.NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME;

            MyTimerComponent timerComponent = new MyTimerComponent();

            timerComponent.SetRemoveEntityTimer(1440);
            entity.GameLogic = timerComponent;


            MySyncCreate.SendEntityCreated(entity.GetObjectBuilder(), bagDefinition);

            return(entity.EntityId);
        }
Пример #2
0
        static void OnMessageCreateAndInit(ref CreateAndInitMsg msg, MyNetworkClient sender)
        {
            MemoryStream stream = new MemoryStream(msg.ObjectBuilder, 0, msg.BuilderLength);

            MyObjectBuilder_EntityBase entityBuilder;

            if (MyObjectBuilderSerializer.DeserializeGZippedXML(stream, out entityBuilder))
            {
                if (entityBuilder == null)
                {
                    Debug.Fail("Object builder was not deserialized");
                    return;
                }
            }
            else
            {
                Debug.Fail("Deserialization failed");
                return;
            }

            MyPhysicalItemDefinition entityDefinition;

            if (!MyDefinitionManager.Static.TryGetDefinition(msg.DefinitionId, out entityDefinition))
            {
                Debug.Fail("Can not find definition with id:" + msg.DefinitionId.ToString());
                return;
            }

            MyEntities.CreateAndAddFromDefinition(entityBuilder, entityDefinition);
        }
Пример #3
0
        private long SpawnInventoryContainer(MyPhysicalItemDefinition bagDefinition)
        {
            MyEntity builder     = Character;
            var      worldMatrix = Character.WorldMatrix;

            worldMatrix.Translation += worldMatrix.Up + worldMatrix.Forward;

            MyObjectBuilder_EntityBase bagBuilder = new MyObjectBuilder_EntityBase();

            bagBuilder.Name = bagDefinition.DisplayNameText;
            var position = new MyPositionAndOrientation(worldMatrix);

            bagBuilder.PositionAndOrientation = position;
            bagBuilder.EntityId    = MyEntityIdentifier.AllocateId();
            bagBuilder.SubtypeName = bagDefinition.Id.SubtypeName;

            var entity = MyEntities.CreateAndAddFromDefinition(bagBuilder, bagDefinition);

            entity.Physics.ForceActivate();
            entity.Physics.ApplyImpulse(builder.Physics.LinearVelocity, Vector3.Zero);

            MySyncCreate.SendEntityCreated(entity.GetObjectBuilder(), bagDefinition.Id);

            return(entity.EntityId);
        }
Пример #4
0
        static void OnMessageCreateAndInit(ref CreateAndInitMsg msg, MyNetworkClient sender)
        {
            Debug.Fail("Use replication instead of this!");
            MemoryStream stream = new MemoryStream(msg.ObjectBuilder, 0, msg.BuilderLength);

            MyObjectBuilder_EntityBase entityBuilder;

            if (MyObjectBuilderSerializer.DeserializeGZippedXML(stream, out entityBuilder))
            {
                if (entityBuilder == null)
                {
                    Debug.Fail("Object builder was not deserialized");
                    return;
                }
            }
            else
            {
                Debug.Fail("Deserialization failed");
                return;
            }

            MyEntities.CreateAndAddFromDefinition(entityBuilder, msg.DefinitionId);
        }