using System; using Decimation.Content.Buffs.Debuffs; using Decimation.Lib.Util; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace Decimation.Content.Projectiles.NPC { public class MagmaBall : DecimationProjectile { public override string Texture => "Decimation/Content/Projectiles/NPC/MagmaBall"; private bool HitPlayer { get => projectile.ai[0] == 1f; set => projectile.ai[0] = value ? 1 : 0; } private bool AlternativeTexture { get => projectile.localAI[0] == 1f; set => projectile.localAI[0] = value ? 1 : 0; } protected override void Init() { projectile.width = 22; projectile.height = 20; projectile.aiStyle = -1; projectile.hostile = true; projectile.penetrate = 1; AlternativeTexture = Main.rand.NextBool(); } public override void AI() { Lighting.AddLight(projectile.Center, LightingUtils.Rgb255ToRgb1(255, 155, 48)); Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.LavaMoss); projectile.velocity.Y += 1 / 4f; } public override void OnHitPlayer(Player target, int damage, bool crit) { DustUtils.NewDustCircle(16, target.position, target.width, target.height, DustID.Fire, projectile.scale * 3f); target.AddBuff(ModContent.BuffType(), 300); HitPlayer = true; projectile.Kill(); } public override void Kill(int timeLeft) { if (HitPlayer) return; DustUtils.NewDustCircle(4, projectile.position, projectile.width, projectile.height, DustID.Fire, projectile.scale * 3f); Tile currentTile = Framing.GetTileSafely((int) Math.Floor(projectile.position.X / 16f), (int) Math.Ceiling(projectile.position.Y / 16f)); currentTile.liquid = 1; currentTile.lava(true); Main.PlaySound(SoundID.NPCDeath19, projectile.Center); } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { var frameSize = new Vector2(projectile.width, projectile.height); string texturePath = "Content/Projectiles/NPC/MagmaBall"; if (AlternativeTexture) texturePath += "_Alternative"; var texture = mod.GetTexture(texturePath); spriteBatch.Draw ( texture, new Vector2( projectile.position.X - Main.screenPosition.X + frameSize.X / 2, projectile.position.Y - Main.screenPosition.Y + frameSize.Y / 2 ), null, lightColor, projectile.rotation + MathHelper.Pi * .5f, frameSize * 0.5f, projectile.scale, SpriteEffects.None, 0f ); return false; } } }