diff --git a/Projectiles/BaseProjectiles/BaseSwordHoldoutProjectile.cs b/Projectiles/BaseProjectiles/BaseSwordHoldoutProjectile.cs
index 4d6cab5a10..ffbdbf9df0 100644
--- a/Projectiles/BaseProjectiles/BaseSwordHoldoutProjectile.cs
+++ b/Projectiles/BaseProjectiles/BaseSwordHoldoutProjectile.cs
@@ -1,4 +1,6 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
+using System.IO;
using System.Linq;
using CalamityMod.Graphics.Primitives;
using CalamityMod.NPCs;
@@ -6,14 +8,11 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using Terraria;
-using Terraria.DataStructures;
+using Terraria.Audio;
using Terraria.GameContent.Prefixes;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
-using Terraria.Audio;
-using System;
-using System.IO;
namespace CalamityMod.Projectiles.BaseProjectiles
{
@@ -57,19 +56,19 @@ namespace CalamityMod.Projectiles.BaseProjectiles
}
public override bool CanUseItem(Player player)
{
- if (player.itemTime > 0)
+ if (player.itemTime > 0)
+ {
+ return false;
+ }
+ for (int i = 0; i < 1000; i++)
+ {
+ var proj = Main.projectile[i];
+ if (proj.type == ProjectileType && proj.owner == player.whoAmI && proj.active)
{
return false;
}
- for (int i = 0; i < 1000; i++)
- {
- var proj = Main.projectile[i];
- if (proj.type == ProjectileType && proj.owner == player.whoAmI && proj.active)
- {
- return false;
- }
- }
+ }
return base.CanUseItem(player);
}
}
@@ -172,7 +171,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles
///
/// What sound to use when the sword begins the actual swing (after startup frames)
///
- public virtual SoundStyle? UseSound {get; set;} = null;
+ public virtual SoundStyle? UseSound { get; set; } = null;
///
/// The length (from the player) of the projectile's line collision.
/// This helps to prevent blindspots.
@@ -230,6 +229,8 @@ namespace CalamityMod.Projectiles.BaseProjectiles
public float SwingCompletion => swingTimer / (float)swingTime;
public float CooldownCompletion => CooldownTimer / (float)CooldownTime;
+ private bool hasFakedOnSpawn = false;
+
#endregion
#region Overridable Methods
@@ -238,10 +239,10 @@ namespace CalamityMod.Projectiles.BaseProjectiles
///
public virtual void AdditionalAI() { }
///
- /// happens after OnSpawn. Use as not to cancel the default OnSpawn behavior.
+ /// happens at the beginning of AI the first frame.
///
///
- public virtual void Spawn(IEntitySource source) { }
+ public virtual void Spawn() { }
///
/// happens after SetDefaults. Use as not to cancel default SetDefaults behavior.
///
@@ -287,7 +288,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles
Projectile.timeLeft = swingTime * 2;
if (UsesBaseItem)
{
- Projectile.width = Projectile.height = Math.Max(BaseItem.height,BaseItem.width);
+ Projectile.width = Projectile.height = Math.Max(BaseItem.height, BaseItem.width);
}
Projectile.friendly = true;
Projectile.penetrate = -1;
@@ -302,14 +303,12 @@ namespace CalamityMod.Projectiles.BaseProjectiles
Defaults();
}
///
- /// DO NOT OVERRIDE IN MOST SITUATIONS
- /// use Spawn(IEntitySource) instead
- /// That will run spawn code in the proper timing.
+ /// This hook runs at the beginning of AI the first time through.
///
- public override void OnSpawn(IEntitySource source)
+ private void FakeOnSpawn()
{
var player = Main.player[Projectile.owner];
- angle = (player.Center - Main.MouseWorld).SafeNormalize(Vector2.One);
+ angle = (player.Center - player.Calamity().mouseWorld).SafeNormalize(Vector2.One);
Projectile.velocity = Vector2.Zero;
if (angle.X < 0)
{
@@ -330,7 +329,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles
player.GetModPlayer().swingNum++;
}
swingTime = Main.player[Projectile.owner].HeldItem.useTime;
- Spawn(source);
+ Spawn();
StartupTime *= Projectile.MaxUpdates;
CooldownTime *= Projectile.MaxUpdates;
swingTime *= Projectile.MaxUpdates;
@@ -369,16 +368,22 @@ namespace CalamityMod.Projectiles.BaseProjectiles
///
public override void AI()
{
+ if (!hasFakedOnSpawn)
+ {
+ FakeOnSpawn();
+ hasFakedOnSpawn = true;
+ }
var player = Main.player[Projectile.owner];
Projectile.gfxOffY = player.gfxOffY;
+ player.Calamity().mouseWorldListener = true;
var modplayer = player.GetModPlayer();
float adust = MathHelper.ToRadians(225);
if (timer < StartupTime || timer > StartupTime + swingTime)
{
if (inStartup)
- angle = Vector2.Lerp(angle, (player.Center - Main.MouseWorld).SafeNormalize(Vector2.One), RotateInStartup);
+ angle = Vector2.Lerp(angle, (player.Center - player.Calamity().mouseWorld).SafeNormalize(Vector2.One), RotateInStartup);
if (inCooldown)
- angle = Vector2.Lerp(angle, (player.Center - Main.MouseWorld).SafeNormalize(Vector2.One), RotateInCooldown);
+ angle = Vector2.Lerp(angle, (player.Center - player.Calamity().mouseWorld).SafeNormalize(Vector2.One), RotateInCooldown);
if (angle.X < 0)
{
player.direction = 1;
@@ -409,9 +414,9 @@ namespace CalamityMod.Projectiles.BaseProjectiles
oldProjectilePos.RemoveAt(0);
}
}
- if (inSwing && swingTimer == 1 && UseSound != null)
+ if (inSwing && swingTimer == 1 && UseSound != null)
{
- SoundEngine.PlaySound((SoundStyle)UseSound,player.Center);
+ SoundEngine.PlaySound((SoundStyle)UseSound, player.Center);
}
var angle2 = (AlternateSwings && modplayer.swingNum % 2 == 1 ? SwingFunction() : SwingFunction());
Projectile.Center = armCenter - (angle * OffsetDistance * (1 + (Projectile.scale - 1) * 0.75f)).RotatedBy(Projectile.spriteDirection * angle2);
@@ -478,13 +483,13 @@ namespace CalamityMod.Projectiles.BaseProjectiles
GameShaders.Misc["CalamityMod:ExobladeSlash"].Shader.Parameters["flipped"].SetValue(Projectile.spriteDirection == -1 ? false : true);
GameShaders.Misc["CalamityMod:ExobladeSlash"].Apply();
- var positionsToUse = Projectile.oldPos.Take((int)MathHelper.Min(trailLength,swingTimer)).ToArray();
+ var positionsToUse = Projectile.oldPos.Take((int)MathHelper.Min(trailLength, swingTimer)).ToArray();
for (var i = 0; i < positionsToUse.Length; i++)
{
if (i >= timer) break;
positionsToUse[i] += (Projectile.oldRot[i] - MathHelper.PiOver4 * (Projectile.spriteDirection == -1 ? 3 : 1)).ToRotationVector2() * this.trailOffset * oldScale[i];
}
- PrimitiveRenderer.RenderTrail(positionsToUse, new(trailWidth, trailColor, (_,_) => trailOffset, shader: GameShaders.Misc["CalamityMod:ExobladeSlash"]), 25);
+ PrimitiveRenderer.RenderTrail(positionsToUse, new(trailWidth, trailColor, (_, _) => trailOffset, shader: GameShaders.Misc["CalamityMod:ExobladeSlash"]), 25);
Main.spriteBatch.ExitShaderRegion();
Main.player[Projectile.owner].heldProj = Projectile.whoAmI;
@@ -508,7 +513,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles
var player = Main.player[Projectile.owner];
var armcenter = player.Center - new Vector2(5 * player.direction, 2);
var swordDir = armcenter.DirectionTo(Projectile.Center);
- var collisionline = new Vector2(lineCollisionLength / 2f, 0).RotatedBy(swordDir.ToRotation())*Projectile.scale;
+ var collisionline = new Vector2(lineCollisionLength / 2f, 0).RotatedBy(swordDir.ToRotation()) * Projectile.scale;
bool c = Collision.CheckAABBvLineCollision(targetHitbox.Location.ToVector2(), targetHitbox.Size(), Projectile.Center, Projectile.Center + collisionline);
if (c && !float.IsNaN(collisionline.X) && !float.IsNaN(collisionline.Y))
return true;
@@ -528,27 +533,11 @@ namespace CalamityMod.Projectiles.BaseProjectiles
public override void SendExtraAI(BinaryWriter writer)
{
writer.WriteVector2(angle);
- writer.Write(swingTime);
- writer.Write(StartupTime);
- writer.Write(CooldownTime);
- writer.Write(timer);
- writer.Write(swingTimer);
- writer.Write(ExistsTime);
- writer.Write(baseScale);
- writer.Write(Projectile.scale);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
angle = reader.ReadVector2();
- swingTime = reader.Read();
- StartupTime = reader.Read();
- CooldownTime = reader.Read();
- timer = reader.Read();
- swingTimer = reader.Read();
- ExistsTime = reader.Read();
- baseScale = reader.ReadSingle();
- Projectile.scale = reader.ReadSingle();
}
#endregion
diff --git a/Projectiles/Melee/LucreciaHoldout.cs b/Projectiles/Melee/LucreciaHoldout.cs
index 563156fa77..16623a3a65 100644
--- a/Projectiles/Melee/LucreciaHoldout.cs
+++ b/Projectiles/Melee/LucreciaHoldout.cs
@@ -52,7 +52,7 @@ namespace CalamityMod.Projectiles.Melee
Projectile.width = Projectile.height = 54;
}
- public override void Spawn(IEntitySource source)
+ public override void Spawn()
{
var player = Main.player[Projectile.owner];
var modplayer = player.GetModPlayer();
@@ -179,12 +179,13 @@ namespace CalamityMod.Projectiles.Melee
Projectile.scale = baseScale * MathHelper.Lerp(0.9f, 1.4f, eased);
// VFX vars
- Vector2 mousePosition = Main.MouseWorld;
+ Vector2 mousePosition = player.Calamity().mouseWorld;
Vector2 fireDirection = Vector2.Normalize(mousePosition - player.Center);
if (!trailFXTriggered)
{
- Projectile.NewProjectile(Projectile.GetSource_FromThis(), player.Center, fireDirection * 5, ModContent.ProjectileType(), Projectile.damage * 8, Projectile.knockBack, Projectile.owner, 0f, 0f);
+ if (Main.myPlayer == Projectile.owner)
+ Projectile.NewProjectile(Projectile.GetSource_FromThis(), player.Center, fireDirection * 5, ModContent.ProjectileType(), Projectile.damage * 8, Projectile.knockBack, Projectile.owner, 0f, 0f);
SoundStyle swish = new("CalamityMod/Sounds/Custom/MeatySlash");
SoundEngine.PlaySound(swish with { Volume = 0.3f, Pitch = Main.rand.NextFloat(0.1f, 0.2f) }, Projectile.Center);
diff --git a/Projectiles/Melee/MawOfInfinityHoldout.cs b/Projectiles/Melee/MawOfInfinityHoldout.cs
index 50c78908ce..cb0d2546cb 100644
--- a/Projectiles/Melee/MawOfInfinityHoldout.cs
+++ b/Projectiles/Melee/MawOfInfinityHoldout.cs
@@ -37,14 +37,16 @@ namespace CalamityMod.Projectiles.Melee
Projectile.extraUpdates = 5; //ExtraUpdates help make collision more accurate
Projectile.noEnchantmentVisuals = true;
}
- public override void Spawn(IEntitySource source)
+ public override void Spawn()
{
var player = Main.player[Projectile.owner];
var modplayer = player.GetModPlayer();
StartupTime = 10;
CooldownTime = 10;
swingTime -= StartupTime + CooldownTime;
- modplayer.swingNum = modplayer.swingNum++ % 3;
+
+ if (Main.myPlayer == Projectile.owner)
+ modplayer.swingNum = modplayer.swingNum++ % 3;
OffsetDistance = 70;
RotateInStartup = 0.2f;
RotateInCooldown = 0f;
@@ -91,6 +93,7 @@ namespace CalamityMod.Projectiles.Melee
Main.projectile[p].friendly = true;
Main.projectile[p].DamageType = DamageClass.Melee;
Main.projectile[p].timeLeft = 120;
+ Main.projectile[p].netUpdate = true;
}
}
}
@@ -116,8 +119,8 @@ namespace CalamityMod.Projectiles.Melee
case 0:
if (Main.myPlayer == Projectile.owner)
Projectile.NewProjectile(Projectile.GetSource_FromThis(), player.Center, -angle * 3, ModContent.ProjectileType(), Projectile.damage * 2, Projectile.knockBack, player.whoAmI);
- player.itemAnimation = BaseItem.useAnimation;
- player.itemTime = BaseItem.useTime;
+ player.itemAnimation = BaseItem.useAnimation;
+ player.itemTime = BaseItem.useTime;
Projectile.Kill();
return;
}
diff --git a/Projectiles/Melee/MirrorBladeProjectile.cs b/Projectiles/Melee/MirrorBladeProjectile.cs
index d134a0b5f8..56cca4d246 100644
--- a/Projectiles/Melee/MirrorBladeProjectile.cs
+++ b/Projectiles/Melee/MirrorBladeProjectile.cs
@@ -26,7 +26,7 @@ namespace CalamityMod.Projectiles.Melee
public override bool drawSwordTrail => false;
public override Color[] trailColors => new Color[] { Color.Red, Color.MediumPurple, Color.Purple }; public override int StartupTime { get; set; }
public override int CooldownTime { get; set; }
- public override bool AlternateSwings => true;
+ public override bool AlternateSwings => false;
public bool SpawnShards = true;
public override bool useMeleeSpeed => true;
@@ -42,7 +42,7 @@ namespace CalamityMod.Projectiles.Melee
Projectile.extraUpdates = 3;
}
- public override void Spawn(IEntitySource source)
+ public override void Spawn()
{
var player = Main.player[Projectile.owner];
var modplayer = player.GetModPlayer();
diff --git a/Projectiles/Melee/MirrorBlast.cs b/Projectiles/Melee/MirrorBlast.cs
index 6dedd37c92..276bc0972a 100644
--- a/Projectiles/Melee/MirrorBlast.cs
+++ b/Projectiles/Melee/MirrorBlast.cs
@@ -56,8 +56,8 @@ namespace CalamityMod.Projectiles.Melee
{
isShard = reader.ReadBoolean();
hasSpawned = reader.ReadBoolean();
- shardNum = reader.Read();
- shardShield = reader.Read();
+ shardNum = reader.ReadInt32();
+ shardShield = reader.ReadInt32();
}
public override bool? CanDamage()
{
@@ -73,8 +73,10 @@ namespace CalamityMod.Projectiles.Melee
}
public override void AI()
{
+ player.Calamity().mouseWorldListener = true;
if (!hasSpawned)
{
+ Projectile.netUpdate = true;
if (Projectile.ai[0] != 0)
{
//This is used when spawned by Evolution.
@@ -97,6 +99,7 @@ namespace CalamityMod.Projectiles.Melee
if (proj.active && proj.type == ModContent.ProjectileType() && proj.owner == Projectile.owner)
{
(proj.ModProjectile as MirrorBlast).shardNum++;
+ proj.netUpdate = true;
}
}
}
@@ -108,6 +111,7 @@ namespace CalamityMod.Projectiles.Melee
isShard = false;
Projectile.timeLeft = 1200;
Projectile.velocity = Projectile.DirectionTo(player.Center) * -20f;
+ Projectile.netUpdate = true;
return;
}
List positions = new List() //Hardcoded positions for the mirror shield shards so we can make it look nice
diff --git a/Projectiles/Melee/Shortswords/GalileoGladiusProj.cs b/Projectiles/Melee/Shortswords/GalileoGladiusProj.cs
index fa846552c9..4ef4e0f9b3 100644
--- a/Projectiles/Melee/Shortswords/GalileoGladiusProj.cs
+++ b/Projectiles/Melee/Shortswords/GalileoGladiusProj.cs
@@ -41,7 +41,7 @@ namespace CalamityMod.Projectiles.Melee.Shortswords
Projectile.extraUpdates = 3;
}
- public override void Spawn(IEntitySource source)
+ public override void Spawn()
{
angle = angle.RotatedByRandom(0.25f);
}
diff --git a/Projectiles/Melee/Spears/GildedProboscisProj.cs b/Projectiles/Melee/Spears/GildedProboscisProj.cs
index b1e15fc195..b4c31c6166 100644
--- a/Projectiles/Melee/Spears/GildedProboscisProj.cs
+++ b/Projectiles/Melee/Spears/GildedProboscisProj.cs
@@ -36,7 +36,7 @@ namespace CalamityMod.Projectiles.Melee.Spears
Projectile.extraUpdates = 5; //ExtraUpdates help make the VFX smoother
Projectile.noEnchantmentVisuals = true;
}
- public override void Spawn(IEntitySource source)
+ public override void Spawn()
{
//This sets variables for the spear in general, as well as the secondary attack
//The secondary attack is the "default" because it was coded first
diff --git a/Projectiles/Melee/TheMutilatorHoldoutProjectile.cs b/Projectiles/Melee/TheMutilatorHoldoutProjectile.cs
index 31d0477afd..843103b40d 100644
--- a/Projectiles/Melee/TheMutilatorHoldoutProjectile.cs
+++ b/Projectiles/Melee/TheMutilatorHoldoutProjectile.cs
@@ -41,7 +41,7 @@ namespace CalamityMod.Projectiles.Melee
public bool hasGivenBlood = false;
- public override void Spawn(IEntitySource source)
+ public override void Spawn()
{
var player = Main.player[Projectile.owner];
var modplayer = player.GetModPlayer();