using CalamityMod.CalPlayer; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.BaseProjectiles { /// /// An abstract class that contains the necessary code for a minion to work.
/// Contains useful properties for minions, such as IFrames, Enemy Distance Detection, and sets the Owner and Target. /// Also has a hook, with basic animation code that can be overriden. ///
public abstract class BaseMinionProjectile : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Summon"; #region Properties /// /// Input here the correspondent of the minion. /// public abstract int AssociatedProjectileTypeID { get; } /// /// Input here the correspondent of the minion. /// public abstract int AssociatedBuffTypeID { get; } /// /// Input the reference of the minion bool from with .
/// Example for Elemental Axe: /// public override ref bool AssociatedMinionBool => ref ModdedOwner.eAxe; ///
public abstract ref bool AssociatedMinionBool { get; } /// /// The amount of minion slots this summon consumes.
/// Defaults to 1f. ///
public virtual float MinionSlots => 1f; /// /// The distance in which the minion can detect an enemy, in pixels.
/// is set to this value.
/// Defaults to 1200f (75 tiles). ///
public virtual float EnemyDistanceDetection => 1200f; /// /// The amount of local I-Frames this minion has.
/// Multiplied by so changing won't affect this.
/// Defaults to 10. ///
public int IFrames { get => Projectile.localNPCHitCooldown / Projectile.MaxUpdates; set => Projectile.localNPCHitCooldown = value * Projectile.MaxUpdates; } /// /// If , makes the minion only be able to detect and attack enemies through tiles only when there are any bosses alive.
/// Defaults to . ///
public virtual bool PreHardmodeMinionTileVision => false; /// /// If , makes the minion not target certain NPCs (Like Abyss' or Sunken Sea's enemies) until they're hit.
/// Defaults to . ///
public virtual bool PreventTargettingUntilTargetHit => true; /// /// The frames that it takes to go to the next frame of animation.
/// Defaults to 5. ///
public int FramesUntilNextAnimationFrame { get; set; } = 5; /// /// Set here .
/// Defaults to 2. ///
public int TrailingMode { get; set; } = 2; /// /// Set here .
/// Defaults to 5.
///
public int TrailCacheLength { get; set; } = 5; public Player Owner => Main.player[Projectile.owner]; public CalamityPlayer ModdedOwner => Owner.Calamity(); public NPC Target { get; set; } #endregion public override void SetStaticDefaults() { ProjectileID.Sets.MinionTargettingFeature[Type] = true; ProjectileID.Sets.TrailingMode[Type] = TrailingMode; ProjectileID.Sets.TrailCacheLength[Type] = TrailCacheLength; ProjectileID.Sets.DrawScreenCheckFluff[Type] = (int)EnemyDistanceDetection; } public override void SetDefaults() { Projectile.DamageType = DamageClass.Summon; Projectile.minionSlots = MinionSlots; Projectile.penetrate = -1; Projectile.friendly = true; Projectile.tileCollide = false; Projectile.ignoreWater = true; Projectile.minion = true; Projectile.usesLocalNPCImmunity = true; Projectile.netImportant = true; } public override bool PreAI() { Projectile.Calamity().overridesMinionDamagePrevention = !PreventTargettingUntilTargetHit; return true; } public override void AI() { CheckMinionExistence(); DoAnimation(); ChooseTarget(); MinionAI(); } #region AI Methods /// /// Where all of the actual AI of the minion will be placed. /// public abstract void MinionAI(); /// /// The universal way all minions check if they can still exist. /// public virtual void CheckMinionExistence() { Owner.AddBuff(AssociatedBuffTypeID, 2); if (Type != AssociatedProjectileTypeID) return; if (Owner.dead) AssociatedMinionBool = false; if (AssociatedMinionBool) Projectile.timeLeft = 2; } /// /// Basic animation code that the majority of minions use.
/// It will only run if the minion is set to have more than 1 frame of animation.
/// If something more complex is needed, override it. Or leave it blank if not needed at all. ///
public virtual void DoAnimation() { if (Main.projFrames[Type] <= 1) return; Projectile.frameCounter++; if (Projectile.frameCounter >= FramesUntilNextAnimationFrame * Projectile.MaxUpdates) { Projectile.frameCounter = 0; Projectile.frame = (Projectile.frame + 1) % Main.projFrames[Type]; } } /// /// Where the null property is set to a valid target, a non-null value. /// public virtual void ChooseTarget() => Target = Owner.Center.MinionHoming(EnemyDistanceDetection, Owner, !PreHardmodeMinionTileVision || CalamityPlayer.areThereAnyDamnBosses); #endregion } }