/// <summary> /// Players are allowed to spawn any object in creative /// </summary> public static void RequestSpawnCreative(MyObjectBuilder_FloatingObject obj) { if (MySession.Static.HasAdminRights || MySession.Static.CreativeMode) { MyMultiplayer.RaiseStaticEvent(x => RequestSpawnCreative_Implementation, obj); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { MyObjectBuilder_FloatingObject obj2 = objectBuilder as MyObjectBuilder_FloatingObject; if (obj2.Item.Amount <= 0) { throw new ArgumentOutOfRangeException("MyPhysicalInventoryItem.Amount", $"Creating floating object with invalid amount: {obj2.Item.Amount}x '{obj2.Item.PhysicalContent.GetId()}'"); } base.Init(objectBuilder); this.Item = new MyPhysicalInventoryItem(obj2.Item); this.m_modelVariant = obj2.ModelVariant; this.Amount.SetLocalValue(this.Item.Amount); this.Amount.ValueChanged += delegate(SyncBase x) { this.Item.Amount = this.Amount.Value; this.UpdateInternalState(); }; this.InitInternal(); base.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; this.UseDamageSystem = true; MyPhysicalItemDefinition definition = null; this.ItemDefinition = MyDefinitionManager.Static.TryGetPhysicalItemDefinition(this.Item.GetDefinitionId(), out definition) ? definition : null; this.m_timeFromSpawn = MySession.Static.ElapsedPlayTime; this.m_smoothGravity = this.Physics.RigidBody.Gravity; this.m_smoothGravityDir = this.m_smoothGravity; this.m_smoothGravityDir.Normalize(); this.m_supportNormals = new List <Vector3>(); this.m_supportNormals.Capacity = 3; if (!Sync.IsServer) { this.Physics.RigidBody.UpdateMotionType(HkMotionType.Fixed); } }
public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false) { MyObjectBuilder_FloatingObject objectBuilder = (MyObjectBuilder_FloatingObject)base.GetObjectBuilder(copy); objectBuilder.Item = this.Item.GetObjectBuilder(); objectBuilder.ModelVariant = this.m_modelVariant; return(objectBuilder); }
public static void RequestSpawnCreative(MyObjectBuilder_FloatingObject obj) { if (MySession.Static.HasCreativeRights || MySession.Static.CreativeMode) { EndpointId targetEndpoint = new EndpointId(); Vector3D? position = null; MyMultiplayer.RaiseStaticEvent <MyObjectBuilder_FloatingObject>(x => new Action <MyObjectBuilder_FloatingObject>(MyFloatingObjects.RequestSpawnCreative_Implementation), obj, targetEndpoint, position); } }
public static MyObjectBuilder_FloatingObject ChangeObjectBuilder(MyComponentDefinition componentDef, MyObjectBuilder_EntityBase entityOb) { MyObjectBuilder_PhysicalObject content = MyObjectBuilderSerializer.CreateNewObject(componentDef.Id.TypeId, componentDef.Id.SubtypeName) as MyObjectBuilder_PhysicalObject; Vector3D position = (Vector3D)entityOb.PositionAndOrientation.Value.Position; MyPhysicalInventoryItem item = new MyPhysicalInventoryItem(1, content, 1f); MyObjectBuilder_FloatingObject obj1 = PrepareBuilder(ref item); obj1.PositionAndOrientation = new MyPositionAndOrientation(position, (Vector3)entityOb.PositionAndOrientation.Value.Forward, (Vector3)entityOb.PositionAndOrientation.Value.Up); obj1.EntityId = entityOb.EntityId; return(obj1); }
private static void RequestSpawnCreative_Implementation(MyObjectBuilder_FloatingObject obj) { if ((MySession.Static.CreativeMode || MyEventContext.Current.IsLocallyInvoked) || MySession.Static.HasPlayerCreativeRights(MyEventContext.Current.Sender.Value)) { MyEntities.CreateFromObjectBuilderAndAdd(obj, false); } else { (MyMultiplayer.Static as MyMultiplayerServerBase).ValidationFailed(MyEventContext.Current.Sender.Value, true, null, true); } }
private static void RequestSpawnCreative_Implementation(MyObjectBuilder_FloatingObject obj) { if (MySession.Static.CreativeMode || MyEventContext.Current.IsLocallyInvoked || MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value)) { MyEntities.CreateFromObjectBuilderAndAdd(obj); } else { MyEventContext.ValidationFailed(); } }
private static MyObjectBuilder_FloatingObject PrepareBuilder(ref MyPhysicalInventoryItem item) { MyObjectBuilder_FloatingObject local1 = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_FloatingObject>(); local1.Item = item.GetObjectBuilder(); MyPhysicalItemDefinition physicalItemDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(item.Content); local1.ModelVariant = physicalItemDefinition.HasModelVariants ? MyUtils.GetRandomInt(physicalItemDefinition.Models.Length) : 0; MyObjectBuilder_FloatingObject local2 = local1; local2.PersistentFlags |= MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled; return(local2); }
public void SetFloatingObjectFromBuilder(MyObjectBuilder_FloatingObject floatingObject, Vector3D dragPointDelta, float dragVectorLength) { if (this.IsActive) { this.Deactivate(); } this.m_copiedFloatingObjects.Clear(); this.m_copiedFloatingObjectOffsets.Clear(); GetPasteMatrix(); this.m_dragPointToPositionLocal = dragPointDelta; this.m_dragDistance = dragVectorLength; MyPositionAndOrientation?positionAndOrientation = floatingObject.PositionAndOrientation; MyPositionAndOrientation orientation = (positionAndOrientation != null) ? positionAndOrientation.GetValueOrDefault() : MyPositionAndOrientation.Default; this.m_pasteDirUp = (Vector3)orientation.Up; this.m_pasteDirForward = (Vector3)orientation.Forward; this.SetFloatingObjectFromBuilderInternal(floatingObject, Vector3D.Zero); this.Activate(); }
static void OnCreateFloatingObjectsCallback(ref FloatingObjectsCreateMsg msg, MyNetworkClient sender) { //MySandboxGame.Log.WriteLine("FloatingObjectsCreateMsg: " + msg.FloatingObjects.Count); foreach (var floatingObject in msg.FloatingObjects) { foreach (var instance in floatingObject.Instances) { System.Diagnostics.Debug.Assert(instance.Amount > 0); if (instance.Amount <= 0) { continue; } if (MyEntities.EntityExists(instance.Location.EntityId)) { continue; } var objectBuilder = new MyObjectBuilder_FloatingObject(); objectBuilder.Item = new MyObjectBuilder_InventoryItem(); objectBuilder.Item.Amount = instance.Amount; objectBuilder.Item.Content = MyObjectBuilderSerializer.CreateNewObject(((MyDefinitionId)floatingObject.TypeId).TypeId, ((MyDefinitionId)floatingObject.TypeId).SubtypeName); objectBuilder.EntityId = instance.Location.EntityId; objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(instance.Location.Position, instance.Location.Forward, instance.Location.Up); objectBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.CastShadows; MyFloatingObject floatingObjectAdded = (MyFloatingObject)MyEntities.CreateFromObjectBuilderAndAdd(objectBuilder); if (floatingObjectAdded.Physics != null) { floatingObjectAdded.Physics.LinearVelocity = instance.Location.LinearVelocity; floatingObjectAdded.Physics.AngularVelocity = instance.Location.AngularVelocity; } } } if (Sync.IsServer) { Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId); } }
void sensor_StateChanged(bool entering) { if (entering) { MyObjectBuilder_FloatingObject floatingObjectBuilder = new MyObjectBuilder_FloatingObject(); floatingObjectBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = 100, Content = new MyObjectBuilder_Ore() { SubtypeName = "Stone" } }; floatingObjectBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene; floatingObjectBuilder.PositionAndOrientation = new MyPositionAndOrientation() { Position = Sensor.WorldMatrix.Translation + Sensor.WorldMatrix.Forward * 1.5f, Forward = Sensor.WorldMatrix.Forward, Up = Sensor.WorldMatrix.Up }; var floatingObject = Sandbox.ModAPI.MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(floatingObjectBuilder); } }
public void SetFloatingObjectFromBuilder(MyObjectBuilder_FloatingObject floatingObject, Vector3 dragPointDelta, float dragVectorLength) { if (IsActive) { Deactivate(); } m_copiedFloatingObjects.Clear(); m_copiedFloatingObjectOffsets.Clear(); Matrix pasteMatrix = GetPasteMatrix(); m_dragPointToPositionLocal = dragPointDelta; m_dragDistance = dragVectorLength; var transform = floatingObject.PositionAndOrientation ?? MyPositionAndOrientation.Default; m_pasteDirUp = transform.Up; m_pasteDirForward = transform.Forward; SetFloatingObjectFromBuilderInternal(floatingObject, Vector3.Zero); Activate(); }
public static void InventoryDrop(IMyEntity entity, MyFixedPoint amount, MyDefinitionId definitionId) { Vector3D position; if (entity is IMyCharacter) { position = entity.WorldMatrix.Translation + entity.WorldMatrix.Forward * 1.5f + entity.WorldMatrix.Up * 1.5f; // Spawn item 1.5m in front of player. } else { position = entity.WorldMatrix.Translation + entity.WorldMatrix.Forward * 1.5f; // Spawn item 1.5m in front of player in cockpit. } MyObjectBuilder_FloatingObject floatingBuilder = new MyObjectBuilder_FloatingObject(); var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId); var gasContainer = content as MyObjectBuilder_GasContainerObject; if (gasContainer != null) { gasContainer.GasLevel = 1f; } floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = amount, PhysicalContent = content }; floatingBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene; // Very important floatingBuilder.PositionAndOrientation = new MyPositionAndOrientation() { Position = position, Forward = entity.WorldMatrix.Forward.ToSerializableVector3(), Up = entity.WorldMatrix.Up.ToSerializableVector3(), }; floatingBuilder.CreateAndSyncEntity(); }
public static void Spawn(MyPhysicalInventoryItem item, MatrixD worldMatrix, MyPhysicsComponentBase motionInheritedFrom, Action <MyEntity> completionCallback) { if (MyEntities.IsInsideWorld(worldMatrix.Translation)) { MyObjectBuilder_FloatingObject objectBuilder = PrepareBuilder(ref item); objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); Vector3D?relativeOffset = null; MyEntities.CreateFromObjectBuilderParallel(objectBuilder, true, delegate(MyEntity entity) { if ((entity != null) && (entity.Physics != null)) { entity.Physics.ForceActivate(); ApplyPhysics(entity, motionInheritedFrom); if (MyVisualScriptLogicProvider.ItemSpawned != null) { MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, entity.EntityId, item.Amount.ToIntSafe(), worldMatrix.Translation); } if (completionCallback != null) { completionCallback(entity); } } }, null, null, relativeOffset, false, false); } }
public FloatingObject( MyObjectBuilder_FloatingObject definition, Object backingObject ) : base(definition, backingObject) { m_item = new InventoryItemEntity( definition.Item ); }
private void SetFloatingObjectFromBuilderInternal(MyObjectBuilder_FloatingObject floatingObject, Vector3 offset) { Debug.Assert(floatingObject.Item.Amount > 0, "The floating object should gave positive amount"); m_copiedFloatingObjects.Add(floatingObject); m_copiedFloatingObjectOffsets.Add(offset); }
public FloatingObject(MyObjectBuilder_FloatingObject definition, Object backingObject) : base(definition, backingObject) { m_item = new InventoryItemEntity(definition.Item); }
public override bool HandleInput() { bool handled = false; if (m_gridDebugInfo) { LineD line = new LineD(MySector.MainCamera.Position, MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 1000); MyCubeGrid grid; Vector3I cubePos; double distance; if (MyCubeGrid.GetLineIntersection(ref line, out grid, out cubePos, out distance)) { var gridMatrix = grid.WorldMatrix; var boxMatrix = Matrix.CreateTranslation(cubePos * grid.GridSize) * gridMatrix; var block = grid.GetCubeBlock(cubePos); MyRenderProxy.DebugDrawText2D(new Vector2(), cubePos.ToString(), Color.White, 0.7f); MyRenderProxy.DebugDrawOBB(Matrix.CreateScale(new Vector3(grid.GridSize) + new Vector3(0.15f)) * boxMatrix, Color.Red.ToVector3(), 0.2f, true, true); //int[, ,] bones = grid.Skeleton.AddCubeBones(cubePos); //Vector3 closestBone = Vector3.Zero; //Vector3I closestPoint = Vector3I.Zero; //float closestPointDist = float.MaxValue; //int closestBoneIndex = 0; //for (int x = -1; x <= 1; x += 1) //{ // for (int y = -1; y <= 1; y += 1) // { // for (int z = -1; z <= 1; z += 1) // { // int boneIndex = bones[x + 1, y + 1, z + 1]; // Vector3 bone = grid.Skeleton[boneIndex]; // var pos = boxMatrix.Translation + new Vector3(grid.GridSize / 2) * new Vector3(x, y, z); // //MyRenderProxy.DebugDrawSphere(pos, 0.2f, Color.Blue.ToVector3(), 1.0f, false); // MyRenderProxy.DebugDrawText3D(pos, String.Format("{0:G2}, {1:G2}, {2:G2}", bone.X, bone.Y, bone.Z), Color.White, 0.5f, false); // var dist = MyUtils.GetPointLineDistance(ref line, ref pos); // if (dist < closestPointDist) // { // closestPointDist = dist; // closestPoint = new Vector3I(x, y, z); // closestBoneIndex = boneIndex; // closestBone = bone; // } // } // } //} //MyRenderProxy.DebugDrawText3D(boxMatrix.Translation + new Vector3(grid.GridSize / 2) * closestPoint * 1.0f, String.Format("{0:G2}, {1:G2}, {2:G2}", closestBone.X, closestBone.Y, closestBone.Z), Color.Red, 0.5f, false); //var bonePos = grid.Skeleton[bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]]; //MyRenderProxy.DebugDrawSphere(boxMatrix.Translation + new Vector3(grid.GridSize / 2) * closestPoint * 1.0f + bonePos, 0.5f, Color.Red.ToVector3(), 0.4f, true, true); //if (input.IsNewKeyPressed(Keys.P) && block != null) //{ // if (input.IsAnyShiftKeyPressed()) // { // grid.ResetBlockSkeleton(block); // } // else // { // grid.Skeleton[bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]] = Vector3.Zero; // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // } // handled = true; //} //// Move bones to center by 0.1f //if (input.IsNewKeyPressed(Keys.OemOpenBrackets)) //{ // int index = bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]; // grid.Skeleton[index] -= Vector3.Sign(grid.Skeleton[index]) * 0.1f; // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // handled = true; //} //// Reduce max offset by 0.1f //if (input.IsNewKeyPressed(Keys.OemCloseBrackets)) //{ // int index = bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]; // var old = Vector3.Abs(grid.Skeleton[index]); // var max = new Vector3(Math.Max(Math.Max(old.X, old.Y), old.Z)); // if (max.X > 0.1f) // { // grid.Skeleton[index] = Vector3.Clamp(grid.Skeleton[index], -max + 0.1f, max - 0.1f); // } // else // { // grid.Skeleton[index] = Vector3.Zero; // } // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // handled = true; //} } } if (MyInput.Static.IsAnyAltKeyPressed()) { return(handled); } bool shift = MyInput.Static.IsAnyShiftKeyPressed(); bool ctrl = MyInput.Static.IsAnyCtrlKeyPressed(); //if (input.IsNewKeyPressed(Keys.I)) //{ // foreach (var grid in MyEntities.GetEntities().OfType<MyCubeGrid>()) // { // foreach (var block in grid.GetBlocks().ToArray()) // { // grid.DetectMerge(block.Min, block.Max); // } // } // handled = true; //} // Disabled since it is common to have normal control bound to O key. // If you ever need this again, bind it to something more complicated, like key combination. //if (input.IsNewKeyPressed(Keys.O)) //{ // m_gridDebugInfo = !m_gridDebugInfo; // handled = true; //} //for (int i = 0; i <= 9; i++) //{ // if (MyInput.Static.IsNewKeyPressed((Keys)(((int)Keys.D0) + i))) // { // string name = "Slot" + i.ToString(); // if (ctrl) // { // MySession.Static.Name = name; // MySession.Static.WorldID = MySession.Static.GetNewWorldId(); // MySession.Static.Save(name); // } // else if (shift) // { // var path = MyLocalCache.GetSessionSavesPath(name, false, false); // if (System.IO.Directory.Exists(path)) // { // MySession.Static.Unload(); // MySession.Static.Load(path); // } // } // handled = true; // } //} //if (MyInput.Static.IsNewKeyPressed(Keys.End)) //{ // MyMeteorShower.MeteorWave(null); //} // Disabled for god sake! //if (MyInput.Static.IsNewKeyPressed(Keys.PageUp) && MyInput.Static.IsAnyCtrlKeyPressed()) //{ // MyReloadTestComponent.Enabled = true; //} //if (MyInput.Static.IsNewKeyPressed(Keys.PageDown) && MyInput.Static.IsAnyCtrlKeyPressed()) //{ // MyReloadTestComponent.Enabled = false; //} if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad6)) { var view = MySession.Static.CameraController.GetViewMatrix(); var inv = Matrix.Invert(view); //MyPhysicalInventoryItem item = new MyPhysicalInventoryItem(100, var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>("Stone"); var item = new MyPhysicalInventoryItem(1, oreBuilder); var obj = MyFloatingObjects.Spawn(item, inv.Translation + inv.Forward * 1.0f, inv.Forward, inv.Up); obj.Physics.LinearVelocity = inv.Forward * 50; } if (false && MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9)) { List <HkShape> trShapes = new List <HkShape>(); List <HkConvexShape> shapes = new List <HkConvexShape>(); List <Matrix> matrices = new List <Matrix>(); var grid = new HkGridShape(2.5f, HkReferencePolicy.None); const short size = 50; for (short x = 0; x < size; x++) { for (short y = 0; y < size; y++) { for (short z = 0; z < size; z++) { var box = new HkBoxShape(Vector3.One); grid.AddShapes(new System.Collections.Generic.List <HkShape>() { box }, new Vector3S(x, y, z), new Vector3S(x, y, z)); trShapes.Add(new HkConvexTranslateShape(box, new Vector3(x, y, z), HkReferencePolicy.None)); shapes.Add(box); matrices.Add(Matrix.CreateTranslation(new Vector3(x, y, z))); } } } var emptyGeom = new HkGeometry(new List <Vector3>(), new List <int>()); var list = new HkListShape(trShapes.ToArray(), trShapes.Count, HkReferencePolicy.None); var compressedBv = new HkBvCompressedMeshShape(emptyGeom, shapes, matrices, HkWeldingType.None); var mopp = new HkMoppBvTreeShape(list, HkReferencePolicy.None); HkShapeBuffer buf = new HkShapeBuffer(); //HkShapeContainerIterator i = compressedBv.GetIterator(buf); //int count = 0; // will be 125000 //while (i.IsValid) //{ // count++; // i.Next(); //} buf.Dispose(); var info = new HkRigidBodyCinfo(); info.Mass = 10; info.CalculateBoxInertiaTensor(Vector3.One, 10); info.MotionType = HkMotionType.Dynamic; info.QualityType = HkCollidableQualityType.Moving; info.Shape = compressedBv; var body = new HkRigidBody(info); //MyPhysics.HavokWorld.AddRigidBody(body); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad7)) { foreach (var g in MyEntities.GetEntities().OfType <MyCubeGrid>()) { foreach (var s in g.CubeBlocks.Select(s => s.FatBlock).Where(s => s != null).OfType <MyMotorStator>()) { if (s.Rotor != null) { var q = Quaternion.CreateFromAxisAngle(s.Rotor.WorldMatrix.Up, MathHelper.ToRadians(45)); s.Rotor.CubeGrid.WorldMatrix = MatrixD.CreateFromQuaternion(q) * s.Rotor.CubeGrid.WorldMatrix; } } } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad8)) { var view = MySession.Static.CameraController.GetViewMatrix(); var inv = Matrix.Invert(view); var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>("Stone"); var obj = new MyObjectBuilder_FloatingObject() { Item = new MyObjectBuilder_InventoryItem() { PhysicalContent = oreBuilder, Amount = 1000 } }; obj.PositionAndOrientation = new MyPositionAndOrientation(inv.Translation + 2.0f * inv.Forward, inv.Forward, inv.Up); obj.PersistentFlags = MyPersistentEntityFlags2.InScene; var e = MyEntities.CreateFromObjectBuilderAndAdd(obj); e.Physics.LinearVelocity = Vector3.Normalize(inv.Forward) * 50.0f; } if (MyInput.Static.IsNewKeyPressed(MyKeys.Divide)) { } if (MyInput.Static.IsNewKeyPressed(MyKeys.Multiply)) { MyDebugDrawSettings.ENABLE_DEBUG_DRAW = !MyDebugDrawSettings.ENABLE_DEBUG_DRAW; MyDebugDrawSettings.DEBUG_DRAW_STRUCTURAL_INTEGRITY = true; var grids = MyEntities.GetEntities().OfType <MyCubeGrid>(); foreach (var g in grids) { if (!g.IsStatic)// || g.GetBlocks().Count < 800) //to compute only castle { continue; } g.CreateStructuralIntegrity(); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad1)) { var e = MyEntities.GetEntities().OfType <MyCubeGrid>().FirstOrDefault(); if (e != null) { e.Physics.RigidBody.MaxLinearVelocity = 1000; if (e.Physics.RigidBody2 != null) { e.Physics.RigidBody2.MaxLinearVelocity = 1000; } e.Physics.LinearVelocity = new Vector3(1000, 0, 0); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.Decimal)) { MyPrefabManager.Static.SpawnPrefab("respawnship", MySector.MainCamera.Position, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector); } if (MyInput.Static.IsNewKeyPressed(MyKeys.Multiply) && MyInput.Static.IsAnyShiftKeyPressed()) { GC.Collect(2); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad5)) { Thread.Sleep(250); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9)) { var obj = MySession.Static.ControlledEntity != null ? MySession.Static.ControlledEntity.Entity : null; if (obj != null) { const float dist = 5.0f; obj.PositionComp.SetPosition(obj.PositionComp.GetPosition() + obj.WorldMatrix.Forward * dist); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad4)) { MyEntity invObject = MySession.Static.ControlledEntity as MyEntity; if (invObject != null && invObject.HasInventory) { MyFixedPoint amount = 20000; var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>("Stone"); MyInventory inventory = invObject.GetInventory(0) as MyInventory; System.Diagnostics.Debug.Assert(inventory != null, "Null or unexpected type returned!"); inventory.AddItems(amount, oreBuilder); } handled = true; } //if (MyInput.Static.IsNewKeyPressed(Keys.NumPad8)) //{ // var pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 2; // var grid = (MyObjectBuilder_CubeGrid)MyObjectBuilderSerializer.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid); // grid.PositionAndOrientation = new MyPositionAndOrientation(pos, Vector3.Forward, Vector3.Up); // grid.CubeBlocks = new List<MyObjectBuilder_CubeBlock>(); // grid.GridSizeEnum = MyCubeSize.Large; // var block = new MyObjectBuilder_CubeBlock(); // block.BlockOrientation = MyBlockOrientation.Identity; // block.Min = Vector3I.Zero; // //var blockDefinition = Sandbox.Game.Managers.MyDefinitionManager.Static.GetCubeBlockDefinition(new CommonLib.ObjectBuilders.Definitions.MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock")); // block.SubtypeName = "LargeBlockArmorBlock"; // grid.CubeBlocks.Add(block); // grid.LinearVelocity = MySector.MainCamera.ForwardVector * 20; // grid.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; // var x = MyEntities.CreateFromObjectBuilderAndAdd(grid); //} //if (MyInput.Static.IsNewKeyPressed(Keys.NumPad9)) //{ // var pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 2; // var grid = (MyObjectBuilder_CubeGrid)MyObjectBuilderSerializer.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid); // grid.PositionAndOrientation = new MyPositionAndOrientation(pos, Vector3.Forward, Vector3.Up); // grid.CubeBlocks = new List<MyObjectBuilder_CubeBlock>(); // grid.GridSizeEnum = MyCubeSize.Large; // var block = new MyObjectBuilder_CubeBlock(); // block.BlockOrientation = MyBlockOrientation.Identity; // block.Min = Vector3I.Zero; // //var blockDefinition = Sandbox.Game.Managers.MyDefinitionManager.Static.GetCubeBlockDefinition(new CommonLib.ObjectBuilders.Definitions.MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock")); // block.SubtypeName = "LargeBlockGyro"; // grid.CubeBlocks.Add(block); // grid.LinearVelocity = MySector.MainCamera.ForwardVector * 20; // grid.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; // var x = MyEntities.CreateFromObjectBuilderAndAdd(grid); //} if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Delete)) { int count = MyEntities.GetEntities().OfType <MyFloatingObject>().Count(); foreach (var obj in MyEntities.GetEntities().OfType <MyFloatingObject>()) { if (obj == MySession.Static.ControlledEntity) { MySession.Static.SetCameraController(MyCameraControllerEnum.Spectator); } obj.Close(); } handled = true; } if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Decimal)) { foreach (var obj in MyEntities.GetEntities()) { if (obj != MySession.Static.ControlledEntity && (MySession.Static.ControlledEntity == null || obj != MySession.Static.ControlledEntity.Entity.Parent) && obj != MyCubeBuilder.Static.FindClosestGrid()) { obj.Close(); } } handled = true; } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9) || MyInput.Static.IsNewKeyPressed(MyKeys.NumPad5)) { //MyCubeGrid.UserCollisions = input.IsNewKeyPressed(Keys.NumPad9); var body = MySession.Static.ControlledEntity.Entity.GetTopMostParent().Physics; if (body.RigidBody != null) { //body.AddForce(Engine.Physics.MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, new Vector3(0, 0, 10 * body.Mass), null, null); body.RigidBody.ApplyLinearImpulse(body.Entity.WorldMatrix.Forward * body.Mass * 2); } handled = true; } //if (input.IsNewKeyPressed(Keys.J) && input.IsAnyCtrlKeyPressed()) //{ // MyGlobalInputComponent.CopyCurrentGridToClipboard(); // MyEntity addedEntity = MyGlobalInputComponent.PasteEntityFromClipboard(); // if (addedEntity != null) // { // Vector3 pos = addedEntity.GetPosition(); // pos.Z += addedEntity.WorldVolume.Radius * 1.5f; // addedEntity.SetPosition(pos); // } // handled = true; //} if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.OemComma)) { foreach (var e in MyEntities.GetEntities().OfType <MyFloatingObject>().ToArray()) { e.Close(); } } return(handled); }
public void ActivateFloatingObjectClipboard(MyObjectBuilder_FloatingObject floatingObject, Vector3 centerDeltaDirection, float dragVectorLength) { MySessionComponentVoxelHand.Static.Enabled = false; m_floatingObjectClipboard.SetFloatingObjectFromBuilder(floatingObject, centerDeltaDirection, dragVectorLength); this.Activate(); }
void sensor_StateChanged(bool obj) { if (!obj) { return; } int menge = 0; string ore = null; foreach (var o in OreNames) { if (Sensor.CustomName.StartsWith(o, StringComparison.InvariantCultureIgnoreCase)) { ore = o; break; } } String Last3 = Sensor.CustomName.Substring(Sensor.CustomName.Length - 3); try { menge = Int32.Parse(Last3); } catch (FormatException e) { menge = 100; } catch (OverflowException e) { MyAPIGateway.Utilities.ShowNotification(string.Format("Overflow Exception Number too big"), 1000, MyFontEnum.Red); } MyAPIGateway.Utilities.ShowNotification(string.Format("Last3: " + menge, (Entity as Sandbox.ModAPI.Ingame.IMyTerminalBlock).DisplayNameText), 1000, MyFontEnum.Red); if (ore == null) { return; } // We want to spawn ore and throw it at entity which entered sensor MyObjectBuilder_FloatingObject floatingBuilder = new MyObjectBuilder_FloatingObject(); floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = menge, Content = new MyObjectBuilder_Ore() { SubtypeName = ore } }; floatingBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene; // Very important floatingBuilder.PositionAndOrientation = new MyPositionAndOrientation() { Position = Sensor.WorldMatrix.Translation + Sensor.WorldMatrix.Forward * 1.5f, // Spawn ore 1.5m in front of the sensor Forward = Sensor.WorldMatrix.Forward, Up = Sensor.WorldMatrix.Up, }; var floatingObject = Sandbox.ModAPI.MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(floatingBuilder); // Now it only creates ore, we will throw it later }
public override bool HandleInput() { bool handled = false; if (m_gridDebugInfo) { LineD line = new LineD(MySector.MainCamera.Position, MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 1000); MyCubeGrid grid; Vector3I cubePos; double distance; if (MyCubeGrid.GetLineIntersection(ref line, out grid, out cubePos, out distance)) { var gridMatrix = grid.WorldMatrix; var boxMatrix = Matrix.CreateTranslation(cubePos * grid.GridSize) * gridMatrix; var block = grid.GetCubeBlock(cubePos); MyRenderProxy.DebugDrawText2D(new Vector2(), cubePos.ToString(), Color.White, 0.7f); MyRenderProxy.DebugDrawOBB(Matrix.CreateScale(new Vector3(grid.GridSize) + new Vector3(0.15f)) * boxMatrix, Color.Red.ToVector3(), 0.2f, true, true); //int[, ,] bones = grid.Skeleton.AddCubeBones(cubePos); //Vector3 closestBone = Vector3.Zero; //Vector3I closestPoint = Vector3I.Zero; //float closestPointDist = float.MaxValue; //int closestBoneIndex = 0; //for (int x = -1; x <= 1; x += 1) //{ // for (int y = -1; y <= 1; y += 1) // { // for (int z = -1; z <= 1; z += 1) // { // int boneIndex = bones[x + 1, y + 1, z + 1]; // Vector3 bone = grid.Skeleton[boneIndex]; // var pos = boxMatrix.Translation + new Vector3(grid.GridSize / 2) * new Vector3(x, y, z); // //MyRenderProxy.DebugDrawSphere(pos, 0.2f, Color.Blue.ToVector3(), 1.0f, false); // MyRenderProxy.DebugDrawText3D(pos, String.Format("{0:G2}, {1:G2}, {2:G2}", bone.X, bone.Y, bone.Z), Color.White, 0.5f, false); // var dist = MyUtils.GetPointLineDistance(ref line, ref pos); // if (dist < closestPointDist) // { // closestPointDist = dist; // closestPoint = new Vector3I(x, y, z); // closestBoneIndex = boneIndex; // closestBone = bone; // } // } // } //} //MyRenderProxy.DebugDrawText3D(boxMatrix.Translation + new Vector3(grid.GridSize / 2) * closestPoint * 1.0f, String.Format("{0:G2}, {1:G2}, {2:G2}", closestBone.X, closestBone.Y, closestBone.Z), Color.Red, 0.5f, false); //var bonePos = grid.Skeleton[bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]]; //MyRenderProxy.DebugDrawSphere(boxMatrix.Translation + new Vector3(grid.GridSize / 2) * closestPoint * 1.0f + bonePos, 0.5f, Color.Red.ToVector3(), 0.4f, true, true); //if (input.IsNewKeyPressed(Keys.P) && block != null) //{ // if (input.IsAnyShiftKeyPressed()) // { // grid.ResetBlockSkeleton(block); // } // else // { // grid.Skeleton[bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]] = Vector3.Zero; // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // } // handled = true; //} //// Move bones to center by 0.1f //if (input.IsNewKeyPressed(Keys.OemOpenBrackets)) //{ // int index = bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]; // grid.Skeleton[index] -= Vector3.Sign(grid.Skeleton[index]) * 0.1f; // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // handled = true; //} //// Reduce max offset by 0.1f //if (input.IsNewKeyPressed(Keys.OemCloseBrackets)) //{ // int index = bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]; // var old = Vector3.Abs(grid.Skeleton[index]); // var max = new Vector3(Math.Max(Math.Max(old.X, old.Y), old.Z)); // if (max.X > 0.1f) // { // grid.Skeleton[index] = Vector3.Clamp(grid.Skeleton[index], -max + 0.1f, max - 0.1f); // } // else // { // grid.Skeleton[index] = Vector3.Zero; // } // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // handled = true; //} } } if (MyInput.Static.IsAnyAltKeyPressed()) return handled; bool shift = MyInput.Static.IsAnyShiftKeyPressed(); bool ctrl = MyInput.Static.IsAnyCtrlKeyPressed(); //if (input.IsNewKeyPressed(Keys.I)) //{ // foreach (var grid in MyEntities.GetEntities().OfType<MyCubeGrid>()) // { // foreach (var block in grid.GetBlocks().ToArray()) // { // grid.DetectMerge(block.Min, block.Max); // } // } // handled = true; //} // Disabled since it is common to have normal control bound to O key. // If you ever need this again, bind it to something more complicated, like key combination. //if (input.IsNewKeyPressed(Keys.O)) //{ // m_gridDebugInfo = !m_gridDebugInfo; // handled = true; //} //for (int i = 0; i <= 9; i++) //{ // if (MyInput.Static.IsNewKeyPressed((Keys)(((int)Keys.D0) + i))) // { // string name = "Slot" + i.ToString(); // if (ctrl) // { // MySession.Static.Name = name; // MySession.Static.WorldID = MySession.Static.GetNewWorldId(); // MySession.Static.Save(name); // } // else if (shift) // { // var path = MyLocalCache.GetSessionSavesPath(name, false, false); // if (System.IO.Directory.Exists(path)) // { // MySession.Static.Unload(); // MySession.Static.Load(path); // } // } // handled = true; // } //} //if (MyInput.Static.IsNewKeyPressed(Keys.End)) //{ // MyMeteorShower.MeteorWave(null); //} // Disabled for god sake! //if (MyInput.Static.IsNewKeyPressed(Keys.PageUp) && MyInput.Static.IsAnyCtrlKeyPressed()) //{ // MyReloadTestComponent.Enabled = true; //} //if (MyInput.Static.IsNewKeyPressed(Keys.PageDown) && MyInput.Static.IsAnyCtrlKeyPressed()) //{ // MyReloadTestComponent.Enabled = false; //} if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad6)) { var view = MySector.MainCamera.ViewMatrix; var inv = Matrix.Invert(view); //MyPhysicalInventoryItem item = new MyPhysicalInventoryItem(100, var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone"); var item = new MyPhysicalInventoryItem(1, oreBuilder); var obj = MyFloatingObjects.Spawn(item, inv.Translation + inv.Forward * 1.0f, inv.Forward, inv.Up); obj.Physics.LinearVelocity = inv.Forward * 50; } if (false && MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9)) { List<HkShape> trShapes = new List<HkShape>(); List<HkConvexShape> shapes = new List<HkConvexShape>(); List<Matrix> matrices = new List<Matrix>(); var grid = new HkGridShape(2.5f, HkReferencePolicy.None); const short size = 50; for (short x = 0; x < size; x++) { for (short y = 0; y < size; y++) { for (short z = 0; z < size; z++) { var box = new HkBoxShape(Vector3.One); grid.AddShapes(new System.Collections.Generic.List<HkShape>() { box }, new Vector3S(x, y, z), new Vector3S(x, y, z)); trShapes.Add(new HkConvexTranslateShape(box, new Vector3(x, y, z), HkReferencePolicy.None)); shapes.Add(box); matrices.Add(Matrix.CreateTranslation(new Vector3(x, y, z))); } } } var emptyGeom = new HkGeometry(new List<Vector3>(), new List<int>()); var list = new HkListShape(trShapes.ToArray(), trShapes.Count, HkReferencePolicy.None); var compressedBv = new HkBvCompressedMeshShape(emptyGeom, shapes, matrices, HkWeldingType.None); var mopp = new HkMoppBvTreeShape(list, HkReferencePolicy.None); HkShapeBuffer buf = new HkShapeBuffer(); //HkShapeContainerIterator i = compressedBv.GetIterator(buf); //int count = 0; // will be 125000 //while (i.IsValid) //{ // count++; // i.Next(); //} buf.Dispose(); var info = new HkRigidBodyCinfo(); info.Mass = 10; info.CalculateBoxInertiaTensor(Vector3.One, 10); info.MotionType = HkMotionType.Dynamic; info.QualityType = HkCollidableQualityType.Moving; info.Shape = compressedBv; var body = new HkRigidBody(info); //MyPhysics.HavokWorld.AddRigidBody(body); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad7)) { foreach (var g in MyEntities.GetEntities().OfType<MyCubeGrid>()) { foreach (var s in g.CubeBlocks.Select(s => s.FatBlock).Where(s => s != null).OfType<MyMotorStator>()) { if (s.Rotor != null) { var q = Quaternion.CreateFromAxisAngle(s.Rotor.WorldMatrix.Up, MathHelper.ToRadians(45)); s.Rotor.CubeGrid.WorldMatrix = MatrixD.CreateFromQuaternion(q) * s.Rotor.CubeGrid.WorldMatrix; } } } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad8)) { var view = MySector.MainCamera.ViewMatrix; var inv = Matrix.Invert(view); var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone"); var obj = new MyObjectBuilder_FloatingObject() { Item = new MyObjectBuilder_InventoryItem() { PhysicalContent = oreBuilder, Amount = 1000 } }; obj.PositionAndOrientation = new MyPositionAndOrientation(inv.Translation + 2.0f * inv.Forward, inv.Forward, inv.Up); obj.PersistentFlags = MyPersistentEntityFlags2.InScene; var e = MyEntities.CreateFromObjectBuilderAndAdd(obj); e.Physics.LinearVelocity = Vector3.Normalize(inv.Forward) * 50.0f; } if (MyInput.Static.IsNewKeyPressed(MyKeys.Divide)) { } if (MyInput.Static.IsNewKeyPressed(MyKeys.Multiply)) { MyDebugDrawSettings.ENABLE_DEBUG_DRAW = !MyDebugDrawSettings.ENABLE_DEBUG_DRAW; MyDebugDrawSettings.DEBUG_DRAW_STRUCTURAL_INTEGRITY = true; var grids = MyEntities.GetEntities().OfType<MyCubeGrid>(); foreach (var g in grids) { if (!g.IsStatic)// || g.GetBlocks().Count < 800) //to compute only castle continue; g.CreateStructuralIntegrity(); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad1)) { var e = MyEntities.GetEntities().OfType<MyCubeGrid>().FirstOrDefault(); if (e != null) { e.Physics.RigidBody.MaxLinearVelocity = 1000; if (e.Physics.RigidBody2 != null) e.Physics.RigidBody2.MaxLinearVelocity = 1000; e.Physics.LinearVelocity = new Vector3(1000, 0, 0); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.Decimal)) { MyPrefabManager.Static.SpawnPrefab("respawnship", MySector.MainCamera.Position, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector); } if (MyInput.Static.IsNewKeyPressed(MyKeys.Multiply) && MyInput.Static.IsAnyShiftKeyPressed()) { GC.Collect(2); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad5)) { Thread.Sleep(250); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9)) { var obj = MySession.Static.ControlledEntity != null ? MySession.Static.ControlledEntity.Entity : null; if (obj != null) { const float dist = 5.0f; obj.PositionComp.SetPosition(obj.PositionComp.GetPosition() + obj.WorldMatrix.Forward * dist); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad4)) { MyEntity invObject = MySession.Static.ControlledEntity as MyEntity; if (invObject != null && invObject.HasInventory) { MyFixedPoint amount = 20000; var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone"); MyInventory inventory = invObject.GetInventory(0) as MyInventory; System.Diagnostics.Debug.Assert(inventory != null, "Null or unexpected type returned!"); inventory.AddItems(amount, oreBuilder); } handled = true; } //if (MyInput.Static.IsNewKeyPressed(Keys.NumPad8)) //{ // var pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 2; // var grid = (MyObjectBuilder_CubeGrid)MyObjectBuilderSerializer.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid); // grid.PositionAndOrientation = new MyPositionAndOrientation(pos, Vector3.Forward, Vector3.Up); // grid.CubeBlocks = new List<MyObjectBuilder_CubeBlock>(); // grid.GridSizeEnum = MyCubeSize.Large; // var block = new MyObjectBuilder_CubeBlock(); // block.BlockOrientation = MyBlockOrientation.Identity; // block.Min = Vector3I.Zero; // //var blockDefinition = Sandbox.Game.Managers.MyDefinitionManager.Static.GetCubeBlockDefinition(new CommonLib.ObjectBuilders.Definitions.MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock")); // block.SubtypeName = "LargeBlockArmorBlock"; // grid.CubeBlocks.Add(block); // grid.LinearVelocity = MySector.MainCamera.ForwardVector * 20; // grid.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; // var x = MyEntities.CreateFromObjectBuilderAndAdd(grid); //} //if (MyInput.Static.IsNewKeyPressed(Keys.NumPad9)) //{ // var pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 2; // var grid = (MyObjectBuilder_CubeGrid)MyObjectBuilderSerializer.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid); // grid.PositionAndOrientation = new MyPositionAndOrientation(pos, Vector3.Forward, Vector3.Up); // grid.CubeBlocks = new List<MyObjectBuilder_CubeBlock>(); // grid.GridSizeEnum = MyCubeSize.Large; // var block = new MyObjectBuilder_CubeBlock(); // block.BlockOrientation = MyBlockOrientation.Identity; // block.Min = Vector3I.Zero; // //var blockDefinition = Sandbox.Game.Managers.MyDefinitionManager.Static.GetCubeBlockDefinition(new CommonLib.ObjectBuilders.Definitions.MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock")); // block.SubtypeName = "LargeBlockGyro"; // grid.CubeBlocks.Add(block); // grid.LinearVelocity = MySector.MainCamera.ForwardVector * 20; // grid.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; // var x = MyEntities.CreateFromObjectBuilderAndAdd(grid); //} if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Delete)) { int count = MyEntities.GetEntities().OfType<MyFloatingObject>().Count(); foreach (var obj in MyEntities.GetEntities().OfType<MyFloatingObject>()) { if (obj == MySession.Static.ControlledEntity) { MySession.Static.SetCameraController(MyCameraControllerEnum.Spectator); } obj.Close(); } handled = true; } if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Decimal)) { foreach (var obj in MyEntities.GetEntities()) { if (obj != MySession.Static.ControlledEntity && (MySession.Static.ControlledEntity == null || obj != MySession.Static.ControlledEntity.Entity.Parent) && obj != MyCubeBuilder.Static.FindClosestGrid()) obj.Close(); } handled = true; } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9) || MyInput.Static.IsNewKeyPressed(MyKeys.NumPad5)) { //MyCubeGrid.UserCollisions = input.IsNewKeyPressed(Keys.NumPad9); var body = MySession.Static.ControlledEntity.Entity.GetTopMostParent().Physics; if (body.RigidBody != null) { //body.AddForce(Engine.Physics.MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, new Vector3(0, 0, 10 * body.Mass), null, null); body.RigidBody.ApplyLinearImpulse(body.Entity.WorldMatrix.Forward * body.Mass * 2); } handled = true; } //if (input.IsNewKeyPressed(Keys.J) && input.IsAnyCtrlKeyPressed()) //{ // MyGlobalInputComponent.CopyCurrentGridToClipboard(); // MyEntity addedEntity = MyGlobalInputComponent.PasteEntityFromClipboard(); // if (addedEntity != null) // { // Vector3 pos = addedEntity.GetPosition(); // pos.Z += addedEntity.WorldVolume.Radius * 1.5f; // addedEntity.SetPosition(pos); // } // handled = true; //} if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.OemComma)) { foreach (var e in MyEntities.GetEntities().OfType<MyFloatingObject>().ToArray()) e.Close(); } return handled; }
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()); }
public void ActivateFloatingObjectClipboard(MyObjectBuilder_FloatingObject floatingObject, Vector3 centerDeltaDirection, float dragVectorLength) { if (m_shipCreationClipboard.IsActive) return; MySessionComponentVoxelHand.Static.Enabled = false; DeactivateMultiBlockClipboard(); m_floatingObjectClipboard.SetFloatingObjectFromBuilder(floatingObject, centerDeltaDirection, dragVectorLength); }
private void SetFloatingObjectFromBuilderInternal(MyObjectBuilder_FloatingObject floatingObject, Vector3D offset) { this.m_copiedFloatingObjects.Add(floatingObject); this.m_copiedFloatingObjectOffsets.Add(offset); }
public static void InventoryDrop(IMyEntity entity, MyFixedPoint amount, MyDefinitionId definitionId) { Vector3D position; if (entity is IMyCharacter) position = entity.WorldMatrix.Translation + entity.WorldMatrix.Forward * 1.5f + entity.WorldMatrix.Up * 1.5f; // Spawn item 1.5m in front of player. else position = entity.WorldMatrix.Translation + entity.WorldMatrix.Forward * 1.5f; // Spawn item 1.5m in front of player in cockpit. MyObjectBuilder_FloatingObject floatingBuilder = new MyObjectBuilder_FloatingObject(); var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId); var gasContainer = content as MyObjectBuilder_GasContainerObject; if (gasContainer != null) gasContainer.GasLevel = 1f; floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = amount, PhysicalContent = content }; floatingBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene; // Very important floatingBuilder.PositionAndOrientation = new MyPositionAndOrientation() { Position = position, Forward = entity.WorldMatrix.Forward.ToSerializableVector3(), Up = entity.WorldMatrix.Up.ToSerializableVector3(), }; floatingBuilder.CreateAndSyncEntity(); }