コード例 #1
0
ファイル: GuidedMissile.cs プロジェクト: Souper07/Autopilot
        /// <summary>
        /// Only call from game thread! Spawns a rock to explode the missile.
        /// </summary>
        private void Explode()
        {
            myLogger.debugLog(!MyAPIGateway.Multiplayer.IsServer, "Not server!", Logger.severity.FATAL);

            if (MyEntity.Closed)
                return;
            m_stage = Stage.Terminated;

            MyEntity.Physics.LinearVelocity = Vector3.Zero;

            RemoveRock();

            MyObjectBuilder_InventoryItem item = new MyObjectBuilder_InventoryItem() { Amount = 1, PhysicalContent = new MyObjectBuilder_Ore() { SubtypeName = "Stone" } };

            MyObjectBuilder_FloatingObject rockBuilder = new MyObjectBuilder_FloatingObject();
            rockBuilder.Item = item;
            rockBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene;
            rockBuilder.PositionAndOrientation = new MyPositionAndOrientation()
            {
                Position = MyEntity.GetPosition(),
                Forward = Vector3.Forward,
                Up = Vector3.Up
            };

            myRock = MyEntities.CreateFromObjectBuilderAndAdd(rockBuilder);
            if (myRock == null)
            {
                myLogger.alwaysLog("failed to create rock, builder:\n" + MyAPIGateway.Utilities.SerializeToXML(rockBuilder), Logger.severity.ERROR);
                return;
            }
            myLogger.debugLog("created rock at " + myRock.PositionComp.GetPosition() + ", " + myRock.getBestName());
        }
コード例 #2
0
 public void ActivateFloatingObjectClipboard(MyObjectBuilder_FloatingObject floatingObject, Vector3 centerDeltaDirection, float dragVectorLength)
 {
     MySessionComponentVoxelHand.Static.Enabled = false;
     m_floatingObjectClipboard.SetFloatingObjectFromBuilder(floatingObject, centerDeltaDirection, dragVectorLength);
     this.Activate();
 }
コード例 #3
0
        public MyObjectBuilder_EntityBase[] BuildEntities()
        {
            var entity = new MyObjectBuilder_FloatingObject
            {
                EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY),
                PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene,
                Item = new MyObjectBuilder_InventoryItem { ItemId = 0 },
            };

            if (IsDecimal && DecimalUnits.HasValue)
                entity.Item.Amount = DecimalUnits.Value.ToFixedPoint();
            else if (IsInt && Units.HasValue)
                entity.Item.Amount = Units.Value.ToFixedPoint();
            else if (IsUnique)
                entity.Item.Amount = GenerateFloatingObjectModel.UniqueUnits.ToFixedPoint();
            else
                entity.Item.Amount = 1;

            IsValidItemToImport = true;
            entity.Item.PhysicalContent = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_PhysicalObject>(StockItem.TypeId, StockItem.SubtypeId);

            //switch (StockItem.TypeId)
            //{
            //    case MyObjectBuilderTypeEnum.Component:
            //    case MyObjectBuilderTypeEnum.Ingot:
            //    case MyObjectBuilderTypeEnum.Ore:
            //    case MyObjectBuilderTypeEnum.AmmoMagazine:
            //        break;

            //    case MyObjectBuilderTypeEnum.PhysicalGunObject:
            //        // The GunEntity appears to make each 'GunObject' unique through the definition of an EntityId.
            //        // This means, you can't stack them.
            //        // Ownership does not appear to be required at this stage.

            //  ###  Only required for pre-generating the Entity id for a gun that has been handled.  ####
            //        // This is a hack approach, to find the Enum from a SubtypeName like "AngleGrinderItem".
            //        var enumName = StockItem.SubtypeId.Substring(0, StockItem.SubtypeId.Length - 4);
            //        MyObjectBuilderTypeEnum itemEnum;
            //        if (Enum.TryParse<MyObjectBuilderTypeEnum>(enumName, out itemEnum))
            //        {
            //            var gunEntity = MyObjectBuilder_Base.CreateNewObject(itemEnum) as MyObjectBuilder_EntityBase;
            //            gunEntity.EntityId = SpaceEngineersAPI.GenerateEntityId();
            //            gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
            //            ((MyObjectBuilder_PhysicalGunObject)entity.Item.PhysicalContent).GunEntity = gunEntity;
            //        }
            //        break;

            //    default:
            //        // As yet uncatered for items which may be new.
            //        IsValidItemToImport = false;
            //        break;
            //}

            // Figure out where the Character is facing, and plant the new construct 1m out in front, and 1m up from the feet, facing the Character.
            var vectorFwd = _dataModel.CharacterPosition.Forward.ToVector3D();
            var vectorUp = _dataModel.CharacterPosition.Up.ToVector3D();
            vectorFwd.Normalize();
            vectorUp.Normalize();
            var vector = Vector3D.Multiply(vectorFwd, 1.0f) + Vector3D.Multiply(vectorUp, 1.0f);

            entity.PositionAndOrientation = new MyPositionAndOrientation
            {
                Position = Point3D.Add(_dataModel.CharacterPosition.Position.ToPoint3D(), vector).ToVector3D(),
                Forward = _dataModel.CharacterPosition.Forward,
                Up = _dataModel.CharacterPosition.Up
            };

            var entities = new List<MyObjectBuilder_EntityBase>();

            for (var i = 0; i < Multiplier; i++)
            {
                var newEntity = (MyObjectBuilder_FloatingObject)entity.Clone();
                newEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                //if (StockItem.TypeId == SpaceEngineersConsts.PhysicalGunObject)
                //{
                //    Only required for pre-generating the Entity id for a gun that has been handled.
                //    ((MyObjectBuilder_PhysicalGunObject)entity.Item.PhysicalContent).GunEntity.EntityId = SpaceEngineersAPI.GenerateEntityId();
                //}
                entities.Add(newEntity);
            }

            return entities.ToArray();
        }