private void CreateSubpartsConstraint(MyEntitySubpart subpart) { m_subpartsFixedData = new HkFixedConstraintData(); m_subpartsFixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); m_subpartsFixedData.SetInertiaStabilizationFactor(1); var matAD = MatrixD.CreateWorld(Position * CubeGrid.GridSize + Vector3D.Transform(Vector3D.Transform(m_subpartsConstraintPos, WorldMatrix), CubeGrid.PositionComp.LocalMatrix), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); matAD.Translation = CubeGrid.Physics.WorldToCluster(matAD.Translation); var matA = (Matrix)matAD; var matB = subpart.PositionComp.LocalMatrix; m_subpartsFixedData.SetInWorldSpace(ref matA, ref matB, ref matB); //Dont dispose the fixed data or we wont have access to them HkConstraintData constraintData = m_subpartsFixedData; if (Sync.IsServer) // Breakable only on server { constraintData = new HkBreakableConstraintData(m_subpartsFixedData) { Threshold = BreakOffTreshold }; } m_subpartsConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, subpart.Physics.RigidBody, constraintData); Debug.Assert(m_subpartsConstraint.RigidBodyA != null); m_subpartsConstraint.WantRuntime = true; }
/// <summary> /// Called by pool when returned to it. /// </summary> public void Clear(bool returnParticles = true) { Rifle = null; MagazineSubpart = null; Spraying = false; SprayCooldown = 0; Ammo = 0; JustInitialized = false; SoundEmitter.Stop(); OwnerSteamId = 0; OwnerIsLocalPlayer = false; PaintPreviewMaterial = null; if (OwnerInfo != null) { OwnerInfo.ColorSlotSelected -= OwnerColorSlotSelected; OwnerInfo.ColorListChanged -= OwnerColorListChanged; OwnerInfo.SkinSelected -= OwnerSkinSelected; OwnerInfo.ApplyColorChanged -= OwnerPaletteUpdate; OwnerInfo.ApplySkinChanged -= OwnerPaletteUpdate; OwnerInfo.ColorPickModeChanged -= OwnerColorPickModeChanged; OwnerInfo = null; } ClearParticles(); }
private void CheckAndAddLight() { // check if block is initialized if (m_init && (m_light_model == null || m_light_model.Closed) && m_turret.IsFunctional) { Logger.Instance.LogMessage("Setup Subpart"); // setup subpart var turretsub = (Entity as MyEntity).Subparts["MissileTurretBase1"]?.Subparts["MissileTurretBarrels"]; m_light_model = turretsub; m_light_model.OnClose += OnModelClosing; m_light_model.PositionComp.OnPositionChanged += OnModelPositionChanged; // setup light MakeLight(); // set stored terminal data SetTerminalValues(m_turret); // check light status OnEnabledChanged(m_turret); Logger.Instance.LogMessage("init turret: " + m_turret.EntityId); Logger.Instance.LogMessage("init light model: " + m_light_model.EntityId); Logger.Instance.LogMessage("init light: " + m_light_emmitter.RenderObjectID); if (PlayerInput.Instance.isServer) { AddAmmo(); m_turret.GetActionWithName("ShootOnce").Apply(m_turret); } } }
private void CreateSubpartsConstraint(MyEntitySubpart subpart) { m_subpartsFixedData = new HkFixedConstraintData(); m_subpartsFixedData.SetSolvingMethod(HkSolvingMethod.MethodStabilized); m_subpartsFixedData.SetInertiaStabilizationFactor(1); var matAD = MatrixD.CreateWorld(Position * CubeGrid.GridSize + Vector3D.Transform(Vector3D.Transform(m_subpartsConstraintPos, WorldMatrix), CubeGrid.PositionComp.LocalMatrix), PositionComp.LocalMatrix.Forward, PositionComp.LocalMatrix.Up); matAD.Translation = CubeGrid.Physics.WorldToCluster(matAD.Translation); var matA = (Matrix)matAD; var matB = subpart.PositionComp.LocalMatrix; m_subpartsFixedData.SetInWorldSpace(ref matA, ref matB, ref matB); //Dont dispose the fixed data or we wont have access to them HkConstraintData constraintData = m_subpartsFixedData; m_subpartsConstraint = new HkConstraint(CubeGrid.Physics.RigidBody, m_subpartPhysics.RigidBody, constraintData); var info = CubeGrid.Physics.RigidBody.GetCollisionFilterInfo(); info = HkGroupFilter.CalcFilterInfo(CubeGrid.Physics.RigidBody.Layer, HkGroupFilter.GetSystemGroupFromFilterInfo(info), 1, 1); m_subpartPhysics.RigidBody.SetCollisionFilterInfo(info); CubeGrid.Physics.HavokWorld.RefreshCollisionFilterOnEntity(m_subpartPhysics.RigidBody); Debug.Assert(m_subpartsConstraint.RigidBodyA != null); m_subpartsConstraint.WantRuntime = true; }
/// <summary> /// Add part for animation. /// </summary> /// <param name="parent">parent part, null for root.</param> /// <param name="modelFile">Model file name inside Models folder, excluding extension.</param> /// <param name="smoothAnim">smooth animation, linear lerp between keyframes.</param> /// <param name="visible">initialize it visible?</param> /// <returns>part or null for failure.</returns> public AnimaPart AddPart(AnimaPart parent, string modelFile, bool smoothAnim = false, bool visible = true) { if (m_entity == null) { return(null); } // Create part MyEntity parentEntity = (parent != null) ? parent.Entity : m_entity; MyEntity part_entity = new MyEntitySubpart(); part_entity.Flags = EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.NeedsDrawFromParent | EntityFlags.InvalidateOnMove; part_entity.IsPreview = true; part_entity.Init(null, m_modelsFolder + modelFile + ".mwm", parentEntity, null, null); part_entity.Render.EnableColorMaskHsv = true; part_entity.Render.ColorMaskHsv = m_entity.Render.ColorMaskHsv; part_entity.Render.PersistentFlags = MyPersistentEntityFlags2.CastShadows; part_entity.PositionComp.LocalMatrix = Matrix.Identity; part_entity.OnAddedToScene(parent); AnimaPart part = new AnimaPart(this, parent, part_entity); if (!visible) { part.Visible = false; } m_partList.Add(part); return(part); }
public NPCDataAnimator(IMyCubeGrid grid, IMySlimBlock npc, float moveSpeed) { this.grid = grid; this.npc = npc; this.moveSpeed = moveSpeed; top_left_leg = npc.FatBlock.GetSubpart("leg_top_left"); top_right_leg = npc.FatBlock.GetSubpart("leg_top_right"); //gun_muzzle = npc.FatBlock.GetSubpart("muzzle_projectile"); bottom_left_leg = top_left_leg.GetSubpart("leg_bottom_left"); bottom_right_leg = top_right_leg.GetSubpart("leg_bottom_right"); }
private void setAngleOnPart(float angle, MyEntitySubpart part) { var initial = part.PositionComp.LocalMatrix; var current_mat = MatrixD.CreateRotationX(angle * 4); current_mat.M41 = initial.M41; current_mat.M42 = initial.M42; current_mat.M43 = initial.M43; if (!part.Closed) { part.PositionComp.LocalMatrix = current_mat; } }
protected void RotateModels() { if (modelBase1 == null || modelBase2 == null || modelBarrel == null) { if (CubeBlock.Subparts.ContainsKey("GatlingTurretBase1")) { modelBase1 = CubeBlock.Subparts["GatlingTurretBase1"]; modelBase2 = modelBase1.Subparts["GatlingTurretBase2"]; modelBarrel = modelBase2.Subparts["GatlingBarrel"]; if (!modelBase1.Render.IsChild(0)) { ControlLayer.Entity.NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME; return; } } else { return; } } ClampAzimuthAndElevation(); Matrix azimuthRotation; Matrix.CreateRotationY(Azimuth, out azimuthRotation); Matrix localMatrixRef = modelBase1.PositionComp.LocalMatrixRef; azimuthRotation.Translation = localMatrixRef.Translation; Matrix blockLocalMatrix = CubeBlock.PositionComp.LocalMatrixRef; Matrix result2; Matrix.Multiply(ref azimuthRotation, ref blockLocalMatrix, out result2); modelBase1.PositionComp.SetLocalMatrix(ref azimuthRotation, modelBase1.Physics, false, ref result2, true); Matrix elevationRotation; Matrix.CreateRotationX(Elevation, out elevationRotation); localMatrixRef = modelBase2.PositionComp.LocalMatrixRef; elevationRotation.Translation = localMatrixRef.Translation; Matrix result4; Matrix.Multiply(ref elevationRotation, ref result2, out result4); modelBase2.PositionComp.SetLocalMatrix(ref elevationRotation, modelBase2.Physics, true, ref result4, true); gun.GunBase.WorldMatrix = modelBarrel.WorldMatrix; }
public IMyCubeGrid GetTarget() { //var turretBase = Entity as Sandbox.ModAPI.IMyLargeTurretBase; //var fixedWeapon = Entity as Sandbox.ModAPI.IMyUserControllableGun; //if (turretBase != null) //{ // target = turretBase.Target; //} try { MyEntitySubpart subpart1 = cubeBlock.GetSubpart("GatlingTurretBase1"); MyEntitySubpart subpart2 = subpart1.GetSubpart("GatlingTurretBase2"); if (cubeBlock == null || cubeBlock.CubeGrid == null || subpart1 == null || subpart2 == null || subpart1.WorldMatrix == null || subpart2.WorldMatrix == null) { return(null); } var from = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 0.3d; var to = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 800d; LineD ray = new LineD(from, to); List <MyLineSegmentOverlapResult <MyEntity> > result = new List <MyLineSegmentOverlapResult <MyEntity> >(); MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref ray, result, MyEntityQueryType.Both); foreach (var resultItem in result) { if (resultItem.Element == null) { continue; } if (resultItem.Element.EntityId != cubeBlock.CubeGrid.EntityId) { if (resultItem.Element is IMyCubeGrid) { return(resultItem.Element as IMyCubeGrid); } } } } catch (KeyNotFoundException) { } return(null); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { m_drillBase = new MyDrillBase(this, MyDrillConstants.DRILL_HAND_DUST_EFFECT, MyDrillConstants.DRILL_HAND_DUST_STONES_EFFECT, MyDrillConstants.DRILL_HAND_SPARKS_EFFECT, new MyDrillSensorRayCast(-0.5f, 1.8f), new MyDrillCutOut(0.5f, 0.7f), SPIKE_SLOWDOWN_TIME_IN_SECONDS, floatingObjectSpawnOffset: -0.25f, floatingObjectSpawnRadius: 1.4f * 0.25f, sounds: m_sounds ); AddDebugRenderComponent(new Components.MyDebugRenderCompomentDrawDrillBase(m_drillBase)); m_handItemDefId = objectBuilder.GetId(); base.Init(objectBuilder); Init(null, "Models\\Weapons\\HandDrill.mwm", null, null, null); Render.CastShadows = true; Render.NeedsResolveCastShadow = false; m_spike = Subparts["Spike"]; m_spikeBasePos = m_spike.PositionComp.LocalMatrix.Translation; m_drillBase.IgnoredEntities.Add(this); m_drillBase.OnWorldPositionChanged(PositionComp.WorldMatrix); PhysicalObject.GunEntity = (MyObjectBuilder_EntityBase)objectBuilder.Clone(); PhysicalObject.GunEntity.EntityId = this.EntityId; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; m_oreDetectorBase.DetectionRadius = 20; m_oreDetectorBase.OnCheckControl = OnCheckControl; var sinkComp = new MyResourceSinkComponent(); sinkComp.Init( MyStringHash.GetOrCompute("Utility"), MyEnergyConstants.REQUIRED_INPUT_HAND_DRILL, () => m_tryingToDrill ? SinkComp.MaxRequiredInput : 0f); SinkComp = sinkComp; }
void UpdateMatrix() { try { if (!lcd.IsFunctional || !lcd.IsWorking) { return; } subpart = Entity.GetSubpart("top"); if (subpart != null) { var pos = subpart.PositionComp.LocalMatrix; var rot = MatrixD.CreateFromAxisAngle(pos.Up, MathHelper.ToRadians(-rotation)); var tr = pos.Translation; pos = pos * rot; pos.Translation = tr; subpart.PositionComp.LocalMatrix = pos; } if (lcd != null) { var pos = lcd.PositionComp.LocalMatrix; var rot = MatrixD.CreateFromAxisAngle(pos.Up, MathHelper.ToRadians(rotation)); var tr = pos.Translation; pos = pos * rot; pos.Translation = tr; lcd.PositionComp.LocalMatrix = pos; } } catch { } }
public Turret(IMyCubeBlock block) : base(block) { // definition limits MyLargeTurretBaseDefinition definition = CubeBlock.GetCubeBlockDefinition() as MyLargeTurretBaseDefinition; if (definition == null) { throw new NullReferenceException("definition"); } minElevation = Math.Max(MathHelper.ToRadians(definition.MinElevationDegrees), -0.6f); maxElevation = MathHelper.ToRadians(definition.MaxElevationDegrees); minAzimuth = MathHelper.ToRadians(definition.MinAzimuthDegrees); maxAzimuth = MathHelper.ToRadians(definition.MaxAzimuthDegrees); Can360 = Math.Abs(definition.MaxAzimuthDegrees - definition.MinAzimuthDegrees) >= 360; // speeds are in rads per ms (from S.E. source) speedElevation = definition.ElevationSpeed * 100f / 6f; speedAzimuth = definition.RotationSpeed * 100f / 6f; setElevation = myTurret.Elevation; setAzimuth = myTurret.Azimuth; // subparts for turrets form a chain var subparts = ((MyCubeBlock)CubeBlock).Subparts; while (subparts.Count != 0) { m_barrel = subparts.FirstPair().Value; subparts = m_barrel.Subparts; } //Log.DebugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()"); //Log.DebugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()"); }
public override void Close() { if (block == null) { return; } // Unhook from events. block.IsWorkingChanged -= IsWorkingChanged; block.PropertiesChanged -= PropertiesChanged; if (EXPERIMENTAL) { if (_light != null) { MyLights.RemoveLight(_light); _light = null; } if (_lightInner != null) { MyLights.RemoveLight(_lightInner); _lightInner = null; } if (_lightOuter != null) { MyLights.RemoveLight(_lightOuter); _lightOuter = null; } } block = null; subpart = null; NeedsUpdate = MyEntityUpdateEnum.NONE; }
private void UpdateColor(MyEntitySubpart shellSide) { shellSide.SetEmissiveParts(ShieldEmissiveAlpha, _activeColor, 100f); }
private static void MoveSubpart(MyEntitySubpart subpart, Vector3 offset) { if (subpart != null) { var positionComponent = subpart.PositionComp; var localMatrix = positionComponent.LocalMatrix; localMatrix.Translation += offset; positionComponent.LocalMatrix = localMatrix; } }
public AnimatedBarrel(MyEntitySubpart subpart) { this.subpart = subpart; initialTranslation = subpart.PositionComp.LocalMatrix.Translation; }
private void UpdateHealthColor(MyEntitySubpart shellSide) { shellSide.SetEmissiveParts(ShieldHealthEmissive, _activeColor, 100f); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { if (objectBuilder.SubtypeName != null && objectBuilder.SubtypeName.Length > 0) { PhysicalObject = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>(objectBuilder.SubtypeName + "Item"); m_physItemDef = MyDefinitionManager.Static.GetPhysicalItemDefinition(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalGunObject), objectBuilder.SubtypeName + "Item")); } else { PhysicalObject = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>("HandDrillItem"); m_physItemDef = MyDefinitionManager.Static.GetPhysicalItemDefinition(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalGunObject), "HandDrillItem")); } (PositionComp as MyPositionComponent).WorldPositionChanged = WorldPositionChanged; m_handItemDefId = objectBuilder.GetId(); var definition = MyDefinitionManager.Static.TryGetHandItemDefinition(ref m_handItemDefId); m_speedMultiplier = 1f / (definition as MyHandDrillDefinition).SpeedMultiplier; m_drillBase = new MyDrillBase(this, MyDrillConstants.DRILL_HAND_DUST_EFFECT, MyDrillConstants.DRILL_HAND_DUST_STONES_EFFECT, MyDrillConstants.DRILL_HAND_SPARKS_EFFECT, new MyDrillSensorRayCast(-0.5f, 1.8f), new MyDrillCutOut(0.5f, 0.35f * (definition as MyHandDrillDefinition).DistanceMultiplier), SPIKE_SLOWDOWN_TIME_IN_SECONDS, floatingObjectSpawnOffset: -0.25f, floatingObjectSpawnRadius: 1.4f * 0.25f ); m_drillBase.VoxelHarvestRatio = MyDrillConstants.VOXEL_HARVEST_RATIO * (definition as MyHandDrillDefinition).HarvestRatioMultiplier; AddDebugRenderComponent(new Components.MyDebugRenderCompomentDrawDrillBase(m_drillBase)); base.Init(objectBuilder); var physDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(definition.PhysicalItemId); Init(null, physDefinition.Model, null, null, null); Render.CastShadows = true; Render.NeedsResolveCastShadow = false; m_spike = Subparts["Spike"]; m_spikeBasePos = m_spike.PositionComp.LocalMatrix.Translation; m_drillBase.IgnoredEntities.Add(this); m_drillBase.OnWorldPositionChanged(PositionComp.WorldMatrix); PhysicalObject.GunEntity = (MyObjectBuilder_EntityBase)objectBuilder.Clone(); PhysicalObject.GunEntity.EntityId = this.EntityId; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; m_oreDetectorBase.DetectionRadius = 20; m_oreDetectorBase.OnCheckControl = OnCheckControl; var sinkComp = new MyResourceSinkComponent(); sinkComp.Init( MyStringHash.GetOrCompute("Utility"), MyEnergyConstants.REQUIRED_INPUT_HAND_DRILL, () => m_tryingToDrill ? SinkComp.MaxRequiredInput : 0f); SinkComp = sinkComp; foreach (ToolSound toolSound in definition.ToolSounds) { if (toolSound.type == null || toolSound.subtype == null || toolSound.sound == null) { continue; } if (toolSound.type.Equals("Main")) { if (toolSound.subtype.Equals("Idle")) { m_drillBase.m_idleSoundLoop = new MySoundPair(toolSound.sound); } if (toolSound.subtype.Equals("Soundset")) { m_drillBase.m_drillMaterial = MyStringHash.GetOrCompute(toolSound.sound); } } } }
public Turret(IMyCubeBlock block) : base(block) { myLogger = new Logger("Turret", block); Registrar.Add(CubeBlock, this); if (TP_TargetMissiles == null) { myLogger.debugLog("Filling Terminal Properties", Logger.severity.INFO); IMyTerminalBlock term = CubeBlock as IMyTerminalBlock; TP_TargetMissiles = term.GetProperty("TargetMissiles").AsBool(); TP_TargetMeteors = term.GetProperty("TargetMeteors").AsBool(); TP_TargetCharacters = term.GetProperty("TargetCharacters").AsBool(); TP_TargetMoving = term.GetProperty("TargetMoving").AsBool(); TP_TargetLargeGrids = term.GetProperty("TargetLargeShips").AsBool(); TP_TargetSmallGrids = term.GetProperty("TargetSmallShips").AsBool(); TP_TargetStations = term.GetProperty("TargetStations").AsBool(); } // definition limits MyLargeTurretBaseDefinition definition = CubeBlock.GetCubeBlockDefinition() as MyLargeTurretBaseDefinition; if (definition == null) throw new NullReferenceException("definition"); minElevation = Math.Max(MathHelper.ToRadians(definition.MinElevationDegrees), -0.6f); maxElevation = MathHelper.ToRadians(definition.MaxElevationDegrees); minAzimuth = MathHelper.ToRadians(definition.MinAzimuthDegrees); maxAzimuth = MathHelper.ToRadians(definition.MaxAzimuthDegrees); Can360 = Math.Abs(definition.MaxAzimuthDegrees - definition.MinAzimuthDegrees) >= 360; // speeds are in rads per ms (from S.E. source) speedElevation = definition.ElevationSpeed * 100f / 6f; speedAzimuth = definition.RotationSpeed * 100f / 6f; setElevation = myTurret.Elevation; setAzimuth = myTurret.Azimuth; // subparts for turrets form a chain var subparts = ((MyCubeBlock)CubeBlock).Subparts; while (subparts.Count != 0) { m_barrel = subparts.FirstPair().Value; subparts = m_barrel.Subparts; } //myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()"); //myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()"); }
public override void UpdateBeforeSimulation() { if (UI == null || !UI.Initialized_Attractor) { return; } if (Entity == null) { return; } IMyCubeBlock cube = Entity as IMyCubeBlock; var target = GetTarget(); var isShooting = (Entity as Sandbox.ModAPI.IMyUserControllableGun).IsShooting; if (isShooting && target != null && target.Physics != null) { var grid = target; MyEntitySubpart subpart1 = cubeBlock.GetSubpart("GatlingTurretBase1"); MyEntitySubpart subpart2 = subpart1.GetSubpart("GatlingTurretBase2"); if (subpart1 == null || subpart2 == null || subpart1.WorldMatrix == null || subpart2.WorldMatrix == null) { return; } var from = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 0.3d; var to = target.Physics.CenterOfMassWorld; var toTarget = to - from; toTarget.Normalize(); var distance = Vector3D.Distance(from, to); var min = UI.MinSlider.Getter(terminalBlock); var max = UI.MaxSlider.Getter(terminalBlock); var force = UI.StrengthSlider.Getter(terminalBlock); var forceVector = force * toTarget; if (distance > max) { grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, -forceVector, null, null); } else if (distance < min) { var percentage = 1 - (distance * distance) / (min * min); var additionalForce = toTarget * percentage * (UI.StrengthSlider.Max - force); var velocity = new Vector3D(grid.Physics.LinearVelocity); velocity.Normalize(); grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, forceVector + additionalForce / 4, null, null); } else { var velocity = new Vector3D(grid.Physics.LinearVelocity); velocity.Normalize(); grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, force * -velocity / 3, null, null); } DrawShootingEffect(from, to); } Recharge(); }
private void setOffsetOnPart(float offsetChange, MyEntitySubpart part) { offsetChange *= 0.15f; part.PositionComp.LocalMatrix *= Matrix.CreateTranslation(0, offsetChange, 0); }
public override void UpdateBeforeSimulation() { int chargesInInventory = (int)m_inventory.GetItemAmount(chargeDefinitionIds [damageUpgrades]); IMyCubeBlock cube = Entity as IMyCubeBlock; long currentShootTime = ((MyObjectBuilder_InteriorTurret)cube.GetObjectBuilderCubeBlock()).GunBase.LastShootTime; if (currentHeat > 0f) { if ((ticks - lastShootTimeTicks) > beamWeaponInfo.heatDissipationDelay) { currentHeat -= beamWeaponInfo.heatDissipationPerTick; if (currentHeat <= 0f) { currentHeat = 0f; overheated = false; } } } //MyAPIGateway.Utilities.ShowNotification("TIME: " + currentShootTime + " :: " + lastShootTime, 17, MyFontEnum.Red); if (currentShootTime != lastShootTime) { // test hitBool = false; MyEntitySubpart subpart1 = cubeBlock.GetSubpart("InteriorTurretBase1"); MyEntitySubpart subpart2 = subpart1.GetSubpart("InteriorTurretBase2");; //MyAPIGateway.Utilities.ShowNotification("Dif: " + (currentShootTime - lastShootTime), 17, MyFontEnum.Blue); from = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 1.25d; to = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 3000d; LineD testRay = new LineD(from, to); List <MyLineSegmentOverlapResult <MyEntity> > result = new List <MyLineSegmentOverlapResult <MyEntity> >(); MyGamePruningStructure.GetAllEntitiesInRay(ref testRay, result); foreach (var resultItem in result) { IMyCubeGrid grid = resultItem.Element as IMyCubeGrid; IMyDestroyableObject destroyableEntity = resultItem.Element as IMyDestroyableObject; if (grid != null) { IMySlimBlock slimblock; double hitd; Vector3D?resultVec = grid.GetLineIntersectionExactAll(ref testRay, out hitd, out slimblock); if (resultVec != null) { hitBool = true; toTarget = from + subpart2.WorldMatrix.Forward * hitd; if (!MyAPIGateway.Session.CreativeMode) { slimblock.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId); } else { slimblock.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId); } //MyAPIGateway.Utilities.ShowNotification("" + s.BlockDefinition.Id.SubtypeId + " ::: " + resultItem.Distance, 17); } } if (destroyableEntity != null) { IMyEntity ent = (IMyEntity)destroyableEntity; double hitd = (from - ent.WorldMatrix.Translation).Length(); toTarget = from + subpart2.WorldMatrix.Forward * hitd; hitBool = true; if (!MyAPIGateway.Session.CreativeMode) { destroyableEntity.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId); } else { destroyableEntity.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId); } } } // test lastShootTime = currentShootTime; lastShootTimeTicks = ticks; currentHeat += beamWeaponInfo.heatPerTick; if (currentHeat > beamWeaponInfo.maxHeat) { currentHeat = beamWeaponInfo.maxHeat; overheated = true; } } if (ticks - lastShootTimeTicks < 3) { var beamcolor = Color.DodgerBlue; var beamcolor_aux = Color.LightSkyBlue; var maincolor = new Vector4(beamcolor.X / 30, beamcolor.Y / 30, beamcolor.Z / 30, 1f); var auxcolor = new Vector4(beamcolor_aux.X / 30, beamcolor_aux.Y / 30, beamcolor_aux.Z / 30, 1f); var material = MyStringId.GetOrCompute("WeaponLaser"); if (hitBool == false) { if (!MyAPIGateway.Utilities.IsDedicated) { if (!MyAPIGateway.Session.CreativeMode) { VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f); VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f); } else { VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f * 1.2f); VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f * 1.2f); } } } else { if (!MyAPIGateway.Utilities.IsDedicated) { if (!MyAPIGateway.Session.CreativeMode) { VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f); VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f); } else { VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f * 1.2f); VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f * 1.2f); } } } } if (chargesInInventory < beamWeaponInfo.keepAtCharge) { if (resourceSink.RequiredInputByType(electricityDefinition) != (beamWeaponInfo.powerUsage / efficiencyUpgrades)) { resourceSink.SetRequiredInputByType(electricityDefinition, (beamWeaponInfo.powerUsage / efficiencyUpgrades)); setPowerConsumption = (beamWeaponInfo.powerUsage / efficiencyUpgrades); powerConsumption = (beamWeaponInfo.powerUsage / efficiencyUpgrades); } else { if (!functionalBlock.Enabled) { powerConsumption = 0.0001f; } } if (resourceSink.CurrentInputByType(electricityDefinition) == (beamWeaponInfo.powerUsage / efficiencyUpgrades)) { if (!overheated) { m_inventory.AddItems((MyFixedPoint)(beamWeaponInfo.keepAtCharge - chargesInInventory), chargeObjectBuilders [damageUpgrades]); } } } else if (chargesInInventory > beamWeaponInfo.keepAtCharge) { m_inventory.RemoveItemsOfType((MyFixedPoint)(chargesInInventory - beamWeaponInfo.keepAtCharge), chargeObjectBuilders [damageUpgrades]); } else { if (setPowerConsumption != 0.0001f) { resourceSink.SetRequiredInputByType(electricityDefinition, 0.0001f); setPowerConsumption = 0.0001f; powerConsumption = 0.0001f; } } terminalBlock.RefreshCustomInfo(); ticks++; }
internal PartAnimation(EventTriggers eventTrigger, string animationId, Matrix[] rotationSet, Matrix[] rotCeterSet, AnimationType[] typeSet, string[] emissiveIds, int[] currentEmissivePart, int[][] moveToSetIndexer, string subpartId, MyEntitySubpart part, MyEntity mainEnt, string muzzle, uint motionDelay, WeaponSystem system, bool loop = false, bool reverse = false, bool triggerOnce = false, bool resetEmissives = false) { EventTrigger = eventTrigger; RotationSet = rotationSet; RotCenterSet = rotCeterSet; CurrentEmissivePart = currentEmissivePart; AnimationId = animationId; ResetEmissives = resetEmissives; EmissiveIds = emissiveIds; //Unique Animation ID Guid guid = Guid.NewGuid(); _uid = Convert.ToBase64String(guid.ToByteArray()); TypeSet = typeSet; Muzzle = muzzle; MoveToSetIndexer = moveToSetIndexer; NumberOfMoves = MoveToSetIndexer.Length; Part = part; System = system; SubpartId = subpartId; MotionDelay = motionDelay; MainEnt = mainEnt; DoesLoop = loop; DoesReverse = reverse; TriggerOnce = triggerOnce; _currentMove = 0; if (part != null) { FinalPos = HomePos = part.PositionComp.LocalMatrix; var emissivePartCheck = new HashSet <string>(); var emissiveParts = new List <string>(); for (int i = 0; i < NumberOfMoves; i++) { Matrix rotation; Matrix rotAroundCenter; Vector3D translation; AnimationType animationType; EmissiveState currentEmissive; GetCurrentMove(out translation, out rotation, out rotAroundCenter, out animationType, out currentEmissive); if (animationType == AnimationType.Movement) { HasMovement = true; FinalPos.Translation += translation; } if (rotation != Matrix.Zero) { HasMovement = true; FinalPos *= rotation; } if (rotAroundCenter != Matrix.Zero) { HasMovement = true; FinalPos *= rotAroundCenter; } if (currentEmissive.EmissiveParts != null) { for (int j = 0; j < currentEmissive.EmissiveParts.Length; j++) { var currEmissive = currentEmissive.EmissiveParts[j]; if (emissivePartCheck.Contains(currEmissive)) { continue; } emissivePartCheck.Add(currEmissive); emissiveParts.Add(currEmissive); } } Next(); } EmissiveParts = emissiveParts.ToArray(); Reset(); foreach (var evnt in Enum.GetNames(typeof(EventTriggers))) { EventTriggers trigger; Enum.TryParse(evnt, out trigger); EventIdLookup.Add(trigger, evnt + SubpartId); } CheckAffectPivot(part, out MovesPivotPos); } }
private MyEntitySubpart LoadSubpartFromName(string name) { MyEntitySubpart subpart; Subparts.TryGetValue(name, out subpart); // simply return the subpart if it exists in the dictionary if (subpart != null) return subpart; // otherwise load it now and add to dictionary subpart = new MyEntitySubpart(); string fileName = Path.Combine(Path.GetDirectoryName(Model.AssetName), name) + ".mwm"; subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv; subpart.Render.ColorMaskHsv = Render.ColorMaskHsv; subpart.Init(null, fileName, this, null); // add to dictionary Subparts[name] = subpart; if (InScene) subpart.OnAddedToScene(this); return subpart; }