fix starmada, starfleet and basegunholdout projectile syncing
This commit is contained in:
1 parent
e89af3832c
commit
d1ff0e4b89
4 files changed
+61
-22
No files matched your search
@@ -197,27 +197,46 @@ namespace CalamityMod.Projectiles.BaseProjectiles
|
||||
// The center of the player, taking into account if they have a mount or not.
|
||||
Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true);
|
||||
|
||||
// 14NOV2024: Ozzatron: clamped mouse position unnecessary, only used for direction
|
||||
// The vector between the player and the mouse, used for pointing the holdout.
|
||||
Vector2 ownerToMouse = Owner.Calamity().mouseWorld - armPosition;
|
||||
|
||||
// The direction this holdout's pointing at.
|
||||
float holdoutDirection = Projectile.velocity.ToRotation();
|
||||
|
||||
// A range from -1 to 1 for when the holdout is pointing downards of upwards, respectively.
|
||||
// Used for the offsets.
|
||||
float proximityLookingUpwards = Vector2.Dot(ownerToMouse.SafeNormalize(Vector2.Zero), -Vector2.UnitY * Owner.gravDir);
|
||||
// Only the owner should compute aiming from mouse position.
|
||||
// Non-owner clients use the synced rotation/direction to avoid jitter.
|
||||
if (Projectile.owner == Main.myPlayer)
|
||||
{
|
||||
// 14NOV2024: Ozzatron: clamped mouse position unnecessary, only used for direction
|
||||
// The vector between the player and the mouse, used for pointing the holdout.
|
||||
Vector2 ownerToMouse = Owner.Calamity().mouseWorld - armPosition;
|
||||
|
||||
int direction = MathF.Sign(ownerToMouse.X);
|
||||
// A range from -1 to 1 for when the holdout is pointing downards of upwards, respectively.
|
||||
// Used for the offsets.
|
||||
float proximityLookingUpwards = Vector2.Dot(ownerToMouse.SafeNormalize(Vector2.Zero), -Vector2.UnitY * Owner.gravDir);
|
||||
|
||||
Vector2 lengthOffset = Projectile.rotation.ToRotationVector2() * OffsetLengthFromArm;
|
||||
Vector2 armOffset = new Vector2(Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetXUpwards : OffsetXDownwards) * direction, BaseOffsetY * Owner.gravDir + Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetYUpwards : OffsetYDownwards) * Owner.gravDir);
|
||||
Projectile.Center = armPosition + lengthOffset + armOffset;
|
||||
Projectile.velocity = holdoutDirection.AngleTowards(ownerToMouse.ToRotation(), WeaponTurnSpeed).ToRotationVector2();
|
||||
Projectile.rotation = holdoutDirection;
|
||||
int direction = MathF.Sign(ownerToMouse.X);
|
||||
|
||||
Projectile.spriteDirection = direction;
|
||||
Owner.ChangeDir(direction);
|
||||
Vector2 lengthOffset = Projectile.rotation.ToRotationVector2() * OffsetLengthFromArm;
|
||||
Vector2 armOffset = new Vector2(Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetXUpwards : OffsetXDownwards) * direction, BaseOffsetY * Owner.gravDir + Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetYUpwards : OffsetYDownwards) * Owner.gravDir);
|
||||
Projectile.Center = armPosition + lengthOffset + armOffset;
|
||||
Projectile.velocity = holdoutDirection.AngleTowards(ownerToMouse.ToRotation(), WeaponTurnSpeed).ToRotationVector2();
|
||||
Projectile.rotation = holdoutDirection;
|
||||
|
||||
Projectile.spriteDirection = direction;
|
||||
Owner.ChangeDir(direction);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 lengthOffset = Projectile.rotation.ToRotationVector2() * OffsetLengthFromArm;
|
||||
float proximityLookingUpwards = Vector2.Dot(Projectile.velocity.SafeNormalize(Vector2.Zero), -Vector2.UnitY * Owner.gravDir);
|
||||
int direction = Projectile.spriteDirection;
|
||||
|
||||
Vector2 armOffset = new Vector2(Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetXUpwards : OffsetXDownwards) * direction, BaseOffsetY * Owner.gravDir + Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetYUpwards : OffsetYDownwards) * Owner.gravDir);
|
||||
Projectile.Center = armPosition + lengthOffset + armOffset;
|
||||
Projectile.velocity = Projectile.rotation.ToRotationVector2();
|
||||
|
||||
Owner.ChangeDir(direction);
|
||||
}
|
||||
|
||||
int currentDirection = Projectile.spriteDirection;
|
||||
|
||||
Owner.heldProj = Projectile.whoAmI;
|
||||
if (SetUsage)
|
||||
@@ -226,8 +245,8 @@ namespace CalamityMod.Projectiles.BaseProjectiles
|
||||
|
||||
// -Pi/2 because the arms rotation starts with arms pointing down.
|
||||
float armRotation = (Projectile.rotation - MathHelper.PiOver2) * Owner.gravDir + (Owner.gravDir == -1 ? MathHelper.Pi : 0f);
|
||||
Owner.SetCompositeArmFront(true, FrontArmStretch, armRotation + ExtraFrontArmRotation * direction);
|
||||
Owner.SetCompositeArmBack(true, BackArmStretch, armRotation + ExtraBackArmRotation * direction);
|
||||
Owner.SetCompositeArmFront(true, FrontArmStretch, armRotation + ExtraFrontArmRotation * currentDirection);
|
||||
Owner.SetCompositeArmBack(true, BackArmStretch, armRotation + ExtraBackArmRotation * currentDirection);
|
||||
|
||||
if (KeepRefreshingLifetime)
|
||||
Projectile.timeLeft = 2;
|
||||
@@ -235,7 +254,8 @@ namespace CalamityMod.Projectiles.BaseProjectiles
|
||||
if (OffsetLengthFromArm != MaxOffsetLengthFromArm)
|
||||
OffsetLengthFromArm = MathHelper.Lerp(OffsetLengthFromArm, MaxOffsetLengthFromArm, RecoilResolveSpeed);
|
||||
|
||||
Projectile.ForceNetUpdate();
|
||||
if (Projectile.owner == Main.myPlayer)
|
||||
Projectile.ForceNetUpdate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
public int maxFrames = 420;
|
||||
public int initialFireTime = 45;
|
||||
public float shineScale = 0;
|
||||
private bool secondShot = true;
|
||||
|
||||
public override void KillHoldoutLogic()
|
||||
{
|
||||
@@ -69,6 +70,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
|
||||
OffsetLengthFromArm -= 5f;
|
||||
shineScale = 1;
|
||||
secondShot = false;
|
||||
}
|
||||
if (shootingTimer >= 60 && revFrames < maxFrames)
|
||||
{
|
||||
@@ -81,6 +83,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
Projectile.netUpdate = true;
|
||||
}
|
||||
shootingTimer = 0;
|
||||
secondShot = true;
|
||||
}
|
||||
|
||||
shootingTimer += revSpeed;
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
bool leftShootChecks = Owner.whoAmI == Main.myPlayer && (Main.mouseLeft && !Main.mapFullscreen && !Owner.mouseInterface && shootingCooldown == 0) && hasAmmo;
|
||||
bool rightShootChecks = Owner.whoAmI == Main.myPlayer && (Owner.Calamity().mouseRight && !Main.mapFullscreen && !Owner.mouseInterface && starburstCooldown == 0 && starburstTimer == 0);
|
||||
|
||||
if (Main.mouseLeft && !hasAmmo && OffsetLengthFromArm >= 24.5f)
|
||||
if (Owner.whoAmI == Main.myPlayer && Main.mouseLeft && !hasAmmo && OffsetLengthFromArm >= 24.5f)
|
||||
{
|
||||
OffsetLengthFromArm -= 8;
|
||||
SoundStyle click = new("CalamityMod/Sounds/Item/DudFire");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using CalamityMod.Dusts;
|
||||
using CalamityMod.Items.Weapons.Ranged;
|
||||
using CalamityMod.Particles;
|
||||
@@ -57,6 +58,19 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
public bool naildriver => ((starburstTimer <= starburstPerfectTime + perfectLeniancy) && (starburstTimer >= starburstPerfectTime - perfectLeniancy)); // if within perfect frame window
|
||||
public bool scattershot => !naildriver && ((starburstTimer <= starburstPerfectTime + goodLeniancy) && (starburstTimer >= starburstPerfectTime - goodLeniancy)); // If within early or late frame window
|
||||
public override void KillHoldoutLogic() { }
|
||||
public override void SendExtraAIHoldout(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(lastUseTime);
|
||||
writer.Write(gunPower);
|
||||
writer.Write(lastGunPower);
|
||||
}
|
||||
|
||||
public override void ReceiveExtraAIHoldout(BinaryReader reader)
|
||||
{
|
||||
lastUseTime = reader.ReadInt32();
|
||||
gunPower = reader.ReadInt32();
|
||||
lastGunPower = reader.ReadInt32();
|
||||
}
|
||||
public override void SetDefaults()
|
||||
{
|
||||
base.SetDefaults();
|
||||
@@ -97,10 +111,10 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
return;
|
||||
}
|
||||
bool hasAmmo = Owner.PickAmmo(HeldItem, out _, out _, out _, out _, out _, true);
|
||||
bool leftShootChecks = (Main.mouseLeft && !Main.mapFullscreen && !Owner.mouseInterface && shootingCooldown == 0) && hasAmmo;
|
||||
bool rightShootChecks = Owner.Calamity().mouseRight && !Main.mapFullscreen && !Owner.mouseInterface && starburstCooldown == 0 && starburstTimer == 0;
|
||||
bool leftShootChecks = Owner.whoAmI == Main.myPlayer && (Main.mouseLeft && !Main.mapFullscreen && !Owner.mouseInterface && shootingCooldown == 0) && hasAmmo;
|
||||
bool rightShootChecks = Owner.whoAmI == Main.myPlayer && Owner.Calamity().mouseRight && !Main.mapFullscreen && !Owner.mouseInterface && starburstCooldown == 0 && starburstTimer == 0;
|
||||
|
||||
if (Main.mouseLeft && !hasAmmo && shake < 0.1f)
|
||||
if (Owner.whoAmI == Main.myPlayer && Main.mouseLeft && !hasAmmo && shake < 0.1f)
|
||||
{
|
||||
shake = 0.8f;
|
||||
SoundStyle click = new("CalamityMod/Sounds/Item/DudFire");
|
||||
@@ -111,6 +125,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
FireShotgun();
|
||||
if (rightShootChecks)
|
||||
{
|
||||
Projectile.ForceNetUpdate();
|
||||
SoundStyle blast1 = new("CalamityMod/Sounds/Item/StarfleetStarburst");
|
||||
AudSlot1 = SoundEngine.PlaySound(blast1 with { Volume = 0.7f + gunPower * 0.1f, Pitch = 0f, MaxInstances = 8 }, Projectile.Center);
|
||||
SoundStyle blast2 = new("CalamityMod/Sounds/Item/StarfleetStarburst");
|
||||
@@ -192,6 +207,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
}
|
||||
public void FireShotgun()
|
||||
{
|
||||
Projectile.ForceNetUpdate();
|
||||
// 50% chance to not consume ammo
|
||||
Owner.PickAmmo(HeldItem, out _, out _, out _, out _, out _, Main.rand.NextBool());
|
||||
|
||||
|
||||
Reference in new issue
Block a user