Files
CalamityModPublic/Projectiles/Rogue/BouncyBol.cs
T
Ozzatron 60688c4259 Merge of BasicallyIAmFox's Entity Iterators PR with 2.0.4.001
- Some entity iterators were intentionally excluded due to complex merge conflicts with fully reworked weapons.
- NOTABLE: ProjectileUtils generic homing code had its iterator excluded due to a behavioral change which was not easily resolved.
2024-05-13 21:42:17 -04:00

103 lines
3.3 KiB
C#

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Rogue
{
public class BouncyBol : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
public override string Texture => "CalamityMod/Items/Weapons/Rogue/BouncySpikyBall";
private bool hasHitEnemy = false;
private int targetNPC = -1;
private List<int> previousNPCs = new List<int>() { -1 };
public override void SetDefaults()
{
Projectile.width = 14;
Projectile.height = 14;
Projectile.friendly = true;
Projectile.penetrate = 8;
Projectile.timeLeft = 600;
Projectile.DamageType = RogueDamageClass.Instance;
Projectile.aiStyle = ProjAIStyleID.GroundProjectile;
}
public override void AI()
{
if (hasHitEnemy && Projectile.timeLeft < 575)
{
Projectile.velocity.X *= 1.005f; //you broke up, time to yeet yourself out
Projectile.velocity.Y *= 1.005f;
if (Projectile.velocity.X > 16f)
{
Projectile.velocity.X = 16f;
}
if (Projectile.velocity.Y > 16f)
{
Projectile.velocity.Y = 16f;
}
}
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
float minDist = 999f;
int index = 0;
foreach (NPC npc in Main.ActiveNPCs)
{
bool hasHitNPC = false;
for (int j = 0; j < previousNPCs.Count; j++)
{
if (previousNPCs[j] == npc.whoAmI)
{
hasHitNPC = true;
}
}
if (npc == target)
{
previousNPCs.Add(npc.whoAmI);
}
if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC)
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = npc.whoAmI;
}
}
}
Vector2 velocityNew;
if (minDist < 999f)
{
Projectile.damage = (int)(Projectile.damage * 1.1f);
hasHitEnemy = true;
targetNPC = index;
velocityNew = Main.npc[index].Center - Projectile.Center;
velocityNew.Normalize();
velocityNew *= 15f;
Projectile.velocity = velocityNew;
}
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
if (Projectile.velocity.X != oldVelocity.X)
{
Projectile.velocity.X = -oldVelocity.X * 1.001f;
}
if (Projectile.velocity.Y != oldVelocity.Y)
{
Projectile.velocity.Y = -oldVelocity.Y * 1.001f;
}
return false;
}
}
}