135 lines
4.8 KiB
C#
135 lines
4.8 KiB
C#
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.Projectiles.Ranged
|
|
{
|
|
public class MiniRocket : ModProjectile
|
|
{
|
|
public static Item FalseLauncher = null;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Rocket");
|
|
Main.projFrames[projectile.type] = 4;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
projectile.width = 14;
|
|
projectile.height = 14;
|
|
projectile.friendly = true;
|
|
projectile.penetrate = 1;
|
|
projectile.timeLeft = 95;
|
|
projectile.ranged = true;
|
|
}
|
|
|
|
private static void DefineFalseLauncher()
|
|
{
|
|
int rocketID = ItemID.RocketLauncher;
|
|
FalseLauncher = new Item();
|
|
FalseLauncher.SetDefaults(rocketID, true);
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.ToRadians(90);
|
|
|
|
if (projectile.ai[0] == 0f)
|
|
{
|
|
Main.PlaySound(SoundID.Item11, (int)projectile.Center.X, (int)projectile.Center.Y);
|
|
projectile.ai[0] = 1f;
|
|
}
|
|
|
|
//Animation
|
|
projectile.frameCounter++;
|
|
if (projectile.frameCounter > 7)
|
|
{
|
|
projectile.frame++;
|
|
projectile.frameCounter = 0;
|
|
}
|
|
if (projectile.frame >= Main.projFrames[projectile.type])
|
|
{
|
|
projectile.frame = 0;
|
|
}
|
|
|
|
if (projectile.velocity.Length() >= 8f)
|
|
{
|
|
for (int num246 = 0; num246 < 2; num246++)
|
|
{
|
|
float num247 = 0f;
|
|
float num248 = 0f;
|
|
if (num246 == 1)
|
|
{
|
|
num247 = projectile.velocity.X * 0.5f;
|
|
num248 = projectile.velocity.Y * 0.5f;
|
|
}
|
|
int num249 = Dust.NewDust(new Vector2(projectile.position.X + 3f + num247, projectile.position.Y + 3f + num248) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 6, 0f, 0f, 100, default, 1f);
|
|
Main.dust[num249].scale *= 2f + (float)Main.rand.Next(10) * 0.1f;
|
|
Main.dust[num249].velocity *= 0.2f;
|
|
Main.dust[num249].noGravity = true;
|
|
num249 = Dust.NewDust(new Vector2(projectile.position.X + 3f + num247, projectile.position.Y + 3f + num248) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 31, 0f, 0f, 100, default, 0.5f);
|
|
Main.dust[num249].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f;
|
|
Main.dust[num249].velocity *= 0.05f;
|
|
}
|
|
}
|
|
CalamityGlobalProjectile.HomeInOnNPC(projectile, !projectile.tileCollide, 200f, 12f, 20f);
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
CalamityGlobalProjectile.ExpandHitboxBy(projectile, 32);
|
|
projectile.maxPenetrate = -1;
|
|
projectile.penetrate = -1;
|
|
projectile.usesLocalNPCImmunity = true;
|
|
projectile.localNPCHitCooldown = 10;
|
|
projectile.Damage();
|
|
Main.PlaySound(SoundID.Item14, projectile.position);
|
|
for (int num621 = 0; num621 < 20; num621++)
|
|
{
|
|
int num622 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 31, 0f, 0f, 100, default, 2f);
|
|
Main.dust[num622].velocity *= 3f;
|
|
if (Main.rand.NextBool(2))
|
|
{
|
|
Main.dust[num622].scale = 0.5f;
|
|
Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
|
|
}
|
|
}
|
|
for (int num623 = 0; num623 < 30; num623++)
|
|
{
|
|
int num624 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 6, 0f, 0f, 100, default, 3f);
|
|
Main.dust[num624].noGravity = true;
|
|
Main.dust[num624].velocity *= 5f;
|
|
num624 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 6, 0f, 0f, 100, default, 2f);
|
|
Main.dust[num624].velocity *= 2f;
|
|
}
|
|
CalamityUtils.ExplosionGores(projectile.Center, 3);
|
|
|
|
// Construct a fake item to use with vanilla code for the sake of picking ammo.
|
|
if (FalseLauncher is null)
|
|
DefineFalseLauncher();
|
|
Player player = Main.player[projectile.owner];
|
|
int projID = ProjectileID.RocketI;
|
|
float shootSpeed = 0f;
|
|
bool canShoot = true;
|
|
int damage = 0;
|
|
float kb = 0f;
|
|
player.PickAmmo(FalseLauncher, ref projID, ref shootSpeed, ref canShoot, ref damage, ref kb, true);
|
|
int blastRadius = 0;
|
|
if (projID == ProjectileID.RocketII)
|
|
blastRadius = 3;
|
|
else if (projID == ProjectileID.RocketIV)
|
|
blastRadius = 6;
|
|
|
|
CalamityGlobalProjectile.ExpandHitboxBy(projectile, 14);
|
|
|
|
if (projectile.owner == Main.myPlayer && blastRadius > 0)
|
|
{
|
|
CalamityUtils.ExplodeandDestroyTiles(projectile, blastRadius, true, new List<int>() { }, new List<int>() { });
|
|
}
|
|
}
|
|
}
|
|
}
|