144 lines
5.7 KiB
C#
144 lines
5.7 KiB
C#
using CalamityMod.Buffs.Summon;
|
|
using CalamityMod.CalPlayer;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.Projectiles.Summon
|
|
{
|
|
public class MagicHat : ModProjectile
|
|
{
|
|
public const float Range = 1500.0001f;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Magic Hat");
|
|
ProjectileID.Sets.MinionSacrificable[Projectile.type] = true;
|
|
ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true;
|
|
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 8;
|
|
ProjectileID.Sets.TrailingMode[Projectile.type] = 1;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 30;
|
|
Projectile.height = 30;
|
|
Projectile.netImportant = true;
|
|
Projectile.friendly = true;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.minionSlots = 5f;
|
|
Projectile.timeLeft = 18000;
|
|
Projectile.penetrate = -1;
|
|
Projectile.tileCollide = false;
|
|
Projectile.timeLeft *= 5;
|
|
Projectile.minion = true;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
CalamityPlayer modPlayer = player.Calamity();
|
|
CalamityGlobalProjectile modProj = Projectile.Calamity();
|
|
|
|
//set up minion buffs and bools
|
|
bool hatExists = Projectile.type == ModContent.ProjectileType<MagicHat>();
|
|
player.AddBuff(ModContent.BuffType<MagicHatBuff>(), 3600);
|
|
if (hatExists)
|
|
{
|
|
if (player.dead)
|
|
{
|
|
modPlayer.magicHat = false;
|
|
}
|
|
if (modPlayer.magicHat)
|
|
{
|
|
Projectile.timeLeft = 2;
|
|
}
|
|
}
|
|
|
|
//projectile movement
|
|
Projectile.Center = player.Center + Vector2.UnitY * (player.gfxOffY - 60f);
|
|
if (player.gravDir == -1f)
|
|
{
|
|
Projectile.position.Y += 120f;
|
|
Projectile.rotation = MathHelper.Pi;
|
|
}
|
|
else
|
|
{
|
|
Projectile.rotation = 0f;
|
|
}
|
|
Projectile.position.X = (int)Projectile.position.X;
|
|
Projectile.position.Y = (int)Projectile.position.Y;
|
|
|
|
//Change the summons scale size a little bit to make it pulse in and out
|
|
float scalar = (float)Main.mouseTextColor / 200f - 0.35f;
|
|
scalar *= 0.2f;
|
|
Projectile.scale = scalar + 0.95f;
|
|
|
|
//on summon dust and flexible damage
|
|
if (Projectile.localAI[0] == 0f)
|
|
{
|
|
int dustAmt = 50;
|
|
for (int dustIndex = 0; dustIndex < dustAmt; dustIndex++)
|
|
{
|
|
int dustEffects = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y + 16f), Projectile.width, Projectile.height - 16, 234, 0f, 0f, 0, default, 1f);
|
|
Main.dust[dustEffects].velocity *= 2f;
|
|
Main.dust[dustEffects].scale *= 1.15f;
|
|
}
|
|
Projectile.localAI[0] += 1f;
|
|
}
|
|
|
|
//finding an enemy, then shooting projectiles if it's detected
|
|
if (Projectile.owner == Main.myPlayer)
|
|
{
|
|
float detectionRange = Range;
|
|
bool enemyDetected = false;
|
|
|
|
for (int i = 0; i < Main.maxNPCs; i++)
|
|
{
|
|
NPC npc = Main.npc[i];
|
|
if (npc.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float extraDistance = (npc.width / 2) + (npc.height / 2);
|
|
|
|
if (Vector2.Distance(npc.Center, Projectile.Center) < (detectionRange + extraDistance))
|
|
{
|
|
enemyDetected = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (enemyDetected)
|
|
{
|
|
Projectile.ai[1] += 1f;
|
|
if (Projectile.ai[1] % 5f == 0f)
|
|
{
|
|
int amount = Main.rand.Next(1, 2);
|
|
for (int i = 0; i < amount; i++)
|
|
{
|
|
int projType = Utils.SelectRandom(Main.rand, new int[]
|
|
{
|
|
ModContent.ProjectileType<MagicUmbrella>(),
|
|
ModContent.ProjectileType<MagicRifle>(),
|
|
ModContent.ProjectileType<MagicHammer>(),
|
|
ModContent.ProjectileType<MagicAxe>(),
|
|
ModContent.ProjectileType<MagicBird>()
|
|
});
|
|
float velocityX = Main.rand.NextFloat(-10f, 10f);
|
|
float velocityY = Main.rand.NextFloat(-15f, -8f);
|
|
int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.oldPosition.X + (float)(Projectile.width / 2), Projectile.oldPosition.Y + (float)(Projectile.height / 2), velocityX, velocityY, projType, Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f);
|
|
if (Main.projectile.IndexInRange(p))
|
|
Main.projectile[p].originalDamage = Projectile.originalDamage;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//glowmask effect
|
|
public override Color? GetAlpha(Color lightColor) => new Color(200, 200, 200, 200);
|
|
|
|
//no contact damage
|
|
public override bool? CanDamage() => false;
|
|
}
|
|
}
|