private void CreateTopGrid(out MyCubeGrid topGrid, out MyAttachableTopBlockBase topBlock, long builtBy, MyCubeBlockDefinitionGroup topGroup) { if (topGroup == null) { topGrid = null; topBlock = null; return; } var gridSize = CubeGrid.GridSizeEnum; float size = MyDefinitionManager.Static.GetCubeSize(gridSize); var matrix = MatrixD.CreateWorld(Vector3D.Transform(m_constraintBasePos, Subpart3.WorldMatrix), WorldMatrix.Forward, WorldMatrix.Up); var definition = topGroup[gridSize]; Debug.Assert(definition != null); var block = MyCubeGrid.CreateBlockObjectBuilder(definition, Vector3I.Zero, MyBlockOrientation.Identity, MyEntityIdentifier.AllocateId(), OwnerId, fullyBuilt: MySession.Static.CreativeMode); var gridBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_CubeGrid>(); gridBuilder.GridSizeEnum = gridSize; gridBuilder.IsStatic = false; gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(matrix); gridBuilder.CubeBlocks.Add(block); var grid = MyEntityFactory.CreateEntity <MyCubeGrid>(gridBuilder); grid.Init(gridBuilder); topGrid = grid; topBlock = (MyPistonTop)topGrid.GetCubeBlock(Vector3I.Zero).FatBlock; if (!CanPlaceTop(topBlock, builtBy)) { topGrid = null; topBlock = null; grid.Close(); return; } //topGrid.SetPosition(topGrid.WorldMatrix.Translation - (topBlock.WorldMatrix.Translation/*Vector3.Transform(topBlock.DummyPosLoc, topGrid.WorldMatrix) - topGrid.WorldMatrix.Translation*/)); MyEntities.Add(grid); if (MyFakes.ENABLE_SENT_GROUP_AT_ONCE) { MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(grid), MyExternalReplicable.FindByObject(CubeGrid)); } }
protected void CreateRotorGrid(out MyCubeGrid rotorGrid, out MyMotorRotor rotorBlock, long builtBy, MyCubeBlockDefinitionGroup rotorGroup) { if (rotorGroup == null) { CreateRotorGridFailed(builtBy, out rotorGrid, out rotorBlock); return; } var gridSize = CubeGrid.GridSizeEnum; float size = MyDefinitionManager.Static.GetCubeSize(gridSize); var matrix = MatrixD.CreateWorld(Vector3D.Transform(DummyPosition, CubeGrid.WorldMatrix), WorldMatrix.Forward, WorldMatrix.Up); var definition = rotorGroup[gridSize]; Debug.Assert(definition != null); var block = MyCubeGrid.CreateBlockObjectBuilder(definition, Vector3I.Zero, MyBlockOrientation.Identity, MyEntityIdentifier.AllocateId(), OwnerId, fullyBuilt: MySession.Static.CreativeMode); var gridBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_CubeGrid>(); gridBuilder.GridSizeEnum = gridSize; gridBuilder.IsStatic = false; gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(matrix); gridBuilder.CubeBlocks.Add(block); var grid = MyEntityFactory.CreateEntity <MyCubeGrid>(gridBuilder); grid.Init(gridBuilder); rotorGrid = grid; rotorBlock = (MyMotorRotor)rotorGrid.GetCubeBlock(Vector3I.Zero).FatBlock; rotorGrid.PositionComp.SetPosition(rotorGrid.WorldMatrix.Translation - (Vector3D.Transform(rotorBlock.DummyPosLoc, rotorGrid.WorldMatrix) - rotorGrid.WorldMatrix.Translation)); if (!CanPlaceRotor(rotorBlock, builtBy)) { CreateRotorGridFailed(builtBy, out rotorGrid, out rotorBlock); grid.Close(); return; } if (Sync.IsServer) { MyEntities.Add(grid); } else { grid.Close(); } }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { if (GetCurrentMovementState() != MyCharacterMovementEnum.Standing && GetCurrentMovementState() != MyCharacterMovementEnum.RotatingLeft && GetCurrentMovementState() != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = MyFrameOption.None; } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { if (!UseAnimationForWeapon) { StoreWeaponRelativeMatrix(); UseAnimationForWeapon = true; m_resetWeaponAnimationState = true; } } if (!animDefinition.LeftHandItem.TypeId.IsNull) { if (m_leftHandItem != null) { (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased(); m_leftHandItem.Close(); } m_leftHandItem = MyEntityFactory.CreateEntity(animDefinition.LeftHandItem.TypeId); var ob = MyEntityFactory.CreateObjectBuilder(m_leftHandItem); m_leftHandItem.Init(ob); (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlAcquired(this); UpdateLeftHandItemPosition(); MyEntities.Add(m_leftHandItem); } }
private void CreateTopGrid(out MyCubeGrid topGrid, out MyPistonTop topBlock, MyCubeBlockDefinitionGroup topGroup) { if (topGroup == null) { topGrid = null; topBlock = null; return; } var gridSize = CubeGrid.GridSizeEnum; float size = MyDefinitionManager.Static.GetCubeSize(gridSize); var matrix = MatrixD.CreateWorld(Vector3D.Transform(m_constraintBasePos, Subpart3.WorldMatrix), WorldMatrix.Forward, WorldMatrix.Up); var definition = topGroup[gridSize]; Debug.Assert(definition != null); var block = MyCubeGrid.CreateBlockObjectBuilder(definition, Vector3I.Zero, MyBlockOrientation.Identity, MyEntityIdentifier.AllocateId(), OwnerId, fullyBuilt: MySession.Static.CreativeMode); var gridBuilder = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_CubeGrid>(); gridBuilder.GridSizeEnum = gridSize; gridBuilder.IsStatic = false; gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(matrix); gridBuilder.CubeBlocks.Add(block); var grid = MyEntityFactory.CreateEntity <MyCubeGrid>(gridBuilder); grid.Init(gridBuilder); topGrid = grid; topBlock = (MyPistonTop)topGrid.GetCubeBlock(Vector3I.Zero).FatBlock; //topGrid.SetPosition(topGrid.WorldMatrix.Translation - (topBlock.WorldMatrix.Translation/*Vector3.Transform(topBlock.DummyPosLoc, topGrid.WorldMatrix) - topGrid.WorldMatrix.Translation*/)); MyEntities.Add(grid); MySyncCreate.SendEntityCreated(grid.GetObjectBuilder()); m_topBlockId = topBlock.EntityId; }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { var currentMovementState = GetCurrentMovementState(); if (DefinitionId.Value.SubtypeId == medievelMaleSubtypeId) { if (command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly if (currentMovementState == MyCharacterMovementEnum.RotatingLeft || currentMovementState == MyCharacterMovementEnum.RotatingRight || currentMovementState == MyCharacterMovementEnum.Standing) { bonesArea = TopBody + " LowerBody"; } else { bonesArea = TopBody; } frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } else if (m_lastBonesArea == TopBody + " LowerBody") { StopLowerCharacterAnimation(0.2f); } m_lastBonesArea = bonesArea; } else { if (currentMovementState != MyCharacterMovementEnum.Standing && currentMovementState != MyCharacterMovementEnum.RotatingLeft && currentMovementState != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { if (!UseAnimationForWeapon) { StoreWeaponRelativeMatrix(); UseAnimationForWeapon = true; m_resetWeaponAnimationState = true; } } if (!animDefinition.LeftHandItem.TypeId.IsNull) { if (m_leftHandItem != null) { (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased(); m_leftHandItem.Close(); } m_leftHandItem = MyEntityFactory.CreateEntity(animDefinition.LeftHandItem.TypeId); var ob = MyEntityFactory.CreateObjectBuilder(m_leftHandItem); m_leftHandItem.Init(ob); var leftHandTool = m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>; if (leftHandTool != null) { leftHandTool.OnControlAcquired(this); } (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlAcquired(this); UpdateLeftHandItemPosition(); MyEntities.Add(m_leftHandItem); } }