private void ShowImpactFXForBulletOwner(ProjectileView view, SmartEntity owner)
        {
            this.ShowImpactFXForView(view);
            Bullet      bullet       = view.Bullet;
            List <Buff> appliedBuffs = bullet.AppliedBuffs;
            int         num          = (appliedBuffs != null) ? appliedBuffs.Count : 0;
            FactionType ownerFaction = bullet.OwnerFaction;

            for (int i = 0; i < num; i++)
            {
                string impactAssetNameBasedOnFaction = bullet.AppliedBuffs[i].BuffType.GetImpactAssetNameBasedOnFaction(ownerFaction);
                if (!string.IsNullOrEmpty(impactAssetNameBasedOnFaction))
                {
                    this.ShowImpactFXForView(view, impactAssetNameBasedOnFaction);
                }
            }
            Service.Get <EventManager>().SendEvent(EventId.ProjectileViewImpacted, owner);
        }
 private void ShowImpactFXForBeam(SmartEntity owner, SmartEntity target)
 {
     if (owner != null && target != null)
     {
         int i     = 0;
         int count = this.activeProjectiles.Count;
         while (i < count)
         {
             ProjectileView projectileView = this.activeProjectiles[i];
             Bullet         bullet         = projectileView.Bullet;
             if (bullet.Owner == owner && bullet.Target == target)
             {
                 if (bullet.AppliedBeamHitFXThisSegment)
                 {
                     break;
                 }
                 bullet.AppliedBeamHitFXThisSegment = true;
                 GameObjectViewComponent gameObjectViewComp = target.GameObjectViewComp;
                 if (gameObjectViewComp != null)
                 {
                     GameObject centerOfMass = gameObjectViewComp.CenterOfMass;
                     Vector3    position;
                     if (centerOfMass == null)
                     {
                         position   = gameObjectViewComp.MainTransform.position;
                         position.y = projectileView.TargetLocation.y;
                     }
                     else
                     {
                         position = centerOfMass.transform.position;
                     }
                     projectileView.SetTargetLocation(position);
                     this.ShowImpactFXForBulletOwner(projectileView, owner);
                     return;
                 }
                 break;
             }
             else
             {
                 i++;
             }
         }
     }
 }
 public void OnViewFrameTime(float dt)
 {
     this.miter.Init(this.activeProjectiles);
     while (this.miter.Active())
     {
         Vector3        vector         = Vector3.zero;
         Vector3        vector2        = Vector3.zero;
         ProjectileView projectileView = this.activeProjectiles[this.miter.Index];
         float          distSquared;
         bool           flag       = projectileView.Update(dt * this.speed, out distSquared);
         BuffTypeVO     buffTypeVO = this.ShouldDeflectProjectile(projectileView, distSquared);
         bool           flag2      = buffTypeVO != null && buffTypeVO.IsDeflector;
         if (flag | flag2)
         {
             Bullet bullet = projectileView.Bullet;
             if (flag2)
             {
                 vector  = projectileView.ViewPath.CurrentLocation;
                 vector2 = this.ChooseDeflectionTarget(projectileView.StartLocation);
                 Vector3 vector3 = Vector3.Normalize(vector2 - vector);
                 vector3 *= (float)(bullet.ProjectileType.MaxSpeed * 3 * GameConstants.DEFLECTION_VELOCITY_PERCENT) * 0.01f;
                 vector3 *= (float)GameConstants.DEFLECTION_DURATION_MS * 0.001f;
                 vector2  = vector + vector3;
             }
             else if (!bullet.ProjectileType.IsBeam)
             {
                 this.ShowImpactFXForBulletOwner(projectileView, bullet.Owner);
             }
             this.ReturnProjectileViewToPool(projectileView);
             this.activeProjectiles.RemoveAt(this.miter.Index);
             this.miter.OnRemove(this.miter.Index);
             if (flag2)
             {
                 bullet.ChangeToDeflection((uint)GameConstants.DEFLECTION_DURATION_MS, vector, vector2);
                 this.SpawnProjectile(bullet);
                 Service.Get <EventManager>().SendEvent(EventId.ProjectileViewDeflected, buffTypeVO);
             }
         }
         this.miter.Next();
     }
     this.miter.Reset();
 }
        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 BuffTypeVO ShouldDeflectProjectile(ProjectileView view, float distSquared)
        {
            SmartEntity target = view.Bullet.Target;

            if (target == null || target.TroopComp == null || !target.TroopComp.IsAbilityModeActive)
            {
                return(null);
            }
            Bullet bullet = view.Bullet;

            if (bullet.IsDeflection)
            {
                return(null);
            }
            if (!bullet.ProjectileType.IsDeflectable)
            {
                return(null);
            }
            TroopComponent     troopComp = target.TroopComp;
            ITroopDeployableVO troopType = troopComp.TroopType;
            float num = (float)(troopType.SizeX + troopType.SizeY) * 0.5f;

            num += 1.33f;
            float num2 = num * 0.5f * 3f;

            if (distSquared > num2 * num2)
            {
                return(null);
            }
            string selfBuff = troopComp.AbilityVO.SelfBuff;

            if (string.IsNullOrEmpty(selfBuff))
            {
                return(null);
            }
            return(Service.Get <IDataController>().GetOptional <BuffTypeVO>(selfBuff));
        }
        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 void ShowImpactFXForView(ProjectileView view)
 {
     this.ShowImpactFXForView(view, view.ProjectileType.HitSparkAssetName);
 }
        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);
        }