Made the Squirrel Minion less crazy
This commit is contained in:
1 parent
8e870cbaab
commit
bba4c631d5
3 files changed
+186
-489
No files matched your search
@@ -1,11 +1,12 @@
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace CalamityMod.Projectiles.Summon
|
||||
{
|
||||
public class SquirrelSquireAcorn : ModProjectile
|
||||
{
|
||||
public const float Gravity = 0.5f;
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Acorn");
|
||||
@@ -20,22 +21,18 @@ namespace CalamityMod.Projectiles.Summon
|
||||
projectile.minion = true;
|
||||
projectile.penetrate = 2;
|
||||
projectile.timeLeft = 180;
|
||||
projectile.aiStyle = 1;
|
||||
}
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
projectile.velocity.X *= 0.9995f;
|
||||
projectile.velocity.Y = projectile.velocity.Y + 0.01f;
|
||||
projectile.rotation += MathHelper.ToRadians(180) * projectile.direction;
|
||||
projectile.velocity.Y += Gravity;
|
||||
projectile.rotation += (projectile.velocity.X > 0f).ToDirectionInt() * 0.3f;
|
||||
}
|
||||
|
||||
public override void Kill(int timeLeft)
|
||||
{
|
||||
for (int k = 0; k < 5; k++)
|
||||
{
|
||||
Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 7, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using CalamityMod.Buffs.Summon;
|
||||
using CalamityMod.CalPlayer;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
@@ -10,7 +11,15 @@ namespace CalamityMod.Projectiles.Summon
|
||||
{
|
||||
public class SquirrelSquireMinion : ModProjectile
|
||||
{
|
||||
public float dust = 0f;
|
||||
public int StuckTimer;
|
||||
public bool TryingToGetCloseToOwner
|
||||
{
|
||||
get => projectile.ai[0] == 1f;
|
||||
set => projectile.ai[0] = value.ToInt();
|
||||
}
|
||||
public ref float AttackTimer => ref projectile.ai[1];
|
||||
public bool OnSolidGround => projectile.velocity.Y == 0f && WorldGen.SolidTile((int) projectile.Center.X / 16, (int) projectile.Bottom.Y / 16 + 2);
|
||||
public Player Owner => Main.player[projectile.owner];
|
||||
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
@@ -22,7 +31,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
projectile.width = 64;
|
||||
projectile.width = 34;
|
||||
projectile.height = 64;
|
||||
projectile.netImportant = true;
|
||||
projectile.friendly = true;
|
||||
@@ -35,498 +44,178 @@ namespace CalamityMod.Projectiles.Summon
|
||||
projectile.minion = true;
|
||||
}
|
||||
|
||||
public override void SendExtraAI(BinaryWriter writer) => writer.Write(StuckTimer);
|
||||
|
||||
public override void ReceiveExtraAI(BinaryReader reader) => StuckTimer = reader.ReadInt32();
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
Player player = Main.player[projectile.owner];
|
||||
CalamityPlayer modPlayer = player.Calamity();
|
||||
CalamityGlobalProjectile modProj = projectile.Calamity();
|
||||
if (dust == 0f)
|
||||
if (projectile.localAI[0] == 0f)
|
||||
{
|
||||
modProj.spawnedPlayerMinionDamageValue = player.MinionDamage();
|
||||
modProj.spawnedPlayerMinionProjectileDamageValue = projectile.damage;
|
||||
int dustAmt = 36;
|
||||
for (int d = 0; d < dustAmt; d++)
|
||||
{
|
||||
Vector2 source = Vector2.Normalize(projectile.velocity) * new Vector2((float)projectile.width / 2f, (float)projectile.height) * 0.75f;
|
||||
source = source.RotatedBy((double)((float)(d - (dustAmt / 2 - 1)) * MathHelper.TwoPi / (float)dustAmt), default) + projectile.Center;
|
||||
Vector2 dustVel = source - projectile.Center;
|
||||
int dusty = Dust.NewDust(source + dustVel, 0, 0, 7, dustVel.X * 1.1f, dustVel.Y * 1.1f, 100, default, 1.4f);
|
||||
Main.dust[dusty].noGravity = true;
|
||||
Main.dust[dusty].noLight = true;
|
||||
Main.dust[dusty].velocity = dustVel;
|
||||
}
|
||||
dust += 1f;
|
||||
DoInitializationEffects();
|
||||
projectile.localAI[0] = 1f;
|
||||
}
|
||||
if (player.MinionDamage() != modProj.spawnedPlayerMinionDamageValue)
|
||||
|
||||
// Re-adjust damage as needed.
|
||||
if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue)
|
||||
{
|
||||
int damage2 = (int)((float)modProj.spawnedPlayerMinionProjectileDamageValue /
|
||||
modProj.spawnedPlayerMinionDamageValue *
|
||||
player.MinionDamage());
|
||||
projectile.damage = damage2;
|
||||
int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / projectile.Calamity().spawnedPlayerMinionDamageValue * Owner.MinionDamage());
|
||||
projectile.damage = trueDamage;
|
||||
}
|
||||
bool projTypeCheck = projectile.type == ModContent.ProjectileType<SquirrelSquireMinion>();
|
||||
player.AddBuff(ModContent.BuffType<SquirrelSquireBuff>(), 3600);
|
||||
if (projTypeCheck)
|
||||
|
||||
projectile.frameCounter++;
|
||||
|
||||
VerifyIdentity();
|
||||
if (!projectile.WithinRange(Owner.Center, 1000f) || TryingToGetCloseToOwner || Collision.SolidCollision(projectile.position + Vector2.One * 4f, projectile.width - 8, projectile.height - 8))
|
||||
{
|
||||
if (player.dead)
|
||||
// Once far off, don't go back to normal until 350 pixels away from the owner or less.
|
||||
TryingToGetCloseToOwner = !projectile.WithinRange(Owner.Center, 350f) && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height);
|
||||
|
||||
ReturnToOwner();
|
||||
if (!projectile.WithinRange(Owner.Center, 2000f))
|
||||
{
|
||||
modPlayer.squirrel = false;
|
||||
projectile.Center = Owner.Center;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
if (modPlayer.squirrel)
|
||||
{
|
||||
projectile.tileCollide = false;
|
||||
return;
|
||||
}
|
||||
|
||||
NPC potentialTarget = projectile.Center.MinionHoming(800f, Owner, false);
|
||||
if (potentialTarget is null)
|
||||
FollowOwner();
|
||||
else
|
||||
AttackTarget(potentialTarget);
|
||||
|
||||
projectile.rotation = 0f;
|
||||
projectile.tileCollide = true;
|
||||
}
|
||||
|
||||
public void DoInitializationEffects()
|
||||
{
|
||||
projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage();
|
||||
projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage;
|
||||
|
||||
int dustQuantity = 36;
|
||||
for (int d = 0; d < dustQuantity; d++)
|
||||
{
|
||||
Dust dust = Dust.NewDustPerfect(projectile.Center, 7);
|
||||
dust.scale = 1.4f;
|
||||
dust.velocity = (MathHelper.TwoPi * d / dustQuantity).ToRotationVector2() * 4f;
|
||||
dust.noGravity = true;
|
||||
dust.noLight = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void VerifyIdentity()
|
||||
{
|
||||
Owner.AddBuff(ModContent.BuffType<SquirrelSquireBuff>(), 3600);
|
||||
if (projectile.type == ModContent.ProjectileType<SquirrelSquireMinion>())
|
||||
{
|
||||
if (Owner.dead)
|
||||
Owner.Calamity().squirrel = false;
|
||||
if (Owner.Calamity().squirrel)
|
||||
projectile.timeLeft = 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnToOwner()
|
||||
{
|
||||
projectile.frame = 12 + projectile.frameCounter / 8 % 4;
|
||||
projectile.velocity = projectile.velocity.MoveTowards(projectile.SafeDirectionTo(Owner.Top) * 8f, 0.8f);
|
||||
projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt();
|
||||
projectile.rotation = projectile.velocity.X * 0.025f;
|
||||
}
|
||||
|
||||
public void AttemptToJumpToDestination(Vector2 destination)
|
||||
{
|
||||
if (OnSolidGround)
|
||||
{
|
||||
float jumpSpeed = MathHelper.Lerp(6f, 13f, Utils.InverseLerp(100f, 250f, MathHelper.Distance(projectile.Center.X, destination.X), true));
|
||||
projectile.velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(projectile.Center, Owner.Center, 0.4f, jumpSpeed);
|
||||
projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt();
|
||||
projectile.netUpdate = true;
|
||||
projectile.frame = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (projectile.frameCounter % 5 == 4 && projectile.frame < 7)
|
||||
projectile.frame++;
|
||||
}
|
||||
}
|
||||
|
||||
public void FollowOwner()
|
||||
{
|
||||
projectile.rotation = 0f;
|
||||
|
||||
// Slow down and just idly vibe if close enough to the owner.
|
||||
float horizontalDistanceFromOwner = MathHelper.Distance(projectile.Center.X, Owner.Center.X);
|
||||
float verticalDistanceFromOwner = MathHelper.Distance(projectile.Center.Y, Owner.Center.Y);
|
||||
if (horizontalDistanceFromOwner < 100f && verticalDistanceFromOwner < 450f)
|
||||
{
|
||||
projectile.velocity.X *= 0.94f;
|
||||
if (OnSolidGround)
|
||||
{
|
||||
projectile.frame = projectile.frameCounter / 5 % 4;
|
||||
projectile.velocity *= 0.9f;
|
||||
}
|
||||
StuckTimer = 0;
|
||||
}
|
||||
|
||||
// Otherwise try to catch up with them on foot.
|
||||
else
|
||||
{
|
||||
AttemptToJumpToDestination(Owner.Center);
|
||||
// Determine if there's something in the way of this minion and its owner.
|
||||
if (!Collision.CanHit(projectile.position, projectile.width, projectile.height, Owner.Center, 2, 2) || MathHelper.Distance(projectile.position.X, projectile.oldPosition.X) < 1f)
|
||||
{
|
||||
StuckTimer++;
|
||||
|
||||
// If stuck for a sufficiently long time fly to the owner again.
|
||||
if (StuckTimer > 180)
|
||||
{
|
||||
TryingToGetCloseToOwner = true;
|
||||
StuckTimer = 0;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
}
|
||||
else if (StuckTimer > 0)
|
||||
StuckTimer--;
|
||||
}
|
||||
|
||||
// Enforce gravity.
|
||||
projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f);
|
||||
}
|
||||
|
||||
public void AttackTarget(NPC target)
|
||||
{
|
||||
float horizontalDistanceFromTarget = MathHelper.Distance(projectile.Center.X, target.Center.X);
|
||||
|
||||
if (horizontalDistanceFromTarget > 350f)
|
||||
AttemptToJumpToDestination(target.Center);
|
||||
else if (OnSolidGround)
|
||||
{
|
||||
projectile.velocity.X *= 0.94f;
|
||||
if (OnSolidGround)
|
||||
{
|
||||
projectile.frame = projectile.frameCounter / 5 % 4;
|
||||
projectile.velocity *= 0.9f;
|
||||
}
|
||||
AttackTimer++;
|
||||
|
||||
// Pelt the target with acorns.
|
||||
projectile.frame = 8 + (int)(AttackTimer / 6.4) % 4;
|
||||
if (Main.myPlayer == projectile.owner && AttackTimer % 30f == 27f)
|
||||
{
|
||||
projectile.spriteDirection = (target.Center.X > projectile.Center.X).ToDirectionInt();
|
||||
Vector2 acornSpawnPosition = projectile.Center + new Vector2(projectile.spriteDirection * 6f, 10f);
|
||||
float acornShootSpeed = 14f;
|
||||
Vector2 acornShootVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(acornSpawnPosition, target.Center + target.velocity * 25f, SquirrelSquireAcorn.Gravity, acornShootSpeed);
|
||||
Projectile.NewProjectile(acornSpawnPosition, acornShootVelocity, ModContent.ProjectileType<SquirrelSquireAcorn>(), projectile.damage, projectile.knockBack, projectile.owner);
|
||||
}
|
||||
}
|
||||
bool leftofPlayer = false;
|
||||
bool rightofPlayer = false;
|
||||
bool flag3 = false;
|
||||
bool flag4 = false;
|
||||
if (projectile.lavaWet)
|
||||
{
|
||||
projectile.ai[0] = 1f;
|
||||
projectile.ai[1] = 0f;
|
||||
}
|
||||
float minionOffset = 40f * (projectile.minionPos + 1f) * player.direction;
|
||||
if (player.Center.X < projectile.Center.X - 10f + minionOffset)
|
||||
leftofPlayer = true;
|
||||
else if (player.Center.X > projectile.Center.X + 10f + minionOffset)
|
||||
rightofPlayer = true;
|
||||
|
||||
if (projectile.ai[1] == 0f)
|
||||
{
|
||||
float playerDist = (player.Center - projectile.Center).Length();
|
||||
if (playerDist > 1000f)
|
||||
{
|
||||
projectile.ai[0] = 1f;
|
||||
}
|
||||
if (playerDist > 2000f) //teleport to player if too far
|
||||
{
|
||||
projectile.position = player.position;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
}
|
||||
if (projectile.ai[0] != 0f) //flying back to the player
|
||||
{
|
||||
projectile.tileCollide = false;
|
||||
float npcDetectRange = 800f;
|
||||
bool npcFound = false;
|
||||
int targetIndex = -1;
|
||||
for (int index = 0; index < Main.maxNPCs; ++index)
|
||||
{
|
||||
NPC npc = Main.npc[index];
|
||||
if (npc.CanBeChasedBy(projectile, false))
|
||||
{
|
||||
float npcDist = Vector2.Distance(npc.Center, player.Center);
|
||||
if (npcDist < npcDetectRange)
|
||||
{
|
||||
if (Collision.CanHit(projectile.position, projectile.width, projectile.height, npc.position, npc.width, npc.height))
|
||||
targetIndex = index;
|
||||
npcFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return to normal if npc found
|
||||
if (npcFound && targetIndex >= 0)
|
||||
projectile.ai[0] = 0f;
|
||||
|
||||
Vector2 homeBase = player.Center - projectile.Center;
|
||||
homeBase.X -= 40f * player.direction;
|
||||
if (!npcFound)
|
||||
homeBase.X -= 40f * projectile.minionPos * player.direction;
|
||||
homeBase.Y -= 60f;
|
||||
float playerDist = homeBase.Length();
|
||||
float speed = playerDist;
|
||||
float acceleration = 0.4f;
|
||||
|
||||
//if close enough to the player and has tile to stand on, return to normal
|
||||
if (playerDist < 100f && player.velocity.Y == 0f && projectile.Bottom.Y <= player.Bottom.Y && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height))
|
||||
{
|
||||
projectile.ai[0] = 0f;
|
||||
if (projectile.velocity.Y < -6f)
|
||||
projectile.velocity.Y = -6f;
|
||||
}
|
||||
if (playerDist > 2000f)
|
||||
{
|
||||
projectile.position = player.position;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
if (playerDist < 50f)
|
||||
{
|
||||
if (Math.Abs(projectile.velocity.X) > 2f || Math.Abs(projectile.velocity.Y) > 2f)
|
||||
{
|
||||
projectile.velocity *= 0.99f;
|
||||
}
|
||||
acceleration = 0.01f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (playerDist < 100f)
|
||||
{
|
||||
acceleration = 0.1f;
|
||||
}
|
||||
if (playerDist > 300f)
|
||||
{
|
||||
acceleration = 1f;
|
||||
}
|
||||
playerDist = speed / playerDist;
|
||||
homeBase *= playerDist;
|
||||
}
|
||||
if (projectile.velocity.X < homeBase.X)
|
||||
{
|
||||
projectile.velocity.X += acceleration;
|
||||
if (acceleration > 0.05f && projectile.velocity.X < 0f)
|
||||
{
|
||||
projectile.velocity.X += acceleration;
|
||||
}
|
||||
}
|
||||
if (projectile.velocity.X > homeBase.X)
|
||||
{
|
||||
projectile.velocity.X -= acceleration;
|
||||
if (acceleration > 0.05f && projectile.velocity.X > 0f)
|
||||
{
|
||||
projectile.velocity.X -= acceleration;
|
||||
}
|
||||
}
|
||||
if (projectile.velocity.Y < homeBase.Y)
|
||||
{
|
||||
projectile.velocity.Y += acceleration;
|
||||
if (acceleration > 0.05f && projectile.velocity.Y < 0f)
|
||||
{
|
||||
projectile.velocity.Y += acceleration * 2f;
|
||||
}
|
||||
}
|
||||
if (projectile.velocity.Y > homeBase.Y)
|
||||
{
|
||||
projectile.velocity.Y -= acceleration;
|
||||
if (acceleration > 0.05f && projectile.velocity.Y > 0f)
|
||||
{
|
||||
projectile.velocity.Y -= acceleration * 2f;
|
||||
}
|
||||
}
|
||||
if (projectile.frame < 12 || projectile.frame == 16)
|
||||
{
|
||||
projectile.frame = 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
projectile.frameCounter++;
|
||||
if (projectile.frameCounter > 3)
|
||||
{
|
||||
projectile.frame++;
|
||||
projectile.frameCounter = 0;
|
||||
}
|
||||
if (projectile.frame >= 16)
|
||||
{
|
||||
projectile.frame = 13;
|
||||
}
|
||||
}
|
||||
if (projectile.velocity.X > 0.5f)
|
||||
projectile.spriteDirection = 1;
|
||||
else if (projectile.velocity.X < -0.5f)
|
||||
projectile.spriteDirection = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
float minionOffset2 = (float)(40 * projectile.minionPos);
|
||||
float attackCooldown = 30f;
|
||||
float directionCooldown = 60f;
|
||||
--projectile.localAI[0];
|
||||
if (projectile.localAI[0] < 0f)
|
||||
projectile.localAI[0] = 0f;
|
||||
if (projectile.ai[1] > 0f)
|
||||
{
|
||||
--projectile.ai[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 targetPos = projectile.position;
|
||||
float range = 100000f;
|
||||
float maxDist = range;
|
||||
int targetIndex = -1;
|
||||
NPC target = projectile.OwnerMinionAttackTargetNPC;
|
||||
if (target != null && target.CanBeChasedBy(projectile, false))
|
||||
{
|
||||
float npcDist = Vector2.Distance(target.Center, projectile.Center);
|
||||
if (npcDist < range)
|
||||
{
|
||||
if (targetIndex == -1 && npcDist <= maxDist)
|
||||
{
|
||||
maxDist = npcDist;
|
||||
targetPos = target.Center;
|
||||
}
|
||||
if (Collision.CanHit(projectile.Center, projectile.width, projectile.height, target.Center, target.width, target.height))
|
||||
{
|
||||
range = npcDist;
|
||||
targetPos = target.Center;
|
||||
targetIndex = target.whoAmI;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targetIndex == -1)
|
||||
{
|
||||
for (int index = 0; index < Main.maxNPCs; ++index)
|
||||
{
|
||||
NPC npc = Main.npc[index];
|
||||
if (npc.CanBeChasedBy(projectile, false))
|
||||
{
|
||||
float npcDist = Vector2.Distance(npc.Center, projectile.Center);
|
||||
if (npcDist < range)
|
||||
{
|
||||
if (targetIndex == -1 && npcDist <= maxDist)
|
||||
{
|
||||
maxDist = npcDist;
|
||||
targetPos = npc.Center;
|
||||
}
|
||||
if (Collision.CanHit(projectile.Center, projectile.width, projectile.height, npc.Center, npc.width, npc.height))
|
||||
{
|
||||
range = npcDist;
|
||||
targetPos = npc.Center;
|
||||
targetIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targetIndex == -1 && maxDist < range)
|
||||
range = maxDist;
|
||||
float num13 = 400f;
|
||||
if ((double)projectile.position.Y > Main.worldSurface * 16D)
|
||||
num13 = 200f;
|
||||
if (range < num13 + minionOffset2 && targetIndex == -1)
|
||||
{
|
||||
float xDist = targetPos.X - projectile.Center.X;
|
||||
if (xDist < -5f)
|
||||
{
|
||||
leftofPlayer = true;
|
||||
rightofPlayer = false;
|
||||
}
|
||||
else if (xDist > 5f)
|
||||
{
|
||||
rightofPlayer = true;
|
||||
leftofPlayer = false;
|
||||
}
|
||||
}
|
||||
else if (targetIndex >= 0 && range < 800f + minionOffset2)
|
||||
{
|
||||
projectile.localAI[0] = directionCooldown;
|
||||
float xDist = targetPos.X - projectile.Center.X;
|
||||
if (Math.Abs(xDist) > 300f)
|
||||
{
|
||||
if (xDist < -50f)
|
||||
{
|
||||
leftofPlayer = true;
|
||||
rightofPlayer = false;
|
||||
}
|
||||
else if (xDist > 50f)
|
||||
{
|
||||
rightofPlayer = true;
|
||||
leftofPlayer = false;
|
||||
}
|
||||
}
|
||||
else if (projectile.owner == Main.myPlayer)
|
||||
{
|
||||
projectile.ai[1] = attackCooldown;
|
||||
float speed = 12f;
|
||||
Vector2 source = projectile.Center - Vector2.UnitY * 8f;
|
||||
Vector2 projVel = targetPos - source;
|
||||
projVel.X += Main.rand.NextFloat(-10f, 10f);
|
||||
projVel.Y += Main.rand.NextFloat(-10f, 10f) - Math.Abs(projVel.X) * Main.rand.NextFloat(0.0001f, 0.01f);
|
||||
projVel.Normalize();
|
||||
projVel *= speed;
|
||||
int damage = projectile.damage;
|
||||
int projType = ModContent.ProjectileType<SquirrelSquireAcorn>();
|
||||
int index = Projectile.NewProjectile(source, projVel, projType, damage, projectile.knockBack, projectile.owner);
|
||||
if (projVel.X < 0f)
|
||||
projectile.direction = projectile.spriteDirection = -1;
|
||||
else if (projVel.X > 0f)
|
||||
projectile.direction = projectile.spriteDirection = 1;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (projectile.ai[1] != 0f) //If on attack cooldown
|
||||
{
|
||||
leftofPlayer = false;
|
||||
rightofPlayer = false;
|
||||
}
|
||||
else if (projectile.localAI[0] == 0f)
|
||||
projectile.direction = projectile.spriteDirection = player.direction;
|
||||
projectile.tileCollide = true;
|
||||
float num18 = 0.2f;
|
||||
float num19 = 6f;
|
||||
if (num19 < Math.Abs(player.velocity.X) + Math.Abs(player.velocity.Y))
|
||||
{
|
||||
num19 = Math.Abs(player.velocity.X) + Math.Abs(player.velocity.Y);
|
||||
num18 = 0.3f;
|
||||
}
|
||||
if (leftofPlayer)
|
||||
{
|
||||
if (projectile.velocity.X > -3.5f)
|
||||
projectile.velocity.X -= num18;
|
||||
else
|
||||
projectile.velocity.X -= num18 * 0.25f;
|
||||
}
|
||||
else if (rightofPlayer)
|
||||
{
|
||||
if (projectile.velocity.X < 3.5f)
|
||||
projectile.velocity.X += num18;
|
||||
else
|
||||
projectile.velocity.X += num18 * 0.25f;
|
||||
}
|
||||
else
|
||||
{
|
||||
projectile.velocity.X *= 0.9f;
|
||||
if (projectile.velocity.X >= -num18 && projectile.velocity.X <= num18)
|
||||
projectile.velocity.X = 0f;
|
||||
}
|
||||
if (leftofPlayer | rightofPlayer)
|
||||
{
|
||||
int i = (int)projectile.Center.X / 16;
|
||||
int j = (int)projectile.Center.Y / 16;
|
||||
if (leftofPlayer)
|
||||
--i;
|
||||
if (rightofPlayer)
|
||||
++i;
|
||||
if (WorldGen.SolidTile(i + (int)projectile.velocity.X, j))
|
||||
flag4 = true;
|
||||
}
|
||||
if (player.position.Y + player.height - 8f > projectile.position.Y + projectile.height)
|
||||
flag3 = true;
|
||||
Collision.StepUp(ref projectile.position, ref projectile.velocity, projectile.width, projectile.height, ref projectile.stepSpeed, ref projectile.gfxOffY, 1, false, 0);
|
||||
if (projectile.velocity.Y == 0f)
|
||||
{
|
||||
if (!flag3 && (projectile.velocity.X < 0f || projectile.velocity.X > 0f))
|
||||
{
|
||||
int i = (int)projectile.Center.X / 16;
|
||||
int j = (int)projectile.Center.Y / 16 + 1;
|
||||
if (leftofPlayer)
|
||||
--i;
|
||||
if (rightofPlayer)
|
||||
++i;
|
||||
WorldGen.SolidTile(i, j);
|
||||
}
|
||||
if (flag4)
|
||||
{
|
||||
int i = (int)projectile.Center.X / 16;
|
||||
int j = (int)projectile.Center.Y / 16 + 1;
|
||||
if (WorldGen.SolidTile(i, j) || Main.tile[i, j].halfBrick() || (int)Main.tile[i, j].slope() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
int i2 = (int)projectile.Center.X / 16;
|
||||
int j2 = (int)projectile.Center.Y / 16;
|
||||
if (leftofPlayer)
|
||||
--i2;
|
||||
if (rightofPlayer)
|
||||
++i2;
|
||||
i2 += (int)projectile.velocity.X;
|
||||
if (!WorldGen.SolidTile(i2, j2 - 1) && !WorldGen.SolidTile(i2, j2 - 2))
|
||||
projectile.velocity.Y = -5.1f;
|
||||
else if (!WorldGen.SolidTile(i2, j2 - 2))
|
||||
projectile.velocity.Y = -7.1f;
|
||||
else if (WorldGen.SolidTile(i2, j2 - 5))
|
||||
projectile.velocity.Y = -11.1f;
|
||||
else if (WorldGen.SolidTile(i2, j2 - 4))
|
||||
projectile.velocity.Y = -10.1f;
|
||||
else
|
||||
projectile.velocity.Y = -9.1f;
|
||||
}
|
||||
catch
|
||||
{
|
||||
projectile.velocity.Y = -9.1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (projectile.velocity.X > num19)
|
||||
projectile.velocity.X = num19;
|
||||
if (projectile.velocity.X < -num19)
|
||||
projectile.velocity.X = -num19;
|
||||
if (projectile.velocity.X < -0.05f)
|
||||
projectile.direction = projectile.spriteDirection = -1;
|
||||
if (projectile.velocity.X > 0.05f)
|
||||
projectile.direction = projectile.spriteDirection = 1;
|
||||
if (projectile.ai[1] > 0f)
|
||||
{
|
||||
if (projectile.localAI[1] == 0f)
|
||||
{
|
||||
projectile.localAI[1] = 1f;
|
||||
projectile.frame = 8;
|
||||
}
|
||||
if (projectile.frame >= 8 && projectile.frame <= 11)
|
||||
{
|
||||
projectile.frameCounter++;
|
||||
if (projectile.frameCounter > 8)
|
||||
{
|
||||
projectile.frame++;
|
||||
projectile.frameCounter = 0;
|
||||
}
|
||||
if (projectile.frame == 11)
|
||||
projectile.frame = 8;
|
||||
}
|
||||
}
|
||||
else if (projectile.velocity.Y == 0f)
|
||||
{
|
||||
projectile.localAI[1] = 0f;
|
||||
if (projectile.velocity.X == 0f)
|
||||
{
|
||||
projectile.frameCounter++;
|
||||
if (projectile.frameCounter > 4)
|
||||
{
|
||||
projectile.frame++;
|
||||
projectile.frameCounter = 0;
|
||||
}
|
||||
if (projectile.frame >= 4)
|
||||
{
|
||||
projectile.frame = 0;
|
||||
}
|
||||
}
|
||||
else if (Math.Abs(projectile.velocity.X) > 0.8f)
|
||||
{
|
||||
projectile.frameCounter += (int)Math.Abs(projectile.velocity.X);
|
||||
projectile.frameCounter++;
|
||||
if (projectile.frameCounter > 20)
|
||||
{
|
||||
projectile.frame++;
|
||||
projectile.frameCounter = 0;
|
||||
}
|
||||
if (projectile.frame < 4)
|
||||
projectile.frame = 4;
|
||||
if (projectile.frame >= 8)
|
||||
projectile.frame = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
projectile.frameCounter++;
|
||||
if (projectile.frameCounter > 4)
|
||||
{
|
||||
projectile.frame++;
|
||||
projectile.frameCounter = 0;
|
||||
}
|
||||
if (projectile.frame >= 4)
|
||||
{
|
||||
projectile.frame = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (projectile.velocity.Y < 0f)
|
||||
{
|
||||
projectile.frameCounter = 0;
|
||||
projectile.frame = 16;
|
||||
}
|
||||
else if (projectile.velocity.Y > 0f)
|
||||
{
|
||||
projectile.frameCounter = 0;
|
||||
projectile.frame = 16;
|
||||
}
|
||||
projectile.velocity.Y += 0.4f;
|
||||
if (projectile.velocity.Y > 10f)
|
||||
projectile.velocity.Y = 10f;
|
||||
Vector2 velocity = projectile.velocity;
|
||||
}
|
||||
}
|
||||
projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f);
|
||||
}
|
||||
|
||||
public override bool CanDamage() => false;
|
||||
|
||||
|
||||
@@ -61,5 +61,16 @@ namespace CalamityMod
|
||||
int num4 = Math.Max(0, Math.Min(tileRectangle.Bottom, Main.maxTilesY));
|
||||
return new Rectangle(num, num2, num3 - num, num4 - num2);
|
||||
}
|
||||
|
||||
// REMOVE THIS IN CALAMITY 1.4, it's a 1.4 Utils.cs function.
|
||||
// Due to its temporary state, this method will not receive an XML documentation comment.
|
||||
public static Vector2 MoveTowards(this Vector2 currentPosition, Vector2 targetPosition, float maxAmountAllowedToMove)
|
||||
{
|
||||
Vector2 v = targetPosition - currentPosition;
|
||||
if (v.Length() < maxAmountAllowedToMove)
|
||||
return targetPosition;
|
||||
|
||||
return currentPosition + v.SafeNormalize(Vector2.Zero) * maxAmountAllowedToMove;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user