Пример #1
0
        private static bool CheckCollision(ProjectileCE projectile, IntVec3 cell, Thing launcher)
        {
            if (projectile.def.projectile.flyOverhead)
            {
                // All VFE shields are bullet shields. Don't block flying projectiles.
                return(false);
            }

            var     map           = projectile.Map;
            Vector3 exactPosition = projectile.ExactPosition;

            refreshShields(map);

            foreach (var building in shields)
            {
                var shield = building as Building_Shield;
                if (!ShieldInterceptsProjectile(shield, projectile, launcher))
                {
                    continue;
                }

                projectile.ExactPosition = BlockerRegistry.GetExactPosition(projectile.OriginIV3.ToVector3(),
                                                                            exactPosition,
                                                                            new Vector3(shield.Position.x, 0, shield.Position.z),
                                                                            shield.ShieldRadius * shield.ShieldRadius);

                if (!(projectile is ProjectileCE_Explosive))
                {
                    shield.AbsorbDamage(projectile.def.projectile.GetDamageAmount(launcher), projectile.def.projectile.damageDef, projectile.ExactRotation.eulerAngles.y);
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
        public static bool CheckForCollisionCallback(ProjectileCE projectile, IntVec3 cell, Thing launcher)
        {
            /* Check if an active shield can block this projectile, we don't check if the projectile flies overhead, as those projectiles don't call this function
             */
            Map     map           = projectile.Map;
            Vector3 exactPosition = projectile.ExactPosition;
            IntVec3 origin        = projectile.OriginIV3;

            getShields(map);

            foreach (Building building in shields)
            {
                var  shield    = building as Building_Shield;
                var  generator = shield.GetComp <Comp_ShieldGenerator>();
                bool isActive  = generator.IsActive();
                if (!isActive)
                {
                    continue;
                }
                bool blockDirect = generator.BlockDirect_Active();
                if (!blockDirect)
                {
                    continue;
                }
                int   fieldRadius      = (int)generator.FieldRadius_Active();
                int   fieldRadiusSq    = fieldRadius * fieldRadius;
                float DistanceSq       = projectile.Position.DistanceToSquared(shield.Position) - fieldRadiusSq;
                float originDistanceSq = origin.DistanceToSquared(shield.Position) - fieldRadiusSq;
                if (DistanceSq > 0)
                {
                    continue;
                }
                if (originDistanceSq < 0)
                {
                    continue;
                }
                Vector3    shieldPosition2D = new Vector3(shield.Position.x, 0, shield.Position.z);
                Quaternion targetAngle      = projectile.ExactRotation;
                Quaternion shieldProjAng    = Quaternion.LookRotation(exactPosition - shieldPosition2D);
                if ((Quaternion.Angle(targetAngle, shieldProjAng) > 90))
                {
                    HitSoundDef.PlayOneShot((SoundInfo) new TargetInfo(shield.Position, map, false));


                    int damage = (projectile.def.projectile.GetDamageAmount(launcher));

                    generator.FieldIntegrity_Current -= damage;

                    exactPosition = BlockerRegistry.GetExactPosition(origin.ToVector3(), projectile.ExactPosition, shield.Position.ToVector3(), (fieldRadius - 1) * (fieldRadius - 1));
                    MoteMaker.ThrowLightningGlow(exactPosition, map, 0.5f);
                    projectile.ExactPosition = exactPosition;

                    return(true);
                }
            }
            return(false);
        }