257 lines
10 KiB
C#
257 lines
10 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;
|
|
using Terraria.Audio;
|
|
namespace CalamityMod.Projectiles.Summon
|
|
{
|
|
public class PinkButterfly : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Summon";
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.projFrames[Projectile.type] = 4;
|
|
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.ignoreWater = true;
|
|
Projectile.minionSlots = 0.5f;
|
|
Projectile.timeLeft = 18000;
|
|
Projectile.penetrate = -1;
|
|
Projectile.tileCollide = false;
|
|
Projectile.timeLeft *= 5;
|
|
Projectile.minion = true;
|
|
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.5f;
|
|
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, 73, vector7.X, vector7.Y, 100, default, 1.1f);
|
|
Main.dust[num228].noGravity = true;
|
|
}
|
|
Projectile.localAI[0] += 1f;
|
|
}
|
|
if (Math.Abs(Projectile.velocity.X) > 0.2f)
|
|
{
|
|
Projectile.spriteDirection = -Projectile.direction;
|
|
}
|
|
Projectile.rotation = Projectile.velocity.X * 0.02f;
|
|
Projectile.frameCounter++;
|
|
if (Projectile.frameCounter > 6)
|
|
{
|
|
Projectile.frame++;
|
|
Projectile.frameCounter = 0;
|
|
}
|
|
if (Projectile.frame > 3)
|
|
{
|
|
Projectile.frame = 0;
|
|
}
|
|
Lighting.AddLight(Projectile.Center, 0.3f, 0.2f, 0.3f);
|
|
float num633 = 1200f;
|
|
float num634 = 1500f;
|
|
float num635 = 2400f;
|
|
float num636 = 150f;
|
|
bool flag64 = Projectile.type == ModContent.ProjectileType<PinkButterfly>();
|
|
player.AddBuff(ModContent.BuffType<ResurrectionButterflyBuff>(), 3600);
|
|
if (flag64)
|
|
{
|
|
if (player.dead)
|
|
{
|
|
modPlayer.resButterfly = false;
|
|
}
|
|
if (modPlayer.resButterfly)
|
|
{
|
|
Projectile.timeLeft = 2;
|
|
}
|
|
}
|
|
Projectile.MinionAntiClump();
|
|
bool flag24 = false;
|
|
if (flag24)
|
|
{
|
|
return;
|
|
}
|
|
Vector2 vector46 = Projectile.position;
|
|
bool flag25 = false;
|
|
int targetIndex = -1;
|
|
if (player.HasMinionAttackTargetNPC)
|
|
{
|
|
NPC npc = Main.npc[player.MinionAttackTargetNPC];
|
|
if ((npc.CanBeChasedBy(Projectile, false) || npc.type == NPCID.DukeFishron) && npc.active)
|
|
{
|
|
float num646 = Vector2.Distance(npc.Center, Projectile.Center);
|
|
if (!flag25 && num646 < num633)
|
|
{
|
|
vector46 = npc.Center;
|
|
flag25 = true;
|
|
targetIndex = npc.whoAmI;
|
|
}
|
|
}
|
|
}
|
|
if (!flag25)
|
|
{
|
|
for (int num645 = 0; num645 < Main.maxNPCs; num645++)
|
|
{
|
|
NPC nPC2 = Main.npc[num645];
|
|
if ((nPC2.CanBeChasedBy(Projectile, false) || nPC2.type == NPCID.DukeFishron) && nPC2.active)
|
|
{
|
|
float num646 = Vector2.Distance(nPC2.Center, Projectile.Center);
|
|
if (!flag25 && num646 < num633)
|
|
{
|
|
num633 = num646;
|
|
vector46 = nPC2.Center;
|
|
flag25 = true;
|
|
targetIndex = num645;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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 = 12f;
|
|
vector47 *= scaleFactor2;
|
|
Projectile.velocity = (Projectile.velocity * 40f + vector47) / 41f;
|
|
}
|
|
else
|
|
{
|
|
float num649 = 6f;
|
|
vector47 *= -num649;
|
|
Projectile.velocity = (Projectile.velocity * 40f + vector47) / 41f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag26 = false;
|
|
if (!flag26)
|
|
{
|
|
flag26 = Projectile.ai[0] == 1f;
|
|
}
|
|
float num650 = 10f;
|
|
if (flag26)
|
|
{
|
|
num650 = 24f;
|
|
}
|
|
Vector2 center2 = Projectile.Center;
|
|
Vector2 vector48 = player.Center - center2 + new Vector2(-40f, -40f);
|
|
float num651 = vector48.Length();
|
|
if (num651 > 200f && num650 < 12f)
|
|
{
|
|
num650 = 12f;
|
|
}
|
|
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 = player.Center.X - (float)(Projectile.width / 2);
|
|
Projectile.position.Y = player.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 fire timer
|
|
if (Projectile.ai[1] > 0f)
|
|
Projectile.ai[1] += (float)Main.rand.Next(1, 3);
|
|
|
|
// Reset timer
|
|
if (Projectile.ai[1] > 300f)
|
|
{
|
|
Projectile.ai[1] = 0f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
|
|
// Prevent firing immediately
|
|
if (Projectile.localAI[0] < 120f)
|
|
Projectile.localAI[0] += 1f;
|
|
|
|
// Fire projectiles
|
|
if (Projectile.ai[0] == 0f)
|
|
{
|
|
float velocity = 8f;
|
|
int projectileType = ModContent.ProjectileType<SakuraBullet>();
|
|
if (flag25 && Projectile.ai[1] == 0f && Projectile.localAI[0] >= 120f)
|
|
{
|
|
Projectile.ai[1] += 1f;
|
|
if (Main.myPlayer == Projectile.owner)
|
|
{
|
|
SoundEngine.PlaySound(SoundID.Item8, Projectile.position);
|
|
Vector2 value19 = vector46 - Projectile.Center;
|
|
value19.Normalize();
|
|
value19 *= velocity;
|
|
int numProj = 2;
|
|
float rotation = MathHelper.ToRadians(4);
|
|
for (int i = 0; i < numProj + 1; i++)
|
|
{
|
|
Vector2 perturbedSpeed = value19.RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numProj - 1)));
|
|
int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, perturbedSpeed, projectileType, Projectile.damage / 2, Projectile.knockBack * 0.5f, Projectile.owner, targetIndex, 0f);
|
|
if (Main.projectile.IndexInRange(p))
|
|
Main.projectile[p].originalDamage = Projectile.originalDamage;
|
|
}
|
|
Projectile.netUpdate = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
SpriteEffects spriteEffects = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
|
Texture2D texture2D13 = ModContent.Request<Texture2D>(Texture).Value;
|
|
int num214 = ModContent.Request<Texture2D>(Texture).Value.Height / Main.projFrames[Projectile.type];
|
|
int y6 = num214 * Projectile.frame;
|
|
Main.EntitySpriteDraw(texture2D13, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, num214)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), Projectile.scale, spriteEffects, 0);
|
|
return false;
|
|
}
|
|
|
|
public override bool? CanDamage() => false;
|
|
}
|
|
}
|