152 lines
7.3 KiB
C#
152 lines
7.3 KiB
C#
using CalamityMod.Projectiles.Melee;
|
|
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Items.Weapons.Melee
|
|
{
|
|
public class CometQuasher : ModItem, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Items.Weapons.Melee";
|
|
public override void SetDefaults()
|
|
{
|
|
Item.width = 46;
|
|
Item.height = 62;
|
|
Item.scale = 1.5f;
|
|
Item.damage = 160;
|
|
Item.DamageType = DamageClass.Melee;
|
|
Item.useAnimation = 22;
|
|
Item.useStyle = ItemUseStyleID.Swing;
|
|
Item.useTime = 22;
|
|
Item.useTurn = true;
|
|
Item.knockBack = 7.75f;
|
|
Item.UseSound = SoundID.Item1;
|
|
Item.autoReuse = true;
|
|
Item.value = CalamityGlobalItem.Rarity8BuyPrice;
|
|
Item.rare = ItemRarityID.Yellow;
|
|
Item.shootSpeed = 9f;
|
|
}
|
|
|
|
public override void ModifyHitNPC(Player player, NPC target, ref NPC.HitModifiers modifiers)
|
|
{
|
|
modifiers.CritDamage *= 0.5f;
|
|
}
|
|
public override void OnHitNPC(Player player, NPC target, NPC.HitInfo hit, int damageDone)
|
|
{
|
|
var source = player.GetSource_ItemUse(Item);
|
|
float cometSpeed = Item.shootSpeed;
|
|
Vector2 realPlayerPos = player.RotatedRelativePoint(player.MountedCenter, true);
|
|
float mouseXDist = (float)Main.mouseX + Main.screenPosition.X - realPlayerPos.X;
|
|
float mouseYDist = (float)Main.mouseY + Main.screenPosition.Y - realPlayerPos.Y;
|
|
if (player.gravDir == -1f)
|
|
{
|
|
mouseYDist = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - realPlayerPos.Y;
|
|
}
|
|
float mouseDistance = (float)Math.Sqrt((double)(mouseXDist * mouseXDist + mouseYDist * mouseYDist));
|
|
if ((float.IsNaN(mouseXDist) && float.IsNaN(mouseYDist)) || (mouseXDist == 0f && mouseYDist == 0f))
|
|
{
|
|
mouseXDist = (float)player.direction;
|
|
mouseYDist = 0f;
|
|
mouseDistance = cometSpeed;
|
|
}
|
|
else
|
|
{
|
|
mouseDistance = cometSpeed / mouseDistance;
|
|
}
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
realPlayerPos = new Vector2(player.position.X + (float)player.width * 0.5f + (float)(Main.rand.Next(201) * -(float)player.direction) + ((float)Main.mouseX + Main.screenPosition.X - player.position.X), player.MountedCenter.Y - 600f);
|
|
realPlayerPos.X = (realPlayerPos.X + player.Center.X) / 2f + (float)Main.rand.Next(-200, 201);
|
|
realPlayerPos.Y -= (float)(100 * i);
|
|
mouseXDist = (float)Main.mouseX + Main.screenPosition.X - realPlayerPos.X + (float)Main.rand.Next(-40, 41) * 0.03f;
|
|
mouseYDist = (float)Main.mouseY + Main.screenPosition.Y - realPlayerPos.Y;
|
|
if (mouseYDist < 0f)
|
|
{
|
|
mouseYDist *= -1f;
|
|
}
|
|
if (mouseYDist < 20f)
|
|
{
|
|
mouseYDist = 20f;
|
|
}
|
|
mouseDistance = (float)Math.Sqrt((double)(mouseXDist * mouseXDist + mouseYDist * mouseYDist));
|
|
mouseDistance = cometSpeed / mouseDistance;
|
|
mouseXDist *= mouseDistance;
|
|
mouseYDist *= mouseDistance;
|
|
float cometSpawnXOffset = mouseXDist;
|
|
float cometSpawnYOffset = mouseYDist + (float)Main.rand.Next(-40, 41) * 0.02f;
|
|
int proj = Projectile.NewProjectile(source, realPlayerPos.X, realPlayerPos.Y, cometSpawnXOffset * 0.75f, cometSpawnYOffset * 0.75f, ModContent.ProjectileType<CometQuasherMeteor>(), (int)(Item.damage * 0.5f), Item.knockBack, player.whoAmI, 0f, 0.5f + (float)Main.rand.NextDouble() * 0.3f);
|
|
Main.projectile[proj].Calamity().lineColor = Main.rand.Next(3);
|
|
}
|
|
}
|
|
|
|
public override void OnHitPvp(Player player, Player target, Player.HurtInfo hurtInfo)
|
|
{
|
|
var source = player.GetSource_ItemUse(Item);
|
|
float cometSpeed = Item.shootSpeed;
|
|
Vector2 realPlayerPos = player.RotatedRelativePoint(player.MountedCenter, true);
|
|
float mouseXDist = (float)Main.mouseX + Main.screenPosition.X - realPlayerPos.X;
|
|
float mouseYDist = (float)Main.mouseY + Main.screenPosition.Y - realPlayerPos.Y;
|
|
if (player.gravDir == -1f)
|
|
{
|
|
mouseYDist = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - realPlayerPos.Y;
|
|
}
|
|
float mouseDistance = (float)Math.Sqrt((double)(mouseXDist * mouseXDist + mouseYDist * mouseYDist));
|
|
if ((float.IsNaN(mouseXDist) && float.IsNaN(mouseYDist)) || (mouseXDist == 0f && mouseYDist == 0f))
|
|
{
|
|
mouseXDist = (float)player.direction;
|
|
mouseYDist = 0f;
|
|
mouseDistance = cometSpeed;
|
|
}
|
|
else
|
|
{
|
|
mouseDistance = cometSpeed / mouseDistance;
|
|
}
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
realPlayerPos = new Vector2(player.position.X + (float)player.width * 0.5f + (float)(Main.rand.Next(201) * -(float)player.direction) + ((float)Main.mouseX + Main.screenPosition.X - player.position.X), player.MountedCenter.Y - 600f);
|
|
realPlayerPos.X = (realPlayerPos.X + player.Center.X) / 2f + (float)Main.rand.Next(-200, 201);
|
|
realPlayerPos.Y -= (float)(100 * i);
|
|
mouseXDist = (float)Main.mouseX + Main.screenPosition.X - realPlayerPos.X + (float)Main.rand.Next(-40, 41) * 0.03f;
|
|
mouseYDist = (float)Main.mouseY + Main.screenPosition.Y - realPlayerPos.Y;
|
|
if (mouseYDist < 0f)
|
|
{
|
|
mouseYDist *= -1f;
|
|
}
|
|
if (mouseYDist < 20f)
|
|
{
|
|
mouseYDist = 20f;
|
|
}
|
|
mouseDistance = (float)Math.Sqrt((double)(mouseXDist * mouseXDist + mouseYDist * mouseYDist));
|
|
mouseDistance = cometSpeed / mouseDistance;
|
|
mouseXDist *= mouseDistance;
|
|
mouseYDist *= mouseDistance;
|
|
float cometSpawnXOffset = mouseXDist;
|
|
float cometSpawnYOffset = mouseYDist + (float)Main.rand.Next(-40, 41) * 0.02f;
|
|
int proj = Projectile.NewProjectile(source, realPlayerPos.X, realPlayerPos.Y, cometSpawnXOffset * 0.75f, cometSpawnYOffset * 0.75f, ModContent.ProjectileType<CometQuasherMeteor>(), (int)(Item.damage * 0.5f), Item.knockBack, player.whoAmI, 0f, 0.5f + (float)Main.rand.NextDouble() * 0.3f);
|
|
Main.projectile[proj].Calamity().lineColor = Main.rand.Next(3);
|
|
}
|
|
}
|
|
|
|
public override void MeleeEffects(Player player, Rectangle hitbox)
|
|
{
|
|
if (Main.rand.NextBool(3))
|
|
{
|
|
Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 6);
|
|
}
|
|
}
|
|
|
|
public override void AddRecipes()
|
|
{
|
|
CreateRecipe().
|
|
AddIngredient(ItemID.MeteoriteBar, 25).
|
|
AddIngredient(ItemID.Ectoplasm, 5).
|
|
AddTile(TileID.MythrilAnvil).
|
|
Register();
|
|
}
|
|
}
|
|
}
|