Skip to content

Commit

Permalink
backport small change to dungeon guardian pet AI from 1.4 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Nov 29, 2021
1 parent c94d3ed commit 97670a7
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 2 deletions.
132 changes: 131 additions & 1 deletion Projectiles/Minions/CombatPets/VanillaClonePets/BabySkeletron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using AmuletOfManyMinions.Projectiles.Minions.VanillaClones;
using Microsoft.Xna.Framework;
using System;
using Microsoft.Xna.Framework.Graphics;

namespace AmuletOfManyMinions.Projectiles.Minions.CombatPets.VanillaClonePets
{
Expand All @@ -26,15 +27,30 @@ public class BabySkeletronHeadMinion : CombatPetHoverDasherMinion
{
internal override int BuffId => BuffType<BabySkeletronHeadMinionBuff>();
public override string Texture => "Terraria/Projectile_" + ProjectileID.BabySkeletronHead;

internal override bool DoBumblingMovement => true;

internal static int FallDuration = 90;
internal int fallStartFrame = -FallDuration;
internal bool IsFalling => animationFrame - fallStartFrame < FallDuration;
public override void SetStaticDefaults()
{
base.SetStaticDefaults();
IdleLocationSets.circlingHead.Add(Projectile.type);
}

public override void SetDefaults()
{
base.SetDefaults();
attackThroughWalls = true;
}

public override void Animate(int minFrame = 0, int? maxFrame = null)
{
if(vectorToTarget is null)
if(IsFalling)
{
return;
} else if(vectorToTarget is null)
{
Projectile.rotation = 0.05f * Projectile.velocity.X;
} else
Expand All @@ -43,5 +59,119 @@ public override void Animate(int minFrame = 0, int? maxFrame = null)
}
}

public override void AfterMoving()
{
base.AfterMoving();
Projectile.friendly &= !IsFalling;
}

public override void OnHitTarget(NPC target)
{
// start falling, approximately
if(player.whoAmI != Main.myPlayer)
{
StartFalling();
}
}

public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
StartFalling();
}
private void StartFalling()
{
fallStartFrame = animationFrame;
float xVel = -4 * Math.Sign(Projectile.velocity.X);
float yVel = -4;
Projectile.velocity = new Vector2(xVel, yVel);
}

private void DoFallingMovement()
{
Projectile.velocity.X *= 0.9f;
if(Projectile.velocity.Y < 16)
{
Projectile.velocity.Y += 0.5f;
}
if(animationFrame - fallStartFrame >= FallDuration - 1 || Projectile.Center.X - player.Center.X > 600)
{
// go somewhere off screen before we start falling, synced MP
Vector2 spawnOffset = default;
if(Main.rand.NextBool())
{
spawnOffset.X = Math.Sign(Main.rand.NextFloat() - 0.5f) * (32 + Main.screenWidth / 2);
spawnOffset.Y = Main.rand.Next(Main.screenHeight) - Main.screenHeight/2;
} else
{
spawnOffset.Y = Math.Sign(Main.rand.NextFloat() - 0.5f) * (32 + Main.screenHeight/ 2);
spawnOffset.X = Main.rand.Next(Main.screenWidth) - Main.screenWidth/2;
}
fallStartFrame = animationFrame - FallDuration - 1;
Projectile.position = player.Center + spawnOffset;
Projectile.velocity = Vector2.Zero;
if(player.whoAmI == Main.myPlayer)
{
Projectile.netUpdate = true; // lazy networking implementation here
}
}
}


public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
{
// lots more knockback and damage, but applied after initial damage reduction from defense
knockback += 5;
damage *= 8;
base.ModifyHitNPC(target, ref damage, ref knockback, ref crit, ref hitDirection);
}

public override void IdleMovement(Vector2 vectorToIdlePosition)
{
if(IsFalling)
{
DoFallingMovement();
} else
{
base.IdleMovement(vectorToIdlePosition);
}
}

public override void TargetedMovement(Vector2 vectorToTargetPosition)
{
if(IsFalling)
{
DoFallingMovement();
} else
{
base.TargetedMovement(vectorToTargetPosition);
}
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
lightColor = new Color(
Math.Max(lightColor.R, (byte)25),
Math.Max(lightColor.G, (byte)25),
Math.Max(lightColor.B, (byte)25));
return base.PreDraw(spriteBatch, lightColor);
}

public override Vector2? FindTarget()
{
float searchRange = targetSearchDistance;
if (PlayerTargetPosition(searchRange, player.Center, 0.67f * searchRange, losCenter: player.Center) is Vector2 target)
{
return target - Projectile.Center;
}
else if (SelectedEnemyInRange(searchRange, 0.67f * searchRange, losCenter: player.Center) is Vector2 target2)
{
return target2 - Projectile.Center;
}
else
{
return null;
}
}

}
}
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
displayName = The Amulet Of Many Minions
author = billybobmcbo, SkyanUltra, direwolf420, Metallumere, SPATULA LEMMY
version = 0.13.0.2
version = 0.13.0.3
homepage = https://forums.terraria.org/index.php?threads/the-amulet-of-many-minions.97188/
2 changes: 2 additions & 0 deletions description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ over 30 new minions, and several armor sets and accessories for both Squires and


=== Version History ==
v0.13.0.3 - Minor AI change
- Rework Dungeon Guardian Pet AI to behave more like real Dungeon Guardian
v0.13.0.2 - Bugfixes
- Multiplayer loading fix
- Add missing recipes
Expand Down

0 comments on commit 97670a7

Please sign in to comment.