Roxcal rework by jav

This commit is contained in:
Mishiro Usui authored and Cameron Ewell committed 2023-10-24 11:42:25 -04:00
1 parent bf4abd1829
commit 11aa4ecb1b
6 files changed
+336 -400

No files matched your search

+53 -286
View File
@@ -1,303 +1,70 @@
using Terraria.DataStructures;
using System.Collections.Generic;
using CalamityMod.Items.Materials;
using CalamityMod.Projectiles.Melee;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
namespace CalamityMod.Items.Weapons.Melee
{
public class Roxcalibur : ModItem, ILocalizedModType
{
public new string LocalizationCategory => "Items.Weapons.Melee";
private int Roxcooldown = 901;
private int RoxCanUse = 0;
private int RoxCanAlt = 0;
private bool RoxAlt = false;
private bool Didrefresh = false;
public class Roxcalibur : ModItem, ILocalizedModType
{
public override void SetStaticDefaults()
{
ItemID.Sets.ItemsThatAllowRepeatedRightClick[Item.type] = true;
}
public string LocalizationCategory => "Items.Weapons.Melee";
public override void SetDefaults()
{
Item.damage = 150;
Item.knockBack = 13;
public static int BaseUseTime = 40;
public override void SetDefaults()
{
Item.damage = 200;
Item.knockBack = 13f;
Item.DamageType = DamageClass.Melee;
Item.useStyle = ItemUseStyleID.Swing;
Item.UseSound = SoundID.NPCHit42;
Item.width = 100;
Item.height = 100;
Item.autoReuse = true;
Item.useAnimation = Item.useTime = 64;
Item.shoot = ModContent.ProjectileType<Rox1>();
Item.shootSpeed = 10f;
Item.value = CalamityGlobalItem.Rarity4BuyPrice;
Item.rare = ItemRarityID.LightRed;
Item.useStyle = ItemUseStyleID.Shoot;
Item.UseSound = SoundID.NPCHit42;
Item.width = 100;
Item.height = 100;
Item.useAnimation = Item.useTime = BaseUseTime;
Item.reuseDelay = 10;
Item.shoot = ModContent.ProjectileType<RoxcaliburProj>();
Item.shootSpeed = 4f;
Item.value = CalamityGlobalItem.Rarity4BuyPrice;
Item.rare = ItemRarityID.LightRed;
Item.Calamity().donorItem = true;
Item.noUseGraphic = true;
Item.noMelee = true;
Item.autoReuse = false;
Item.channel = true;
}
// Terraria seems to really dislike high crit values in SetDefaults
public override void ModifyWeaponCrit(Player player, ref float crit) => crit += 8;
public override void ModifyWeaponCrit(Player player, ref float crit)
{
crit += 8f;
}
public override bool CanUseItem(Player player) => Main.hardMode && player.ownedProjectileCounts[Item.shoot] < 1;
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
Projectile.NewProjectile(source, position, velocity, type, damage, knockback, ai2: player.itemTimeMax); //needed to set ai2
return false;
}
public override void ModifyTooltips(List<TooltipLine> list)
{
list.FindAndReplace("[WOF]", Main.hardMode ? string.Empty : this.GetLocalizedValue("LockedInfo") + "\n");
}
public override void UpdateInventory(Player player)
{
//Timers for the cooldown and usage of the weapon
Roxcooldown++;
RoxCanUse++;
RoxCanAlt++;
if (Roxcooldown == 600)
{
for (int i = 0; i < 50; i++)
{
int d = Dust.NewDust(player.Center, player.width, player.height, 191, Main.rand.Next(-8, 9), Main.rand.Next(-8, 9), 100, default, 1);
Main.dust[d].noGravity = true;
Main.dust[d].position = player.Center;
}
SoundEngine.PlaySound(SoundID.Item70, player.Center);
}
// Resets the weapon usage if the alt fire collides with the ground
if (RoxAlt && player.ownedProjectileCounts[ModContent.ProjectileType<RoxSlam>()] <= 0)
{
player.itemAnimation = 0;
player.itemTime = 0;
RoxCanUse = 0;
RoxAlt = false;
Didrefresh = false;
}
// Controls what happens when the alt fire is active
if (RoxAlt && player.ownedProjectileCounts[ModContent.ProjectileType<RoxSlam>()] > 0)
{
if (player.mount.Active)
{
player.mount.Dismount(player);
}
player.maxFallSpeed = 22f;
player.controlJump = false;
player.controlUp = false;
player.dashDelay = 60;
}
}
public override bool CanUseItem(Player player)
{
//Only useable in hardmode and if a second has passed after the alt fire ended
return Main.hardMode && RoxCanUse >= 60;
}
public override bool AltFunctionUse(Player player)
{
return RoxCanAlt >= Item.useAnimation + 5 && player.position.Y != player.oldPosition.Y && !player.mount.Active && player.gravDir != -1;
}
public override void UseStyle(Player player, Rectangle heldItemFrame)
{
//Modifies the altfire use style and the location of the sprite of the weapon
if (player.altFunctionUse == 2)
{
player.itemLocation.X -= 32f * player.direction;
player.itemLocation.Y -= 60f;
Item.useStyle = ItemUseStyleID.HoldUp;
RoxAlt = true;
}
//Modifies to use style and hold out of the main fire mode
else
{
player.itemLocation += new Vector2(-7.5f * player.direction, 8.5f * player.gravDir).RotatedBy(player.itemRotation);
Item.useStyle = ItemUseStyleID.Swing;
RoxAlt = false;
}
}
//Makes the alt fire only spawn the projectile once
// TODO -- Fix this, because tmod removed this function
//public override bool OnlyShootOnSwing => RoxAlt;
public override void UseItemHitbox(Player player, ref Rectangle hitbox, ref bool noHitbox)
{
//Changes the hitbox of the alt fire to fit the sprite
if (player.altFunctionUse == 2)
{
if (player.direction == 1)
{
hitbox.X = (int)player.position.X - 9;
}
else
{
hitbox.X = (int)player.position.X - 22;
}
hitbox.Y = (int)player.position.Y + 20;
hitbox.Width = 52;
}
//Why did i need to fix this hitbox i have no clue
else
{
if (player.direction == -1)
{
hitbox.X += 16;
}
hitbox.Width -= 15;
}
}
public override float UseSpeedMultiplier(Player player)
{
//If you use alt fire it can hold the sword for way longer
if (player.altFunctionUse == 2)
{
//Use animation 40/0.1 = 400
return 0.1f;
}
else
{
return 1f;
}
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (player.altFunctionUse == 2)
{
//Prevents the player from getting stuck on tiles like platforms
if (player.position.Y == player.oldPosition.Y)
{
player.itemAnimation = 0;
player.itemTime = 0;
RoxAlt = false;
RoxCanUse = 0;
if (Didrefresh)
{
Roxcooldown = 600;
Didrefresh = false;
}
}
// Makes the player forcefully dive down
if (CalamityUtils.CountHookProj() <= 0)
player.velocity.Y = player.maxFallSpeed;
//Rotates the sprite of the item on alt fire to have it point downwards
player.itemRotation = player.direction * MathHelper.ToRadians(135f);
//Dust trail
int dusty = hitbox.Y + (hitbox.Height / 2);
Dust.NewDust(new Vector2(hitbox.X, dusty), hitbox.Width, hitbox.Height / 2, 191, player.velocity.X * 0.25f, player.velocity.Y * 0.25f, 160, default, 0.7f);
}
else
{
Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 191, 0f, 0f, 160, default, 0.7f);
}
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
if (Item.useStyle == ItemUseStyleID.HoldUp)
{
//Spawns a projectile on the tip of the sword in the alt fire
float positionx;
float positiony = position.Y + (Item.height / 2) + 23;
int cooldown = 0;
//Check if the entire cooldown has passed
if (Roxcooldown >= 600)
{
cooldown = 1;
}
// Makes the projectile spawn in the proper position on the X axis
if (player.direction == 1)
{
positionx = position.X + 6;
}
else
{
positionx = position.X - 8;
}
Projectile.NewProjectile(source, positionx, positiony - (player.height / 10f), player.velocity.X, player.velocity.Y, ModContent.ProjectileType<RoxSlam>(), 0, 0, player.whoAmI, cooldown);
//Resets the cooldown after shooting
if (Roxcooldown >= 600)
{
Roxcooldown = 0;
//"Why yes i did refresh the cooldown whatcha gonna do about it?" -continues on OnHitNPC
Didrefresh = true;
}
return false;
}
else
{
for (int i = 0; i < 2; i++)
{
Vector2 pertubedspeed = new Vector2(velocity.X / 2, -10f * player.gravDir).RotatedByRandom(MathHelper.ToRadians(10f));
Projectile.NewProjectile(source, position.X, position.Y, pertubedspeed.X, pertubedspeed.Y, ModContent.ProjectileType<Rox1>(), (int)(damage * 0.5), 1f, player.whoAmI, Main.rand.Next(3));
}
RoxCanAlt = 0;
return false;
}
}
public override void OnHitNPC(Player player, NPC target, NPC.HitInfo hit, int damageDone)
{
if (Item.useStyle == ItemUseStyleID.HoldUp)
{
if (player.whoAmI == Main.myPlayer)
{
//"Well you did refresh the cooldown but like i dont want it to be wasted on an enemy hit so imma ask you for a refund"
if (Didrefresh)
{
Roxcooldown = 600;
Didrefresh = false;
}
//End the alt attack
player.itemAnimation = 0;
player.itemTime = 0;
RoxAlt = false;
RoxCanUse = 0;
player.velocity.Y = -16f;
player.fallStart = (int)(player.position.Y / 16f);
}
}
}
public override void OnHitPvp(Player player, Player target, Player.HurtInfo hurtInfo)
{
if (Item.useStyle == ItemUseStyleID.HoldUp)
{
if (player.whoAmI == Main.myPlayer)
{
//"Well you did refresh the cooldown but like i dont want it to be wasted on a player hit so imma ask you for a refund"
if (Didrefresh)
{
Roxcooldown = 600;
Didrefresh = false;
}
//End the alt attack
player.itemAnimation = 0;
player.itemTime = 0;
RoxAlt = false;
RoxCanUse = 0;
player.velocity.Y = -16f;
player.fallStart = (int)(player.position.Y / 16f);
}
}
}
public override void ModifyTooltips(List<TooltipLine> list) => list.FindAndReplace("[WOF]", Main.hardMode ? string.Empty : this.GetLocalizedValue("LockedInfo") + "\n");
public override void AddRecipes()
{
CreateRecipe().
AddIngredient(ItemID.HellstoneBar, 25).
AddIngredient(ItemID.SoulofNight, 10).
AddIngredient<EssenceofHavoc>(5).
AddIngredient(ItemID.Obsidian, 10).
AddIngredient(ItemID.StoneBlock, 100).
AddIngredient(ItemID.Amethyst, 2).
AddTile(TileID.Anvils).
Register();
}
}
public override void AddRecipes()
{
CreateRecipe()
.AddIngredient(ItemID.HellstoneBar, 25)
.AddIngredient(ItemID.SoulofNight, 10)
.AddIngredient<EssenceofHavoc>(5)
.AddIngredient(ItemID.Obsidian, 10)
.AddIngredient(ItemID.StoneBlock, 100)
.AddIngredient(ItemID.Amethyst, 2)
.AddTile(TileID.Anvils)
.Register();
}
}
}
@@ -965,8 +965,9 @@ Roxcalibur: {
// The WOF tag generates a new line above when placed at the start of a line
Tooltip:
'''
[WOF]Press <left> to shoot several rock shards
Press <right> to dive downwards and bounce off enemies
[WOF]Hold <left> to charge up a strike
Release with the cursor above your player to swing normally, releasing rock shards
Release with the cursor below your player to dive downwards and bounce off enemies
Diving into blocks creates a shockwave
You couldn't get it out of the rock, so you just brought the rock instead
'''
@@ -207,8 +207,7 @@ RedtideWhirlpool.DisplayName: Whirlpool
RemsRevengeProj.DisplayName: Rem's Revenge
RendingNeedle.DisplayName: Rending Needle
Rox1.DisplayName: Rock
RoxShockwave.DisplayName: Rox Shockwave
RoxSlam.DisplayName: Rox Slam
RoxcaliburProj.DisplayName: Roxcalibur
RSSolarFlare.DisplayName: Flare
SandBlade.DisplayName: Sand Blade
SandFire.DisplayName: Fire
-22
View File
@@ -1,22 +0,0 @@
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Melee
{
public class RoxShockwave : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetDefaults()
{
Projectile.penetrate = -1;
Projectile.width = 450;
Projectile.height = 450;
Projectile.DamageType = DamageClass.Melee;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.timeLeft = 40;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 10;
}
}
}
-88
View File
@@ -1,88 +0,0 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
namespace CalamityMod.Projectiles.Melee
{
public class RoxSlam : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetDefaults()
{
Projectile.width = 10;
Projectile.height = 35;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Melee;
Projectile.timeLeft = 400;
Projectile.tileCollide = true;
}
public override void AI()
{
Player player = Main.player[Projectile.owner];
//Kills the projectile if the alt attack ended
if (player.itemAnimation == 0)
{
Projectile.Kill();
}
//Makes the projectiles track the player
float posX;
float posY = player.Center.Y + 63;
// Makes the projectile follow the proper position on the X axis
if (player.direction == 1)
{
posX = player.Center.X + 6;
}
else
{
posX = player.Center.X - 8;
}
Projectile.Center = new Vector2(posX, posY - (player.height / 10f));
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
//This will only happen if the cooldown was full
if (Projectile.ai[0] == 1 && Main.myPlayer == Projectile.owner)
{
Player player = Main.player[Projectile.owner];
//Bounce
player.velocity.Y = -18f;
//reset player fall damage
player.fallStart = (int)(player.position.Y / 16f);
//Spawns the shockwave
int slamDamage = (int)player.GetTotalDamage<MeleeDamageClass>().ApplyTo(300);
float slamKB = player.GetTotalKnockback<MeleeDamageClass>().ApplyTo(12f);
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType<RoxShockwave>(), slamDamage, slamKB, Projectile.owner);
SoundEngine.PlaySound(SoundID.Item14, Projectile.position);
Projectile.Kill();
//Pretty things
for (int dustexplode = 0; dustexplode < 360; dustexplode++)
{
Vector2 dustd = new Vector2(17f, 17f).RotatedBy(MathHelper.ToRadians(dustexplode));
int d = Dust.NewDust(Projectile.Center, Projectile.width, Projectile.height, 51, dustd.X, dustd.Y, 100, default, 3f);
Main.dust[d].noGravity = true;
Main.dust[d].position = Projectile.Center;
}
return false;
}
//If the cooldown wasnt full, just bounce
else if (Main.myPlayer == Projectile.owner)
{
Player player = Main.player[Projectile.owner];
player.velocity.Y = -14f;
//reset player fall damage
player.fallStart = (int)(player.position.Y / 16f);
SoundEngine.PlaySound(SoundID.Tink, Projectile.position);
Projectile.Kill();
return false;
}
return false;
}
}
}
+279
View File
@@ -0,0 +1,279 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
using CalamityMod.Items.Weapons.Melee;
namespace CalamityMod.Projectiles.Melee
{
public class RoxcaliburProj : ModProjectile, ILocalizedModType
{
public string LocalizationCategory => "Projectiles.Melee";
public override string Texture => "CalamityMod/Items/Weapons/Melee/Roxcalibur";
public override void SetDefaults()
{
Projectile.penetrate = -1;
Projectile.width = 100;
Projectile.height = 100;
Projectile.DamageType = DamageClass.Melee;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.timeLeft = 3600;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 150;
}
private const int Charging = 0, Swinging = 1, Plunging = 2, Recoil = 3;
private int Animation = Charging;
const int plungeSpeed = 20;
public float BaseChargeTime = 60 * 2;
ref float ChargeLevel => ref Projectile.ai[0];
ref float HitTimer => ref Projectile.ai[1];
private Vector2 RockOffset() => Projectile.velocity * 0.25f * Projectile.Size.Length();
public override bool? CanDamage() => HitTimer < 5 && Animation != Charging ? base.CanDamage() : false; //returning true means it can damage friendlies etc
//large "explosion" hitbox that lasts for 5 frames after bonk hit
public override void ModifyDamageHitbox(ref Rectangle hitbox)
{
if (HitTimer > 0 && HitTimer < 5)
{
float hitboxModifier = 2f + 1.5f * ChargeLevel;
Vector2 HitboxSize = new(Projectile.width * hitboxModifier, Projectile.height * hitboxModifier);
Vector2 HitboxCenter = Projectile.Center + RockOffset();
hitbox = new Rectangle((int)(HitboxCenter.X - HitboxSize.X / 2f), (int)(HitboxCenter.Y - HitboxSize.Y / 2f), (int)HitboxSize.X, (int)HitboxSize.Y);
}
}
//more precise hitbox. makes the weapon harder to use but looks visually better: use it if you want.
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
{
if (HitTimer <= 0)
{
float size = Projectile.Size.Length();
Vector2 hiltPos = Projectile.Center - Projectile.velocity * size / 2;
Vector2 endPos = Projectile.Center + Projectile.velocity * size / 2;
float useless = 0f;
return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), hiltPos, endPos, size / 2, ref useless);
}
return base.Colliding(projHitbox, targetHitbox);
}
public override void AI()
{
ref float origAnimMax = ref Projectile.ai[2];
ref float rotation = ref Projectile.localAI[0];
ref float playerDirection = ref Projectile.localAI[1];
ref float PlayedChargeSound = ref Projectile.localAI[2];
Player player = Main.player[Projectile.owner];
if (player == null || !player.active || player.dead)
{
Projectile.Kill();
return;
}
player.heldProj = Projectile.whoAmI;
if (origAnimMax == 0)
{
origAnimMax = player.itemAnimationMax;
}
float HoldoutRadius = (float)Projectile.Size.Length() / 2; //since sprite is diagonal
float attackSpeedModifier = origAnimMax / Roxcalibur.BaseUseTime;
float chargeTime = attackSpeedModifier * BaseChargeTime;
if (player.channel)
{
Animation = Charging;
}
else if (Animation == Charging) //first frame of release
{
Animation = Main.MouseWorld.Y > player.Center.Y ? Plunging : Swinging;
float chargeModifier = ChargeLevel * 3.5f; //modify this to balance damage bonus from charging
if (Animation == Plunging)
{
Projectile.timeLeft = 60 * 2; //maximum 2 second plunge time
}
Projectile.damage = (int)(Projectile.damage * (1 + chargeModifier));
Projectile.netUpdate = true;
SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Custom/LoudSwingWoosh") with { Pitch = -0.5f }, Projectile.Center);
}
switch (Animation)
{
case Charging:
{
if (ChargeLevel < 1)
ChargeLevel += 1f / chargeTime;
else
ChargeLevel = 1;
int direction = -Math.Sign(player.DirectionTo(Main.MouseWorld).X);
playerDirection = -direction;
float rotModifier = (float)Math.Pow(ChargeLevel, 0.4f);
rotation = Utils.SmoothStep(-MathHelper.PiOver2 / 4, MathHelper.PiOver2 / 1.5f, rotModifier);
rotation *= direction;
Projectile.timeLeft = (int)origAnimMax;
if (ChargeLevel >= 1 && player.whoAmI == Main.myPlayer && PlayedChargeSound == 0)
{
PlayedChargeSound = 1;
SoundEngine.PlaySound(SoundID.NPCHit42 with { Pitch = 0.4f }, Projectile.Center);
}
}
break;
case Swinging:
{
if (Projectile.timeLeft > origAnimMax)
{
Projectile.timeLeft = (int)origAnimMax;
}
float progress = Projectile.timeLeft / origAnimMax;
float chargeRotModifier = (ChargeLevel + 1f) / 2f;
float animRotModifier = Math.Clamp(progress, 0, 1);
if (animRotModifier > 0.5f)
animRotModifier = 1 - animRotModifier;
animRotModifier *= animRotModifier;
animRotModifier += 0.02f;
rotation += playerDirection * animRotModifier * chargeRotModifier * MathHelper.TwoPi * 0.2f;
Projectile.localNPCHitCooldown = (int)Math.Ceiling(origAnimMax); //only hit once per swing
//int shardTimer = (int)Math.Ceiling(((1 - ChargeLevel) * 0.6f + 0.4f) * 9);
int shardTimer = ChargeLevel >= 0.95f ? 2 : ChargeLevel >= 0.5f ? 4 : 6;
if (progress < 0.8f && progress > 0.2f && Projectile.timeLeft % shardTimer == 0)
{
Vector2 roxSpeed = (Projectile.velocity * 8f).RotatedByRandom((double)MathHelper.ToRadians(10f));
int rox = ModContent.ProjectileType<Rox1>();
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center + RockOffset(), roxSpeed, rox, (int)(Projectile.damage * 0.4f), 1f, player.whoAmI, (float)Main.rand.Next(3), 0f, 0f);
}
}
break;
case Plunging:
{
//I would make this set your velocity.Y if it wasn't capped, tried uncapping it by changing Player.maxFallSpeed but it does not work properly!
//this also makes you go through platforms which is cool and good imo
Vector2 plunge = Vector2.UnitY * player.gravDir * plungeSpeed * (ChargeLevel + 1f) / 2f;
if ((player.velocity.Y == 0 && Projectile.velocity.Y * player.gravDir > 0) || Collision.SolidCollision(player.position + plunge, player.width, player.height))
{
CollisionEffects();
break;
}
player.position += plunge;
player.velocity.X *= 0.95f;
player.velocity.Y = 0;
float chargeRotModifier = (ChargeLevel + 1f) / 2f;
float anglediff = RotationDifference(Projectile.velocity, Vector2.UnitY * player.gravDir);
int dir = Math.Abs(anglediff) > MathHelper.PiOver2 ? (int)playerDirection : Math.Sign(anglediff);
rotation += dir * Math.Abs(anglediff) * 0.12f * chargeRotModifier;
//rotation += playerDirection * animRotModifier * chargeRotModifier * MathHelper.TwoPi * 6 / origAnimMax;
Projectile.localNPCHitCooldown = (int)Math.Ceiling(origAnimMax); //only hit once per swing
if (Collision.SolidTiles(Projectile.position, Projectile.width, Projectile.height, false))
{
CollisionEffects();
break;
}
}
break;
case Recoil:
{
if (Projectile.timeLeft > origAnimMax / 3)
Projectile.timeLeft = (int)(origAnimMax / 3);
float modifier = Math.Clamp(Projectile.timeLeft / origAnimMax, 0, 1);
rotation -= playerDirection * modifier * MathHelper.TwoPi * 2 / origAnimMax;
}
break;
}
if (HitTimer > 0 && HitTimer <= 5)
{
HitTimer++;
}
Projectile.velocity = (-Vector2.UnitY * player.gravDir).RotatedBy(rotation);
Projectile.Center = (Vector2)player.HandPosition + Projectile.velocity * HoldoutRadius;
Projectile.rotation = Projectile.velocity.ToRotation();
Projectile.spriteDirection = Projectile.direction = (int)playerDirection;
player.ChangeDir(Projectile.direction);
player.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation();
player.itemTime = Math.Max(player.itemTime, 2);
player.itemAnimation = Math.Max(player.itemAnimation, 2);
if (Projectile.spriteDirection == -1)
{
Projectile.rotation += MathHelper.ToRadians(-45f) + MathHelper.Pi;
}
else
{
Projectile.rotation += MathHelper.ToRadians(-135f) + MathHelper.Pi;
}
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
CollisionEffects();
}
private void CollisionEffects()
{
if (HitTimer == 0)
{
HitTimer = 1;
SoundEngine.PlaySound(SoundID.Item14, Projectile.Center);
if (Animation == Plunging)
{
Player player = Main.player[Projectile.owner];
player.velocity.Y = -player.gravDir * plungeSpeed * (ChargeLevel + 1f) / 2f;
}
Animation = Recoil;
//dust ring
const int dusts = 24;
for (int i = 0; i < dusts; i++)
{
Vector2 dir = Vector2.UnitY.RotatedBy(MathHelper.TwoPi * i / dusts);
Vector2 pos = Projectile.Center + RockOffset() + dir * 20 * Projectile.scale;
int d = Dust.NewDust(pos, 0, 0, DustID.Stone, dir.X * 12 * Projectile.scale, dir.Y * 12 * Projectile.scale, newColor: Color.Black, Scale: Projectile.scale);
if (d.WithinBounds(Main.maxDust))
{
Main.dust[d].noGravity = true;
}
}
}
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
Rectangle rectangle = texture.Bounds;
Vector2 origin2 = rectangle.Size() / 2f;
SpriteEffects effects = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Vector2 pos = Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY);
if (Animation == Charging && ChargeLevel > 0.95f)
{
float shake = 2.5f * (ChargeLevel - 0.95f) / 0.05f;
pos += Main.rand.NextVector2Circular(shake, shake);
}
Main.EntitySpriteDraw(texture, pos, new Microsoft.Xna.Framework.Rectangle?(rectangle), Projectile.GetAlpha(lightColor), Projectile.rotation, origin2, Projectile.scale, effects, 0);
return false;
}
public static float RotationDifference(Vector2 from, Vector2 to) => (float)Math.Atan2(to.Y * from.X - to.X * from.Y, from.X * to.X + from.Y * to.Y);
}
}