106 lines
4.7 KiB
C#
106 lines
4.7 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Terraria;
|
|
using Terraria.Audio;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Enemy
|
|
{
|
|
public class InkBombHostile : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Enemy";
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 30;
|
|
Projectile.height = 30;
|
|
Projectile.hostile = true;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.penetrate = 1;
|
|
Projectile.timeLeft = 150;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Projectile.ai[0] += 1f;
|
|
if (Projectile.ai[0] > 10f)
|
|
{
|
|
Projectile.ai[0] = 10f;
|
|
if (Projectile.velocity.Y == 0f && Projectile.velocity.X != 0f)
|
|
{
|
|
Projectile.velocity.X = 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 = Projectile.velocity.Y - 0.01f;
|
|
}
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
Texture2D tex = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value;
|
|
Vector2 drawOrigin = new(tex.Width * 0.5f, Projectile.height * 0.5f);
|
|
Vector2 vector = new Vector2(Projectile.Center.X, Projectile.Center.Y) - Main.screenPosition + new Vector2(0, Projectile.gfxOffY);
|
|
Rectangle rectangle = new(0, tex.Height / Main.projFrames[Projectile.type] * Projectile.frame, tex.Width, tex.Height / Main.projFrames[Projectile.type]);
|
|
Main.EntitySpriteDraw(tex, vector, rectangle, Color.DarkGray, Projectile.rotation, drawOrigin, Projectile.scale, SpriteEffects.None, 0);
|
|
|
|
return false;
|
|
}
|
|
|
|
public override void OnKill(int timeLeft)
|
|
{
|
|
SoundEngine.PlaySound(SoundID.NPCDeath28, Projectile.Center);
|
|
if (Projectile.owner == Main.myPlayer)
|
|
{
|
|
int randProjAmt = Main.rand.Next(5, 9);
|
|
for (int i = 0; i < randProjAmt; i++)
|
|
{
|
|
Vector2 randProjRotation = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101));
|
|
randProjRotation.Normalize();
|
|
randProjRotation *= Main.rand.Next(50, 401) * 0.01f;
|
|
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, randProjRotation.X, randProjRotation.Y, ModContent.ProjectileType<InkPoisonCloud>(), (int)Math.Round(Projectile.damage * 0.165), 1f, Projectile.owner, Main.rand.Next(-45, 1));
|
|
}
|
|
}
|
|
Projectile.position.X = Projectile.position.X + (float)(Projectile.width / 2);
|
|
Projectile.position.Y = Projectile.position.Y + (float)(Projectile.height / 2);
|
|
Projectile.width = 60;
|
|
Projectile.height = 60;
|
|
Projectile.position.X = Projectile.position.X - (float)(Projectile.width / 2);
|
|
Projectile.position.Y = Projectile.position.Y - (float)(Projectile.height / 2);
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
int inkDust = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Wraith, 0f, 0f, 100, default, 2f);
|
|
Main.dust[inkDust].velocity *= 3f;
|
|
if (Main.rand.NextBool())
|
|
{
|
|
Main.dust[inkDust].scale = 0.5f;
|
|
Main.dust[inkDust].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
|
|
}
|
|
}
|
|
for (int j = 0; j < 15; j++)
|
|
{
|
|
int inkDust2 = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Asphalt, 0f, 0f, 100, default, 3f);
|
|
Main.dust[inkDust2].noGravity = true;
|
|
Main.dust[inkDust2].velocity *= 5f;
|
|
inkDust2 = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Asphalt, 0f, 0f, 100, default, 2f);
|
|
Main.dust[inkDust2].velocity *= 2f;
|
|
}
|
|
}
|
|
|
|
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, 12f, targetHitbox);
|
|
|
|
public override void OnHitPlayer(Player target, Player.HurtInfo info)
|
|
{
|
|
if (info.Damage <= 0)
|
|
return;
|
|
|
|
target.AddBuff(BuffID.Darkness, 300, true);
|
|
Projectile.Kill();
|
|
}
|
|
}
|
|
}
|