212 lines
9.5 KiB
C#
212 lines
9.5 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
using CalamityMod.NPCs.Providence;
|
|
using CalamityMod.World;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using System.IO;
|
|
using Terraria;
|
|
using Terraria.Enums;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.Projectiles.Boss
|
|
{
|
|
public class ProvidenceHolyRay : ModProjectile
|
|
{
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Holy Ray");
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
projectile.width = 48;
|
|
projectile.height = 48;
|
|
projectile.hostile = true;
|
|
projectile.alpha = 255;
|
|
projectile.penetrate = -1;
|
|
projectile.tileCollide = false;
|
|
projectile.timeLeft = 600;
|
|
cooldownSlot = 1;
|
|
}
|
|
|
|
public override void SendExtraAI(BinaryWriter writer)
|
|
{
|
|
writer.Write(projectile.localAI[0]);
|
|
writer.Write(projectile.localAI[1]);
|
|
}
|
|
|
|
public override void ReceiveExtraAI(BinaryReader reader)
|
|
{
|
|
projectile.localAI[0] = reader.ReadSingle();
|
|
projectile.localAI[1] = reader.ReadSingle();
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Vector2? vector78 = null;
|
|
|
|
if (projectile.velocity.HasNaNs() || projectile.velocity == Vector2.Zero)
|
|
{
|
|
projectile.velocity = -Vector2.UnitY;
|
|
}
|
|
|
|
if (Main.npc[(int)projectile.ai[1]].active && Main.npc[(int)projectile.ai[1]].type == ModContent.NPCType<Providence>())
|
|
{
|
|
Vector2 value21 = new Vector2(27f, 59f);
|
|
Vector2 fireFrom = new Vector2(Main.npc[(int)projectile.ai[1]].Center.X, Main.npc[(int)projectile.ai[1]].Center.Y - 32f);
|
|
Vector2 value22 = Utils.Vector2FromElipse(Main.npc[(int)projectile.ai[1]].localAI[0].ToRotationVector2(), value21 * Main.npc[(int)projectile.ai[1]].localAI[1]);
|
|
projectile.position = fireFrom + value22 - new Vector2((float)projectile.width, (float)projectile.height) / 2f;
|
|
}
|
|
|
|
if (projectile.velocity.HasNaNs() || projectile.velocity == Vector2.Zero)
|
|
{
|
|
projectile.velocity = -Vector2.UnitY;
|
|
}
|
|
|
|
float num801 = 1f;
|
|
projectile.localAI[0] += 1f;
|
|
if (projectile.localAI[0] >= ((CalamityWorld.revenge || CalamityWorld.bossRushActive) ? 100f : 180f))
|
|
{
|
|
projectile.Kill();
|
|
return;
|
|
}
|
|
|
|
projectile.scale = (float)Math.Sin((double)(projectile.localAI[0] * 3.14159274f / ((CalamityWorld.revenge || CalamityWorld.bossRushActive) ? 100f : 180f))) * 10f * num801;
|
|
if (projectile.scale > num801)
|
|
{
|
|
projectile.scale = num801;
|
|
}
|
|
|
|
float num804 = projectile.velocity.ToRotation();
|
|
num804 += projectile.ai[0];
|
|
projectile.rotation = num804 - 1.57079637f;
|
|
projectile.velocity = num804.ToRotationVector2();
|
|
|
|
float num805 = 3f; //3f
|
|
float num806 = (float)projectile.width;
|
|
|
|
Vector2 samplingPoint = projectile.Center;
|
|
if (vector78.HasValue)
|
|
{
|
|
samplingPoint = vector78.Value;
|
|
}
|
|
|
|
float[] array3 = new float[(int)num805];
|
|
Collision.LaserScan(samplingPoint, projectile.velocity, num806 * projectile.scale, 2400f, array3);
|
|
float num807 = 0f;
|
|
int num3;
|
|
for (int num808 = 0; num808 < array3.Length; num808 = num3 + 1)
|
|
{
|
|
num807 += array3[num808];
|
|
num3 = num808;
|
|
}
|
|
num807 /= num805;
|
|
|
|
// Fire laser through walls at max length if target cannot be seen
|
|
if (!Collision.CanHitLine(Main.npc[(int)projectile.ai[1]].Center, 1, 1, Main.player[Main.npc[(int)projectile.ai[1]].target].Center, 1, 1))
|
|
{
|
|
num807 = 2400f;
|
|
}
|
|
|
|
float amount = 0.5f; //0.5f
|
|
projectile.localAI[1] = MathHelper.Lerp(projectile.localAI[1], num807, amount); //length of laser, linear interpolation
|
|
Vector2 vector79 = projectile.Center + projectile.velocity * (projectile.localAI[1] - 14f);
|
|
for (int num809 = 0; num809 < 2; num809 = num3 + 1)
|
|
{
|
|
float num810 = projectile.velocity.ToRotation() + ((Main.rand.Next(2) == 1) ? -1f : 1f) * 1.57079637f;
|
|
float num811 = (float)Main.rand.NextDouble() * 2f + 2f;
|
|
Vector2 vector80 = new Vector2((float)Math.Cos((double)num810) * num811, (float)Math.Sin((double)num810) * num811);
|
|
int num812 = Dust.NewDust(vector79, 0, 0, 244, vector80.X, vector80.Y, 0, default, 1f);
|
|
Main.dust[num812].noGravity = true;
|
|
Main.dust[num812].scale = 1.7f;
|
|
num3 = num809;
|
|
}
|
|
|
|
if (Main.rand.NextBool(5))
|
|
{
|
|
Vector2 value29 = projectile.velocity.RotatedBy(1.5707963705062866, default) * ((float)Main.rand.NextDouble() - 0.5f) * (float)projectile.width;
|
|
int num813 = Dust.NewDust(vector79 + value29 - Vector2.One * 4f, 8, 8, 244, 0f, 0f, 100, default, 1.5f);
|
|
Dust dust = Main.dust[num813];
|
|
dust.velocity *= 0.5f;
|
|
Main.dust[num813].velocity.Y = -Math.Abs(Main.dust[num813].velocity.Y);
|
|
}
|
|
|
|
DelegateMethods.v3_1 = new Vector3(0.3f, 0.65f, 0.7f);
|
|
Utils.PlotTileLine(projectile.Center, projectile.Center + projectile.velocity * projectile.localAI[1], (float)projectile.width * projectile.scale, new Utils.PerLinePoint(DelegateMethods.CastLight));
|
|
}
|
|
|
|
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
|
|
{
|
|
if (projectile.velocity == Vector2.Zero)
|
|
{
|
|
return false;
|
|
}
|
|
Texture2D texture2D19 = Main.projectileTexture[projectile.type];
|
|
Texture2D texture2D20 = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/ProvidenceHolyRayMid");
|
|
Texture2D texture2D21 = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/ProvidenceHolyRayEnd");
|
|
float num223 = projectile.localAI[1]; //length of laser
|
|
Color color44 = new Color(255, 255, 255, 0) * 0.9f;
|
|
SpriteBatch arg_ABD8_0 = Main.spriteBatch;
|
|
Texture2D arg_ABD8_1 = texture2D19;
|
|
Vector2 arg_ABD8_2 = projectile.Center - Main.screenPosition;
|
|
Rectangle? sourceRectangle2 = null;
|
|
arg_ABD8_0.Draw(arg_ABD8_1, arg_ABD8_2, sourceRectangle2, color44, projectile.rotation, texture2D19.Size() / 2f, projectile.scale, SpriteEffects.None, 0f);
|
|
num223 -= (float)(texture2D19.Height / 2 + texture2D21.Height) * projectile.scale;
|
|
Vector2 value20 = projectile.Center;
|
|
value20 += projectile.velocity * projectile.scale * (float)texture2D19.Height / 2f;
|
|
if (num223 > 0f)
|
|
{
|
|
float num224 = 0f;
|
|
Rectangle rectangle7 = new Rectangle(0, 16 * (projectile.timeLeft / 3 % 5), texture2D20.Width, 16);
|
|
while (num224 + 1f < num223)
|
|
{
|
|
if (num223 - num224 < (float)rectangle7.Height)
|
|
{
|
|
rectangle7.Height = (int)(num223 - num224);
|
|
}
|
|
Main.spriteBatch.Draw(texture2D20, value20 - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(rectangle7), color44, projectile.rotation, new Vector2((float)(rectangle7.Width / 2), 0f), projectile.scale, SpriteEffects.None, 0f);
|
|
num224 += (float)rectangle7.Height * projectile.scale;
|
|
value20 += projectile.velocity * (float)rectangle7.Height * projectile.scale;
|
|
rectangle7.Y += 16;
|
|
if (rectangle7.Y + rectangle7.Height > texture2D20.Height)
|
|
{
|
|
rectangle7.Y = 0;
|
|
}
|
|
}
|
|
}
|
|
SpriteBatch arg_AE2D_0 = Main.spriteBatch;
|
|
Texture2D arg_AE2D_1 = texture2D21;
|
|
Vector2 arg_AE2D_2 = value20 - Main.screenPosition;
|
|
sourceRectangle2 = null;
|
|
arg_AE2D_0.Draw(arg_AE2D_1, arg_AE2D_2, sourceRectangle2, color44, projectile.rotation, texture2D21.Frame(1, 1, 0, 0).Top(), projectile.scale, SpriteEffects.None, 0f);
|
|
return false;
|
|
}
|
|
|
|
public override void CutTiles()
|
|
{
|
|
DelegateMethods.tilecut_0 = TileCuttingContext.AttackProjectile;
|
|
Vector2 unit = projectile.velocity;
|
|
Utils.PlotTileLine(projectile.Center, projectile.Center + unit * projectile.localAI[1], (float)projectile.width * projectile.scale, new Utils.PerLinePoint(DelegateMethods.CutTiles));
|
|
}
|
|
|
|
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
|
|
{
|
|
if (projHitbox.Intersects(targetHitbox))
|
|
{
|
|
return true;
|
|
}
|
|
float num6 = 0f;
|
|
if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + projectile.velocity * projectile.localAI[1], 22f * projectile.scale, ref num6))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public override void OnHitPlayer(Player target, int damage, bool crit)
|
|
{
|
|
target.AddBuff(ModContent.BuffType<HolyFlames>(), 300);
|
|
}
|
|
}
|
|
}
|