Turned Squirrel Squire into a sentry (Forgive me for my sins)
This commit is contained in:
1 parent
12a9523e41
commit
fcd7b0adca
7 files changed
+34
-216
No files matched your search
@@ -1,37 +0,0 @@
|
||||
using CalamityMod.CalPlayer;
|
||||
using CalamityMod.Projectiles.Summon;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Buffs.Summon
|
||||
{
|
||||
public class SquirrelSquireBuff : ModBuff
|
||||
{
|
||||
public override void SetDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Squirrel Squire");
|
||||
Description.SetDefault("The squirrel squire will protect you");
|
||||
Main.buffNoTimeDisplay[Type] = true;
|
||||
Main.buffNoSave[Type] = true;
|
||||
//Main.persistentBuff[Type] = true;
|
||||
}
|
||||
|
||||
public override void Update(Player player, ref int buffIndex)
|
||||
{
|
||||
CalamityPlayer modPlayer = player.Calamity();
|
||||
if (player.ownedProjectileCounts[ModContent.ProjectileType<SquirrelSquireMinion>()] > 0)
|
||||
{
|
||||
modPlayer.squirrel = true;
|
||||
}
|
||||
if (!modPlayer.squirrel)
|
||||
{
|
||||
player.DelBuff(buffIndex);
|
||||
buffIndex--;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.buffTime[buffIndex] = 18000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 693 B |
@@ -999,7 +999,6 @@ namespace CalamityMod.CalPlayer
|
||||
public bool aValkyrie = false;
|
||||
public bool apexShark = false;
|
||||
public bool gastricBelcher = false;
|
||||
public bool squirrel = false;
|
||||
public bool hauntedDishes = false;
|
||||
public bool stormjaw = false;
|
||||
public bool sGod = false;
|
||||
@@ -2026,7 +2025,6 @@ namespace CalamityMod.CalPlayer
|
||||
endoCooper = false;
|
||||
apexShark = false;
|
||||
gastricBelcher = false;
|
||||
squirrel = false;
|
||||
hauntedDishes = false;
|
||||
stormjaw = false;
|
||||
SPG = false;
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace CalamityMod.Items.Weapons.Summon
|
||||
item.shoot = ModContent.ProjectileType<SquirrelSquireMinion>();
|
||||
item.shootSpeed = 10f;
|
||||
item.summon = true;
|
||||
item.sentry = true;
|
||||
}
|
||||
|
||||
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
|
||||
@@ -41,7 +42,8 @@ namespace CalamityMod.Items.Weapons.Summon
|
||||
speedX = 0;
|
||||
speedY = 0;
|
||||
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0f, 30f);
|
||||
//projectile.ai[1] is attack cooldown. Setting it here prevents immediate attacks
|
||||
player.UpdateMaxTurrets();
|
||||
//projectile.ai[1] is attack cooldown. Setting it here prevents immediate attacks
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -874,7 +874,6 @@ namespace CalamityMod
|
||||
{
|
||||
sAssociation.Call("AddMinionInfo", summonItem, summonBuff, summonProjectile);
|
||||
}
|
||||
RegisterSummon(ItemType<SquirrelSquireStaff>(), BuffType<SquirrelSquireBuff>(), ProjectileType<SquirrelSquireMinion>());
|
||||
RegisterSummon(ItemType<WulfrumController>(), BuffType<WulfrumDroidBuff>(), ProjectileType<WulfrumDroid>());
|
||||
RegisterSummon(ItemType<SunSpiritStaff>(), BuffType<SolarSpirit>(), ProjectileType<SolarPixie>());
|
||||
RegisterSummon(ItemType<FrostBlossomStaff>(), BuffType<FrostBlossomBuff>(), ProjectileType<FrostBlossom>());
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Acorn");
|
||||
ProjectileID.Sets.MinionShot[projectile.type] = true;
|
||||
ProjectileID.Sets.SentryShot[projectile.type] = true;
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
|
||||
@@ -11,28 +11,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
{
|
||||
public class SquirrelSquireMinion : ModProjectile
|
||||
{
|
||||
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
|
||||
{
|
||||
get
|
||||
{
|
||||
bool groundSolid = false;
|
||||
for (int i = (int)projectile.Left.X / 16 - 1; i < (int)projectile.Right.X / 16 + 1; i++)
|
||||
{
|
||||
bool bottomTileSolid = CalamityUtils.ParanoidTileRetrieval(i, (int)projectile.Bottom.Y / 16).IsTileSolidGround();
|
||||
bool firstTileDownSolid = CalamityUtils.ParanoidTileRetrieval(i, (int)projectile.Bottom.Y / 16 + 1).IsTileSolidGround();
|
||||
bool secondTileDownSolid = CalamityUtils.ParanoidTileRetrieval(i, (int)projectile.Bottom.Y / 16 + 2).IsTileSolidGround();
|
||||
groundSolid |= bottomTileSolid || firstTileDownSolid || secondTileDownSolid;
|
||||
}
|
||||
return projectile.velocity.Y == 0f && groundSolid;
|
||||
}
|
||||
}
|
||||
public bool Attacking
|
||||
{
|
||||
get => projectile.localAI[1] == 1f;
|
||||
@@ -45,7 +24,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
DisplayName.SetDefault("Squirrel Squire");
|
||||
ProjectileID.Sets.MinionSacrificable[projectile.type] = true;
|
||||
ProjectileID.Sets.MinionTargettingFeature[projectile.type] = true;
|
||||
Main.projFrames[projectile.type] = 17;
|
||||
Main.projFrames[projectile.type] = 17; //About half of these frames are now unused, but I'll still keep them here incase
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
@@ -55,18 +34,13 @@ namespace CalamityMod.Projectiles.Summon
|
||||
projectile.netImportant = true;
|
||||
projectile.friendly = true;
|
||||
projectile.ignoreWater = true;
|
||||
projectile.minionSlots = 1f;
|
||||
projectile.timeLeft = 18000;
|
||||
projectile.timeLeft = Projectile.SentryLifeTime;
|
||||
projectile.penetrate = -1;
|
||||
projectile.tileCollide = false;
|
||||
projectile.timeLeft *= 5;
|
||||
projectile.tileCollide = true;
|
||||
projectile.minion = true;
|
||||
projectile.sentry = true;
|
||||
}
|
||||
|
||||
public override void SendExtraAI(BinaryWriter writer) => writer.Write(StuckTimer);
|
||||
|
||||
public override void ReceiveExtraAI(BinaryReader reader) => StuckTimer = reader.ReadInt32();
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
if (projectile.localAI[0] == 0f)
|
||||
@@ -82,28 +56,23 @@ namespace CalamityMod.Projectiles.Summon
|
||||
projectile.damage = trueDamage;
|
||||
}
|
||||
|
||||
projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f);
|
||||
projectile.frameCounter++;
|
||||
|
||||
VerifyIdentity();
|
||||
if (!projectile.WithinRange(Owner.Center, 1000f) || TryingToGetCloseToOwner || Collision.SolidCollision(projectile.position + Vector2.One * 4f, projectile.width - 8, projectile.height - 8))
|
||||
{
|
||||
// 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))
|
||||
{
|
||||
projectile.Center = Owner.Center;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
projectile.tileCollide = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Attacking = false;
|
||||
NPC potentialTarget = projectile.Center.MinionHoming(800f, Owner, false);
|
||||
if (potentialTarget is null)
|
||||
FollowOwner();
|
||||
{
|
||||
if (projectile.frameCounter > 3)
|
||||
{
|
||||
projectile.frame++;
|
||||
projectile.frameCounter = 0;
|
||||
}
|
||||
if (projectile.frame > 3)
|
||||
{
|
||||
projectile.frame = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Attacking = true;
|
||||
@@ -112,6 +81,7 @@ namespace CalamityMod.Projectiles.Summon
|
||||
|
||||
projectile.rotation = 0f;
|
||||
projectile.tileCollide = true;
|
||||
projectile.StickToTiles(false, false);
|
||||
}
|
||||
|
||||
public void DoInitializationEffects()
|
||||
@@ -130,144 +100,30 @@ namespace CalamityMod.Projectiles.Summon
|
||||
}
|
||||
}
|
||||
|
||||
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(8f, 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);
|
||||
AttackTimer++;
|
||||
|
||||
// Determine if the minion is stuck.
|
||||
if (MathHelper.Distance(projectile.position.X, projectile.oldPosition.X) < 1f)
|
||||
// Pelt the target with acorns.
|
||||
projectile.frame = 8 + (int)(AttackTimer / 6.4) % 4;
|
||||
if (Main.myPlayer == projectile.owner && AttackTimer % 30f == 27f)
|
||||
{
|
||||
StuckTimer++;
|
||||
projectile.spriteDirection = (target.Center.X > projectile.Center.X).ToDirectionInt();
|
||||
Vector2 acornSpawnPosition = projectile.Center + new Vector2(projectile.spriteDirection * 6f, 10f);
|
||||
float acornShootSpeed = MathHelper.Lerp(15f, 32f, projectile.Distance(target.Center) / 800f);
|
||||
Vector2 acornShootVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(acornSpawnPosition, target.Top + target.velocity * 25f, SquirrelSquireAcorn.Gravity, acornShootSpeed);
|
||||
|
||||
// If stuck for a sufficiently long time fly to the owner again.
|
||||
if (StuckTimer > 180)
|
||||
{
|
||||
TryingToGetCloseToOwner = true;
|
||||
StuckTimer = 0;
|
||||
projectile.netUpdate = true;
|
||||
}
|
||||
if (projectile.WithinRange(target.Center, 200f))
|
||||
acornShootVelocity = (target.Center - acornSpawnPosition).SafeNormalize(-Vector2.UnitY) * acornShootSpeed;
|
||||
|
||||
Projectile.NewProjectile(acornSpawnPosition, acornShootVelocity, ModContent.ProjectileType<SquirrelSquireAcorn>(), projectile.damage, projectile.knockBack, projectile.owner);
|
||||
}
|
||||
else if (StuckTimer > 0)
|
||||
StuckTimer--;
|
||||
|
||||
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 = MathHelper.Lerp(15f, 32f, projectile.Distance(target.Center) / 800f);
|
||||
Vector2 acornShootVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(acornSpawnPosition, target.Top + target.velocity * 25f, SquirrelSquireAcorn.Gravity, acornShootSpeed);
|
||||
|
||||
if (projectile.WithinRange(target.Center, 200f))
|
||||
acornShootVelocity = (target.Center - acornSpawnPosition).SafeNormalize(-Vector2.UnitY) * acornShootSpeed;
|
||||
|
||||
Projectile.NewProjectile(acornSpawnPosition, acornShootVelocity, ModContent.ProjectileType<SquirrelSquireAcorn>(), projectile.damage, projectile.knockBack, projectile.owner);
|
||||
}
|
||||
}
|
||||
projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f);
|
||||
projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.4f, -12f, 12f);
|
||||
}
|
||||
|
||||
public override bool CanDamage() => false;
|
||||
|
||||
public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough)
|
||||
{
|
||||
fallThrough = !Attacking && projectile.Bottom.Y < Owner.Top.Y;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnTileCollide(Vector2 oldVelocity) => false;
|
||||
|
||||
public override void Kill(int timeLeft)
|
||||
|
||||
Reference in new issue
Block a user