DirectionTo safening
This commit is contained in:
1 parent
8a112b2b91
commit
2f060b9398
24 files changed
+34
-39
No files matched your search
@@ -67,7 +67,7 @@ namespace CalamityMod.Items.Weapons.Magic
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector2 spawnOffset = player.DirectionTo(Main.MouseWorld).RotatedBy(offsetAngle) * -Main.rand.NextFloat(40f, 96f);
|
||||
Vector2 spawnOffset = player.SafeDirectionTo(Main.MouseWorld, Vector2.UnitY).RotatedBy(offsetAngle) * -Main.rand.NextFloat(40f, 96f);
|
||||
Vector2 shootDirection = (Main.MouseWorld - (position + spawnOffset)).SafeNormalize(Vector2.UnitX * player.direction);
|
||||
int beam = Projectile.NewProjectile(position + spawnOffset, shootDirection * shootSpeed, type, damage, knockBack, player.whoAmI);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace CalamityMod.Items.Weapons.Melee
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Violence");
|
||||
Tooltip.SetDefault("Does things");
|
||||
Tooltip.SetDefault("Releases a blazing fork which stays near the mouse and shreds enemies");
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
@@ -37,17 +37,12 @@ namespace CalamityMod.Items.Weapons.Melee
|
||||
item.shootSpeed = 15f;
|
||||
}
|
||||
|
||||
public override bool AltFunctionUse(Player player) => true;
|
||||
|
||||
public override bool CanUseItem(Player player) => player.altFunctionUse == 2 || player.ownedProjectileCounts[item.shoot] <= 0;
|
||||
|
||||
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)
|
||||
return true;
|
||||
|
||||
Vector2 shootVelocity = new Vector2(speedX, speedY);
|
||||
Projectile.NewProjectile(position, shootVelocity, ModContent.ProjectileType<ViolenceSlashProjectile>(), damage, knockBack, player.whoAmI, 0f, shootVelocity.ToRotation());
|
||||
Projectile.NewProjectile(position, shootVelocity, type, damage, knockBack, player.whoAmI, 0f, shootVelocity.ToRotation());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
|
||||
FlyAcceleration = MathHelper.Lerp(FlyAcceleration, idealFlyAcceleration, 0.3f);
|
||||
|
||||
float directionToTargetOrthogonality = Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.DirectionTo(destination));
|
||||
float directionToTargetOrthogonality = Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.SafeDirectionTo(destination));
|
||||
|
||||
// Fly towards the target if it's far.
|
||||
if (distanceFromDestination > 320f)
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
NPC potentialTarget = projectile.Center.ClosestNPCAt(180f, false);
|
||||
if (potentialTarget != null)
|
||||
{
|
||||
Vector2 shootVelocity = projectile.DirectionTo(potentialTarget.Center) * 13f;
|
||||
Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 13f;
|
||||
Projectile.NewProjectile(projectile.Center - shootVelocity * 2.5f, shootVelocity, ModContent.ProjectileType<FabBolt>(), projectile.damage, projectile.knockBack, projectile.owner);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
projectile.velocity = projectile.velocity.RotatedBy(MathHelper.Clamp(angleOffset, -0.2f, 0.2f));
|
||||
projectile.velocity = projectile.velocity.SafeNormalize(-Vector2.UnitY) * (projectile.velocity.Length() + HomingAcceleration);
|
||||
|
||||
if (Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.DirectionTo(target.Center)) < 0.75f)
|
||||
if (Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.SafeDirectionTo(target.Center)) < 0.75f)
|
||||
projectile.velocity *= 0.75f;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace CalamityMod.Projectiles.Magic
|
||||
float delayFactor = Utils.InverseLerp(20f, 35f, Time, true);
|
||||
float homeSpeed = MathHelper.Lerp(0f, 0.075f, delayFactor);
|
||||
|
||||
projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.DirectionTo(target.Center) * 16f, homeSpeed);
|
||||
projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(target.Center) * 16f, homeSpeed);
|
||||
projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitY) * oldSpeed;
|
||||
projectile.position += (target.Center - projectile.Center).SafeNormalize(Vector2.Zero) * MathHelper.Lerp(25f, 1f, Utils.InverseLerp(100f, 360f, projectile.Distance(target.Center), true)) * delayFactor;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace CalamityMod.Projectiles.Melee
|
||||
|
||||
if (Main.myPlayer == projectile.owner && !projectile.WithinRange(Main.MouseWorld, projectile.height + 15f))
|
||||
{
|
||||
projectile.velocity = projectile.DirectionTo(Main.MouseWorld);
|
||||
projectile.velocity = projectile.SafeDirectionTo(Main.MouseWorld);
|
||||
projectile.netSpam = 0;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace CalamityMod.Projectiles.Melee
|
||||
{
|
||||
ReturnToOwner();
|
||||
|
||||
float idealAngle = projectile.AngleTo(Owner.Center) - MathHelper.PiOver4 + MathHelper.Pi;
|
||||
float idealAngle = projectile.AngleTo(Owner.Center) - MathHelper.PiOver4;
|
||||
projectile.rotation = projectile.rotation.AngleLerp(idealAngle, 0.1f);
|
||||
projectile.rotation = projectile.rotation.AngleTowards(idealAngle, 0.25f);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace CalamityMod.Projectiles.Melee
|
||||
if (projectile.WithinRange(Main.MouseWorld, projectile.velocity.Length() * 0.7f))
|
||||
projectile.Center = Main.MouseWorld;
|
||||
else
|
||||
projectile.velocity = (projectile.velocity * 6f + projectile.DirectionTo(Main.MouseWorld) * 14f) / 7f;
|
||||
projectile.velocity = (projectile.velocity * 3f + projectile.DirectionTo(Main.MouseWorld) * 19f) / 4f;
|
||||
projectile.netSpam = 0;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace CalamityMod.Projectiles.Melee
|
||||
internal void ReturnToOwner()
|
||||
{
|
||||
projectile.Center = Vector2.Lerp(projectile.Center, Owner.Center, 0.02f);
|
||||
projectile.velocity = projectile.DirectionTo(Owner.Center) * 15f;
|
||||
projectile.velocity = projectile.SafeDirectionTo(Owner.Center) * 22f;
|
||||
if (projectile.Hitbox.Intersects(Owner.Hitbox))
|
||||
{
|
||||
for (int i = 0; i < 75; i++)
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
|
||||
NPC potentialTarget = projectile.Center.ClosestNPCAt(1500f, false);
|
||||
if (potentialTarget != null)
|
||||
projectile.velocity = (projectile.velocity * 29f + projectile.DirectionTo(potentialTarget.Center) * 21f) / 30f;
|
||||
projectile.velocity = (projectile.velocity * 29f + projectile.SafeDirectionTo(potentialTarget.Center) * 21f) / 30f;
|
||||
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2;
|
||||
Time++;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
{
|
||||
NPC potentialTarget = projectile.Center.ClosestNPCAt(1050f);
|
||||
if (potentialTarget != null)
|
||||
projectile.velocity = (projectile.velocity * 12f + projectile.DirectionTo(potentialTarget.Center) * 19f) / 13f;
|
||||
projectile.velocity = (projectile.velocity * 12f + projectile.SafeDirectionTo(potentialTarget.Center) * 19f) / 13f;
|
||||
}
|
||||
else
|
||||
projectile.velocity *= 1.05f;
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
Vector2 laserOrigin = frame.Size() * 0.5f;
|
||||
while (remainingDistance > frame.Height * laserScale)
|
||||
{
|
||||
Vector2 laserDrawPosition = projectile.Center + projectile.DirectionTo(destination) * remainingDistance - Main.screenPosition;
|
||||
Vector2 laserDrawPosition = projectile.Center + projectile.SafeDirectionTo(destination, -Vector2.UnitY) * remainingDistance - Main.screenPosition;
|
||||
spriteBatch.Draw(laserTexture, laserDrawPosition, frame, laserColor, rotation, laserOrigin, laserScale, SpriteEffects.None, 0f);
|
||||
remainingDistance -= frame.Height * laserScale;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace CalamityMod.Projectiles.Rogue
|
||||
|
||||
if (!projectile.WithinRange(target.Center, 30f))
|
||||
{
|
||||
projectile.velocity = (projectile.velocity * 5f + projectile.DirectionTo(target.Center) * newSpeed) / 6f;
|
||||
projectile.velocity = (projectile.velocity * 5f + projectile.SafeDirectionTo(target.Center) * newSpeed) / 6f;
|
||||
projectile.velocity = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(target.Center), 0.15f).ToRotationVector2() * newSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace CalamityMod.Projectiles.Rogue
|
||||
if (ReturningToOwner)
|
||||
{
|
||||
projectile.timeLeft = 2;
|
||||
projectile.velocity = projectile.DirectionTo(Owner.Center) * 24f;
|
||||
projectile.velocity = projectile.SafeDirectionTo(Owner.Center) * 24f;
|
||||
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.Pi + MathHelper.PiOver4;
|
||||
|
||||
// Heal the player and disappear when touching them.
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
Main.PlaySound(SoundID.Item122, ArmPosition);
|
||||
if (Main.myPlayer == projectile.owner)
|
||||
{
|
||||
Vector2 initialVelocity = projectile.DirectionTo(potentialTarget.Center) * 2f;
|
||||
Vector2 initialVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 2f;
|
||||
if (Main.rand.NextBool(2))
|
||||
initialVelocity = initialVelocity.RotatedByRandom(0.4f);
|
||||
float initialAngle = initialVelocity.ToRotation();
|
||||
@@ -148,7 +148,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
}
|
||||
else if (!UsingChargedLaserAttack && AttackTimer == ChargedPelletAttackTime / 2 && Main.myPlayer == projectile.owner)
|
||||
{
|
||||
Vector2 initialVelocity = projectile.DirectionTo(potentialTarget.Center + potentialTarget.velocity * 15f) * 19f;
|
||||
Vector2 initialVelocity = projectile.SafeDirectionTo(potentialTarget.Center + potentialTarget.velocity * 15f) * 19f;
|
||||
Projectile.NewProjectile(ArmPosition, initialVelocity, ModContent.ProjectileType<DaedalusPellet>(), projectile.damage, projectile.knockBack, projectile.owner);
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
projectile.tileCollide = false;
|
||||
|
||||
if (projectile.DistanceSQ(destination - Vector2.UnitY * 16f) > 10f * 10f)
|
||||
projectile.velocity = projectile.DirectionTo(destination - Vector2.UnitY * 16f) * 6f;
|
||||
projectile.velocity = projectile.SafeDirectionTo(destination - Vector2.UnitY * 16f) * 6f;
|
||||
else
|
||||
StuckWalkThroughWallsTimer = 0;
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
internal void FlyNearOwner()
|
||||
{
|
||||
Vector2 destination = Owner.Top - Vector2.UnitY * 45f + (projectile.identity * 0.9f).ToRotationVector2() * 16f;
|
||||
Vector2 idealVelocity = projectile.DirectionTo(destination) * MathHelper.Lerp(2.3f, 8f, Utils.InverseLerp(16f, 160f, projectile.Distance(destination)));
|
||||
Vector2 idealVelocity = projectile.SafeDirectionTo(destination) * MathHelper.Lerp(2.3f, 8f, Utils.InverseLerp(16f, 160f, projectile.Distance(destination)));
|
||||
if (projectile.velocity.Length() < 0.4f)
|
||||
projectile.velocity = Vector2.UnitY.RotatedBy(Main.rand.NextFloat(0.5f, 1.1f) * Main.rand.NextBool(2).ToDirectionInt()) * -3.6f;
|
||||
else if (!projectile.WithinRange(destination, 20f))
|
||||
@@ -110,7 +110,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
{
|
||||
if (Main.myPlayer == projectile.owner && HoverTime % 30 == 29)
|
||||
{
|
||||
Projectile.NewProjectile(projectile.Center, projectile.DirectionTo(target.Center) * 8f, ModContent.ProjectileType<EyeOfNightCell>(), projectile.damage, projectile.knockBack, projectile.owner);
|
||||
Projectile.NewProjectile(projectile.Center, projectile.SafeDirectionTo(target.Center) * 8f, ModContent.ProjectileType<EyeOfNightCell>(), projectile.damage, projectile.knockBack, projectile.owner);
|
||||
HoverTime++;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
|
||||
if (SittingOnGround && HopTimer % 20f == 19f)
|
||||
{
|
||||
projectile.velocity = projectile.DirectionTo(target.Center) * 6f + new Vector2(Math.Sign(projectile.velocity.X) * 2f, -7f);
|
||||
projectile.velocity = projectile.SafeDirectionTo(target.Center) * 6f + new Vector2(Math.Sign(projectile.velocity.X) * 2f, -7f);
|
||||
|
||||
// Release a bunch of blood.
|
||||
if (Main.myPlayer == projectile.owner)
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
NPC potentialTarget = projectile.Center.MinionHoming(1050f, Owner, false);
|
||||
if (Time % 25 == 24 && Main.myPlayer == projectile.owner && potentialTarget != null)
|
||||
{
|
||||
Vector2 shootVelocity = projectile.DirectionTo(potentialTarget.Center) * 10f;
|
||||
Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 10f;
|
||||
Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType<MortalityBeam>(), projectile.damage / 3, projectile.knockBack, projectile.owner);
|
||||
}
|
||||
projectile.Center = player.Center + OffsetAngle.ToRotationVector2() * (150f + (float)Math.Sin(Time * 0.08f) * 15f);
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
public static void HomeInOnTarget(Projectile projectile, NPC target)
|
||||
{
|
||||
float speed = MathHelper.Lerp(11f, 21f, (float)Math.Sin(projectile.identity % 7f / 7f * MathHelper.TwoPi) * 0.5f + 0.5f);
|
||||
projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.DirectionTo(target.Center) * speed, 0.075f);
|
||||
projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(target.Center) * speed, 0.075f);
|
||||
}
|
||||
|
||||
public override Color? GetAlpha(Color lightColor)
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
Time++;
|
||||
NPC potentialTarget = projectile.Center.MinionHoming(1000f, Main.player[projectile.owner], false);
|
||||
if (potentialTarget != null)
|
||||
projectile.velocity = (projectile.velocity * 5f + projectile.DirectionTo(potentialTarget.Center) * 13f) / 6f;
|
||||
projectile.velocity = (projectile.velocity * 5f + projectile.SafeDirectionTo(potentialTarget.Center) * 13f) / 6f;
|
||||
}
|
||||
|
||||
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
projectile.Center = Vector2.Lerp(projectile.Center, destination, 0.03f);
|
||||
|
||||
if (!projectile.WithinRange(destination, 20f))
|
||||
projectile.velocity = (projectile.velocity * 20f + projectile.DirectionTo(destination) * 16f) / 21f;
|
||||
projectile.velocity = (projectile.velocity * 20f + projectile.SafeDirectionTo(destination) * 16f) / 21f;
|
||||
|
||||
if (!projectile.WithinRange(Owner.Center, 1800f))
|
||||
{
|
||||
@@ -142,9 +142,9 @@ namespace CalamityMod.Projectiles.Summon
|
||||
|
||||
projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt();
|
||||
if (!projectile.WithinRange(target.Center, 400f))
|
||||
projectile.velocity = (projectile.velocity * 10f + projectile.DirectionTo(target.Center) * 22f) / 11f;
|
||||
projectile.velocity = (projectile.velocity * 10f + projectile.SafeDirectionTo(target.Center) * 22f) / 11f;
|
||||
else if (projectile.velocity.Length() < 28f)
|
||||
projectile.velocity = projectile.DirectionTo(target.Center) * 29f;
|
||||
projectile.velocity = projectile.SafeDirectionTo(target.Center) * 29f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,14 +48,14 @@ namespace CalamityMod.Projectiles.Summon
|
||||
Vector2 destination = Owner.Center - Vector2.UnitY.RotatedBy(destinationAngularOffset) * 160f;
|
||||
|
||||
if (projectile.DistanceSQ(destination) > 18f * 18f)
|
||||
projectile.velocity = (projectile.velocity * 20f + projectile.DirectionTo(destination) * 9f) / 21f;
|
||||
projectile.velocity = (projectile.velocity * 20f + projectile.SafeDirectionTo(destination) * 9f) / 21f;
|
||||
}
|
||||
else
|
||||
{
|
||||
float nudgedVelocityDirection = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(potentialTarget.Center), 0.078f);
|
||||
projectile.velocity = nudgedVelocityDirection.ToRotationVector2() * MathHelper.Lerp(projectile.velocity.Length(), 16f, 0.25f);
|
||||
if (projectile.DistanceSQ(potentialTarget.Center) < 120f * 120f)
|
||||
projectile.Center += projectile.DirectionTo(potentialTarget.Center) * 3f;
|
||||
if (projectile.WithinRange(potentialTarget.Center, 120f))
|
||||
projectile.Center += projectile.SafeDirectionTo(potentialTarget.Center) * 3f;
|
||||
}
|
||||
if (projectile.ai[0] > 0f)
|
||||
{
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
else if (FiringTime == 80f)
|
||||
{
|
||||
PostSliceDeathTimer = 80;
|
||||
projectile.velocity = projectile.DirectionTo(Main.MouseWorld) * 30f;
|
||||
projectile.velocity = projectile.SafeDirectionTo(Main.MouseWorld) * 30f;
|
||||
}
|
||||
else if (FiringTime == 1f)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
NPC potentialTarget = projectile.Center.MinionHoming(950f, Owner);
|
||||
if (Time % 50 == 49 && Main.myPlayer == projectile.owner && potentialTarget != null)
|
||||
{
|
||||
Vector2 shootVelocity = projectile.DirectionTo(potentialTarget.Center).RotatedByRandom(0.25f) * 8f;
|
||||
Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center).RotatedByRandom(0.25f) * 8f;
|
||||
Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType<WitherBolt>(), projectile.damage, projectile.knockBack, projectile.owner);
|
||||
}
|
||||
projectile.Center = player.Center + OffsetAngle.ToRotationVector2() * 150f;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
|
||||
NPC potentialTarget = projectile.Center.MinionHoming(800f, Main.player[projectile.owner]);
|
||||
if (potentialTarget != null)
|
||||
projectile.velocity = (projectile.velocity * 3f + projectile.DirectionTo(potentialTarget.Center) * oldSpeed) / 4f;
|
||||
projectile.velocity = (projectile.velocity * 3f + projectile.SafeDirectionTo(potentialTarget.Center) * oldSpeed) / 4f;
|
||||
projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitY) * oldSpeed * 1.01f;
|
||||
|
||||
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2;
|
||||
|
||||
Reference in new issue
Block a user