227 lines
9.9 KiB
C#
227 lines
9.9 KiB
C#
using CalamityMod.Buffs.Summon;
|
|
using CalamityMod.CalPlayer;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Summon
|
|
{
|
|
public class DankCreeperMinion : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Summon";
|
|
public override void SetStaticDefaults()
|
|
{
|
|
ProjectileID.Sets.MinionSacrificable[Projectile.type] = true;
|
|
ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 30;
|
|
Projectile.height = 30;
|
|
Projectile.netImportant = true;
|
|
Projectile.friendly = true;
|
|
Projectile.minionSlots = 1;
|
|
Projectile.timeLeft = 18000;
|
|
Projectile.penetrate = -1;
|
|
Projectile.timeLeft *= 5;
|
|
Projectile.minion = true;
|
|
Projectile.tileCollide = false;
|
|
Projectile.MaxUpdates = 3;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = Projectile.MaxUpdates * 24;
|
|
Projectile.DamageType = DamageClass.Summon;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
CalamityPlayer modPlayer = player.Calamity();
|
|
if (Projectile.localAI[0] == 0f)
|
|
{
|
|
int num226 = 36;
|
|
for (int num227 = 0; num227 < num226; num227++)
|
|
{
|
|
Vector2 vector6 = Vector2.Normalize(Projectile.velocity) * new Vector2((float)Projectile.width / 2f, (float)Projectile.height) * 0.75f;
|
|
vector6 = vector6.RotatedBy((double)((float)(num227 - (num226 / 2 - 1)) * 6.28318548f / (float)num226), default) + Projectile.Center;
|
|
Vector2 vector7 = vector6 - Projectile.Center;
|
|
int num228 = Dust.NewDust(vector6 + vector7, 0, 0, 14, vector7.X * 1.5f, vector7.Y * 1.5f, 100, default, 1.4f);
|
|
Main.dust[num228].noGravity = true;
|
|
Main.dust[num228].noLight = true;
|
|
Main.dust[num228].velocity = vector7;
|
|
}
|
|
Projectile.localAI[0] += 1f;
|
|
}
|
|
bool flag64 = Projectile.type == ModContent.ProjectileType<DankCreeperMinion>();
|
|
player.AddBuff(ModContent.BuffType<DankCreeperBuff>(), 3600);
|
|
if (flag64)
|
|
{
|
|
if (player.dead)
|
|
{
|
|
modPlayer.dCreeper = false;
|
|
}
|
|
if (modPlayer.dCreeper)
|
|
{
|
|
Projectile.timeLeft = 2;
|
|
}
|
|
}
|
|
Projectile.MinionAntiClump();
|
|
float num535 = Projectile.position.X;
|
|
float num536 = Projectile.position.Y;
|
|
float num537 = 1300f;
|
|
bool flag19 = false;
|
|
int num538 = 1100;
|
|
if (Projectile.ai[1] != 0f)
|
|
{
|
|
num538 = 1800;
|
|
}
|
|
if (Math.Abs(Projectile.Center.X - Main.player[Projectile.owner].Center.X) + Math.Abs(Projectile.Center.Y - Main.player[Projectile.owner].Center.Y) > (float)num538)
|
|
{
|
|
Projectile.ai[0] = 1f;
|
|
}
|
|
if (Projectile.ai[0] == 0f)
|
|
{
|
|
if (player.HasMinionAttackTargetNPC)
|
|
{
|
|
NPC npc = Main.npc[player.MinionAttackTargetNPC];
|
|
if (npc.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float num539 = npc.position.X + (float)(npc.width / 2);
|
|
float num540 = npc.position.Y + (float)(npc.height / 2);
|
|
float num541 = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - num539) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - num540);
|
|
if (num541 < num537 && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height))
|
|
{
|
|
num535 = num539;
|
|
num536 = num540;
|
|
flag19 = true;
|
|
}
|
|
}
|
|
}
|
|
if (!flag19)
|
|
{
|
|
for (int num542 = 0; num542 < Main.maxNPCs; num542++)
|
|
{
|
|
if (Main.npc[num542].CanBeChasedBy(Projectile, false))
|
|
{
|
|
float num543 = Main.npc[num542].position.X + (float)(Main.npc[num542].width / 2);
|
|
float num544 = Main.npc[num542].position.Y + (float)(Main.npc[num542].height / 2);
|
|
float num545 = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - num543) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - num544);
|
|
if (num545 < num537 && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[num542].position, Main.npc[num542].width, Main.npc[num542].height))
|
|
{
|
|
num537 = num545;
|
|
num535 = num543;
|
|
num536 = num544;
|
|
flag19 = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!flag19)
|
|
{
|
|
float num546 = 8f;
|
|
if (Projectile.ai[0] == 1f)
|
|
{
|
|
num546 = 12f;
|
|
}
|
|
Vector2 vector42 = new Vector2(Projectile.position.X + (float)Projectile.width * 0.5f, Projectile.position.Y + (float)Projectile.height * 0.5f);
|
|
float num547 = player.Center.X - vector42.X;
|
|
float num548 = player.Center.Y - vector42.Y - 60f;
|
|
float num549 = (float)Math.Sqrt((double)(num547 * num547 + num548 * num548));
|
|
if (num549 < 100f && Projectile.ai[0] == 1f && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height))
|
|
{
|
|
Projectile.ai[0] = 0f;
|
|
}
|
|
if (num549 > 2000f)
|
|
{
|
|
Projectile.position.X = player.Center.X - (float)(Projectile.width / 2);
|
|
Projectile.position.Y = player.Center.Y - (float)(Projectile.width / 2);
|
|
}
|
|
if (num549 > 70f)
|
|
{
|
|
num549 = num546 / num549;
|
|
num547 *= num549;
|
|
num548 *= num549;
|
|
Projectile.velocity.X = (Projectile.velocity.X * 20f + num547) / 21f;
|
|
Projectile.velocity.Y = (Projectile.velocity.Y * 20f + num548) / 21f;
|
|
}
|
|
else
|
|
{
|
|
if (Projectile.velocity.X == 0f && Projectile.velocity.Y == 0f)
|
|
{
|
|
Projectile.velocity.X = -0.15f;
|
|
Projectile.velocity.Y = -0.05f;
|
|
}
|
|
Projectile.velocity *= 1.01f;
|
|
}
|
|
Projectile.rotation = Projectile.velocity.X * 0.05f;
|
|
if ((double)Math.Abs(Projectile.velocity.X) > 0.2)
|
|
{
|
|
Projectile.spriteDirection = -Projectile.direction;
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Projectile.ai[1] == -1f)
|
|
{
|
|
Projectile.ai[1] = 11f;
|
|
}
|
|
if (Projectile.ai[1] > 0f)
|
|
{
|
|
Projectile.ai[1] -= 1f;
|
|
}
|
|
if (Projectile.ai[1] == 0f)
|
|
{
|
|
float num550 = 8f; //12
|
|
Vector2 vector43 = new Vector2(Projectile.position.X + (float)Projectile.width * 0.5f, Projectile.position.Y + (float)Projectile.height * 0.5f);
|
|
float num551 = num535 - vector43.X;
|
|
float num552 = num536 - vector43.Y;
|
|
float num553 = (float)Math.Sqrt((double)(num551 * num551 + num552 * num552));
|
|
if (num553 < 100f)
|
|
{
|
|
num550 = 10f; //14
|
|
}
|
|
num553 = num550 / num553;
|
|
num551 *= num553;
|
|
num552 *= num553;
|
|
Projectile.velocity.X = (Projectile.velocity.X * 40f + num551) / 41f;
|
|
Projectile.velocity.Y = (Projectile.velocity.Y * 40f + num552) / 41f;
|
|
}
|
|
else
|
|
{
|
|
if (Math.Abs(Projectile.velocity.X) + Math.Abs(Projectile.velocity.Y) < 10f)
|
|
{
|
|
Projectile.velocity *= 1.05f;
|
|
}
|
|
}
|
|
Projectile.rotation = Projectile.velocity.X * 0.05f;
|
|
if ((double)Math.Abs(Projectile.velocity.X) > 0.2)
|
|
{
|
|
Projectile.spriteDirection = -Projectile.direction;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
|
|
{
|
|
if (Projectile.owner == Main.myPlayer)
|
|
{
|
|
Projectile.ai[1] = -1f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
Texture2D tex = ModContent.Request<Texture2D>(Texture).Value;
|
|
Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0);
|
|
return false;
|
|
}
|
|
}
|
|
}
|