268 lines
11 KiB
C#
268 lines
11 KiB
C#
using CalamityMod.CalPlayer;
|
|
using CalamityMod.Dusts;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Typeless
|
|
{
|
|
public class DemonshadeRedDevil : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Typeless";
|
|
public int dust = 3;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.projFrames[Projectile.type] = 5;
|
|
ProjectileID.Sets.MinionSacrificable[Projectile.type] = true;
|
|
ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 48;
|
|
Projectile.height = 48;
|
|
Projectile.netImportant = true;
|
|
Projectile.friendly = true;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.timeLeft = 18000;
|
|
Projectile.penetrate = -1;
|
|
Projectile.tileCollide = false;
|
|
Projectile.timeLeft *= 5;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
bool isMinion = Projectile.type == ModContent.ProjectileType<DemonshadeRedDevil>();
|
|
Player player = Main.player[Projectile.owner];
|
|
CalamityPlayer modPlayer = player.Calamity();
|
|
if (!modPlayer.redDevil)
|
|
{
|
|
Projectile.active = false;
|
|
return;
|
|
}
|
|
if (isMinion)
|
|
{
|
|
if (player.dead)
|
|
{
|
|
modPlayer.rDevil = false;
|
|
}
|
|
if (modPlayer.rDevil)
|
|
{
|
|
Projectile.timeLeft = 2;
|
|
}
|
|
}
|
|
dust--;
|
|
if (dust >= 0)
|
|
{
|
|
for (int i = 0; i < 50; i++)
|
|
{
|
|
int brimDust = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y + 16f), Projectile.width, Projectile.height - 16, (int)CalamityDusts.Brimstone, 0f, 0f, 0, default, 1f);
|
|
Main.dust[brimDust].velocity *= 2f;
|
|
Main.dust[brimDust].scale *= 1.15f;
|
|
}
|
|
}
|
|
Projectile.frameCounter++;
|
|
if (Projectile.frameCounter > 8)
|
|
{
|
|
Projectile.frame++;
|
|
Projectile.frameCounter = 0;
|
|
}
|
|
if (Projectile.frame > 4)
|
|
{
|
|
Projectile.frame = 0;
|
|
}
|
|
float lights = (float)Main.rand.Next(90, 111) * 0.01f;
|
|
lights *= Main.essScale;
|
|
Lighting.AddLight(Projectile.Center, 1f * lights, 0f * lights, 0.15f * lights);
|
|
Projectile.rotation = Projectile.velocity.X * 0.04f;
|
|
if ((double)Math.Abs(Projectile.velocity.X) > 0.2)
|
|
{
|
|
Projectile.spriteDirection = -Projectile.direction;
|
|
}
|
|
float attackRange = 2000f;
|
|
bool decelerate = false;
|
|
if (Projectile.ai[0] == 2f)
|
|
{
|
|
Projectile.ai[1] += 1f;
|
|
Projectile.extraUpdates = 1;
|
|
if (Projectile.ai[1] > 40f)
|
|
{
|
|
Projectile.ai[1] = 1f;
|
|
Projectile.ai[0] = 0f;
|
|
Projectile.extraUpdates = 0;
|
|
Projectile.numUpdates = 0;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
else
|
|
{
|
|
decelerate = true;
|
|
}
|
|
}
|
|
if (decelerate)
|
|
{
|
|
return;
|
|
}
|
|
Vector2 projPos = Projectile.position;
|
|
bool canAttack = false;
|
|
if (Projectile.ai[0] != 1f)
|
|
{
|
|
Projectile.tileCollide = false;
|
|
}
|
|
if (Projectile.tileCollide && WorldGen.SolidTile(Framing.GetTileSafely((int)Projectile.Center.X / 16, (int)Projectile.Center.Y / 16)))
|
|
{
|
|
Projectile.tileCollide = false;
|
|
}
|
|
if (player.HasMinionAttackTargetNPC)
|
|
{
|
|
NPC npc = Main.npc[player.MinionAttackTargetNPC];
|
|
if (npc.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float npcDist = Vector2.Distance(npc.Center, Projectile.Center);
|
|
if (!canAttack && npcDist < attackRange)
|
|
{
|
|
attackRange = npcDist;
|
|
projPos = npc.Center;
|
|
canAttack = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int j = 0; j < Main.maxNPCs; j++)
|
|
{
|
|
NPC nPC2 = Main.npc[j];
|
|
if (nPC2.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float npcDist = Vector2.Distance(nPC2.Center, Projectile.Center);
|
|
if ((!canAttack && npcDist < attackRange) && Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, nPC2.position, nPC2.width, nPC2.height))
|
|
{
|
|
attackRange = npcDist;
|
|
projPos = nPC2.Center;
|
|
canAttack = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
float separationAnxietyDist = 2000f;
|
|
if (canAttack)
|
|
{
|
|
separationAnxietyDist = 3000f;
|
|
}
|
|
if (Vector2.Distance(player.Center, Projectile.Center) > separationAnxietyDist)
|
|
{
|
|
Projectile.ai[0] = 1f;
|
|
Projectile.tileCollide = false;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
if (canAttack && Projectile.ai[0] == 0f)
|
|
{
|
|
Vector2 projDirection = projPos - Projectile.Center;
|
|
float projDist = projDirection.Length();
|
|
projDirection.Normalize();
|
|
if (projDist > 200f)
|
|
{
|
|
float scaleFactor2 = 16f; //8
|
|
projDirection *= scaleFactor2;
|
|
Projectile.velocity = (Projectile.velocity * 40f + projDirection) / 41f;
|
|
}
|
|
else
|
|
{
|
|
projDirection *= -4f;
|
|
Projectile.velocity = (Projectile.velocity * 40f + projDirection) / 41f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool isReturning = false;
|
|
if (!isReturning)
|
|
{
|
|
isReturning = Projectile.ai[0] == 1f;
|
|
}
|
|
float returnSpeed = 5f; //6
|
|
if (isReturning)
|
|
{
|
|
returnSpeed = 12f; //15
|
|
}
|
|
Vector2 center2 = Projectile.Center;
|
|
Vector2 playerDirection = player.Center - center2 + new Vector2(0f, -30f); //-60
|
|
float playerDist = playerDirection.Length();
|
|
if (playerDist > 200f && returnSpeed < 6.5f) //200 and 8
|
|
{
|
|
returnSpeed = 6.5f; //8
|
|
}
|
|
if (playerDist < 150f && isReturning && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height))
|
|
{
|
|
Projectile.ai[0] = 0f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
if (playerDist > 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 (playerDist > 70f)
|
|
{
|
|
playerDirection.Normalize();
|
|
playerDirection *= returnSpeed;
|
|
Projectile.velocity = (Projectile.velocity * 40f + playerDirection) / 41f;
|
|
}
|
|
else if (Projectile.velocity.X == 0f && Projectile.velocity.Y == 0f)
|
|
{
|
|
Projectile.velocity.X = -0.2f;
|
|
Projectile.velocity.Y = -0.1f;
|
|
}
|
|
}
|
|
if (Projectile.ai[1] > 0f)
|
|
{
|
|
Projectile.ai[1] += (float)Main.rand.Next(1, 4);
|
|
}
|
|
if (Projectile.ai[1] > 80f)
|
|
{
|
|
Projectile.ai[1] = 0f;
|
|
Projectile.netUpdate = true;
|
|
}
|
|
if (Projectile.ai[0] == 0f)
|
|
{
|
|
float speed = 24f;
|
|
int projType = ProjectileID.UnholyTridentFriendly;
|
|
if (canAttack && Projectile.ai[1] == 0f)
|
|
{
|
|
Projectile.ai[1] += 1f;
|
|
if (Main.myPlayer == Projectile.owner && Collision.CanHitLine(Projectile.Center, Projectile.width, Projectile.height, projPos, 0, 0))
|
|
{
|
|
Vector2 velocity = projPos - Projectile.Center;
|
|
velocity.Normalize();
|
|
velocity *= speed;
|
|
int trident = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, projType, Projectile.damage, 0f, Main.myPlayer);
|
|
if (trident.WithinBounds(Main.maxProjectiles))
|
|
{
|
|
Main.projectile[trident].timeLeft = 300;
|
|
Main.projectile[trident].usesLocalNPCImmunity = true;
|
|
Main.projectile[trident].localNPCHitCooldown = 10;
|
|
Main.projectile[trident].DamageType = DamageClass.Generic; //typeless
|
|
}
|
|
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 framing = ModContent.Request<Texture2D>(Texture).Value.Height / Main.projFrames[Projectile.type];
|
|
int y6 = framing * Projectile.frame;
|
|
Main.spriteBatch.Draw(texture2D13, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, framing)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)framing / 2f), Projectile.scale, spriteEffects, 0);
|
|
return false;
|
|
}
|
|
|
|
public override bool? CanDamage() => false;
|
|
}
|
|
}
|