From 212cc839a2ad6bbb3d5ca308fb6d8b94ea070671 Mon Sep 17 00:00:00 2001 From: ben-tk <45545085+termigator1359@users.noreply.github.com> Date: Sat, 19 Dec 2020 12:42:28 -0500 Subject: [PATCH] Fixed Tactical Plague engine damage bugs I think --- Items/Weapons/Summon/TacticalPlagueEngine.cs | 51 +++++++++++++-- Projectiles/Ranged/BloodfireBulletProj.cs | 5 +- .../Summon/TacticalPlagueEngineSummon.cs | 59 +++++++++++++---- Utilities/CalamityUtils.cs | 65 +++++++++++++++++++ 4 files changed, 161 insertions(+), 19 deletions(-) diff --git a/Items/Weapons/Summon/TacticalPlagueEngine.cs b/Items/Weapons/Summon/TacticalPlagueEngine.cs index 56c657f61f..f10cb0b873 100644 --- a/Items/Weapons/Summon/TacticalPlagueEngine.cs +++ b/Items/Weapons/Summon/TacticalPlagueEngine.cs @@ -13,7 +13,7 @@ namespace CalamityMod.Items.Weapons.Summon { DisplayName.SetDefault("Tactical Plague Engine"); Tooltip.SetDefault("Summons a plague jet to pummel your enemies into submission\n" + - "Consumes bullets\n" + + "Requires bullets to shoot\n" + "Sometimes shoots a missile instead of a bullet"); } @@ -34,17 +34,58 @@ namespace CalamityMod.Items.Weapons.Summon item.summon = true; item.shoot = ModContent.ProjectileType(); item.shootSpeed = 16f; + item.useAmmo = AmmoID.Bullet; } + public override bool ConsumeAmmo(Player player) => false; + + public override bool CanUseItem(Player player) => player.HasAmmo(item, false); + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - if (player.altFunctionUse != 2) - { - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0f, 1f); - } + // Undo the vanilla addition of ammo damage + damage -= GetVanillaAmmoDamage(player); + + Projectile.NewProjectile(position.X, position.Y, speedX, speedY, item.shoot, damage, knockBack, player.whoAmI, 0f, 1f); return false; } + private int GetVanillaAmmoDamage(Player player) + { + Item ammo = null; + int ammoBonus = 0; + bool ammoSlots = false; + for (int index = Main.maxInventory - 4; index < Main.maxInventory; ++index) + { + if (player.inventory[index].ammo == item.useAmmo && player.inventory[index].stack > 0) + { + ammo = player.inventory[index]; + ammoSlots = true; + break; + } + } + if (!ammoSlots) + { + for (int index = 0; index < Main.maxInventory - 4; ++index) + { + if (player.inventory[index].ammo == item.useAmmo && player.inventory[index].stack > 0) + { + ammo = player.inventory[index]; + break; + } + } + } + + if (ammo != null) + { + if (ammo.damage > 0) + { + ammoBonus = (int)(ammo.damage * player.MinionDamage()); + } + } + return ammoBonus; + } + public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); diff --git a/Projectiles/Ranged/BloodfireBulletProj.cs b/Projectiles/Ranged/BloodfireBulletProj.cs index 9b80c993a3..0fecc1e3ef 100644 --- a/Projectiles/Ranged/BloodfireBulletProj.cs +++ b/Projectiles/Ranged/BloodfireBulletProj.cs @@ -74,7 +74,10 @@ namespace CalamityMod.Projectiles.Ranged // For the sake of bonus damage, life regen time caps at 3600, aka 60 seconds. This is its natural cap in vanilla. int regenTimeForCalc = (int)MathHelper.Clamp(owner.lifeRegenTime, 0f, 3600f); - return (int)(regenDamageRatio * regenTimeForCalc); + int bloodFireBonus = (int)(regenDamageRatio * regenTimeForCalc); + + // Main.NewText("Bloodfire Regen Bonus: " + bloodFireBonus, Color.Red); + return bloodFireBonus; } public override void Kill(int timeLeft) diff --git a/Projectiles/Summon/TacticalPlagueEngineSummon.cs b/Projectiles/Summon/TacticalPlagueEngineSummon.cs index 155c43d720..bf8441924b 100644 --- a/Projectiles/Summon/TacticalPlagueEngineSummon.cs +++ b/Projectiles/Summon/TacticalPlagueEngineSummon.cs @@ -1,7 +1,7 @@ using CalamityMod.Buffs.Summon; -using CalamityMod.Dusts; -using CalamityMod.Items.Weapons.Ranged; using CalamityMod.CalPlayer; +using CalamityMod.Dusts; +using CalamityMod.Items.Weapons.Summon; using Microsoft.Xna.Framework; using System; using Terraria; @@ -50,7 +50,7 @@ namespace CalamityMod.Projectiles.Summon Dust dust = Dust.NewDustPerfect(projectile.Center + velocity * 2f, (int)CalamityDusts.Plague, velocity); dust.noGravity = true; } - FalseGun = ItemLoader.GetItem(ModContent.ItemType()).item; + FalseGun = GetItem(); projectile.localAI[0] = 1f; } if (projectile.frameCounter++ > 6f) @@ -82,9 +82,19 @@ namespace CalamityMod.Projectiles.Summon projectile.timeLeft = 2; } } + + // Try and find a gun every 2.5 seconds if for some reason there is none + if (FalseGun is null) + { + if (player.miscCounter % 150 == 0) + { + FalseGun = GetItem(); + } + } + NPC potentialTarget = projectile.Center.MinionHoming(1560f, player); - if (potentialTarget is null || !player.HasAmmo(FalseGun, false)) + if (potentialTarget is null || FalseGun is null || !player.HasAmmo(FalseGun, false)) { float acceleration = 0.1f; Vector2 distanceVector = player.Center - projectile.Center; @@ -145,23 +155,24 @@ namespace CalamityMod.Projectiles.Summon if (projectile.ai[0]++ % 75f == 24f) { - int damage = projectile.damage; + int shoot = ProjectileID.Bullet; + float shootSpeed = 0f; + bool canShoot = true; + int dmg = projectile.damage; + float kBack = projectile.knockBack * 0.5f; + + player.PickAmmoSummon(FalseGun, ref shoot, ref shootSpeed, ref canShoot, ref dmg, ref kBack); + if (projectile.ai[1]++ % 20f == 0f) { int idx = Projectile.NewProjectile(projectile.Center, projectile.DirectionTo(potentialTarget.Center) * 18f, ModContent.ProjectileType(), - (int)(damage * 1.5), 5f, projectile.owner); + (int)(dmg * 1.5), kBack * 5f, projectile.owner); if (idx.WithinBounds(Main.maxProjectiles)) Main.projectile[idx].Calamity().forceMinion = true; } else { - int shoot = 0; - float shootSpeed = 0f; - bool canShoot = true; - float knockBack = projectile.knockBack * 0.5f; - player.PickAmmo(FalseGun, ref shoot, ref shootSpeed, ref canShoot, ref damage, ref knockBack); - int idx = Projectile.NewProjectile(projectile.Center, projectile.DirectionTo(potentialTarget.Center) * shootSpeed, shoot, - damage, knockBack, projectile.owner); + int idx = Projectile.NewProjectile(projectile.Center, projectile.DirectionTo(potentialTarget.Center) * shootSpeed, shoot, dmg, kBack, projectile.owner); // There's airway for a small bug in here, but the potential alterative (that has indeed been appearing), where // the projectile simply cannot exist, is far worse than this. If you have another solution, let me know. if (idx.WithinBounds(Main.maxProjectiles)) @@ -172,6 +183,28 @@ namespace CalamityMod.Projectiles.Summon } } + private Item GetItem() + { + Item item = null; + Player player = Main.player[projectile.owner]; + + if (!Main.mouseItem.IsAir && Main.mouseItem.type == ModContent.ItemType()) + item = Main.mouseItem; + + if (item is null) + { + for (int index = 0; index < Main.maxInventory - 4; ++index) + { + if (player.inventory[index].type == ModContent.ItemType() && player.inventory[index].stack > 0) + { + item = player.inventory[index]; + break; + } + } + } + return item; + } + public override bool CanDamage() => false; } } diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 0e36dc7df1..054949d705 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -754,6 +754,71 @@ namespace CalamityMod return hitbox; } + public static void PickAmmoSummon(this Player player, Item item, ref int shoot, ref float speed, ref bool canShoot, ref int dmg, ref float kBack, bool dontConsume = false) + { + Item ammo = null; + bool ammoSlots = false; + // Check if there is ammo in the dedicated ammo slots first + for (int index = Main.maxInventory - 4; index < Main.maxInventory; ++index) + { + if (player.inventory[index].ammo == item.useAmmo && player.inventory[index].stack > 0) + { + ammo = player.inventory[index]; + canShoot = true; + ammoSlots = true; + break; + } + } + if (!ammoSlots) + { + for (int index = 0; index < Main.maxInventory - 4; ++index) + { + if (player.inventory[index].ammo == item.useAmmo && player.inventory[index].stack > 0) + { + ammo = player.inventory[index]; + canShoot = true; + break; + } + } + } + if (ammo is null || !canShoot) + return; + + if (ammo.shoot > 0) + shoot = ammo.shoot; + speed += ammo.shootSpeed; + kBack += ammo.knockBack; + + // Main.NewText("Damage before: " + dmg, Color.Green); + int ammoBonus = 0; + if (ammo.damage > 0) + { + ammoBonus = (int)(ammo.damage * player.MinionDamage()); + // Main.NewText("Ammo Bonus: " + ammoBonus, Color.Red); + } + dmg += ammoBonus; + // Main.NewText("Damage after: " + dmg, Color.Red); + + bool dontConsumeAmmo = dontConsume; + if (player.ammoBox && Main.rand.NextBool(5)) + dontConsumeAmmo = true; + if (player.ammoPotion && Main.rand.NextBool(5)) + dontConsumeAmmo = true; + if (player.ammoCost80 && Main.rand.NextBool(5)) + dontConsumeAmmo = true; + if (player.ammoCost75 && Main.rand.NextBool(4)) + dontConsumeAmmo = true; + if (Main.rand.NextFloat() > player.Calamity().rangedAmmoCost) + dontConsumeAmmo = true; + if (dontConsumeAmmo || !ammo.consumable) + return; + --ammo.stack; + if (ammo.stack > 0) + return; + ammo.active = false; + ammo.TurnToAir(); + } + public static void ConsumeItemViaQuickBuff(Player player, Item item, int buffType, int buffTime, bool reducedPotionSickness) { bool showsOver = false;