public override void HoldItem(Player player) { // Reset style to swing when neutral if (player.itemAnimation == 0) { item.useStyle = 1; } if (player.itemTime > 0) { if (player.itemTime == 1) { PlayerFX.ItemFlashFX(player, 175); } if (player.velocity.Y == 0) { for (int i = 0; i < 3; i++) // 3 extra recharge speed { if (player.itemTime > 0) { player.itemTime--; } if (player.itemTime == 1) { PlayerFX.ItemFlashFX(player, 175); } } } } }
/// <summary> /// Charge item time faster when not moving, or grounded (or both!) /// Also handles the item.useStyle to allow for custom animation /// </summary> /// <param name="slashDelay">Delay before slash appears, as a ratio (default 0.9f) of the total attack time (1f - no delay to 0f - start at the end)</param> /// <param name="ai1">Set ai1, usually the direction of the slash, or power attack. </param> /// <param name="customCharge">Custom function call replacing normal charge effect, using player.itemTime; </param> /// <returns>True on the frame of a charged attack</returns> public static bool HoldItemManager(Player player, Item item, int slashProjectileID, Color chargeColour = default(Color), float slashDelay = 0.9f, float ai1 = 1f, Action <Player, bool> customCharge = null, int delaySpeed = 4) { bool charged = false; // Attacking if (player.itemAnimation > 0) { // JUST attacked bool onAttackFrame = player.itemAnimation == player.itemAnimationMax - 1; if (WeaponOut.modOverhaul != null) { onAttackFrame = player.itemAnimation == player.itemAnimationMax - 2; } if (onAttackFrame) { if (ai1 == 1f || ai1 == -1f) { // Use isBeingGrabbed for alternating swings ai1 = item.isBeingGrabbed ? 1f : -1f; item.isBeingGrabbed = !item.isBeingGrabbed; } else if (ai1 == 0) { // Used to identify a charged attack item.beingGrabbed = true; charged = true; } if (Main.myPlayer == player.whoAmI) { // First frame of attack Vector2 mouse = new Vector2(Main.screenPosition.X + Main.mouseX, Main.screenPosition.Y + Main.mouseY); SetAttackRotation(player); Vector2 velocity = (mouse - player.MountedCenter).SafeNormalize(new Vector2(player.direction, 0)); int p = Projectile.NewProjectile( player.MountedCenter, velocity, slashProjectileID, (int)(item.damage * player.meleeDamage), item.scale, player.whoAmI, (int)(player.itemAnimationMax * slashDelay - player.itemAnimationMax), ai1); } // Set item time anyway, if not shoot, also make next slash upwards if (item.shoot <= 0 && player.itemTime == 0) { player.itemTime = item.useTime; item.isBeingGrabbed = false; } } item.useStyle = 0; } else { item.useStyle = 1; item.beingGrabbed = false; } // when counting down if (player.itemTime > 0) { // internalChargeTicker hangs the item time until past the delaySpeed // in which case it allows the itemTime to be reduced on that frame. // If not moving much, boost item charge speed //int delaySpeed = 4; // default, item charged 1 1 / 3 speed // If grounded, half the dleay speed if (player.velocity.Y == 0) { delaySpeed /= 2; } // cap delaySpeed = Math.Max(delaySpeed, 1); // Reset if swinging if (player.itemAnimation > 0) { player.itemTime = Math.Max(player.itemTime, item.useTime); } else if (Main.myPlayer == player.whoAmI) { if (customCharge != null) { customCharge(player, false); } else { for (int i = 0; i < 3; i++) { // Charging dust Vector2 vector = new Vector2( Main.rand.Next(-2048, 2048) * (0.003f * player.itemTime) - 4, Main.rand.Next(-2048, 2048) * (0.003f * player.itemTime) - 4); Dust d = Main.dust[Dust.NewDust( player.MountedCenter + vector, 1, 1, 45, 0, 0, 255, chargeColour, 1.5f)]; d.velocity = -vector / 16; d.velocity -= player.velocity / 8; d.noLight = true; d.noGravity = true; } } } // allow item time when past "limit" if (internalChargeTicker >= delaySpeed) { internalChargeTicker = 0; } // delay item time unless at 0 if (internalChargeTicker > 0) { player.itemTime++; } internalChargeTicker++; // flash and correct if (player.itemTime <= 1) { player.itemTime = 1; if (customCharge != null) { customCharge(player, true); } else { PlayerFX.ItemFlashFX(player, 45, new PlayerFX.SoundData(25) { volumeScale = 0.5f }); } } } // HACK: allows the player to swing the sword when held on the mouse if (Main.mouseItem.type == item.type) { if (player.controlUseItem && player.itemAnimation == 0 && player.itemTime == 0 && player.releaseUseItem) { player.itemAnimation = 1; } } return(charged); }