Пример #1
0
        public void TreatRocketProjectile(ProjectileWithAngle projectileWithAngle)
        {
            float rocketAbsorbtionCost = this.properties.forceFieldMaxCharge * this.properties.rocketAbsorbtionProportion;

            if (this.forceFieldCharge > rocketAbsorbtionCost)
            {
                this.forceFieldCharge -= rocketAbsorbtionCost;
                if (this.forceFieldCharge <= 0)
                {
                    this.forceFieldCharge = 0;
                    this.forceFieldState  = ForceFieldState.Offline;
                    SoundDefOf.EnergyShield_Broken.PlayOneShot(new TargetInfo(projectileWithAngle.projectile.Position, this.Map));
                }
                SoundInfo soundInfo = SoundInfo.InMap(new TargetInfo(projectileWithAngle.projectile.Position, this.Map), MaintenanceType.None);
                SoundDefOf.Thunder_OnMap.PlayOneShot(soundInfo);
                GenExplosion.DoExplosion(projectileWithAngle.projectile.Position, this.Map, 1.9f, DamageDefOf.Flame, projectileWithAngle.projectile);
                projectileWithAngle.projectile.Destroy();
                ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition);
            }
            else
            {
                // Force field charge is too low to repel a rocket.
                this.forceFieldCharge = 0;
                this.forceFieldState  = ForceFieldState.Offline;
            }
        }
Пример #2
0
 public void TreatStandardProjectile(ProjectileWithAngle projectileWithAngle)
 {
     this.forceFieldCharge -= projectileWithAngle.projectile.def.projectile.damageAmountBase;
     if (this.forceFieldCharge <= 0)
     {
         this.forceFieldCharge = 0;
         this.forceFieldState  = ForceFieldState.Offline;
     }
     projectileWithAngle.projectile.Destroy();
     ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition);
 }
Пример #3
0
        public bool IsProjectileIncoming(ref ProjectileWithAngle projectileWithAngle)
        {
            Vector3    generatorToProjectile = this.Position.ToVector3() - projectileWithAngle.projectile.ExactPosition;
            Quaternion forceFieldQuaternion  = Quaternion.LookRotation(this.generatorForwardVector);

            projectileWithAngle.incidentAngle = Quaternion.Angle(projectileWithAngle.projectile.ExactRotation, forceFieldQuaternion);
            if (projectileWithAngle.incidentAngle > 90f)
            {
                return(true);
            }
            return(false);
        }
Пример #4
0
 public void TreatStandardProjectile(ProjectileWithAngle projectileWithAngle)
 {
     this.forceFieldCharge -= projectileWithAngle.projectile.def.projectile.GetDamageAmount(1f);
     if (this.forceFieldCharge <= 0)
     {
         this.forceFieldCharge = 0;
         this.forceFieldState  = ForceFieldState.Offline;
         SoundDefOf.EnergyShield_Broken.PlayOneShot(new TargetInfo(projectileWithAngle.projectile.Position, this.Map));
     }
     else
     {
         SoundDefOf.EnergyShield_AbsorbDamage.PlayOneShot(new TargetInfo(projectileWithAngle.projectile.Position, this.Map));
     }
     projectileWithAngle.projectile.Destroy();
     ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition);
 }
Пример #5
0
        public void TreatRocketProjectile(ProjectileWithAngle projectileWithAngle)
        {
            float rocketAbsorbtionCost = ForceFieldGeneratorProperties.forceFieldMaxCharge * ForceFieldGeneratorProperties.rocketAbsorbtionProportion;

            if (this.forceFieldCharge > rocketAbsorbtionCost)
            {
                this.forceFieldCharge -= rocketAbsorbtionCost;
                if (this.forceFieldCharge <= 0)
                {
                    this.forceFieldCharge = 0;
                    this.forceFieldState  = ForceFieldState.Offline;
                }
                SoundInfo soundInfo = SoundInfo.InWorld(projectileWithAngle.projectile.Position, MaintenanceType.None);
                SoundDefOf.Thunder_OnMap.PlayOneShot(soundInfo);
                GenExplosion.DoExplosion(projectileWithAngle.projectile.Position, 1.9f, DamageDefOf.Flame, null, null, null);
                projectileWithAngle.projectile.Destroy();
                ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition);
            }
            else
            {
                this.forceFieldCharge = 0;
                this.forceFieldState  = ForceFieldState.Offline;
            }
        }
Пример #6
0
        public List <ProjectileWithAngle> GetIncomingProjectiles()
        {
            List <ProjectileWithAngle> incomingProjectiles = new List <ProjectileWithAngle>();

            foreach (IntVec3 cell in this.coveredCells)
            {
                List <Thing> thingsInCell = Find.ThingGrid.ThingsListAt(cell);
                foreach (Thing thing in thingsInCell)
                {
                    if (thing is Projectile)
                    {
                        ProjectileWithAngle projectileWithAngle = new ProjectileWithAngle();
                        projectileWithAngle.projectile    = thing as Projectile;
                        projectileWithAngle.incidentAngle = 0f;

                        if (IsProjectileIncoming(ref projectileWithAngle))
                        {
                            incomingProjectiles.Add(projectileWithAngle);
                        }
                    }
                }
            }
            return(incomingProjectiles);
        }
Пример #7
0
        public void TreatExplosiveProjectile(ProjectileWithAngle projectileWithAngle)
        {
            if (this.forceFieldCharge < ForceFieldGeneratorProperties.explosiveRepelCharge)
            {
                // Force field charge is too low to repell an explosive.
                return;
            }
            this.forceFieldCharge -= ForceFieldGeneratorProperties.explosiveRepelCharge;
            if (this.forceFieldCharge <= 0)
            {
                this.forceFieldCharge = 0;
                this.forceFieldState  = ForceFieldState.Offline;
            }

            Projectile deflectedProjectile = ThingMaker.MakeThing(projectileWithAngle.projectile.def) as Projectile;

            GenSpawn.Spawn(deflectedProjectile, projectileWithAngle.projectile.Position);

            float   rebounceAngleInDegrees  = (180f - projectileWithAngle.incidentAngle);
            float   rebounceAngleInRadians  = (float)(rebounceAngleInDegrees * Math.PI / 180f);
            float   rebounceVectorMagnitude = Rand.Range(1.5f, 3.5f);
            Vector3 rebounceVector          = new Vector3(0f, 0f, 0f);
            float   xSign = +1f;
            float   zSign = +1f;
            Thing   projectileLauncher = ReflectionHelper.GetInstanceField(typeof(Projectile), projectileWithAngle.projectile, "launcher") as Thing;

            if (projectileLauncher == null)
            {
                Log.Warning("M&Co. ForceField mod: projectileLauncher is null!");
                return;
            }
            if (this.Rotation == Rot4.North)
            {
                if (projectileWithAngle.projectile.Position.x >= projectileLauncher.Position.x)
                {
                    xSign = +1f;
                }
                else
                {
                    xSign = -1f;
                }
                zSign = +1f;
            }
            else if (this.Rotation == Rot4.East)
            {
                if (projectileWithAngle.projectile.Position.z >= projectileLauncher.Position.z)
                {
                    zSign = +1f;
                }
                else
                {
                    zSign = -1f;
                }
                xSign = +1f;
            }
            else if (this.Rotation == Rot4.South)
            {
                if (projectileWithAngle.projectile.Position.x >= projectileLauncher.Position.x)
                {
                    xSign = +1f;
                }
                else
                {
                    xSign = -1f;
                }
                zSign = -1f;
            }
            else // West.
            {
                if (projectileWithAngle.projectile.Position.z >= projectileLauncher.Position.z)
                {
                    zSign = +1f;
                }
                else
                {
                    zSign = -1f;
                }
                xSign = -1f;
            }

            rebounceVector = new Vector3(xSign * rebounceVectorMagnitude * (float)Math.Sin(rebounceAngleInRadians), 0f, zSign * rebounceVectorMagnitude * (float)Math.Cos(rebounceAngleInRadians));
            TargetInfo rebounceCell = new TargetInfo((projectileWithAngle.projectile.ExactPosition + rebounceVector).ToIntVec3());

            deflectedProjectile.Launch(this, projectileWithAngle.projectile.ExactPosition, rebounceCell);
            projectileWithAngle.projectile.Destroy();
            ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition);
        }
 public void TreatStandardProjectile(ProjectileWithAngle projectileWithAngle)
 {
     this.forceFieldCharge -= projectileWithAngle.projectile.def.projectile.damageAmountBase;
     if (this.forceFieldCharge <= 0)
     {
         this.forceFieldCharge = 0;
         this.forceFieldState = ForceFieldState.Offline;
     }
     projectileWithAngle.projectile.Destroy();
     ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition);
 }
        public void TreatExplosiveProjectile(ProjectileWithAngle projectileWithAngle)
        {
            if (this.forceFieldCharge < ForceFieldGeneratorProperties.explosiveRepelCharge)
            {
                // Force field charge is too low to repell an explosive.
                return;
            }
            this.forceFieldCharge -= ForceFieldGeneratorProperties.explosiveRepelCharge;
            if (this.forceFieldCharge <= 0)
            {
                this.forceFieldCharge = 0;
                this.forceFieldState = ForceFieldState.Offline;
            }

            Projectile deflectedProjectile = ThingMaker.MakeThing(projectileWithAngle.projectile.def) as Projectile;
            GenSpawn.Spawn(deflectedProjectile, projectileWithAngle.projectile.Position);

            float rebounceAngleInDegrees = (180f - projectileWithAngle.incidentAngle);
            float rebounceAngleInRadians = (float)(rebounceAngleInDegrees * Math.PI / 180f);
            float rebounceVectorMagnitude = Rand.Range(1.5f, 3.5f);
            Vector3 rebounceVector = new Vector3(0f, 0f, 0f);
            float xSign = +1f;
            float zSign = +1f;
            Thing projectileLauncher = ReflectionHelper.GetInstanceField(typeof(Projectile), projectileWithAngle.projectile, "launcher") as Thing;
            if (projectileLauncher == null)
            {
                Log.Warning("M&Co. ForceField mod: projectileLauncher is null!");
                return;
            }
            if (this.Rotation == Rot4.North)
            {
                if (projectileWithAngle.projectile.Position.x >= projectileLauncher.Position.x)
                {
                    xSign = +1f;
                }
                else
                {
                    xSign = -1f;
                }
                zSign = +1f;
            }
            else if (this.Rotation == Rot4.East)
            {
                if (projectileWithAngle.projectile.Position.z >= projectileLauncher.Position.z)
                {
                    zSign = +1f;
                }
                else
                {
                    zSign = -1f;
                }
                xSign = +1f;
            }
            else if (this.Rotation == Rot4.South)
            {
                if (projectileWithAngle.projectile.Position.x >= projectileLauncher.Position.x)
                {
                    xSign = +1f;
                }
                else
                {
                    xSign = -1f;
                }
                zSign = -1f;
            }
            else // West.
            {
                if (projectileWithAngle.projectile.Position.z >= projectileLauncher.Position.z)
                {
                    zSign = +1f;
                }
                else
                {
                    zSign = -1f;
                }
                xSign = -1f;
            }

            rebounceVector = new Vector3(xSign * rebounceVectorMagnitude * (float)Math.Sin(rebounceAngleInRadians), 0f, zSign * rebounceVectorMagnitude * (float)Math.Cos(rebounceAngleInRadians));
            TargetInfo rebounceCell = new TargetInfo((projectileWithAngle.projectile.ExactPosition + rebounceVector).ToIntVec3());
            deflectedProjectile.Launch(this, projectileWithAngle.projectile.ExactPosition, rebounceCell);
            projectileWithAngle.projectile.Destroy();
            ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition);
        }
 public void TreatRocketProjectile(ProjectileWithAngle projectileWithAngle)
 {
     float rocketAbsorbtionCost = ForceFieldGeneratorProperties.forceFieldMaxCharge * ForceFieldGeneratorProperties.rocketAbsorbtionProportion;
     if (this.forceFieldCharge > rocketAbsorbtionCost)
     {
         this.forceFieldCharge -= rocketAbsorbtionCost;
         if (this.forceFieldCharge <= 0)
         {
             this.forceFieldCharge = 0;
             this.forceFieldState = ForceFieldState.Offline;
         }
         SoundInfo soundInfo = SoundInfo.InWorld(projectileWithAngle.projectile.Position, MaintenanceType.None);
         SoundDefOf.Thunder_OnMap.PlayOneShot(soundInfo);
         GenExplosion.DoExplosion(projectileWithAngle.projectile.Position, 1.9f, DamageDefOf.Flame, null, null, null);
         projectileWithAngle.projectile.Destroy();
         ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition);
     }
     else
     {
         this.forceFieldCharge = 0;
         this.forceFieldState = ForceFieldState.Offline;
     }
 }
 public bool IsProjectileIncoming(ref ProjectileWithAngle projectileWithAngle)
 {
     Vector3 generatorToProjectile = this.Position.ToVector3() - projectileWithAngle.projectile.ExactPosition;
     Quaternion forceFieldQuaternion = Quaternion.LookRotation(this.generatorForwardVector);
     projectileWithAngle.incidentAngle = Quaternion.Angle(projectileWithAngle.projectile.ExactRotation, forceFieldQuaternion);
     if (projectileWithAngle.incidentAngle > 90f)
     {
         return true;
     }
     return false;
 }
        public List<ProjectileWithAngle> GetIncomingProjectiles()
        {
            List<ProjectileWithAngle> incomingProjectiles = new List<ProjectileWithAngle>();
            foreach (IntVec3 cell in this.coveredCells)
            {
                List<Thing> thingsInCell = Find.ThingGrid.ThingsListAt(cell);
                foreach (Thing thing in thingsInCell)
                {
                    if (thing is Projectile)
                    {
                        ProjectileWithAngle projectileWithAngle = new ProjectileWithAngle();
                        projectileWithAngle.projectile = thing as Projectile;
                        projectileWithAngle.incidentAngle = 0f;

                        if (IsProjectileIncoming(ref projectileWithAngle))
                        {
                            incomingProjectiles.Add(projectileWithAngle);
                        }
                    }
                }
            }
            return incomingProjectiles;
        }