////////////////

        public void BehaviorAsKinetic(Projectile projectile, Vector2 oldVelocity)
        {
            var config = DestructibleTilesConfig.Instance;

            var rect = new Rectangle(
                (int)projectile.position.X + (int)oldVelocity.X,
                (int)projectile.position.Y + (int)oldVelocity.Y,
                projectile.width,
                projectile.height
                );

            bool onlySometimesRespects;
            bool respectsPlatforms = ProjectileAttributeHelpers.DoesVanillaProjectileHitPlatforms(
                projectile,
                out onlySometimesRespects
                ) && !onlySometimesRespects;

            int damage = DestructibleTilesProjectile.ComputeProjectileDamage(projectile);

            IList <(ushort, ushort)> hits = DestructibleTilesProjectile.FindNearbyHittableTiles(
                projectile.Center,
                rect,
                respectsPlatforms
                );

            if (config.DebugModeInfo)
            {
                this.OutputKineticProjectileDebugInfo(projectile, oldVelocity, hits);
            }

            foreach ((ushort x, ushort y) in hits)
            {
                DestructibleTilesProjectile.HitTile(damage, x, y, hits.Count);
            }
        }
        ////////////////

        public static void HitTilesInRadius(int tileX, int tileY, int radius, int damage)
        {
            int radiusTiles        = (int)Math.Round((double)(radius / 16));
            int radiusTilesSquared = radiusTiles * radiusTiles;

            int left   = tileX - (radiusTiles + 1);
            int right  = tileX + (radiusTiles + 1);
            int top    = tileY - (radiusTiles + 1);
            int bottom = tileY + (radiusTiles + 1);

            for (int i = left; i < right; i++)
            {
                if (i < 0 || i >= Main.maxTilesX - 1)
                {
                    continue;
                }

                for (int j = top; j < bottom; j++)
                {
                    if (j < 0 || j >= Main.maxTilesY - 1)
                    {
                        continue;
                    }
                    if (TileHelpers.IsAir(Framing.GetTileSafely(i, j)))
                    {
                        continue;
                    }

                    int xOff = i - tileX;
                    int yOff = j - tileY;

                    int currTileDistSquared = (xOff * xOff) + (yOff * yOff);
                    if (currTileDistSquared > radiusTilesSquared)
                    {
                        continue;
                    }

                    float percentToCenter = 1f - ((float)currTileDistSquared / (float)radiusTilesSquared);

                    DestructibleTilesProjectile.HitTile(damage, i, j, 1, percentToCenter);
                }
            }
        }
        public void BehaviorAsBeam(Projectile projectile)
        {
            bool hasCooldown;

            if (!DestructibleTilesProjectile.CanHitTiles(projectile, out hasCooldown) || hasCooldown)
            {
                return;
            }

            Vector2 projPos     = projectile.Center + (projectile.velocity * projectile.localAI[1]);
            Point?  tilePosNull = TileFinderHelpers.GetNearestTile(projPos, TilePattern.CommonSolid, 32);

            if (!tilePosNull.HasValue)
            {
                return;
            }

//DebugHelpers.Print("proj_"+projectile.whoAmI,
//	"vel: "+projectile.velocity.X.ToString("N2")+":"+projectile.velocity.Y.ToString("N2")+
//	", ai: "+string.Join(", ", projectile.ai.Select(f=>f.ToString("N1")))+
//	", localAi: "+string.Join(", ", projectile.localAI.Select(f=>f.ToString("N1"))),
//	20 );
//var rpos1 = (projPos / 16f) * 16f;
//var rpos2 = new Vector2( rpos1.X + 16, rpos1.Y + 16 );
//Dust.QuickBox( rpos1, rpos2, 0, Color.Blue, d => { } );
            var tilePos = tilePosNull.Value;
            int damage  = DestructibleTilesProjectile.ComputeBeamProjectileDamage(projectile);

            if (DestructibleTilesProjectile.HitTile(damage, tilePos.X, tilePos.Y, 1))
            {
                bool _;
                projectile.localAI[1] = TileCollisionHelpers.MeasureWorldDistanceToTile(projectile.Center, projectile.velocity, 2400f, out _);
//var pos1 = tilePos.ToVector2() * 16f;
//var pos2 = new Vector2( pos1.X + 16, pos1.Y + 16 );
//Dust.QuickBox( pos1, pos2, 0, Color.Red, d => { } );
            }
        }
Esempio n. 4
0
        ////

        public static bool DamageTile(int tileX, int tileY, int damage, int totalHits)
        {
            return(DestructibleTilesProjectile.HitTile(damage, tileX, tileY, totalHits));
        }