137 lines
5.1 KiB
C#
137 lines
5.1 KiB
C#
using System;
|
|
using CalamityMod.Buffs.DamageOverTime;
|
|
using CalamityMod.Dusts;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.Audio;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.Projectiles.Magic
|
|
{
|
|
public class BrimstoneFireball : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Magic";
|
|
public override void SetStaticDefaults()
|
|
{
|
|
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 5;
|
|
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 20;
|
|
Projectile.height = 20;
|
|
Projectile.friendly = true;
|
|
Projectile.DamageType = DamageClass.Magic;
|
|
Projectile.penetrate = 3;
|
|
Projectile.timeLeft = 300;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = 20;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Lighting.AddLight(Projectile.Center, 0.25f, 0f, 0f);
|
|
if (Projectile.wet)
|
|
{
|
|
Projectile.Kill();
|
|
SpawnFireballs(true);
|
|
}
|
|
Projectile.localAI[0] += 1f;
|
|
if (Projectile.localAI[0] > 4f)
|
|
{
|
|
int brimstone = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f);
|
|
Main.dust[brimstone].noGravity = true;
|
|
Main.dust[brimstone].velocity *= 0f;
|
|
}
|
|
Projectile.ai[0] += 1f;
|
|
if (Projectile.ai[0] > 5f)
|
|
{
|
|
Projectile.ai[0] = 5f;
|
|
if (Projectile.velocity.Y == 0.0 && Projectile.velocity.X != 0.0)
|
|
{
|
|
Projectile.velocity.X *= 0.97f;
|
|
if (Projectile.velocity.X > -0.01f && Projectile.velocity.X < 0.01f)
|
|
{
|
|
Projectile.velocity.X = 0f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
}
|
|
Projectile.velocity.Y += 0.2f;
|
|
Projectile.rotation += (Math.Abs(Projectile.velocity.X) + Math.Abs(Projectile.velocity.Y)) * 0.1f * Projectile.direction;
|
|
}
|
|
if (Projectile.velocity.Y <= 16f)
|
|
return;
|
|
Projectile.velocity.Y = 16f;
|
|
}
|
|
|
|
public override bool OnTileCollide(Vector2 oldVelocity)
|
|
{
|
|
SoundEngine.PlaySound(SoundID.Item20, Projectile.Center);
|
|
Projectile.penetrate--;
|
|
if (Projectile.penetrate <= 0)
|
|
{
|
|
Projectile.Kill();
|
|
}
|
|
else
|
|
{
|
|
Projectile.ai[0] += 0.1f;
|
|
if (Projectile.velocity.X != oldVelocity.X)
|
|
{
|
|
Projectile.velocity.X = -oldVelocity.X;
|
|
}
|
|
if (Projectile.velocity.Y != oldVelocity.Y)
|
|
{
|
|
Projectile.velocity.Y = -oldVelocity.Y;
|
|
}
|
|
Projectile.velocity *= 0.8f;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1);
|
|
return false;
|
|
}
|
|
|
|
public override void OnKill(int timeLeft)
|
|
{
|
|
SoundEngine.PlaySound(SoundID.Item20, Projectile.Center);
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
|
|
{
|
|
target.AddBuff(ModContent.BuffType<BrimstoneFlames>(), 120);
|
|
|
|
if (target.HasBuff(BuffID.Wet) || target.Calamity().eutrophication > 0 || target.Calamity().rTide > 0 || target.Calamity().cDepth > 0)
|
|
{
|
|
SpawnFireballs(false);
|
|
}
|
|
}
|
|
|
|
public void SpawnFireballs(bool isFromLiquidHit)
|
|
{
|
|
if (Projectile.owner == Main.myPlayer)
|
|
{
|
|
int homerAmt = 2;
|
|
if (!isFromLiquidHit && Projectile.numHits > 0)
|
|
homerAmt = 1;
|
|
|
|
for (int j = 0; j < homerAmt; j++)
|
|
{
|
|
Vector2 velocity = new Vector2(Main.rand.NextFloat(-100f, 100f), Main.rand.NextFloat(-100f, -50f));
|
|
while (velocity.X == 0f)
|
|
{
|
|
velocity.X = (float)Main.rand.Next(-100, 101);
|
|
}
|
|
velocity.Normalize();
|
|
velocity *= Main.rand.NextFloat(7f, 10f);
|
|
float damageMult = isFromLiquidHit ? 1f : 0.25f;
|
|
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.oldPosition.X + (float)(Projectile.width / 2), Projectile.oldPosition.Y + (float)(Projectile.height / 2), velocity.X, velocity.Y, ModContent.ProjectileType<BrimstoneHomer>(), (int)(Projectile.damage * damageMult), 0f, Projectile.owner, 0f, 0f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|