Implemented Magna Cannon to Base Holdout.

1. Implemented Magna Cannon to the BaseGunHoldoutProjectile abstract class.
2. Gave multiplayer support to Magna Cannon.
This commit is contained in:
Memes committed 2024-05-17 16:30:58 +02:00
1 parent 52da30c8f0
commit fa4e98fdec
3 files changed
+56 -84

No files matched your search

+11 -4
View File
@@ -22,10 +22,8 @@ namespace CalamityMod.Items.Weapons.Ranged
public new string LocalizationCategory => "Items.Weapons.Ranged";
public override void SetStaticDefaults()
{
ItemID.Sets.IsRangedSpecialistWeapon[Item.type] = true;
}
public override void SetStaticDefaults() => ItemID.Sets.IsRangedSpecialistWeapon[Item.type] = true;
public override void SetDefaults()
{
Item.width = 56;
@@ -49,6 +47,15 @@ namespace CalamityMod.Items.Weapons.Ranged
public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0;
public override void HoldItem(Player player) => player.Calamity().mouseRotationListener = true;
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
Vector2 spawnPosition = player.RotatedRelativePoint(player.MountedCenter);
Projectile.NewProjectileDirect(source, spawnPosition, player.Calamity().mouseWorld - player.RotatedRelativePoint(player.MountedCenter), ModContent.ProjectileType<MagnaCannonHoldout>(), 0, 0f, player.whoAmI);
return false;
}
public override void AddRecipes()
{
CreateRecipe().
+44 -79
View File
@@ -1,67 +1,48 @@
using System;
using CalamityMod.Items.Weapons.Ranged;
using CalamityMod.Items.Weapons.Ranged;
using CalamityMod.Particles;
using CalamityMod.Projectiles.BaseProjectiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Utilities;
using Terraria;
using Terraria.Audio;
using Terraria.Localization;
using Terraria.GameContent;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Ranged
{
public class MagnaCannonHoldout : ModProjectile
public class MagnaCannonHoldout : BaseGunHoldoutProjectile
{
// Take the name and texture from the weapon
public override LocalizedText DisplayName => CalamityUtils.GetItemName<MagnaCannon>();
public override string Texture => "CalamityMod/Items/Weapons/Ranged/MagnaCannon";
public static int FramesPerLoad = 9;
public static int MaxLoadableShots = 20;
public static float BulletSpeed = 12f;
private Player Owner => Main.player[Projectile.owner];
public SlotId MagnaChargeSlot;
public override int AssociatedItemID => ModContent.ItemType<MagnaCannon>();
public override float MaxOffsetLengthFromArm => 20f;
public override float OffsetXUpwards => -5f;
public override float BaseOffsetY => -5f;
private ref float CurrentChargingFrames => ref Projectile.ai[0];
private ref float ShotsLoaded => ref Projectile.ai[1];
private ref float ShootTimer => ref Projectile.ai[2];
private bool FullyCharged => CurrentChargingFrames >= MagnaCannon.FullChargeFrames;
public int Time = 0;
public SlotId MagnaChargeSlot;
public static int FramesPerLoad = 9;
public static int MaxLoadableShots = 20;
public static float BulletSpeed = 12f;
public override void SetDefaults()
public override void KillHoldoutLogic()
{
Projectile.width = 58;
Projectile.height = 30;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.DamageType = DamageClass.Ranged;
Projectile.ignoreWater = true;
if (Owner.CantUseHoldout(false) || HeldItem.type != Owner.ActiveItem().type)
Projectile.Kill();
}
public override void AI()
public override void HoldoutAI()
{
Time++;
if (Time == 1)
Projectile.alpha = 255;
else
Projectile.alpha = 0;
if (Owner.dead) // destroy the holdout if the player dies
{
Projectile.Kill();
return;
}
Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true);
Vector2 tipPosition = armPosition + Projectile.velocity * Projectile.width * 0.9f;
if (SoundEngine.TryGetActiveSound(MagnaChargeSlot, out var ChargeSound) && ChargeSound.IsPlaying)
ChargeSound.Position = Projectile.Center;
// Fire if the owner stops channeling or otherwise cannot use the weapon.
if (Owner.CantUseHoldout())
{
KeepRefreshingLifetime = false;
if (ShotsLoaded > 0)
{
// While bullets are remaining, refresh the lifespan; it will not refresh again after bullets run out
@@ -75,24 +56,19 @@ namespace CalamityMod.Projectiles.Ranged
SoundEngine.PlaySound(MagnaCannon.Fire, Projectile.position);
Vector2 shootVelocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * BulletSpeed;
Projectile.NewProjectile(Projectile.GetSource_FromThis(), tipPosition, shootVelocity.RotatedByRandom(MathHelper.ToRadians(9f)), ModContent.ProjectileType<MagnaShot>(), Projectile.damage, Projectile.knockBack * (FullyCharged ? 3 : 1), Projectile.owner);
Projectile.NewProjectile(Projectile.GetSource_FromThis(), GunTipPosition, shootVelocity.RotatedByRandom(MathHelper.ToRadians(9f)), ModContent.ProjectileType<MagnaShot>(), Projectile.damage, Projectile.knockBack * (FullyCharged ? 3 : 1), Projectile.owner);
for (int i = 0; i <= 3; i++)
{
Dust dust = Dust.NewDustPerfect(tipPosition, 187, shootVelocity.RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.9f, 1.2f), 0, default, Main.rand.NextFloat(1.5f, 2.3f));
Dust dust = Dust.NewDustPerfect(GunTipPosition, 187, shootVelocity.RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.9f, 1.2f), 0, default, Main.rand.NextFloat(1.5f, 2.3f));
dust.noGravity = true;
}
ShotsLoaded--;
ShootTimer = (FullyCharged ? 4f : 5f);
Projectile.netSpam = 0;
Projectile.netUpdate = true;
ShootTimer = FullyCharged ? 4f : 5f;
}
}
else
{
// While channeled, keep refreshing the projectile lifespan
Projectile.timeLeft = 2;
// Loads shots until maxed out
if (ShotsLoaded < MaxLoadableShots && CurrentChargingFrames % FramesPerLoad == 0)
ShotsLoaded++;
@@ -116,13 +92,13 @@ namespace CalamityMod.Projectiles.Ranged
{
if (!FullyCharged)
{
Particle streak = new ManaDrainStreak(Owner, Main.rand.NextFloat(0.06f + (CurrentChargingFrames / 180), 0.08f + (CurrentChargingFrames / 180)), Main.rand.NextVector2CircularEdge(2f, 2f) * Main.rand.NextFloat(0.3f * CurrentChargingFrames, 0.3f * CurrentChargingFrames), 0f, Color.White, Color.Aqua, 7, tipPosition);
Particle streak = new ManaDrainStreak(Owner, Main.rand.NextFloat(0.06f + (CurrentChargingFrames / 180), 0.08f + (CurrentChargingFrames / 180)), Main.rand.NextVector2CircularEdge(2f, 2f) * Main.rand.NextFloat(0.3f * CurrentChargingFrames, 0.3f * CurrentChargingFrames), 0f, Color.White, Color.Aqua, 7, GunTipPosition);
GeneralParticleHandler.SpawnParticle(streak);
}
float orbScale = MathHelper.Clamp(CurrentChargingFrames, 0f, MagnaCannon.FullChargeFrames);
Particle orb = new GenericBloom(tipPosition, Projectile.velocity, Color.DarkBlue, orbScale / 135f, 2);
Particle orb = new GenericBloom(GunTipPosition, Projectile.velocity, Color.DarkBlue, orbScale / 135f, 2);
GeneralParticleHandler.SpawnParticle(orb);
Particle orb2 = new GenericBloom(tipPosition, Projectile.velocity, Color.Aqua, orbScale / 200f, 2);
Particle orb2 = new GenericBloom(GunTipPosition, Projectile.velocity, Color.Aqua, orbScale / 200f, 2);
GeneralParticleHandler.SpawnParticle(orb2);
}
@@ -131,49 +107,38 @@ namespace CalamityMod.Projectiles.Ranged
{
for (int i = 0; i < 36; i++)
{
Dust chargefull = Dust.NewDustPerfect(tipPosition, 160);
Dust chargefull = Dust.NewDustPerfect(GunTipPosition, 160);
chargefull.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 18f + Owner.velocity;
chargefull.scale = Main.rand.NextFloat(1f, 1.5f);
chargefull.noGravity = true;
}
}
}
UpdateProjectileHeldVariables(armPosition);
ManipulatePlayerVariables();
}
private void UpdateProjectileHeldVariables(Vector2 armPosition)
{
if (Main.myPlayer == Projectile.owner)
{
float interpolant = Utils.GetLerpValue(5f, 40f, Projectile.Distance(Main.MouseWorld), true);
Vector2 oldVelocity = Projectile.velocity;
Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant);
}
Projectile.Center = armPosition + Projectile.velocity * 20;
Projectile.rotation = Projectile.velocity.ToRotation() + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f);
Projectile.spriteDirection = Projectile.direction;
// Rumble (only while channeling)
float rumble = MathHelper.Clamp(CurrentChargingFrames, 0f, MagnaCannon.FullChargeFrames);
if (!Owner.CantUseHoldout())
Projectile.position += Main.rand.NextVector2Circular(rumble / 43f, rumble / 43f);
}
private void ManipulatePlayerVariables()
{
Owner.ChangeDir(Projectile.direction);
Owner.heldProj = Projectile.whoAmI;
Owner.itemTime = 2;
Owner.itemAnimation = 2;
Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation();
}
public override void OnKill(int timeLeft)
{
if (SoundEngine.TryGetActiveSound(MagnaChargeSlot, out var ChargeSound))
ChargeSound?.Stop();
}
public override bool? CanDamage() => false;
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture = TextureAssets.Projectile[Type].Value;
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
float drawRotation = Projectile.rotation + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f);
Vector2 rotationPoint = texture.Size() * 0.5f;
SpriteEffects flipSprite = (Projectile.spriteDirection * Owner.gravDir == -1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
if (!Owner.CantUseHoldout())
{
float rumble = MathHelper.Clamp(CurrentChargingFrames, 0f, MagnaCannon.FullChargeFrames);
drawPosition += Main.rand.NextVector2Circular(rumble / 43f, rumble / 43f);
}
Main.EntitySpriteDraw(texture, drawPosition, null, Projectile.GetAlpha(lightColor), drawRotation, rotationPoint, Projectile.scale * Owner.gravDir, flipSprite);
return false;
}
}
}
+1 -1
View File
@@ -887,7 +887,7 @@ namespace CalamityMod
/// </summary>
/// <param name="player">The player using the holdout.</param>
/// <returns>Returns <see langword="true"/> if the player CAN'T use the item.</returns>
public static bool CantUseHoldout(this Player player) => player == null || !player.active || player.dead || !player.channel || player.CCed || player.noItems;
public static bool CantUseHoldout(this Player player, bool needsToHold = true) => player == null || !player.active || player.dead || (!player.channel && needsToHold) || player.CCed || player.noItems;
/// <summary>
/// Makes the given player send the given packet to all appropriate receivers.<br />