From eefe854500f15c3c93c36be388b35f413d016b60 Mon Sep 17 00:00:00 2001 From: Memes <114233643+Mr-Memes@users.noreply.github.com> Date: Sat, 23 Nov 2024 17:39:49 +0100 Subject: [PATCH] MP-fixed Anahita's Arpeggio. --- Items/Weapons/Magic/AnahitasArpeggio.cs | 13 +++++-------- Projectiles/Magic/AnahitasArpeggioNote.cs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Items/Weapons/Magic/AnahitasArpeggio.cs b/Items/Weapons/Magic/AnahitasArpeggio.cs index 23a16ea650..bcdc0a7855 100644 --- a/Items/Weapons/Magic/AnahitasArpeggio.cs +++ b/Items/Weapons/Magic/AnahitasArpeggio.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; +using System.Linq; using CalamityMod.Projectiles.Magic; using Microsoft.Xna.Framework; -using System.Linq; using Terraria; using Terraria.Audio; using Terraria.DataStructures; @@ -15,7 +15,6 @@ namespace CalamityMod.Items.Weapons.Magic { public new string LocalizationCategory => "Items.Weapons.Magic"; public float RotationOffset; - public static int MusicNoteAmt = 0; public static readonly SoundStyle CapSound = new("CalamityMod/Sounds/Item/HarpLV6"); public static readonly SoundStyle EndSound = new("CalamityMod/Sounds/Item/HarpEnd"); @@ -48,7 +47,7 @@ namespace CalamityMod.Items.Weapons.Magic { // Max music note check is in Shoot instead of CanUseItem so that the weapon can still be visually played while at the cap int musicNoteCap = Main.zenithWorld ? 7 : 6; - if (MusicNoteAmt >= musicNoteCap) + if (player.ownedProjectileCounts[type] >= musicNoteCap) { Main.musicPitch = -0.5f; SoundEngine.PlaySound(CapSound with { Volume = 0.8f }, player.Center); @@ -56,12 +55,10 @@ namespace CalamityMod.Items.Weapons.Magic } else { - if (MusicNoteAmt <= 0) + if (player.ownedProjectileCounts[type] <= 0) RotationOffset = Main.rand.NextFloat(0f, MathHelper.TwoPi); - int note = Projectile.NewProjectile(source, position, Vector2.Zero, type, damage, knockback, player.whoAmI, 0f, 0f, RotationOffset); - Main.projectile[note].localAI[1] = MusicNoteAmt; - MusicNoteAmt++; + Projectile.NewProjectileDirect(source, position, Vector2.Zero, type, damage, knockback, player.whoAmI, 0f, 0f, RotationOffset); return false; } } @@ -77,7 +74,7 @@ namespace CalamityMod.Items.Weapons.Magic // Consume much less mana while the maximum number of notes are present public override void ModifyManaCost(Player player, ref float reduce, ref float mult) { - if (MusicNoteAmt >= 6) + if (player.ownedProjectileCounts[Item.shoot] >= 6) mult *= 0.25f; } diff --git a/Projectiles/Magic/AnahitasArpeggioNote.cs b/Projectiles/Magic/AnahitasArpeggioNote.cs index 3a6d4d73e3..9594cebe87 100644 --- a/Projectiles/Magic/AnahitasArpeggioNote.cs +++ b/Projectiles/Magic/AnahitasArpeggioNote.cs @@ -2,6 +2,7 @@ using CalamityMod.Systems; using Microsoft.Xna.Framework; using System; +using System.IO; using Terraria; using Terraria.Audio; using Terraria.ID; @@ -19,6 +20,7 @@ namespace CalamityMod.Projectiles.Magic public int LingeringTime = 300; public int FadeOutTime = 20; public bool HasSetFadeOutVelocity = false; + private bool _hasSpawned; public Player Owner => Main.player[Projectile.owner]; @@ -43,6 +45,12 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { + if (!_hasSpawned) + { + NoteSequence = Owner.ownedProjectileCounts[Type] - 1; + _hasSpawned = true; + } + Timer++; // Slight size oscillation @@ -67,6 +75,7 @@ namespace CalamityMod.Projectiles.Magic else Lighting.AddLight(Projectile.Center, 0f, 0f, 1.25f); + Main.NewText(NoteSequence); if (AIState == 0f) // Orbiting the player { @@ -81,7 +90,6 @@ namespace CalamityMod.Projectiles.Magic // If the player stops using the weapon, switch to fade away mode if (Owner.releaseUseItem) { - AnahitasArpeggio.MusicNoteAmt = 0; Owner.Calamity().arpeggioCooldown = 40; AIState = 1f; } @@ -197,5 +205,9 @@ namespace CalamityMod.Projectiles.Magic if (!SoundEngine.TryGetActiveSound(SingularSoundInstanceSystem.SoundSlot, out var activeSound)) SingularSoundInstanceSystem.PlaySingleInstance(AnahitasArpeggio.HitSound, 60, 60, Owner); } + + public override void SendExtraAI(BinaryWriter writer) => writer.Write(Projectile.localAI[1]); + + public override void ReceiveExtraAI(BinaryReader reader) => Projectile.localAI[1] = reader.ReadSingle(); } }