From db9ccff61bb568630a0632346bed0ce444caeadc Mon Sep 17 00:00:00 2001 From: termigator1359 <45545085+termigator1359@users.noreply.github.com> Date: Tue, 12 May 2020 11:41:05 -0400 Subject: [PATCH] added an ActiveItem utility --- CalPlayer/CalamityPlayer.cs | 26 ++++----- CalPlayer/CalamityPlayerFishing.cs | 2 +- CalPlayer/CalamityPlayerMiscEffects.cs | 28 +++++----- Items/Accessories/StatMeter.cs | 2 +- Items/Accessories/TheCamper.cs | 12 ++--- Items/Ammo/AstralSolution.cs | 2 +- Items/CalamityGlobalItem.cs | 4 +- Projectiles/CalamityGlobalProjectile.cs | 2 +- .../DraedonsArsenal/GatlingLaserProj.cs | 6 +-- Projectiles/Healing/FungalHeal.cs | 16 +++--- Projectiles/Magic/DarkSparkPrism.cs | 6 +-- Projectiles/Magic/GhastlyVisageProj.cs | 8 +-- Projectiles/Magic/MelterAmp.cs | 2 +- Projectiles/Magic/PurgeProj.cs | 6 +-- Projectiles/Magic/SparklingBeam.cs | 2 +- Projectiles/Magic/T1000Proj.cs | 6 +-- Projectiles/Magic/ValkyrieRayStaff.cs | 2 +- Projectiles/Magic/YharimsCrystalPrism.cs | 6 +-- Projectiles/Melee/DevilsSunriseProj.cs | 4 +- Projectiles/Melee/MurasamaProj.cs | 4 +- Projectiles/Pets/Sparks.cs | 2 +- Projectiles/Ranged/ButcherGun.cs | 12 ++--- Projectiles/Ranged/ContagionBow.cs | 4 +- Projectiles/Ranged/DaemonsFlameBow.cs | 12 ++--- Projectiles/Ranged/DrataliornusBow.cs | 10 ++-- Projectiles/Ranged/FlakKrakenGun.cs | 4 +- .../Ranged/FlurrystormCannonShooting.cs | 12 ++--- Projectiles/Ranged/NorfleetCannon.cs | 10 ++-- Projectiles/Ranged/PhangasmBow.cs | 12 ++--- Projectiles/Ranged/StarfleetMK2Gun.cs | 10 ++-- Projectiles/Rogue/SylvanSlashAttack.cs | 54 +++++++++---------- Projectiles/Typeless/EnergyShell.cs | 2 +- .../Typeless/RelicOfDeliveranceSpear.cs | 4 +- Utilities/CalamityUtils.cs | 7 +-- 34 files changed, 151 insertions(+), 150 deletions(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 795f954a4a..6047958071 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -2726,7 +2726,7 @@ namespace CalamityMod.CalPlayer } if (CalamityMod.RageHotKey.JustPressed) { - if (gaelRageCooldown == 0 && player.HeldItem.type == ModContent.ItemType() && + if (gaelRageCooldown == 0 && player.ActiveItem().type == ModContent.ItemType() && rage > 0) { Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SilvaDispel"), (int)player.position.X, (int)player.position.Y); @@ -3376,12 +3376,12 @@ namespace CalamityMod.CalPlayer { CalamityPlayerMiscEffects.CalamityPostUpdateMiscEffects(player, mod); - if (player.HeldItem.type == ModContent.ItemType()) + if (player.ActiveItem().type == ModContent.ItemType()) { gaelSwitchTimer = GaelSwitchPhase.LoseRage; rage += (int)MathHelper.Min(5, 10000 - rage); } - else if (player.HeldItem.type != ModContent.ItemType() && gaelSwitchTimer == GaelSwitchPhase.LoseRage) + else if (player.ActiveItem().type != ModContent.ItemType() && gaelSwitchTimer == GaelSwitchPhase.LoseRage) { rage = 0; gaelSwitchTimer = GaelSwitchPhase.None; @@ -3584,7 +3584,7 @@ namespace CalamityMod.CalPlayer #region Pre Kill public override bool PreKill(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource) { - if (invincible && player.inventory[player.selectedItem].type != ModContent.ItemType()) + if (invincible && player.ActiveItem().type != ModContent.ItemType()) { if (player.statLife <= 0) { @@ -4410,7 +4410,7 @@ namespace CalamityMod.CalPlayer { target.AddBuff(BuffID.Midas, 120, false); } - if (ZoneCalamity && CalamityMod.fireWeaponList.Contains(player.inventory[player.selectedItem].type)) + if (ZoneCalamity && CalamityMod.fireWeaponList.Contains(player.ActiveItem().type)) { target.AddBuff(ModContent.BuffType(), 240, false); } @@ -4728,7 +4728,7 @@ namespace CalamityMod.CalPlayer { target.AddBuff(BuffID.Midas, 120, false); } - if (ZoneCalamity && CalamityMod.fireWeaponList.Contains(player.inventory[player.selectedItem].type)) + if (ZoneCalamity && CalamityMod.fireWeaponList.Contains(player.ActiveItem().type)) { target.AddBuff(ModContent.BuffType(), 240, false); } @@ -4745,7 +4745,7 @@ namespace CalamityMod.CalPlayer target.AddBuff(BuffID.Venom, 120, false); } } - if (proj.type == ProjectileID.IchorArrow && player.inventory[player.selectedItem].type == ModContent.ItemType()) + if (proj.type == ProjectileID.IchorArrow && player.ActiveItem().type == ModContent.ItemType()) { target.AddBuff(BuffID.Midas, 300, false); } @@ -4985,7 +4985,7 @@ namespace CalamityMod.CalPlayer bool isSummon = proj.minion || proj.sentry || CalamityMod.projectileMinionList.Contains(proj.type); bool hasClassType = proj.melee || proj.ranged || proj.magic || isSummon || proj.Calamity().rogue; - Item heldItem = player.inventory[player.selectedItem]; + Item heldItem = player.ActiveItem(); if (isTrueMelee && soaring) { @@ -5629,7 +5629,7 @@ namespace CalamityMod.CalPlayer { if (CalamityMod.projectileDestroyExceptionList.TrueForAll(x => proj.type != x)) { - if (player.HeldItem.type == ModContent.ItemType() + if (player.ActiveItem().type == ModContent.ItemType() && proj.active && proj.hostile && player.altFunctionUse == 2 && Main.rand.NextBool(2)) { for (int j = 0; j < 3; j++) @@ -6141,7 +6141,7 @@ namespace CalamityMod.CalPlayer } } - if (lol || (invincible && player.inventory[player.selectedItem].type != ModContent.ItemType())) + if (lol || (invincible && player.ActiveItem().type != ModContent.ItemType())) { return false; } @@ -6233,7 +6233,7 @@ namespace CalamityMod.CalPlayer { damage = (int)(damage * 0.7); } - if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0 && player.HeldItem.type == ModContent.ItemType()) + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0 && player.ActiveItem().type == ModContent.ItemType()) { damage = (int)(damage * 0.5); } @@ -9296,7 +9296,7 @@ namespace CalamityMod.CalPlayer // This doesn't trigger stealth strike effects (ConsumeStealthStrike instead of StealthStrike) // so non-rogue weapons can't call lasers down from the sky and such. // Using any item which deals no damage or is a tool doesn't consume stealth. - Item it = player.HeldItem; + Item it = player.ActiveItem(); bool hasDamage = it.damage > 0; bool hasHitboxes = !it.noMelee || it.shoot > 0; bool isPickaxe = it.pick > 0; @@ -9354,7 +9354,7 @@ namespace CalamityMod.CalPlayer stealthGenMoving += 0.15f; } - if (CalamityMod.daggerList.Contains(player.inventory[player.selectedItem].type) && player.invis) + if (CalamityMod.daggerList.Contains(player.ActiveItem().type) && player.invis) { stealthGenStandstill += 0.08f; stealthGenMoving += 0.08f; diff --git a/CalPlayer/CalamityPlayerFishing.cs b/CalPlayer/CalamityPlayerFishing.cs index fdd3b70157..9f2d5cf8ac 100644 --- a/CalPlayer/CalamityPlayerFishing.cs +++ b/CalPlayer/CalamityPlayerFishing.cs @@ -591,7 +591,7 @@ namespace CalamityMod.CalPlayer if (modPlayer.ZoneAbyss || modPlayer.ZoneSulphur) canSulphurFish = true; - Item item = player.inventory[player.selectedItem]; + Item item = player.ActiveItem(); if (!canSulphurFish || item.fishingPole <= 0 || item.holdStyle != 1) fishingLevel = -1; } diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 12508aa88a..cce27f6054 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -1278,7 +1278,7 @@ namespace CalamityMod.CalPlayer player.endurance += 0.01f; player.statDefense += 2; } - if (!modPlayer.polarisBoost || player.inventory[player.selectedItem].type != ModContent.ItemType()) + if (!modPlayer.polarisBoost || player.ActiveItem().type != ModContent.ItemType()) { modPlayer.polarisBoost = false; if (player.FindBuffIndex(ModContent.BuffType()) > -1) @@ -2534,27 +2534,27 @@ namespace CalamityMod.CalPlayer } } - if (CalamityMod.scopedWeaponList.Contains(player.inventory[player.selectedItem].type)) + if (CalamityMod.scopedWeaponList.Contains(player.ActiveItem().type)) player.scope = true; - if (CalamityMod.highTestFishList.Contains(player.inventory[player.selectedItem].type)) + if (CalamityMod.highTestFishList.Contains(player.ActiveItem().type)) player.accFishingLine = true; - if (CalamityMod.boomerangList.Contains(player.inventory[player.selectedItem].type) && player.invis) + if (CalamityMod.boomerangList.Contains(player.ActiveItem().type) && player.invis) modPlayer.throwingDamage += 0.1f; - if (CalamityMod.javelinList.Contains(player.inventory[player.selectedItem].type) && player.invis) + if (CalamityMod.javelinList.Contains(player.ActiveItem().type) && player.invis) player.armorPenetration += 5; - if (CalamityMod.flaskBombList.Contains(player.inventory[player.selectedItem].type) && player.invis) + if (CalamityMod.flaskBombList.Contains(player.ActiveItem().type) && player.invis) modPlayer.throwingVelocity += 0.1f; - if (CalamityMod.spikyBallList.Contains(player.inventory[player.selectedItem].type) && player.invis) + if (CalamityMod.spikyBallList.Contains(player.ActiveItem().type) && player.invis) modPlayer.throwingCrit += 10; if (modPlayer.planarSpeedBoost != 0) { - if (player.inventory[player.selectedItem].type != ModContent.ItemType()) + if (player.ActiveItem().type != ModContent.ItemType()) modPlayer.planarSpeedBoost = 0; } @@ -2564,10 +2564,10 @@ namespace CalamityMod.CalPlayer !modPlayer.ZoneSunkenSea && !player.ZoneSnow && !player.ZoneCorrupt && !player.ZoneCrimson && !player.ZoneHoly && !player.ZoneDesert && !player.ZoneUndergroundDesert && !player.ZoneGlowshroom && !player.ZoneDungeon && !player.ZoneBeach && !player.ZoneMeteor; - if (player.ZoneUnderworldHeight && !modPlayer.ZoneCalamity && CalamityMod.fireWeaponList.Contains(player.inventory[player.selectedItem].type)) + if (player.ZoneUnderworldHeight && !modPlayer.ZoneCalamity && CalamityMod.fireWeaponList.Contains(player.ActiveItem().type)) player.endurance += 0.03f; - if ((player.ZoneDesert || player.ZoneUndergroundDesert) && CalamityMod.daggerList.Contains(player.inventory[player.selectedItem].type)) + if ((player.ZoneDesert || player.ZoneUndergroundDesert) && CalamityMod.daggerList.Contains(player.ActiveItem().type)) player.scope = true; if (modPlayer.ZoneSunkenSea) @@ -2576,7 +2576,7 @@ namespace CalamityMod.CalPlayer player.ignoreWater = true; } - if (player.ZoneSnow && CalamityMod.iceWeaponList.Contains(player.inventory[player.selectedItem].type)) + if (player.ZoneSnow && CalamityMod.iceWeaponList.Contains(player.ActiveItem().type)) player.statDefense += 5; if (modPlayer.ZoneAstral) @@ -2585,7 +2585,7 @@ namespace CalamityMod.CalPlayer player.wingTimeMax = (int)((double)player.wingTimeMax * 1.05); } - if (player.ZoneJungle && CalamityMod.natureWeaponList.Contains(player.inventory[player.selectedItem].type)) + if (player.ZoneJungle && CalamityMod.natureWeaponList.Contains(player.ActiveItem().type)) player.AddBuff(BuffID.DryadsWard, 5, true); // Dryad's Blessing if (modPlayer.ZoneAbyss) @@ -2605,7 +2605,7 @@ namespace CalamityMod.CalPlayer player.endurance += 0.05f; } - if (player.ZoneRockLayerHeight && ZoneForest && CalamityMod.flaskBombList.Contains(player.inventory[player.selectedItem].type)) + if (player.ZoneRockLayerHeight && ZoneForest && CalamityMod.flaskBombList.Contains(player.ActiveItem().type)) player.blackBelt = true; if (player.ZoneHoly) @@ -3160,7 +3160,7 @@ namespace CalamityMod.CalPlayer } // Navy Fishing Rod's electric aura when in-use - if (player.inventory[player.selectedItem].type == ModContent.ItemType() && player.ownedProjectileCounts[ModContent.ProjectileType()] != 0) + if (player.ActiveItem().type == ModContent.ItemType() && player.ownedProjectileCounts[ModContent.ProjectileType()] != 0) { const int FramesPerHit = 120; diff --git a/Items/Accessories/StatMeter.cs b/Items/Accessories/StatMeter.cs index 36eb6d66b9..4256880aa8 100644 --- a/Items/Accessories/StatMeter.cs +++ b/Items/Accessories/StatMeter.cs @@ -33,7 +33,7 @@ namespace CalamityMod.Items.Accessories Item heldItem = null; if (player.selectedItem >= 0 && player.selectedItem < Main.maxInventory) - heldItem = player.inventory[player.selectedItem]; + heldItem = player.ActiveItem(); // Replace the vanilla tooltip with a full stat readout foreach (TooltipLine l in list) diff --git a/Items/Accessories/TheCamper.cs b/Items/Accessories/TheCamper.cs index b7e2755d4d..0b4fac1ec4 100644 --- a/Items/Accessories/TheCamper.cs +++ b/Items/Accessories/TheCamper.cs @@ -68,13 +68,13 @@ namespace CalamityMod.Items.Accessories } } } - if (player.HeldItem != null && !player.HeldItem.IsAir && player.HeldItem.stack > 0) + if (player.ActiveItem() != null && !player.ActiveItem().IsAir && player.ActiveItem().stack > 0) { - bool summon = player.HeldItem.summon; - bool rogue = player.HeldItem.Calamity().rogue; - bool melee = player.HeldItem.melee; - bool ranged = player.HeldItem.ranged; - bool magic = player.HeldItem.magic; + bool summon = player.ActiveItem().summon; + bool rogue = player.ActiveItem().Calamity().rogue; + bool melee = player.ActiveItem().melee; + bool ranged = player.ActiveItem().ranged; + bool magic = player.ActiveItem().magic; if (summon) { player.minionKB += 0.10f; diff --git a/Items/Ammo/AstralSolution.cs b/Items/Ammo/AstralSolution.cs index fd66b17ec2..eb11992048 100644 --- a/Items/Ammo/AstralSolution.cs +++ b/Items/Ammo/AstralSolution.cs @@ -29,7 +29,7 @@ namespace CalamityMod.Items.Ammo public override bool ConsumeAmmo(Player player) { - return !(player.itemAnimation < player.HeldItem.useAnimation - 3); + return !(player.itemAnimation < player.ActiveItem().useAnimation - 3); } } } diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index ed2121e06f..c4e4f2810d 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -650,7 +650,7 @@ namespace CalamityMod.Items } return false; } - if (player.HeldItem.type == ModContent.ItemType()) + if (player.ActiveItem().type == ModContent.ItemType()) { bool hasBlades = false; for (int i = 0; i < Main.projectile.Length; i++) @@ -684,7 +684,7 @@ namespace CalamityMod.Items } return false; } - if (player.HeldItem.type == ModContent.ItemType()) + if (player.ActiveItem().type == ModContent.ItemType()) { bool canContinue = true; int count = 0; diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index e1bb089af7..733c1d5776 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -604,7 +604,7 @@ namespace CalamityMod.Projectiles { if (projectile.timeLeft > 570) //all of these have a time left of 600 or 660 { - if (player.inventory[player.selectedItem].type == ItemID.BeesKnees) + if (player.ActiveItem().type == ItemID.BeesKnees) { projectile.magic = false; projectile.ranged = true; diff --git a/Projectiles/DraedonsArsenal/GatlingLaserProj.cs b/Projectiles/DraedonsArsenal/GatlingLaserProj.cs index 0a1692cb45..dc73b8464b 100644 --- a/Projectiles/DraedonsArsenal/GatlingLaserProj.cs +++ b/Projectiles/DraedonsArsenal/GatlingLaserProj.cs @@ -61,14 +61,14 @@ namespace CalamityMod.Projectiles.DraedonsArsenal } if (flag && Main.myPlayer == projectile.owner && fireLasers) { - int weaponDamage2 = player.GetWeaponDamage(player.inventory[player.selectedItem]); + int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); bool flag2 = player.channel && !player.noItems && !player.CCed; if (flag2) { // Consume 2 ammo per shot - CalamityGlobalItem.ConsumeAdditionalAmmo(player, player.inventory[player.selectedItem], 2); + CalamityGlobalItem.ConsumeAdditionalAmmo(player, player.ActiveItem(), 2); - float scaleFactor = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + float scaleFactor = player.ActiveItem().shootSpeed * projectile.scale; Vector2 value2 = vector; Vector2 value3 = Main.screenPosition + new Vector2(Main.mouseX, Main.mouseY) - value2; if (player.gravDir == -1f) diff --git a/Projectiles/Healing/FungalHeal.cs b/Projectiles/Healing/FungalHeal.cs index 885829ac9e..8b064add99 100644 --- a/Projectiles/Healing/FungalHeal.cs +++ b/Projectiles/Healing/FungalHeal.cs @@ -26,14 +26,14 @@ namespace CalamityMod.Projectiles.Healing if (projectile.localAI[0] == 0f) { Player player = Main.player[projectile.owner]; - if ((player.inventory[player.selectedItem].summon && - !player.inventory[player.selectedItem].melee && - !player.inventory[player.selectedItem].ranged && - !player.inventory[player.selectedItem].magic && - !player.inventory[player.selectedItem].Calamity().rogue) || - player.inventory[player.selectedItem].hammer > 0 || - player.inventory[player.selectedItem].pick > 0 || - player.inventory[player.selectedItem].axe > 0) + if ((player.ActiveItem().summon && + !player.ActiveItem().melee && + !player.ActiveItem().ranged && + !player.ActiveItem().magic && + !player.ActiveItem().Calamity().rogue) || + player.ActiveItem().hammer > 0 || + player.ActiveItem().pick > 0 || + player.ActiveItem().axe > 0) { projectile.timeLeft = 600; } diff --git a/Projectiles/Magic/DarkSparkPrism.cs b/Projectiles/Magic/DarkSparkPrism.cs index bdcff0a9db..d3638d596b 100644 --- a/Projectiles/Magic/DarkSparkPrism.cs +++ b/Projectiles/Magic/DarkSparkPrism.cs @@ -58,7 +58,7 @@ namespace CalamityMod.Projectiles.Magic { num26 = 5f; } - projectile.damage = (int)((float)player.inventory[player.selectedItem].damage * player.magicDamage); + projectile.damage = (int)(player.ActiveItem().damage * player.MagicDamage()); projectile.ai[0] += 1f; projectile.ai[1] += 1f; if (projectile.localAI[0] == 0f) @@ -87,7 +87,7 @@ namespace CalamityMod.Projectiles.Magic flag10 = true; if (Main.myPlayer == projectile.owner) { - float scaleFactor5 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + float scaleFactor5 = player.ActiveItem().shootSpeed * projectile.scale; Vector2 value12 = vector; Vector2 value13 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - value12; if (player.gravDir == -1f) @@ -129,7 +129,7 @@ namespace CalamityMod.Projectiles.Magic } if (flag10 && Main.myPlayer == projectile.owner) { - bool flag11 = !flag9 || player.CheckMana(player.inventory[player.selectedItem].mana, true, false); + bool flag11 = !flag9 || player.CheckMana(player.ActiveItem().mana, true, false); bool flag12 = player.channel && flag11 && !player.noItems && !player.CCed; if (flag12) { diff --git a/Projectiles/Magic/GhastlyVisageProj.cs b/Projectiles/Magic/GhastlyVisageProj.cs index d867918511..1ee6267dcb 100644 --- a/Projectiles/Magic/GhastlyVisageProj.cs +++ b/Projectiles/Magic/GhastlyVisageProj.cs @@ -146,12 +146,12 @@ namespace CalamityMod.Projectiles.Magic { int num42 = ModContent.ProjectileType(); float scaleFactor11 = 6f; - int weaponDamage2 = player.GetWeaponDamage(player.inventory[player.selectedItem]); - float weaponKnockback2 = player.inventory[player.selectedItem].knockBack; + int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); + float weaponKnockback2 = player.ActiveItem().knockBack; if (flag16) { - weaponKnockback2 = player.GetWeaponKnockback(player.inventory[player.selectedItem], weaponKnockback2); - float scaleFactor12 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + weaponKnockback2 = player.GetWeaponKnockback(player.ActiveItem(), weaponKnockback2); + float scaleFactor12 = player.ActiveItem().shootSpeed * projectile.scale; Vector2 vector19 = vector; Vector2 value18 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - vector19; if (player.gravDir == -1f) diff --git a/Projectiles/Magic/MelterAmp.cs b/Projectiles/Magic/MelterAmp.cs index 67fbeac7fa..ece39897a6 100644 --- a/Projectiles/Magic/MelterAmp.cs +++ b/Projectiles/Magic/MelterAmp.cs @@ -43,7 +43,7 @@ namespace CalamityMod.Projectiles.Magic projectile.active = false; return; } - if (!player.inventory[player.selectedItem].magic || player.inventory[player.selectedItem].shoot != ModContent.ProjectileType()) + if (!player.ActiveItem().magic || player.ActiveItem().shoot != ModContent.ProjectileType()) { projectile.active = false; return; diff --git a/Projectiles/Magic/PurgeProj.cs b/Projectiles/Magic/PurgeProj.cs index 6f18cc87a5..b14f401183 100644 --- a/Projectiles/Magic/PurgeProj.cs +++ b/Projectiles/Magic/PurgeProj.cs @@ -75,11 +75,11 @@ namespace CalamityMod.Projectiles.Magic } if (flag && Main.myPlayer == projectile.owner) { - int weaponDamage2 = player.GetWeaponDamage(player.inventory[player.selectedItem]); - bool flag2 = player.channel && player.CheckMana(player.inventory[player.selectedItem].mana, true, false) && !player.noItems && !player.CCed; + int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); + bool flag2 = player.channel && player.CheckMana(player.ActiveItem().mana, true, false) && !player.noItems && !player.CCed; if (flag2) { - float scaleFactor = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + float scaleFactor = player.ActiveItem().shootSpeed * projectile.scale; Vector2 value2 = vector; Vector2 value3 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - value2; if (player.gravDir == -1f) diff --git a/Projectiles/Magic/SparklingBeam.cs b/Projectiles/Magic/SparklingBeam.cs index b536965a93..c36d09d386 100644 --- a/Projectiles/Magic/SparklingBeam.cs +++ b/Projectiles/Magic/SparklingBeam.cs @@ -238,7 +238,7 @@ namespace CalamityMod.Projectiles.Magic } else { // Do we still have enough mana? If not, we kill the projectile because we cannot use it anymore - if (Main.time % 10 < 1 && !player.CheckMana(player.inventory[player.selectedItem].mana, true)) + if (Main.time % 10 < 1 && !player.CheckMana(player.ActiveItem().mana, true)) { projectile.Kill(); } diff --git a/Projectiles/Magic/T1000Proj.cs b/Projectiles/Magic/T1000Proj.cs index 4147e4f8c8..99104817dc 100644 --- a/Projectiles/Magic/T1000Proj.cs +++ b/Projectiles/Magic/T1000Proj.cs @@ -75,11 +75,11 @@ namespace CalamityMod.Projectiles.Magic } if (flag && Main.myPlayer == projectile.owner) { - int weaponDamage2 = player.GetWeaponDamage(player.inventory[player.selectedItem]); - bool flag2 = player.channel && player.CheckMana(player.inventory[player.selectedItem].mana, true, false) && !player.noItems && !player.CCed; + int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); + bool flag2 = player.channel && player.CheckMana(player.ActiveItem().mana, true, false) && !player.noItems && !player.CCed; if (flag2) { - float scaleFactor = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + float scaleFactor = player.ActiveItem().shootSpeed * projectile.scale; Vector2 value2 = vector; Vector2 value3 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - value2; if (player.gravDir == -1f) diff --git a/Projectiles/Magic/ValkyrieRayStaff.cs b/Projectiles/Magic/ValkyrieRayStaff.cs index 5e52313fe0..6f4fd13085 100644 --- a/Projectiles/Magic/ValkyrieRayStaff.cs +++ b/Projectiles/Magic/ValkyrieRayStaff.cs @@ -37,7 +37,7 @@ namespace CalamityMod.Projectiles.Magic // Calculate how quickly the staff should charge. Charge increases by some number close to 1 every frame. // Speed increasing reforges make this number greater than 1. Slowing reforges make it smaller than 1. if (projectile.localAI[0] == 0f) - projectile.localAI[0] = 47f / Main.player[projectile.owner].HeldItem.useTime; + projectile.localAI[0] = 47f / player.ActiveItem().useTime; // Increment the timer for the staff. If the timer has passed 47, destroy it. projectile.ai[0] += projectile.localAI[0]; diff --git a/Projectiles/Magic/YharimsCrystalPrism.cs b/Projectiles/Magic/YharimsCrystalPrism.cs index 8592f7e5cc..e578bb4856 100644 --- a/Projectiles/Magic/YharimsCrystalPrism.cs +++ b/Projectiles/Magic/YharimsCrystalPrism.cs @@ -42,7 +42,7 @@ namespace CalamityMod.Projectiles.Magic Vector2 rrp = player.RotatedRelativePoint(player.MountedCenter, true); // Update damage based on curent magic damage stat (so Mana Sickness affects it) - projectile.damage = (int)((player.HeldItem?.damage ?? 0) * player.MagicDamage()); + projectile.damage = (int)((player.ActiveItem()?.damage ?? 0) * player.MagicDamage()); // ai[0] is the overall frame counter. projectile.ai[0] += 1f; @@ -77,11 +77,11 @@ namespace CalamityMod.Projectiles.Magic if (projectile.owner == Main.myPlayer) { // Scale seemingly never changes, so this just scales with shoot speed (Yharim's Crystal is 30 by default) - float speedTimesScale = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + float speedTimesScale = player.ActiveItem().shootSpeed * projectile.scale; UpdateAim(rrp, speedTimesScale); // CheckMana returns true if the mana cost can be paid. If mana isn't consumed this frame, the CheckMana short-circuits out of being evaluated. - bool allowContinuedUse = !ShouldConsumeMana() || player.CheckMana(player.inventory[player.selectedItem].mana, true, false); + bool allowContinuedUse = !ShouldConsumeMana() || player.CheckMana(player.ActiveItem().mana, true, false); bool crystalStillInUse = player.channel && allowContinuedUse && !player.noItems && !player.CCed; // The beams are only projected once (on frame 1). diff --git a/Projectiles/Melee/DevilsSunriseProj.cs b/Projectiles/Melee/DevilsSunriseProj.cs index 402a915562..db87deba3c 100644 --- a/Projectiles/Melee/DevilsSunriseProj.cs +++ b/Projectiles/Melee/DevilsSunriseProj.cs @@ -67,8 +67,8 @@ namespace CalamityMod.Projectiles.Melee { float scaleFactor6 = 1f; - if (player.inventory[player.selectedItem].shoot == projectile.type) - scaleFactor6 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + if (player.ActiveItem().shoot == projectile.type) + scaleFactor6 = player.ActiveItem().shootSpeed * projectile.scale; Vector2 vector13 = Main.MouseWorld - vector; vector13.Normalize(); diff --git a/Projectiles/Melee/MurasamaProj.cs b/Projectiles/Melee/MurasamaProj.cs index 4cfecc40cb..625d47d292 100644 --- a/Projectiles/Melee/MurasamaProj.cs +++ b/Projectiles/Melee/MurasamaProj.cs @@ -53,9 +53,9 @@ namespace CalamityMod.Projectiles.Melee if (player.channel && !player.noItems && !player.CCed) { float scaleFactor6 = 1f; - if (player.inventory[player.selectedItem].shoot == projectile.type) + if (player.ActiveItem().shoot == projectile.type) { - scaleFactor6 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + scaleFactor6 = player.ActiveItem().shootSpeed * projectile.scale; } Vector2 vector13 = Main.MouseWorld - vector; vector13.Normalize(); diff --git a/Projectiles/Pets/Sparks.cs b/Projectiles/Pets/Sparks.cs index 9f0e658007..452b26e55e 100644 --- a/Projectiles/Pets/Sparks.cs +++ b/Projectiles/Pets/Sparks.cs @@ -45,7 +45,7 @@ namespace CalamityMod.Projectiles.Pets if (new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height).Intersects(new Rectangle((int)item.position.X, (int)item.position.Y, item.width, item.height))) { - if (projectile.owner == Main.myPlayer && (player.inventory[player.selectedItem].type != 0 || player.itemAnimation <= 0)) + if (projectile.owner == Main.myPlayer && (player.ActiveItem().type != 0 || player.itemAnimation <= 0)) { // TODO, fix this maybe? if (!ItemLoader.OnPickup(item, player)) diff --git a/Projectiles/Ranged/ButcherGun.cs b/Projectiles/Ranged/ButcherGun.cs index 81eb1119c6..f5e40a58fb 100644 --- a/Projectiles/Ranged/ButcherGun.cs +++ b/Projectiles/Ranged/ButcherGun.cs @@ -85,7 +85,7 @@ namespace CalamityMod.Projectiles.Ranged projectile.ai[1] = (float)(num40 - num41 * num39); flag15 = true; } - bool flag16 = player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed; + bool flag16 = player.channel && player.HasAmmo(player.ActiveItem(), true) && !player.noItems && !player.CCed; if (projectile.localAI[0] > 0f) { projectile.localAI[0] -= 1f; @@ -103,13 +103,13 @@ namespace CalamityMod.Projectiles.Ranged { int num42 = 14; float scaleFactor11 = 14f; - int weaponDamage2 = player.GetWeaponDamage(player.inventory[player.selectedItem]); - float weaponKnockback2 = player.inventory[player.selectedItem].knockBack; + int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); + float weaponKnockback2 = player.ActiveItem().knockBack; if (flag16) { - player.PickAmmo(player.inventory[player.selectedItem], ref num42, ref scaleFactor11, ref flag16, ref weaponDamage2, ref weaponKnockback2, false); - weaponKnockback2 = player.GetWeaponKnockback(player.inventory[player.selectedItem], weaponKnockback2); - float scaleFactor12 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + player.PickAmmo(player.ActiveItem(), ref num42, ref scaleFactor11, ref flag16, ref weaponDamage2, ref weaponKnockback2, false); + weaponKnockback2 = player.GetWeaponKnockback(player.ActiveItem(), weaponKnockback2); + float scaleFactor12 = player.ActiveItem().shootSpeed * projectile.scale; Vector2 vector19 = vector; Vector2 value18 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - vector19; if (player.gravDir == -1f) diff --git a/Projectiles/Ranged/ContagionBow.cs b/Projectiles/Ranged/ContagionBow.cs index 1e49a6b92f..96483efc4a 100644 --- a/Projectiles/Ranged/ContagionBow.cs +++ b/Projectiles/Ranged/ContagionBow.cs @@ -85,10 +85,10 @@ namespace CalamityMod.Projectiles.Ranged } if (flag && Main.myPlayer == projectile.owner) { - bool flag2 = player.channel && player.CheckMana(player.inventory[player.selectedItem].mana, true, false) && !player.noItems && !player.CCed; + bool flag2 = player.channel && player.CheckMana(player.ActiveItem().mana, true, false) && !player.noItems && !player.CCed; if (flag2) { - float scaleFactor = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + float scaleFactor = player.ActiveItem().shootSpeed * projectile.scale; Vector2 value2 = vector; Vector2 value3 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - value2; if (player.gravDir == -1f) diff --git a/Projectiles/Ranged/DaemonsFlameBow.cs b/Projectiles/Ranged/DaemonsFlameBow.cs index e86672be02..a4d3999efa 100644 --- a/Projectiles/Ranged/DaemonsFlameBow.cs +++ b/Projectiles/Ranged/DaemonsFlameBow.cs @@ -74,7 +74,7 @@ namespace CalamityMod.Projectiles.Ranged flag15 = true; int arg_1EF4_0 = (int)projectile.ai[0] / (num40 - num41 * num39); } - bool flag16 = player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed; + bool flag16 = player.channel && player.HasAmmo(player.ActiveItem(), true) && !player.noItems && !player.CCed; if (projectile.localAI[0] > 0f) { projectile.localAI[0] -= 1f; @@ -92,13 +92,13 @@ namespace CalamityMod.Projectiles.Ranged { int num42 = 14; float scaleFactor11 = 14f; - int weaponDamage2 = player.GetWeaponDamage(player.inventory[player.selectedItem]); - float weaponKnockback2 = player.inventory[player.selectedItem].knockBack; + int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); + float weaponKnockback2 = player.ActiveItem().knockBack; if (flag16) { - player.PickAmmo(player.inventory[player.selectedItem], ref num42, ref scaleFactor11, ref flag16, ref weaponDamage2, ref weaponKnockback2, false); - weaponKnockback2 = player.GetWeaponKnockback(player.inventory[player.selectedItem], weaponKnockback2); - float scaleFactor12 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + player.PickAmmo(player.ActiveItem(), ref num42, ref scaleFactor11, ref flag16, ref weaponDamage2, ref weaponKnockback2, false); + weaponKnockback2 = player.GetWeaponKnockback(player.ActiveItem(), weaponKnockback2); + float scaleFactor12 = player.ActiveItem().shootSpeed * projectile.scale; Vector2 vector19 = vector; Vector2 value18 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - vector19; if (player.gravDir == -1f) diff --git a/Projectiles/Ranged/DrataliornusBow.cs b/Projectiles/Ranged/DrataliornusBow.cs index d454833f74..8a317572fa 100644 --- a/Projectiles/Ranged/DrataliornusBow.cs +++ b/Projectiles/Ranged/DrataliornusBow.cs @@ -76,7 +76,7 @@ namespace CalamityMod.Projectiles.Ranged timeToFire = true; } - bool canFire = player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed; + bool canFire = player.channel && player.HasAmmo(player.ActiveItem(), true) && !player.noItems && !player.CCed; if (projectile.soundDelay <= 0 && canFire) { @@ -91,13 +91,13 @@ namespace CalamityMod.Projectiles.Ranged { int type = 14; float scaleFactor = 18f; - int damage = player.GetWeaponDamage(player.inventory[player.selectedItem]); - float knockBack = player.inventory[player.selectedItem].knockBack; + int damage = player.GetWeaponDamage(player.ActiveItem()); + float knockBack = player.ActiveItem().knockBack; - player.PickAmmo(player.inventory[player.selectedItem], ref type, ref scaleFactor, ref canFire, ref damage, ref knockBack, false); + player.PickAmmo(player.ActiveItem(), ref type, ref scaleFactor, ref canFire, ref damage, ref knockBack, false); type = ModContent.ProjectileType(); - knockBack = player.GetWeaponKnockback(player.inventory[player.selectedItem], knockBack); + knockBack = player.GetWeaponKnockback(player.ActiveItem(), knockBack); Vector2 playerPosition = player.RotatedRelativePoint(player.MountedCenter, true); projectile.velocity = Main.screenPosition - playerPosition; diff --git a/Projectiles/Ranged/FlakKrakenGun.cs b/Projectiles/Ranged/FlakKrakenGun.cs index 5571b2b96a..3b338314f4 100644 --- a/Projectiles/Ranged/FlakKrakenGun.cs +++ b/Projectiles/Ranged/FlakKrakenGun.cs @@ -42,7 +42,7 @@ namespace CalamityMod.Projectiles.Ranged { num26 = 5f; } - projectile.damage = (int)(player.inventory[player.selectedItem].damage * player.RangedDamage()); + projectile.damage = (int)(player.ActiveItem().damage * player.RangedDamage()); projectile.ai[0] += 1f; projectile.ai[1] += 1f; int num27 = 10; @@ -57,7 +57,7 @@ namespace CalamityMod.Projectiles.Ranged flag10 = true; if (Main.myPlayer == projectile.owner) { - float scaleFactor5 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + float scaleFactor5 = player.ActiveItem().shootSpeed * projectile.scale; Vector2 value12 = vector; Vector2 value13 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - value12; if (player.gravDir == -1f) diff --git a/Projectiles/Ranged/FlurrystormCannonShooting.cs b/Projectiles/Ranged/FlurrystormCannonShooting.cs index 2d92db8535..286986f8e6 100644 --- a/Projectiles/Ranged/FlurrystormCannonShooting.cs +++ b/Projectiles/Ranged/FlurrystormCannonShooting.cs @@ -89,7 +89,7 @@ namespace CalamityMod.Projectiles.Ranged projectile.ai[1] = (float)(num40 - num41 * num39); flag15 = true; } - bool flag16 = player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed; + bool flag16 = player.channel && player.HasAmmo(player.ActiveItem(), true) && !player.noItems && !player.CCed; if (projectile.localAI[0] > 0f) { projectile.localAI[0] -= 1f; @@ -107,13 +107,13 @@ namespace CalamityMod.Projectiles.Ranged { int num42 = 14; float scaleFactor11 = 14f; - int weaponDamage2 = player.GetWeaponDamage(player.inventory[player.selectedItem]); - float weaponKnockback2 = player.inventory[player.selectedItem].knockBack; + int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); + float weaponKnockback2 = player.ActiveItem().knockBack; if (flag16) { - player.PickAmmo(player.inventory[player.selectedItem], ref num42, ref scaleFactor11, ref flag16, ref weaponDamage2, ref weaponKnockback2, false); - weaponKnockback2 = player.GetWeaponKnockback(player.inventory[player.selectedItem], weaponKnockback2); - float scaleFactor12 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + player.PickAmmo(player.ActiveItem(), ref num42, ref scaleFactor11, ref flag16, ref weaponDamage2, ref weaponKnockback2, false); + weaponKnockback2 = player.GetWeaponKnockback(player.ActiveItem(), weaponKnockback2); + float scaleFactor12 = player.ActiveItem().shootSpeed * projectile.scale; Vector2 vector19 = vector; Vector2 value18 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - vector19; if (player.gravDir == -1f) diff --git a/Projectiles/Ranged/NorfleetCannon.cs b/Projectiles/Ranged/NorfleetCannon.cs index ec74639dfd..d28ceb5ce7 100644 --- a/Projectiles/Ranged/NorfleetCannon.cs +++ b/Projectiles/Ranged/NorfleetCannon.cs @@ -65,7 +65,7 @@ namespace CalamityMod.Projectiles.Ranged projectile.ai[1] = baseUseTime - modifier * projectile.localAI[0]; timeToFire = true; } - bool canFire = player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed; + bool canFire = player.channel && player.HasAmmo(player.ActiveItem(), true) && !player.noItems && !player.CCed; if (projectile.soundDelay <= 0 && canFire) { projectile.soundDelay = baseUseTime - modifier * (int)projectile.localAI[0]; @@ -79,12 +79,12 @@ namespace CalamityMod.Projectiles.Ranged { int type = 12; float scaleFactor = 30f; - int damage = player.GetWeaponDamage(player.inventory[player.selectedItem]); - float knockBack = player.inventory[player.selectedItem].knockBack; + int damage = player.GetWeaponDamage(player.ActiveItem()); + float knockBack = player.ActiveItem().knockBack; for (int i = 0; i < 5; i++) { - player.PickAmmo(player.inventory[player.selectedItem], ref type, ref scaleFactor, ref canFire, ref damage, ref knockBack, false); - knockBack = player.GetWeaponKnockback(player.inventory[player.selectedItem], knockBack); + player.PickAmmo(player.ActiveItem(), ref type, ref scaleFactor, ref canFire, ref damage, ref knockBack, false); + knockBack = player.GetWeaponKnockback(player.ActiveItem(), knockBack); Vector2 playerPosition = player.RotatedRelativePoint(player.MountedCenter, true); projectile.velocity = Main.screenPosition - playerPosition; projectile.velocity.X += Main.mouseX; diff --git a/Projectiles/Ranged/PhangasmBow.cs b/Projectiles/Ranged/PhangasmBow.cs index ba5aadfb48..cd85a5abc1 100644 --- a/Projectiles/Ranged/PhangasmBow.cs +++ b/Projectiles/Ranged/PhangasmBow.cs @@ -58,7 +58,7 @@ namespace CalamityMod.Projectiles.Ranged flag15 = true; int arg_1EF4_0 = (int)projectile.ai[0] / (num40 - num41 * num39); } - bool flag16 = player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed; + bool flag16 = player.channel && player.HasAmmo(player.ActiveItem(), true) && !player.noItems && !player.CCed; if (projectile.localAI[0] > 0f) { projectile.localAI[0] -= 1f; @@ -77,13 +77,13 @@ namespace CalamityMod.Projectiles.Ranged { int num42 = 14; float scaleFactor11 = 14f; - int weaponDamage2 = player.GetWeaponDamage(player.inventory[player.selectedItem]); - float weaponKnockback2 = player.inventory[player.selectedItem].knockBack; + int weaponDamage2 = player.GetWeaponDamage(player.ActiveItem()); + float weaponKnockback2 = player.ActiveItem().knockBack; if (flag16) { - player.PickAmmo(player.inventory[player.selectedItem], ref num42, ref scaleFactor11, ref flag16, ref weaponDamage2, ref weaponKnockback2, false); - weaponKnockback2 = player.GetWeaponKnockback(player.inventory[player.selectedItem], weaponKnockback2); - float scaleFactor12 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; + player.PickAmmo(player.ActiveItem(), ref num42, ref scaleFactor11, ref flag16, ref weaponDamage2, ref weaponKnockback2, false); + weaponKnockback2 = player.GetWeaponKnockback(player.ActiveItem(), weaponKnockback2); + float scaleFactor12 = player.ActiveItem().shootSpeed * projectile.scale; Vector2 vector19 = vector; Vector2 value18 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - vector19; if (player.gravDir == -1f) diff --git a/Projectiles/Ranged/StarfleetMK2Gun.cs b/Projectiles/Ranged/StarfleetMK2Gun.cs index 4372a7928a..40b0bf1e3b 100644 --- a/Projectiles/Ranged/StarfleetMK2Gun.cs +++ b/Projectiles/Ranged/StarfleetMK2Gun.cs @@ -68,7 +68,7 @@ namespace CalamityMod.Projectiles.Ranged projectile.ai[1] = baseUseTime - modifier * projectile.localAI[0]; timeToFire = true; } - bool canFire = player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed; + bool canFire = player.channel && player.HasAmmo(player.ActiveItem(), true) && !player.noItems && !player.CCed; if (projectile.soundDelay <= 0 && canFire) { projectile.soundDelay = baseUseTime - modifier * (int)projectile.localAI[0]; @@ -82,12 +82,12 @@ namespace CalamityMod.Projectiles.Ranged { int type = ModContent.ProjectileType(); float scaleFactor = 16f; - int damage = player.GetWeaponDamage(player.inventory[player.selectedItem]); - float knockBack = player.inventory[player.selectedItem].knockBack; - player.PickAmmo(player.inventory[player.selectedItem], ref type, ref scaleFactor, ref canFire, ref damage, ref knockBack, false); + int damage = player.GetWeaponDamage(player.ActiveItem()); + float knockBack = player.ActiveItem().knockBack; + player.PickAmmo(player.ActiveItem(), ref type, ref scaleFactor, ref canFire, ref damage, ref knockBack, false); for (int i = 0; i < 5; i++) { - knockBack = player.GetWeaponKnockback(player.inventory[player.selectedItem], knockBack); + knockBack = player.GetWeaponKnockback(player.ActiveItem(), knockBack); Vector2 playerPosition = player.RotatedRelativePoint(player.MountedCenter, true); projectile.velocity = Main.screenPosition - playerPosition; projectile.velocity.X += Main.mouseX; diff --git a/Projectiles/Rogue/SylvanSlashAttack.cs b/Projectiles/Rogue/SylvanSlashAttack.cs index b37be1ec9d..72c1212f54 100644 --- a/Projectiles/Rogue/SylvanSlashAttack.cs +++ b/Projectiles/Rogue/SylvanSlashAttack.cs @@ -29,6 +29,9 @@ namespace CalamityMod.Projectiles.Rogue public override void AI() { + if (Main.myPlayer != projectile.owner) + return; + Player player = Main.player[projectile.owner]; float num = 0f; Vector2 vector = player.RotatedRelativePoint(player.MountedCenter, true); @@ -46,33 +49,30 @@ namespace CalamityMod.Projectiles.Rogue Main.PlaySound(SoundID.Item15, projectile.Center); projectile.soundDelay = 24; } - if (Main.myPlayer == projectile.owner) - { - if (player.channel && !player.noItems && !player.CCed) - { - float scaleFactor6 = 1f; - if (player.inventory[player.selectedItem].shoot == projectile.type) - { - scaleFactor6 = player.inventory[player.selectedItem].shootSpeed * projectile.scale; - } - Vector2 vector13 = Main.MouseWorld - vector; - vector13.Normalize(); - if (vector13.HasNaNs()) - { - vector13 = Vector2.UnitX * (float)player.direction; - } - vector13 *= scaleFactor6; - if (vector13.X != projectile.velocity.X || vector13.Y != projectile.velocity.Y) - { - projectile.netUpdate = true; - } - projectile.velocity = vector13; - } - else - { - projectile.Kill(); - } - } + if (player.channel && !player.noItems && !player.CCed) + { + float scaleFactor6 = 1f; + if (player.ActiveItem().shoot == projectile.type) + { + scaleFactor6 = player.ActiveItem().shootSpeed * projectile.scale; + } + Vector2 vector13 = Main.MouseWorld - vector; + vector13.Normalize(); + if (vector13.HasNaNs()) + { + vector13 = Vector2.UnitX * (float)player.direction; + } + vector13 *= scaleFactor6; + if (vector13.X != projectile.velocity.X || vector13.Y != projectile.velocity.Y) + { + projectile.netUpdate = true; + } + projectile.velocity = vector13; + } + else + { + projectile.Kill(); + } Vector2 vector14 = projectile.Center + projectile.velocity * 3f; Lighting.AddLight(vector14, 0.2f, 2f, 3f); if (Main.rand.NextBool(3)) diff --git a/Projectiles/Typeless/EnergyShell.cs b/Projectiles/Typeless/EnergyShell.cs index d819990126..8fbc89e969 100644 --- a/Projectiles/Typeless/EnergyShell.cs +++ b/Projectiles/Typeless/EnergyShell.cs @@ -54,7 +54,7 @@ namespace CalamityMod.Projectiles.Typeless Player player = Main.player[projectile.owner]; projectile.Center = player.Center; //if player is dead, null, or stops holding the Lion Heart, kill the projectile - if (player.dead || player is null || player.HeldItem.type != ModContent.ItemType()) + if (player.dead || player is null || player.ActiveItem().type != ModContent.ItemType()) { projectile.Kill(); } diff --git a/Projectiles/Typeless/RelicOfDeliveranceSpear.cs b/Projectiles/Typeless/RelicOfDeliveranceSpear.cs index 09f206ccff..6044b01d8e 100644 --- a/Projectiles/Typeless/RelicOfDeliveranceSpear.cs +++ b/Projectiles/Typeless/RelicOfDeliveranceSpear.cs @@ -79,12 +79,12 @@ namespace CalamityMod.Projectiles.Typeless if (projectile.velocity == Vector2.Zero) { // Immediately die if the player is not holding the spear - if (player.HeldItem == null) + if (player.ActiveItem() == null) { projectile.Kill(); return; } - if (player.HeldItem.type != ModContent.ItemType()) + if (player.ActiveItem().type != ModContent.ItemType()) { projectile.Kill(); return; diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 4204c4d2f5..cf4cc53275 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -53,6 +53,7 @@ namespace CalamityMod public static CalamityGlobalNPC Calamity(this NPC npc) => npc.GetGlobalNPC(); public static CalamityGlobalItem Calamity(this Item item) => item.GetGlobalItem(); public static CalamityGlobalProjectile Calamity(this Projectile proj) => proj.GetGlobalProjectile(); + public static Item ActiveItem(this Player player) => Main.mouseItem.IsAir ? player.HeldItem : Main.mouseItem; #endregion #region Player Utilities @@ -302,7 +303,7 @@ namespace CalamityMod public static Rectangle FixSwingHitbox(float hitboxWidth, float hitboxHeight) { Player player = Main.player[Main.myPlayer]; - Item item = player.inventory[player.selectedItem]; + Item item = player.ActiveItem(); float hitbox_X, hitbox_Y; float mountOffsetY = player.mount.PlayerOffsetHitbox; @@ -2192,12 +2193,12 @@ namespace CalamityMod public static void DrawFishingLine(this Projectile projectile, int fishingRodType, Color poleColor, int xPositionAdditive = 45, float yPositionAdditive = 35f) { Player player = Main.player[projectile.owner]; - if (projectile.bobber && player.inventory[player.selectedItem].holdStyle > 0) + if (projectile.bobber && player.ActiveItem().holdStyle > 0) { float pPosX = player.MountedCenter.X; float pPosY = player.MountedCenter.Y; pPosY += player.gfxOffY; - int type = player.inventory[player.selectedItem].type; + int type = player.ActiveItem().type; float gravDir = player.gravDir; if (type == fishingRodType)