Пример #1
0
        public static float ComputeDamage(int tileX, int tileY, int damage, int totalHits)
        {
            if (!TileDataManager.IsValidTile(tileX, tileY))
            {
                return(0f);
            }

            return(DestructibleTilesProjectile.ComputeHitDamage(Framing.GetTileSafely(tileX, tileY), damage, totalHits));
        }
        public static bool HitTile(int damage, int tileX, int tileY, int totalHits, float percent = 1f)
        {
            var  mymod  = DestructibleTilesMod.Instance;
            var  config = DestructibleTilesConfig.Instance;
            Tile tile   = Framing.GetTileSafely(tileX, tileY);
            //HitTile plrTileHits = Main.LocalPlayer.hitTile;

            //int tileHitId = plrTileHits.HitObject( tileX, tileY, 1 );
            int dmg = (int)(DestructibleTilesProjectile.ComputeHitDamage(tile, damage, totalHits) * percent);

            if (config.DebugModeInfo)
            {
                Main.NewText(HamstarHelpers.Helpers.Tiles.Attributes.TileAttributeHelpers.GetVanillaTileDisplayName(tile.type) + " hit for " + dmg.ToString("N2"));
            }

            if (mymod.TileDataMngr.AddDamage(tileX, tileY, dmg) >= 100)                 //
            //if( plrTileHits.AddDamage( tileHitId, dmg, true ) >= 100 ) {
            //	plrTileHits.Clear( tileHitId );
            {
                bool isTileKilled = TileHelpers.KillTileSynced(
                    tileX: tileX,
                    tileY: tileY,
                    effectOnly: false,
                    dropsItem: config.DestroyedTilesDropItems,
                    forceSyncIfUnchanged: true,
                    suppressErrors: false
                    );

                if (isTileKilled)
                {
                    WorldGen.SquareTileFrame(tileX, tileY);                         // unnecessary?

                    ParticleFxHelpers.MakeDustCloud(
                        new Vector2((tileX * 16) + 8, (tileY * 16) + 8),
                        1,
                        0.3f,
                        1.2f
                        );
                }

                return(isTileKilled);
            }

            return(false);
        }