private void ReturnProjectileViewToPool(ProjectileView view)
        {
            string bulletAssetName = view.ProjectileType.GetBulletAssetName(view.IsOnGround);

            if (view.Emitter != null)
            {
                EmitterPool emitter = this.GetEmitter(bulletAssetName);
                if (emitter != null && emitter is SingleEmitterPool)
                {
                    SingleEmitterPool singleEmitterPool = (SingleEmitterPool)emitter;
                    singleEmitterPool.StopEmissionAndReturnToPool(view.Emitter, 0f, 0f);
                }
            }
            if (view.MeshTracker != null && view.MeshTracker.gameObject != null && this.meshes.ContainsKey(bulletAssetName))
            {
                this.meshes[bulletAssetName].ReturnToPool(view.MeshTracker.gameObject);
            }
            view.OnReturnToPool();
            this.projectilePool.Push(view);
        }
        private void StartDirectionalEmitter(SmartEntity owner, GameObject gunLocator, Vector3 startLocation, Vector3 endLocation, string assetName, float fadeTime)
        {
            EmitterPool emitter = this.GetEmitter(assetName);

            if (emitter != null)
            {
                if (emitter is MultipleEmittersPool)
                {
                    MultipleEmittersPool multipleEmittersPool = (MultipleEmittersPool)emitter;
                    GameObject           emitterRoot          = multipleEmittersPool.GetEmitterRoot();
                    float num = 0f;
                    if (emitterRoot != null)
                    {
                        ParticleSystem[] allEmitters = MultipleEmittersPool.GetAllEmitters(emitterRoot);
                        Transform        transform   = emitterRoot.transform;
                        transform.position = startLocation;
                        if (gunLocator != null)
                        {
                            DerivedTransformationObject derivedTransformationObject = new DerivedTransformationObject(gunLocator, Vector3.zero, true);
                            Service.Get <DerivedTransformationManager>().AddDerivedTransformation(emitterRoot, derivedTransformationObject);
                            this.AssociateEntityWithEmitterObject(owner, emitterRoot);
                        }
                        else
                        {
                            GameObjectViewComponent gameObjectViewComponent = null;
                            if (owner != null)
                            {
                                gameObjectViewComponent = owner.GameObjectViewComp;
                            }
                            if (gameObjectViewComponent == null)
                            {
                                transform.LookAt(endLocation);
                            }
                            else
                            {
                                transform.rotation = gameObjectViewComponent.MainTransform.rotation;
                            }
                        }
                        emitterRoot.SetActive(true);
                        ParticleSystem[] array = allEmitters;
                        for (int i = 0; i < array.Length; i++)
                        {
                            ParticleSystem particleSystem = array[i];
                            if (particleSystem != null)
                            {
                                if (particleSystem.duration > num)
                                {
                                    num = particleSystem.duration;
                                }
                                this.PlayParticle(particleSystem);
                            }
                        }
                        multipleEmittersPool.StopEmissionAndReturnToPool(emitterRoot, num, fadeTime);
                        return;
                    }
                }
                else if (emitter is SingleEmitterPool)
                {
                    SingleEmitterPool singleEmitterPool = (SingleEmitterPool)emitter;
                    ParticleSystem    emitter2          = singleEmitterPool.GetEmitter();
                    if (emitter2 != null)
                    {
                        this.PlayParticleAt(emitter2, startLocation);
                        singleEmitterPool.StopEmissionAndReturnToPool(emitter2, emitter2.startLifetime, fadeTime);
                    }
                }
            }
        }
        private void ShowImpactFXForView(ProjectileView view, string assetName)
        {
            EmitterPool emitter = this.GetEmitter(assetName);

            if (emitter == null)
            {
                return;
            }
            Vector3 vector = view.TargetLocation;

            if (view.TargetTracker != null)
            {
                vector = view.TargetTracker.position;
            }
            else if (view.MeshTracker != null)
            {
                vector = view.MeshTracker.position;
            }
            bool directional = view.ProjectileType.Directional;
            bool seeksTarget = view.ProjectileType.SeeksTarget;

            if (directional)
            {
                Vector3 a = view.StartLocation - vector;
                a.Normalize();
                vector += a * 0.2f;
            }
            if (emitter is MultipleEmittersPool)
            {
                MultipleEmittersPool multipleEmittersPool = (MultipleEmittersPool)emitter;
                GameObject           emitterRoot          = multipleEmittersPool.GetEmitterRoot();
                float num = 0f;
                if (emitterRoot != null)
                {
                    emitterRoot.SetActive(true);
                    ParticleSystem[] allEmitters = MultipleEmittersPool.GetAllEmitters(emitterRoot);
                    Transform        transform   = emitterRoot.transform;
                    transform.position = vector;
                    if (directional)
                    {
                        transform.LookAt(view.StartLocation);
                    }
                    ParticleSystem[] array = allEmitters;
                    for (int i = 0; i < array.Length; i++)
                    {
                        ParticleSystem particleSystem = array[i];
                        if (particleSystem.duration > num)
                        {
                            num = particleSystem.duration;
                        }
                        this.PlayParticle(particleSystem);
                    }
                    if (seeksTarget && view.Bullet.Target != null && view.Bullet.Target.GameObjectViewComp != null && !GameUtils.IsEntityDead(view.Bullet.Target))
                    {
                        SmartEntity target         = view.Bullet.Target;
                        Vector3     positionOffset = emitterRoot.transform.position - target.GameObjectViewComp.MainTransform.position;
                        DerivedTransformationObject derivedTransformationObject = new DerivedTransformationObject(target.GameObjectViewComp.MainGameObject, positionOffset, false);
                        Service.Get <DerivedTransformationManager>().AddDerivedTransformation(emitterRoot, derivedTransformationObject);
                        this.AssociateEntityWithEmitterObject(target, emitterRoot);
                    }
                    multipleEmittersPool.StopEmissionAndReturnToPool(emitterRoot, num, 0f);
                    return;
                }
            }
            else if (emitter is SingleEmitterPool)
            {
                SingleEmitterPool singleEmitterPool = (SingleEmitterPool)emitter;
                ParticleSystem    emitter2          = singleEmitterPool.GetEmitter();
                if (emitter2 != null)
                {
                    if (directional)
                    {
                        this.PlayParticleLookingAt(emitter2, vector, view.StartLocation);
                    }
                    else
                    {
                        this.PlayParticleAt(emitter2, vector);
                    }
                    singleEmitterPool.StopEmissionAndReturnToPool(emitter2, emitter2.startLifetime, 0f);
                }
            }
        }
        private ProjectileView SpawnProjectile(Bullet bullet, bool isOnGround)
        {
            if (!ProjectileUtils.AreAllBulletAssetsLoaded(bullet, this.loadedAssets))
            {
                this.LoadBulletAssets(bullet);
                if (bullet.ProjectileType != null)
                {
                    Service.Get <StaRTSLogger>().Warn("Loading assets on demand for projectile " + bullet.ProjectileType.Uid);
                }
            }
            bool             isDeflection   = bullet.IsDeflection;
            ProjectileTypeVO projectileType = bullet.ProjectileType;
            GameObject       gunLocator     = bullet.GunLocator;
            Vector3          vector;

            if (!isDeflection && gunLocator != null)
            {
                vector = gunLocator.transform.position;
            }
            else
            {
                vector = bullet.SpawnWorldLocation;
            }
            Vector3 targetWorldLocation = bullet.TargetWorldLocation;

            if (isOnGround)
            {
                vector.y = 0f;
                targetWorldLocation.y = 0f;
            }
            else if (projectileType.IsBeam || (bullet.Owner != null && bullet.Target != null && bullet.Target.ShieldBorderComp != null))
            {
                targetWorldLocation.y = vector.y;
            }
            ProjectileView projectileView = (this.projectilePool.Count > 0) ? this.projectilePool.Pop() : new ProjectileView();

            projectileView.Init(projectileType, bullet, isOnGround);
            if (!isDeflection && !string.IsNullOrEmpty(projectileType.MuzzleFlashAssetName))
            {
                this.StartDirectionalEmitter(bullet.Owner, gunLocator, vector, targetWorldLocation, projectileType.MuzzleFlashAssetName, projectileType.MuzzleFlashFadeTime);
                int num = 0;
                if (bullet.AppliedBuffs != null)
                {
                    num = bullet.AppliedBuffs.Count;
                }
                FactionType ownerFaction = bullet.OwnerFaction;
                for (int i = 0; i < num; i++)
                {
                    string muzzleAssetNameBasedOnFaction = bullet.AppliedBuffs[i].BuffType.GetMuzzleAssetNameBasedOnFaction(ownerFaction);
                    if (!string.IsNullOrEmpty(muzzleAssetNameBasedOnFaction))
                    {
                        this.StartDirectionalEmitter(bullet.Owner, gunLocator, vector, targetWorldLocation, muzzleAssetNameBasedOnFaction, projectileType.MuzzleFlashFadeTime);
                    }
                }
            }
            GameObject     gameObject      = null;
            float          num2            = bullet.TravelTime / 1000f;
            GameObject     gameObject2     = null;
            ParticleSystem particleSystem  = null;
            string         bulletAssetName = projectileType.GetBulletAssetName(isOnGround);
            EmitterPool    emitter         = this.GetEmitter(bulletAssetName);

            if (emitter != null)
            {
                float num3 = num2;
                float delayPostEmitterStop = 0f;
                if (projectileType.IsBeam)
                {
                    num3 = num2 * (float)(projectileType.BeamEmitterLength - projectileType.BeamInitialZeroes) / (float)(projectileType.BeamLifeLength - projectileType.BeamInitialZeroes);
                    delayPostEmitterStop = num2 - num3;
                }
                if (emitter is MultipleEmittersPool)
                {
                    MultipleEmittersPool multipleEmittersPool = (MultipleEmittersPool)emitter;
                    gameObject = multipleEmittersPool.GetEmitterRoot();
                    if (gameObject != null)
                    {
                        multipleEmittersPool.StopEmissionAndReturnToPool(gameObject, num3, delayPostEmitterStop);
                    }
                }
                else if (emitter is SingleEmitterPool)
                {
                    SingleEmitterPool singleEmitterPool = (SingleEmitterPool)emitter;
                    particleSystem = singleEmitterPool.GetEmitter();
                    if (particleSystem != null)
                    {
                        singleEmitterPool.StopEmissionAndReturnToPool(particleSystem, num3, delayPostEmitterStop);
                    }
                }
                if (this.meshes.ContainsKey(bulletAssetName))
                {
                    gameObject2 = this.meshes[bulletAssetName].GetMesh();
                }
            }
            Transform targetTransform = this.GetTargetTransform(bullet, vector, targetWorldLocation);

            if (gameObject2 != null && particleSystem != null)
            {
                projectileView.InitWithMeshAndEmitter(num2, vector, targetWorldLocation, gameObject2, particleSystem, targetTransform);
            }
            else if (gameObject2 != null && gameObject == null)
            {
                projectileView.InitWithMesh(num2, vector, targetWorldLocation, gameObject2, targetTransform);
            }
            else if (particleSystem != null)
            {
                projectileView.InitWithEmitter(num2, vector, targetWorldLocation, particleSystem, targetTransform);
            }
            else if (gameObject != null)
            {
                projectileView.InitWithEmitters(num2, vector, targetWorldLocation, gameObject, gameObject2, targetTransform);
            }
            else
            {
                projectileView.InitWithoutBullet(num2, vector, targetWorldLocation, targetTransform);
            }
            this.activeProjectiles.Add(projectileView);
            if (!isOnGround && !string.IsNullOrEmpty(projectileType.GroundBulletAssetName))
            {
                this.SpawnProjectile(bullet, true);
            }
            return(projectileView);
        }