public static void CreateFracturedBlock(MyObjectBuilder_FracturedBlock fracturedBlock, long grid, Vector3I position) { var msg = new CreateFractureBlockMsg(); msg.FracturedBlock = fracturedBlock; msg.Grid = grid; msg.Position = position; MySession.Static.SyncLayer.SendMessageToAll(ref msg); }
static void OnCreateFracturedBlockMessage(long gridId, Vector3I position, [Serialize(MyObjectFlags.Dynamic, DynamicSerializerType = typeof(MyObjectBuilderDynamicSerializer))] MyObjectBuilder_FracturedBlock fracturedBlock) { MyCubeGrid grid; if (MyEntities.TryGetEntityById(gridId, out grid)) { grid.EnableGenerators(false, true); grid.CreateFracturedBlock(fracturedBlock, position); grid.EnableGenerators(true, true); } }
public override MyObjectBuilder_CubeBlock GetObjectBuilderCubeBlock(bool copy = false) { MyObjectBuilder_FracturedBlock.ShapeB eb2; MyObjectBuilder_FracturedBlock objectBuilderCubeBlock = base.GetObjectBuilderCubeBlock(copy) as MyObjectBuilder_FracturedBlock; if (!string.IsNullOrEmpty(this.Shape.Name) && !this.Shape.IsCompound()) { eb2 = new MyObjectBuilder_FracturedBlock.ShapeB { Name = this.Shape.Name }; objectBuilderCubeBlock.Shapes.Add(eb2); } else { this.Shape.GetChildren(m_children); foreach (HkdShapeInstanceInfo info in m_children) { eb2 = new MyObjectBuilder_FracturedBlock.ShapeB { Name = info.ShapeName }; eb2.Orientation = Quaternion.CreateFromRotationMatrix(info.GetTransform().GetOrientation()); eb2.Fixed = MyDestructionHelper.IsFixed(info.Shape); MyObjectBuilder_FracturedBlock.ShapeB item = eb2; objectBuilderCubeBlock.Shapes.Add(item); } m_children.Clear(); } foreach (MyDefinitionId id in this.OriginalBlocks) { objectBuilderCubeBlock.BlockDefinitions.Add((SerializableDefinitionId)id); } foreach (MyBlockOrientation orientation in this.Orientations) { objectBuilderCubeBlock.BlockOrientations.Add(orientation); } if (this.MultiBlocks != null) { foreach (MultiBlockPartInfo info2 in this.MultiBlocks) { if (info2 == null) { objectBuilderCubeBlock.MultiBlocks.Add(null); continue; } MyObjectBuilder_FracturedBlock.MyMultiBlockPart item = new MyObjectBuilder_FracturedBlock.MyMultiBlockPart(); item.MultiBlockDefinition = (SerializableDefinitionId)info2.MultiBlockDefinition; item.MultiBlockId = info2.MultiBlockId; objectBuilderCubeBlock.MultiBlocks.Add(item); } } return(objectBuilderCubeBlock); }
public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid) { base.Init(builder, cubeGrid); base.CheckConnectionAllowed = true; MyObjectBuilder_FracturedBlock block = builder as MyObjectBuilder_FracturedBlock; if (block.Shapes.Count == 0) { if (!block.CreatingFracturedBlock) { throw new Exception("No relevant shape was found for fractured block. It was probably reexported and names changed."); } } else { this.OriginalBlocks = new List <MyDefinitionId>(); this.Orientations = new List <MyBlockOrientation>(); List <HkdShapeInstanceInfo> list = new List <HkdShapeInstanceInfo>(); foreach (SerializableDefinitionId id in block.BlockDefinitions) { MyCubeBlockDefinition cubeBlockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(id); string model = cubeBlockDefinition.Model; if (MyModels.GetModelOnlyData(model).HavokBreakableShapes == null) { MyDestructionData.Static.LoadModelDestruction(model, cubeBlockDefinition, Vector3.One, true, false); } HkdBreakableShape shape = MyModels.GetModelOnlyData(model).HavokBreakableShapes[0]; Quaternion? rotation = null; Vector3? translation = null; HkdShapeInstanceInfo item = new HkdShapeInstanceInfo(shape, rotation, translation); list.Add(item); m_children.Add(item); shape.GetChildren(m_children); if (cubeBlockDefinition.BuildProgressModels != null) { MyCubeBlockDefinition.BuildProgressModel[] buildProgressModels = cubeBlockDefinition.BuildProgressModels; for (int j = 0; j < buildProgressModels.Length; j++) { model = buildProgressModels[j].File; if (MyModels.GetModelOnlyData(model).HavokBreakableShapes == null) { MyDestructionData.Static.LoadModelDestruction(model, cubeBlockDefinition, Vector3.One, true, false); } shape = MyModels.GetModelOnlyData(model).HavokBreakableShapes[0]; rotation = null; translation = null; item = new HkdShapeInstanceInfo(shape, rotation, translation); list.Add(item); m_children.Add(item); shape.GetChildren(m_children); } } this.OriginalBlocks.Add(id); } foreach (SerializableBlockOrientation orientation in block.BlockOrientations) { this.Orientations.Add((MyBlockOrientation)orientation); } if (block.MultiBlocks.Count > 0) { this.MultiBlocks = new List <MultiBlockPartInfo>(); foreach (MyObjectBuilder_FracturedBlock.MyMultiBlockPart part in block.MultiBlocks) { if (part == null) { this.MultiBlocks.Add(null); continue; } MultiBlockPartInfo item = new MultiBlockPartInfo(); item.MultiBlockDefinition = part.MultiBlockDefinition; item.MultiBlockId = part.MultiBlockId; this.MultiBlocks.Add(item); } } this.m_shapes.AddRange(block.Shapes); for (int i = 0; i < m_children.Count; i++) { HkdShapeInstanceInfo child = m_children[i]; Func <MyObjectBuilder_FracturedBlock.ShapeB, bool> predicate = s => s.Name == child.ShapeName; IEnumerable <MyObjectBuilder_FracturedBlock.ShapeB> source = this.m_shapes.Where <MyObjectBuilder_FracturedBlock.ShapeB>(predicate); if (source.Count <MyObjectBuilder_FracturedBlock.ShapeB>() <= 0) { child.GetChildren(m_children); } else { MyObjectBuilder_FracturedBlock.ShapeB item = source.First <MyObjectBuilder_FracturedBlock.ShapeB>(); Matrix transform = Matrix.CreateFromQuaternion((Quaternion)item.Orientation); transform.Translation = child.GetTransform().Translation; HkdShapeInstanceInfo info2 = new HkdShapeInstanceInfo(child.Shape.Clone(), transform); if (item.Fixed) { info2.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED); } list.Add(info2); m_shapeInfos.Add(info2); this.m_shapes.Remove(item); } } if (m_shapeInfos.Count == 0) { m_children.Clear(); throw new Exception("No relevant shape was found for fractured block. It was probably reexported and names changed."); } foreach (HkdShapeInstanceInfo info3 in m_shapeInfos) { HkdBreakableShape shape = info3.Shape; if (!string.IsNullOrEmpty(shape.Name)) { this.Render.AddPiece(info3.Shape.Name, Matrix.CreateFromQuaternion(Quaternion.CreateFromRotationMatrix(info3.GetTransform().GetOrientation()))); } } if (base.CubeGrid.CreatePhysics) { HkdBreakableShape?oldParent = null; HkdBreakableShape shape3 = (HkdBreakableShape) new HkdCompoundBreakableShape(oldParent, m_shapeInfos); shape3.RecalcMassPropsFromChildren(); this.Shape = shape3; HkMassProperties massProperties = new HkMassProperties(); shape3.BuildMassProperties(ref massProperties); this.Shape = new HkdBreakableShape(shape3.GetShape(), ref massProperties); shape3.RemoveReference(); foreach (HkdShapeInstanceInfo info4 in m_shapeInfos) { this.Shape.AddShape(ref info4); } this.Shape.SetStrenght(MyDestructionConstants.STRENGTH); this.CreateMountPoints(); } m_children.Clear(); foreach (HkdShapeInstanceInfo info5 in m_shapeInfos) { info5.Shape.RemoveReference(); } foreach (HkdShapeInstanceInfo info6 in list) { info6.RemoveReference(); } m_shapeInfos.Clear(); } }
public static void CreateFracturedBlock(MyObjectBuilder_FracturedBlock fracturedBlock, long gridId, Vector3I position) { Debug.Assert(Sync.IsServer); MyMultiplayer.RaiseStaticEvent(s => MySyncDestructions.OnCreateFracturedBlockMessage, gridId, position, fracturedBlock); }
public static void CreateFracturedBlock(MyObjectBuilder_FracturedBlock fracturedBlock, long gridId, Vector3I position) { Debug.Assert(Sync.IsServer); MyMultiplayer.RaiseStaticEvent(s => MySyncDestructions.OnCreateFracturedBlockMessage, gridId, position, fracturedBlock); }
public static void CreateFracturedBlock(MyObjectBuilder_FracturedBlock fracturedBlock, long grid, Vector3I position) { Debug.Assert(Sync.IsServer); var msg = new CreateFractureBlockMsg(); msg.FracturedBlock = fracturedBlock; msg.Grid = grid; msg.Position = position; MySession.Static.SyncLayer.SendMessageToAll(ref msg); }