Dodu's Handcannon rework (sprite pending)

This commit is contained in:
Ozzatron committed 2021-02-06 22:50:54 -05:00
1 parent c52cf409cd
commit 7b45b0a43e
5 files changed
+145 -62

No files matched your search

+17 -29
View File
@@ -1,4 +1,5 @@
using CalamityMod.Items.Materials;
using CalamityMod.Projectiles.Ranged;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
@@ -11,56 +12,43 @@ namespace CalamityMod.Items.Weapons.Ranged
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Dodu's Handcannon");
Tooltip.SetDefault("The power of the nut rests in your hands");
Tooltip.SetDefault("The power of the nut rests in your hands\n" +
"Fires high explosive peanut shells, literally");
}
public override void SetDefaults()
{
item.width = 70;
item.height = 42;
item.damage = 291;
item.damage = 1071;
item.ranged = true;
item.useTime = 30;
item.useAnimation = 30;
item.autoReuse = true;
item.useStyle = ItemUseStyleID.HoldingOut;
item.noMelee = true;
item.knockBack = 10f;
item.knockBack = 6f;
// Reduce volume to 30% so it stops destroying people's ears.
var sound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LargeWeaponFire");
item.UseSound = sound.WithVolume(0.3f);
item.shoot = ModContent.ProjectileType<HighExplosivePeanutShell>();
item.shootSpeed = 13f;
item.useAmmo = AmmoID.Bullet;
item.value = CalamityGlobalItem.Rarity13BuyPrice;
item.rare = ItemRarityID.Red;
item.Calamity().customRarity = CalamityRarity.PureGreen;
item.Calamity().donorItem = true;
item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LargeWeaponFire");
item.shootSpeed = 24f;
item.shoot = ProjectileID.BulletHighVelocity;
item.useAmmo = AmmoID.Bullet;
}
// Terraria seems to really dislike high crit values in SetDefaults
public override void GetWeaponCrit(Player player, ref int crit) => crit += 16;
public override Vector2? HoldoutOffset() => new Vector2(-15, 5);
public override bool CanUseItem(Player player) => CalamityGlobalItem.HasEnoughAmmo(player, item, 5);
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
for (int i = 0; i < 5; i++)
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ProjectileID.BulletHighVelocity, damage, knockBack, player.whoAmI, 0f, 0f);
// Consume 5 ammo per shot
CalamityGlobalItem.ConsumeAdditionalAmmo(player, item, 5);
return false;
type = item.shoot;
return true;
}
// Disable vanilla ammo consumption
public override bool ConsumeAmmo(Player player)
{
return false;
}
public override Vector2? HoldoutOffset() => new Vector2(-17, 5);
public override void AddRecipes()
{
+4 -32
View File
@@ -92,42 +92,14 @@ namespace CalamityMod.Projectiles.Ranged
// Transform the projectile's hitbox into a big explosion
projectile.position = projectile.Center;
projectile.width = projectile.height = 140;
projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
projectile.position.X = projectile.position.X - projectile.width / 2;
projectile.position.Y = projectile.position.Y - projectile.height / 2;
// Spawn explosion dust (separate method because it's messy)
SpawnExplosionDust();
// Rocket III type explosion is now a utility for convenience
projectile.LargeFieryExplosion();
// Make the explosion cause damage to nearby targets (makes projectile hit twice)
projectile.Damage();
}
// Dust copied from Rocket III
void SpawnExplosionDust()
{
// Sparks and such
Vector2 corner = projectile.position;
for (int i = 0; i < 40; i++)
{
int idx = Dust.NewDust(corner, projectile.width, projectile.height, 31, 0f, 0f, 100, default, 2f);
Main.dust[idx].velocity *= 3f;
if (Main.rand.NextBool(2))
{
Main.dust[idx].scale = 0.5f;
Main.dust[idx].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
}
}
for (int i = 0; i < 70; i++)
{
int idx = Dust.NewDust(corner, projectile.width, projectile.height, 6, 0f, 0f, 100, default, 3f);
Main.dust[idx].noGravity = true;
Main.dust[idx].velocity *= 5f;
idx = Dust.NewDust(corner, projectile.width, projectile.height, 6, 0f, 0f, 100, default, 2f);
Main.dust[idx].velocity *= 2f;
}
// Smoke, which counts as a Gore
CalamityUtils.ExplosionGores(projectile.Center, 3);
}
}
}
@@ -0,0 +1,92 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Ranged
{
public class HighExplosivePeanutShell : ModProjectile
{
private const int Lifetime = 180;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("High Explosive Peanut Shell");
ProjectileID.Sets.TrailCacheLength[projectile.type] = 9;
ProjectileID.Sets.TrailingMode[projectile.type] = 1;
}
public override void SetDefaults()
{
projectile.width = 16;
projectile.height = 16;
projectile.friendly = true;
projectile.ranged = true;
projectile.extraUpdates = 4;
projectile.timeLeft = Lifetime;
}
public override void AI()
{
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2;
projectile.spriteDirection = projectile.direction;
// Lighting
Lighting.AddLight(projectile.Center, 0.75f, 0.65f, 0.08f);
// Dirty dust, done dirt cheap
{
int dustID = 7; // wood flakes
float scale = Main.rand.NextFloat(1f, 1.4f);
Dust d = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, dustID);
d.noGravity = true;
d.scale = scale;
// Dust velocity is a complicated flaking function taken from Holy Fire Bullets
d.velocity *= 0.2f;
float angleDeviation = 0.17f;
float angle = Main.rand.NextFloat(-angleDeviation, angleDeviation);
Vector2 sprayVelocity = projectile.velocity.RotatedBy(angle) * 0.6f;
d.velocity += sprayVelocity;
}
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
CalamityGlobalProjectile.DrawCenteredAndAfterimage(projectile, lightColor, ProjectileID.Sets.TrailingMode[projectile.type], 1);
return false;
}
public override void Kill(int timeLeft)
{
// Grenade Launcher + Lunar Flare sounds for maximum meaty explosion
Main.PlaySound(SoundID.Item62, projectile.Center);
Main.PlaySound(SoundID.Item88, projectile.Center);
// Massively inflate the projectile's hitbox
projectile.position = projectile.Center;
projectile.width = projectile.height = 140;
projectile.position.X = projectile.position.X - projectile.width / 2;
projectile.position.Y = projectile.position.Y - projectile.height / 2;
// Allow infinite piercing and ignoring iframes for this one extra hit
projectile.penetrate = -1;
projectile.usesLocalNPCImmunity = true;
projectile.localNPCHitCooldown = -1;
// Rocket III type explosion is now a utility for convenience
projectile.LargeFieryExplosion();
// Deal damage again. The explosion deals half the damage of the direct hit.
projectile.damage /= 2;
projectile.Damage();
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
Collision.HitTiles(projectile.position, projectile.velocity, projectile.width, projectile.height);
return true; // the projectile does indeed die on collision
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

+32 -1
View File
@@ -284,7 +284,7 @@ namespace CalamityMod
TileID.LihzahrdAltar,
TileID.DesertFossil
};
CalamityUtils.AddWithCondition<int>(explosionCheckList, TileID.Hellstone, !Main.hardMode);
AddWithCondition<int>(explosionCheckList, TileID.Hellstone, !Main.hardMode);
for (int i = minTileX; i <= maxTileX; i++)
{
@@ -353,5 +353,36 @@ namespace CalamityMod
}
}
}
/// <summary>
/// Creates an explosion which is visually identical to vanilla's Rocket III and Rocket IV on-hit explosions.
/// </summary>
/// <param name="projectile">The projectile which is exploding.</param>
public static void LargeFieryExplosion(this Projectile projectile)
{
// Sparks and such
Vector2 corner = projectile.position;
for (int i = 0; i < 40; i++)
{
int idx = Dust.NewDust(corner, projectile.width, projectile.height, 31, 0f, 0f, 100, default, 2f);
Main.dust[idx].velocity *= 3f;
if (Main.rand.NextBool(2))
{
Main.dust[idx].scale = 0.5f;
Main.dust[idx].fadeIn = 1f + Main.rand.Next(10) * 0.1f;
}
}
for (int i = 0; i < 70; i++)
{
int idx = Dust.NewDust(corner, projectile.width, projectile.height, 6, 0f, 0f, 100, default, 3f);
Main.dust[idx].noGravity = true;
Main.dust[idx].velocity *= 5f;
idx = Dust.NewDust(corner, projectile.width, projectile.height, 6, 0f, 0f, 100, default, 2f);
Main.dust[idx].velocity *= 2f;
}
// Smoke, which counts as a Gore
ExplosionGores(projectile.Center, 3);
}
}
}