250 lines
9.2 KiB
C#
250 lines
9.2 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
using Terraria.Audio;
|
|
namespace CalamityMod.Projectiles.Summon
|
|
{
|
|
public class BabyPlaguebringer : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Summon";
|
|
public override string Texture => "CalamityMod/Projectiles/Pets/PlaguebringerBab";
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.projFrames[Projectile.type] = 6;
|
|
ProjectileID.Sets.MinionShot[Projectile.type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 56;
|
|
Projectile.height = 46;
|
|
Projectile.netImportant = true;
|
|
Projectile.friendly = true;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = 15;
|
|
Projectile.MaxUpdates = 2;
|
|
Projectile.minionSlots = 0f;
|
|
Projectile.timeLeft = 360;
|
|
Projectile.penetrate = 3;
|
|
Projectile.tileCollide = false;
|
|
Projectile.timeLeft *= 5;
|
|
Projectile.minion = true;
|
|
Projectile.DamageType = DamageClass.Summon;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
if ((double)Math.Abs(Projectile.velocity.X) > 0.2)
|
|
{
|
|
Projectile.spriteDirection = -Projectile.direction;
|
|
}
|
|
float num633 = 800f;
|
|
float num634 = 1200f;
|
|
float num635 = 3000f;
|
|
float num636 = 500f;
|
|
|
|
//lighting
|
|
float num = (float)Main.rand.Next(90, 111) * 0.01f;
|
|
num *= Main.essScale;
|
|
Lighting.AddLight(Projectile.Center, 0f * num, 0.75f * num, 0f * num);
|
|
|
|
bool flag24 = false;
|
|
if (Projectile.ai[0] == 2f)
|
|
{
|
|
Projectile.ai[1] += 1f;
|
|
Projectile.extraUpdates = 1;
|
|
Projectile.frameCounter++;
|
|
if (Projectile.frameCounter > 3)
|
|
{
|
|
Projectile.frame++;
|
|
Projectile.frameCounter = 0;
|
|
}
|
|
if (Projectile.frame > 5 || Projectile.frame < 4)
|
|
{
|
|
Projectile.frame = 4;
|
|
}
|
|
if (Projectile.ai[1] > 30f)
|
|
{
|
|
Projectile.ai[1] = 1f;
|
|
Projectile.ai[0] = 0f;
|
|
Projectile.extraUpdates = 0;
|
|
Projectile.numUpdates = 0;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
else
|
|
{
|
|
flag24 = true;
|
|
}
|
|
}
|
|
if (flag24)
|
|
{
|
|
return;
|
|
}
|
|
Vector2 vector46 = Projectile.position;
|
|
bool flag25 = false;
|
|
if (player.HasMinionAttackTargetNPC)
|
|
{
|
|
NPC npc = Main.npc[player.MinionAttackTargetNPC];
|
|
if (npc.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float num646 = Vector2.Distance(npc.Center, Projectile.Center);
|
|
if (!flag25 && num646 < num633)
|
|
{
|
|
num633 = num646;
|
|
vector46 = npc.Center;
|
|
flag25 = true;
|
|
}
|
|
}
|
|
}
|
|
if (!flag25)
|
|
{
|
|
for (int num645 = 0; num645 < Main.maxNPCs; num645++)
|
|
{
|
|
NPC nPC2 = Main.npc[num645];
|
|
if (nPC2.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float num646 = Vector2.Distance(nPC2.Center, Projectile.Center);
|
|
if (!flag25 && num646 < num633)
|
|
{
|
|
num633 = num646;
|
|
vector46 = nPC2.Center;
|
|
flag25 = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
float num647 = num634;
|
|
if (flag25)
|
|
{
|
|
num647 = num635;
|
|
}
|
|
if (Vector2.Distance(player.Center, Projectile.Center) > num647)
|
|
{
|
|
Projectile.ai[0] = 1f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
if (flag25 && Projectile.ai[0] == 0f)
|
|
{
|
|
Vector2 vector47 = vector46 - Projectile.Center;
|
|
float num648 = vector47.Length();
|
|
vector47.Normalize();
|
|
if (num648 > 200f)
|
|
{
|
|
float scaleFactor2 = 8f;
|
|
vector47 *= scaleFactor2;
|
|
Projectile.velocity = (Projectile.velocity * 40f + vector47) / 41f;
|
|
}
|
|
else
|
|
{
|
|
float num649 = 4f;
|
|
vector47 *= -num649;
|
|
Projectile.velocity = (Projectile.velocity * 40f + vector47) / 41f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag26 = false;
|
|
if (!flag26)
|
|
{
|
|
flag26 = Projectile.ai[0] == 1f;
|
|
}
|
|
float num650 = 6f;
|
|
if (flag26)
|
|
{
|
|
num650 = 15f;
|
|
}
|
|
Vector2 center2 = Projectile.Center;
|
|
Vector2 vector48 = player.Center - center2 + new Vector2(0f, -60f);
|
|
float num651 = vector48.Length();
|
|
if (num651 > 200f && num650 < 8f)
|
|
{
|
|
num650 = 8f;
|
|
}
|
|
if (num651 < num636 && flag26 && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height))
|
|
{
|
|
Projectile.ai[0] = 0f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
if (num651 > 2000f)
|
|
{
|
|
Projectile.position.X = Main.player[Projectile.owner].Center.X - (float)(Projectile.width / 2);
|
|
Projectile.position.Y = Main.player[Projectile.owner].Center.Y - (float)(Projectile.height / 2);
|
|
Projectile.netUpdate = true;
|
|
}
|
|
if (num651 > 70f)
|
|
{
|
|
vector48.Normalize();
|
|
vector48 *= num650;
|
|
Projectile.velocity = (Projectile.velocity * 40f + vector48) / 41f;
|
|
}
|
|
else if (Projectile.velocity.X == 0f && Projectile.velocity.Y == 0f)
|
|
{
|
|
Projectile.velocity.X = -0.15f;
|
|
Projectile.velocity.Y = -0.05f;
|
|
}
|
|
}
|
|
Projectile.frameCounter++;
|
|
if (Projectile.frameCounter > 12)
|
|
{
|
|
Projectile.frame++;
|
|
Projectile.frameCounter = 0;
|
|
}
|
|
if (Projectile.frame >= 4)
|
|
{
|
|
Projectile.frame = 0;
|
|
}
|
|
if (Projectile.ai[1] > 0f)
|
|
{
|
|
Projectile.ai[1] += (float)Main.rand.Next(1, 4);
|
|
}
|
|
if (Projectile.ai[1] > 40f)
|
|
{
|
|
Projectile.ai[1] = 0f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
if (Projectile.ai[0] == 0f)
|
|
{
|
|
if (Projectile.ai[1] == 0f && flag25 && num633 < 500f)
|
|
{
|
|
Projectile.ai[1] += 1f;
|
|
if (Main.myPlayer == Projectile.owner)
|
|
{
|
|
Projectile.ai[0] = 2f;
|
|
Vector2 value20 = vector46 - Projectile.Center;
|
|
value20.Normalize();
|
|
Projectile.velocity = value20 * 8f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
SoundEngine.PlaySound(SoundID.NPCHit4, Projectile.position);
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
SpriteEffects spriteEffects = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
|
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
|
|
int num214 = texture.Height / Main.projFrames[Projectile.type];
|
|
int y6 = num214 * Projectile.frame;
|
|
Vector2 origin = new Vector2(texture.Width / 2f, num214 / 2f);
|
|
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Rectangle(0, y6, texture.Width, num214), Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, spriteEffects, 0);
|
|
return false;
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(ModContent.BuffType<Plague>(), 120);
|
|
|
|
public override void OnHitPlayer(Player target, Player.HurtInfo info) => target.AddBuff(ModContent.BuffType<Plague>(), 120);
|
|
}
|
|
}
|