Пример #1
0
        internal void AvClose(Vector3D endPos, bool detonateFakeExp = false)
        {
            if (Vector3D.IsZero(TracerFront))
            {
                TracerFront = endPos;
            }
            DetonateFakeExp = detonateFakeExp;
            Dirty           = true;

            if (DetonateFakeExp)
            {
                HitParticle = ParticleState.Dirty;
                if (Ai.Session.Av.ExplosionReady)
                {
                    if (OnScreen != Screen.None)
                    {
                        if (DetonateFakeExp)
                        {
                            SUtils.CreateFakeExplosion(Ai.Session, AmmoDef.AreaEffect.Detonation.DetonationRadius, TracerFront, AmmoDef);
                        }
                        else
                        {
                            SUtils.CreateFakeExplosion(Ai.Session, AmmoDef.AreaEffect.AreaEffectRadius, TracerFront, AmmoDef);
                        }
                    }
                }
            }

            if (!Active)
            {
                Ai.Session.Av.AvShotPool.Return(this);
            }
        }
Пример #2
0
        internal void FatBlockAdded(MyCubeBlock cube)
        {
            try
            {
                var battery      = cube as MyBatteryBlock;
                var weaponType   = (cube is MyConveyorSorter || cube is IMyUserControllableGun);
                var isWeaponBase = weaponType && cube.BlockDefinition != null && (Session.ReplaceVanilla && Session.VanillaIds.ContainsKey(cube.BlockDefinition.Id) || Session.WeaponPlatforms.ContainsKey(cube.BlockDefinition.Id));

                if (!isWeaponBase && (cube is MyConveyor || cube is IMyConveyorTube || cube is MyConveyorSorter || cube is MyCargoContainer || cube is MyCockpit || cube is IMyAssembler || cube is IMyShipConnector) && cube.CubeGrid.IsSameConstructAs(MyGrid))
                {
                    MyInventory inventory;
                    if (cube.HasInventory && cube.TryGetInventory(out inventory) && InventoryMonitor.TryAdd(cube, inventory))
                    {
                        inventory.InventoryContentChanged += CheckAmmoInventory;
                        Construct.RootAi.Construct.NewInventoryDetected = true;

                        int monitors;
                        if (!Session.InventoryMonitors.TryGetValue(inventory, out monitors))
                        {
                            Session.InventoryMonitors[inventory]  = 0;
                            Session.InventoryItems[inventory]     = Session.PhysicalItemListPool.Get();
                            Session.AmmoThreadItemList[inventory] = Session.BetterItemsListPool.Get();
                        }
                        else
                        {
                            Session.InventoryMonitors[inventory] = monitors + 1;
                        }
                    }
                }
                else if (battery != null)
                {
                    if (Batteries.Add(battery))
                    {
                        SourceCount++;
                    }
                    UpdatePowerSources = true;
                }
                else if (isWeaponBase)
                {
                    MyOrientedBoundingBoxD b;
                    BoundingSphereD        s;
                    MyOrientedBoundingBoxD blockBox;
                    SUtils.GetBlockOrientedBoundingBox(cube, out blockBox);
                    if (Session.IsWeaponAreaRestricted(cube.BlockDefinition.Id.SubtypeId, blockBox, cube.CubeGrid, cube.EntityId, null, out b, out s))
                    {
                        if (Session.IsServer)
                        {
                            cube.CubeGrid.RemoveBlock(cube.SlimBlock);
                        }
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in Controller FatBlockAdded: {ex} - {cube?.BlockDefinition == null} - RootAiNull: {Construct.RootAi == null}"); }
        }
Пример #3
0
        internal void End()
        {
            if (AvBarrels1.Count > 0)
            {
                RunAvBarrels1();
            }
            if (AvBarrels2.Count > 0)
            {
                RunAvBarrels2();
            }
            if (HitSounds.Count > 0)
            {
                RunHitSounds();
            }
            if (ParticlesToProcess.Count > 0)
            {
                Session.ProcessParticles();
            }

            for (int i = AvShots.Count - 1; i >= 0; i--)
            {
                var av = AvShots[i];

                var refreshed = av.LastTick == Session.Tick;

                if (refreshed)
                {
                    if (av.PrimeEntity != null)
                    {
                        _models++;

                        if (av.OnScreen != AvShot.Screen.None)
                        {
                            if (!av.PrimeEntity.InScene && !av.Cloaked)
                            {
                                av.PrimeEntity.InScene = true;
                                av.PrimeEntity.Render.UpdateRenderObject(true, false);
                            }
                            av.PrimeEntity.PositionComp.SetWorldMatrix(ref av.PrimeMatrix, null, false, false, false);
                        }

                        if ((av.Cloaked || av.OnScreen == AvShot.Screen.None) && av.PrimeEntity.InScene)
                        {
                            av.PrimeEntity.InScene = false;
                            av.PrimeEntity.Render.RemoveRenderObjects();
                        }
                    }
                    if (av.Triggered && av.TriggerEntity != null)
                    {
                        if (!av.AmmoDef.AreaEffect.Pulse.HideModel && (!av.TriggerEntity.InScene))
                        {
                            av.TriggerEntity.InScene = true;
                            av.TriggerEntity.Render.UpdateRenderObject(true, false);
                        }
                        av.TriggerEntity.PositionComp.SetWorldMatrix(ref av.TriggerMatrix, null, false, false, false);

                        if (av.OnScreen != AvShot.Screen.None && av.AmmoDef.Const.FieldParticle && av.FieldEffect != null)
                        {
                            av.FieldEffect.WorldMatrix = av.PrimeMatrix;
                        }
                    }

                    if (av.HasTravelSound)
                    {
                        if (!av.AmmoSound)
                        {
                            double distSqr;
                            Vector3D.DistanceSquared(ref av.TracerFront, ref Session.CameraPos, out distSqr);
                            if (distSqr <= av.AmmoDef.Const.AmmoTravelSoundDistSqr)
                            {
                                av.AmmoSoundStart();
                            }
                        }
                        else
                        {
                            av.TravelEmitter.SetPosition(av.TracerFront);
                        }
                    }

                    if (av.HitParticle == AvShot.ParticleState.Custom)
                    {
                        av.HitParticle = AvShot.ParticleState.Dirty;
                        if (av.OnScreen != AvShot.Screen.None)
                        {
                            var pos    = av.Hit.HitTick == Session.Tick && !MyUtils.IsZero(av.Hit.SurfaceHit) ? av.Hit.SurfaceHit : av.TracerFront;
                            var matrix = MatrixD.CreateTranslation(pos);

                            MyParticleEffect hitEffect;
                            if (MyParticlesManager.TryCreateParticleEffect(av.AmmoDef.AmmoGraphics.Particles.Hit.Name, ref matrix, ref pos, uint.MaxValue, out hitEffect))
                            {
                                hitEffect.UserColorMultiplier = av.AmmoDef.AmmoGraphics.Particles.Hit.Color;
                                var scaler = 1;
                                hitEffect.UserRadiusMultiplier = av.AmmoDef.AmmoGraphics.Particles.Hit.Extras.Scale * scaler;
                                var scale = av.AmmoDef.Const.HitParticleShrinks ? MathHelper.Clamp(MathHelper.Lerp(1, 0, av.DistanceToLine / av.AmmoDef.AmmoGraphics.Particles.Hit.Extras.MaxDistance), 0.05f, 1) : 1;
                                hitEffect.UserScale = scale * scaler;
                                hitEffect.Velocity  = av.Hit.HitVelocity;
                            }
                        }
                    }
                    else if (av.HitParticle == AvShot.ParticleState.Explosion)
                    {
                        av.HitParticle = AvShot.ParticleState.Dirty;
                        if (ExplosionReady && av.OnScreen != AvShot.Screen.None)
                        {
                            var pos = !MyUtils.IsZero(av.Hit.SurfaceHit) ? av.Hit.SurfaceHit : av.TracerFront;
                            if (av.DetonateFakeExp)
                            {
                                SUtils.CreateFakeExplosion(Session, av.AmmoDef.Const.DetonationRadius, pos, av.Direction, av.Hit.Entity, av.AmmoDef, av.Hit.HitVelocity);
                            }
                            else
                            {
                                SUtils.CreateFakeExplosion(Session, av.AmmoDef.Const.AreaEffectSize, pos, av.Direction, av.Hit.Entity, av.AmmoDef, av.Hit.HitVelocity);
                            }
                        }
                    }

                    if (av.Model != AvShot.ModelState.None)
                    {
                        if (av.AmmoEffect != null && av.AmmoDef.Const.AmmoParticle && av.AmmoDef.Const.PrimeModel)
                        {
                            var offVec = av.TracerFront + Vector3D.Rotate(av.AmmoDef.AmmoGraphics.Particles.Ammo.Offset, av.PrimeMatrix);
                            av.AmmoEffect.WorldMatrix = av.PrimeMatrix;
                            av.AmmoEffect.SetTranslation(ref offVec);
                        }
                    }
                    else if (av.AmmoEffect != null && av.AmmoDef.Const.AmmoParticle)
                    {
                        av.AmmoEffect.SetTranslation(ref av.TracerFront);
                    }
                }

                if (av.EndState.Dirty)
                {
                    av.AvClose();
                }
            }
        }
Пример #4
0
        internal void End()
        {
            if (AvBarrels1.Count > 0)
            {
                RunAvBarrels1();
            }
            if (AvBarrels2.Count > 0)
            {
                RunAvBarrels2();
            }
            if (HitSounds.Count > 0)
            {
                RunHitSounds();
            }

            for (int i = AvShots.Count - 1; i >= 0; i--)
            {
                var av         = AvShots[i];
                var refreshed  = av.LastTick == Session.Tick;
                var shrinkCnt  = av.TracerShrinks.Count;
                var glowCnt    = av.GlowSteps.Count;
                var noNextStep = glowCnt == 0 && shrinkCnt == 0 && av.Dirty;

                if (refreshed)
                {
                    if (av.PrimeEntity != null)
                    {
                        _models++;
                        if (av.OnScreen != AvShot.Screen.None)
                        {
                            if (!av.PrimeEntity.InScene && !av.Cloaked)
                            {
                                av.PrimeEntity.InScene = true;
                                av.PrimeEntity.Render.UpdateRenderObject(true, false);
                            }
                            av.PrimeEntity.PositionComp.SetWorldMatrix(ref av.PrimeMatrix, null, false, false, false);
                        }

                        if ((av.Cloaked || av.OnScreen == AvShot.Screen.None) && av.PrimeEntity.InScene)
                        {
                            av.PrimeEntity.InScene = false;
                            av.PrimeEntity.Render.RemoveRenderObjects();
                        }
                    }
                    if (av.Triggered && av.TriggerEntity != null)
                    {
                        if ((!av.TriggerEntity.InScene))
                        {
                            av.TriggerEntity.InScene = true;
                            av.TriggerEntity.Render.UpdateRenderObject(true, false);
                        }
                        av.TriggerEntity.PositionComp.SetWorldMatrix(ref av.TriggerMatrix, null, false, false, false);
                    }

                    if (av.HasTravelSound)
                    {
                        if (!av.AmmoSound)
                        {
                            double distSqr;
                            Vector3D.DistanceSquared(ref av.TracerFront, ref Session.CameraPos, out distSqr);
                            if (distSqr <= av.AmmoDef.Const.AmmoTravelSoundDistSqr)
                            {
                                av.AmmoSoundStart();
                            }
                        }
                        else
                        {
                            av.TravelEmitter.SetPosition(av.TracerFront);
                        }
                    }

                    if (av.HitParticle == AvShot.ParticleState.Custom)
                    {
                        av.HitParticle = AvShot.ParticleState.Dirty;
                        if (av.OnScreen != AvShot.Screen.None)
                        {
                            var pos    = av.Hit.HitPos;
                            var matrix = MatrixD.CreateTranslation(pos);

                            if (MyParticlesManager.TryCreateParticleEffect(av.AmmoDef.AmmoGraphics.Particles.Hit.Name, ref matrix, ref pos, uint.MaxValue, out av.HitEffect))
                            {
                                av.HitEffect.UserColorMultiplier = av.AmmoDef.AmmoGraphics.Particles.Hit.Color;
                                var scaler = 1;
                                av.HitEffect.UserRadiusMultiplier = av.AmmoDef.AmmoGraphics.Particles.Hit.Extras.Scale * scaler;
                                var scale = av.AmmoDef.Const.HitParticleShrinks ? MathHelper.Clamp(MathHelper.Lerp(1, 0, av.DistanceToLine / av.AmmoDef.AmmoGraphics.Particles.Hit.Extras.MaxDistance), 0.05f, 1) : 1;

                                av.HitEffect.UserScale = scale * scaler;
                                var hitVel = av.Hit.HitVelocity;
                                Vector3D.ClampToSphere(ref hitVel, (float)av.MaxSpeed);
                                av.HitEffect.Velocity = hitVel;
                            }
                        }
                    }
                    else if (av.HitParticle == AvShot.ParticleState.Explosion)
                    {
                        av.HitParticle = AvShot.ParticleState.Dirty;
                        if (ExplosionReady && av.OnScreen != AvShot.Screen.None)
                        {
                            if (av.DetonateFakeExp)
                            {
                                SUtils.CreateFakeExplosion(Session, av.AmmoDef.AreaEffect.Detonation.DetonationRadius, av.TracerFront, av.AmmoDef);
                            }
                            else
                            {
                                SUtils.CreateFakeExplosion(Session, av.AmmoDef.AreaEffect.AreaEffectRadius, av.TracerFront, av.AmmoDef);
                            }
                        }
                    }
                }

                if (noNextStep)
                {
                    AvShotPool.Return(av);
                    AvShots.RemoveAtFast(i);
                }
            }
        }