public void Clean() { Effect?.Stop(); Effect = null; AmmoDef = null; Velocity = Vector3D.Zero; LastTick = 0; Looping = false; }
internal void Close() { // Reset only vars that are not always set Hit = new Hit(); if (AmmoSound) { TravelEmitter.StopSound(true); AmmoSound = false; } HitVelocity = Vector3D.Zero; TracerBack = Vector3D.Zero; TracerFront = Vector3D.Zero; ClosestPointOnLine = Vector3D.Zero; Color = Vector4.Zero; OnScreen = Screen.None; Tracer = TracerState.Off; Trail = TrailState.Off; LifeTime = 0; TracerSteps = 0; TracerStep = 0; DistanceToLine = 0; TracerWidth = 0; TrailWidth = 0; TrailScaler = 0; MaxTrajectory = 0; ShotFade = 0; ParentId = ulong.MaxValue; Dirty = false; AmmoSound = false; HitSoundActive = false; StartSoundActived = false; IsShrapnel = false; HasTravelSound = false; HitParticle = ParticleState.None; Triggered = false; Cloaked = false; Active = false; TrailActivated = false; ShrinkInited = false; Hitting = false; Back = false; LastStep = false; DetonateFakeExp = false; TracerShrinks.Clear(); GlowSteps.Clear(); Offsets.Clear(); // FiringWeapon = null; PrimeEntity = null; TriggerEntity = null; Ai = null; AmmoDef = null; System = null; }
internal void Init(ProInfo info, double firstStepSize, double maxSpeed) { System = info.System; AmmoDef = info.AmmoDef; Ai = info.Ai; IsShrapnel = info.IsShrapnel; if (ParentId != ulong.MaxValue) { Log.Line($"invalid avshot, parentId:{ParentId}"); } ParentId = info.Id; Model = (info.AmmoDef.Const.PrimeModel || info.AmmoDef.Const.TriggerModel) ? Model = ModelState.Exists : Model = ModelState.None; PrimeEntity = info.PrimeEntity; TriggerEntity = info.TriggerEntity; Origin = info.Origin; Offset = AmmoDef.Const.OffsetEffect; MaxTracerLength = info.TracerLength; MuzzleId = info.MuzzleId; WeaponId = info.WeaponId; MaxSpeed = maxSpeed; MaxStepSize = MaxSpeed * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS; ShootVelStep = info.ShooterVel * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS; info.Ai.WeaponBase.TryGetValue(info.Target.FiringCube, out FiringWeapon); MaxTrajectory = info.MaxTrajectory; ShotFade = info.ShotFade; ShrinkInited = false; HitEmitter.CanPlayLoopSounds = false; if (AmmoDef.Const.DrawLine) { Tracer = !AmmoDef.Const.IsBeamWeapon && firstStepSize < MaxTracerLength && !MyUtils.IsZero(firstStepSize - MaxTracerLength, 1E-01F) ? TracerState.Grow : TracerState.Full; } else { Tracer = TracerState.Off; } if (AmmoDef.Const.Trail) { MaxGlowLength = MathHelperD.Clamp(AmmoDef.AmmoGraphics.Lines.Trail.DecayTime * MaxStepSize, 0.1f, MaxTrajectory); Trail = AmmoDef.AmmoGraphics.Lines.Trail.Back ? TrailState.Back : Trail = TrailState.Front; GlowShrinkSize = !AmmoDef.AmmoGraphics.Lines.Trail.UseColorFade ? AmmoDef.Const.TrailWidth / AmmoDef.AmmoGraphics.Lines.Trail.DecayTime : 1f / AmmoDef.AmmoGraphics.Lines.Trail.DecayTime; Back = Trail == TrailState.Back; } else { Trail = TrailState.Off; } TotalLength = MathHelperD.Clamp(MaxTracerLength + MaxGlowLength, 0.1f, MaxTrajectory); }
public static void CreateFakeExplosion(Session session, double radius, Vector3D position, Vector3D direction, MyEntity hitEnt, WeaponDefinition.AmmoDef ammoDef, Vector3 velocity) { var af = ammoDef.AreaEffect; var eInfo = af.Explosions; if (radius > 10) { radius = 10; } var sphere = new BoundingSphereD(position, radius); var cullSphere = sphere; cullSphere.Radius = radius * 5; var drawParticles = !eInfo.NoVisuals && session.Camera.IsInFrustum(ref cullSphere); MyExplosionFlags eFlags; if (drawParticles) { eFlags = MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT; } else { eFlags = MyExplosionFlags.CREATE_DECALS; } var customParticle = eInfo.CustomParticle != string.Empty; var explosionType = !customParticle ? MyExplosionTypeEnum.MISSILE_EXPLOSION : MyExplosionTypeEnum.CUSTOM; MySoundPair customSound = null; if (ammoDef.Const.CustomExplosionSound && !eInfo.NoSound) { customSound = ammoDef.Const.CustomSoundPairs.Count > 0 ? ammoDef.Const.CustomSoundPairs.Pop() : new MySoundPair(eInfo.CustomSound, false); session.FutureEvents.Schedule(ammoDef.Const.ReturnSoundPair, customSound, 1800); } MyExplosionInfo explosionInfo = new MyExplosionInfo { PlayerDamage = 0.0f, Damage = 0f, ExplosionType = explosionType, ExplosionSphere = sphere, LifespanMiliseconds = 0, ParticleScale = eInfo.Scale, Direction = direction, VoxelExplosionCenter = position, ExplosionFlags = eFlags, VoxelCutoutScale = 0f, HitEntity = hitEnt, PlaySound = !eInfo.NoSound, ApplyForceAndDamage = false, ObjectsRemoveDelayInMiliseconds = 0, CustomEffect = eInfo.CustomParticle, CreateParticleEffect = drawParticles, Velocity = velocity, CustomSound = customSound, }; if (hitEnt?.Physics != null) { explosionInfo.Velocity = hitEnt.Physics.LinearVelocity; } MyExplosions.AddExplosion(ref explosionInfo); }
public static void CreateMissileExplosion(Session session, float damage, double radius, Vector3D position, Vector3D direction, MyEntity owner, MyEntity hitEnt, WeaponDefinition.AmmoDef ammoDef, bool forceNoDraw = false) { var af = ammoDef.AreaEffect; var justShrapnel = !af.Explosions.NoShrapnel && af.Explosions.NoDeformation; var justDeform = af.Explosions.NoShrapnel && !af.Explosions.NoDeformation; var eInfo = af.Explosions; var playSound = !eInfo.NoSound && !forceNoDraw; var sphere = new BoundingSphereD(position, radius); var cullSphere = sphere; cullSphere.Radius = radius * 5; MyExplosionFlags eFlags; var drawParticles = !forceNoDraw && !eInfo.NoVisuals && session.Camera.IsInFrustum(ref cullSphere); if (drawParticles) { if (justShrapnel) { eFlags = MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_SHRAPNELS; } else if (justDeform) { eFlags = MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.APPLY_DEFORMATION; } else { eFlags = MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_SHRAPNELS | MyExplosionFlags.APPLY_DEFORMATION; } } else { if (justShrapnel) { eFlags = MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_SHRAPNELS; } else if (justDeform) { eFlags = MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.APPLY_DEFORMATION; } else { eFlags = MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_SHRAPNELS | MyExplosionFlags.APPLY_DEFORMATION; } } var customParticle = eInfo.CustomParticle != string.Empty; var explosionType = !customParticle ? MyExplosionTypeEnum.MISSILE_EXPLOSION : MyExplosionTypeEnum.CUSTOM; var explosionInfo = new MyExplosionInfo { PlayerDamage = 0.1f, Damage = damage, ExplosionType = explosionType, ExplosionSphere = sphere, LifespanMiliseconds = 700, HitEntity = hitEnt, ParticleScale = eInfo.Scale, OwnerEntity = owner, Direction = direction, VoxelExplosionCenter = sphere.Center, ExplosionFlags = eFlags, VoxelCutoutScale = 0.3f, PlaySound = playSound, ApplyForceAndDamage = true, KeepAffectedBlocks = true, CustomEffect = eInfo.CustomParticle, CreateParticleEffect = drawParticles, }; if (hitEnt?.Physics != null) { explosionInfo.Velocity = hitEnt.Physics.LinearVelocity; } MyExplosions.AddExplosion(ref explosionInfo); }
public static void CreateFakeExplosion(Session session, double radius, Vector3D position, WeaponDefinition.AmmoDef ammoDef) { var af = ammoDef.AreaEffect; var eInfo = af.Explosions; if (radius > 10) { radius = 10; } var sphere = new BoundingSphereD(position, radius); var cullSphere = sphere; cullSphere.Radius = radius * 5; var drawParticles = !eInfo.NoVisuals && session.Camera.IsInFrustum(ref cullSphere); MyExplosionFlags eFlags; if (drawParticles) { eFlags = MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT; } else { eFlags = MyExplosionFlags.CREATE_DECALS; } var customParticle = eInfo.CustomParticle != string.Empty; var explosionType = !customParticle ? MyExplosionTypeEnum.MISSILE_EXPLOSION : MyExplosionTypeEnum.CUSTOM; MyExplosionInfo explosionInfo = new MyExplosionInfo() { PlayerDamage = 0.0f, Damage = 0f, ExplosionType = explosionType, ExplosionSphere = sphere, LifespanMiliseconds = 0, ParticleScale = eInfo.Scale, Direction = Vector3.Down, VoxelExplosionCenter = position, ExplosionFlags = eFlags, VoxelCutoutScale = 0f, PlaySound = !eInfo.NoSound, ApplyForceAndDamage = false, ObjectsRemoveDelayInMiliseconds = 0, CustomEffect = eInfo.CustomParticle, CreateParticleEffect = drawParticles, }; MyExplosions.AddExplosion(ref explosionInfo); }