Files
CalamityModPublic/Projectiles/Melee/Cyclone.cs
T
2019-07-09 23:39:59 -04:00

93 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Melee
{
public class Cyclone : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Cyclone");
ProjectileID.Sets.TrailCacheLength[projectile.type] = 10;
ProjectileID.Sets.TrailingMode[projectile.type] = 3;
}
public override void SetDefaults()
{
projectile.width = 40;
projectile.height = 40;
projectile.alpha = 255;
projectile.friendly = true;
projectile.melee = true;
projectile.timeLeft = 300;
projectile.extraUpdates = 2;
projectile.penetrate = 2;
projectile.ignoreWater = true;
projectile.usesLocalNPCImmunity = true;
projectile.localNPCHitCooldown = 10;
}
public override void AI()
{
projectile.rotation += 2.5f;
projectile.alpha -= 5;
if (projectile.alpha < 50)
{
projectile.alpha = 50;
}
float num472 = projectile.Center.X;
float num473 = projectile.Center.Y;
float npcCenterX = 0f;
float npcCenterY = 0f;
float num474 = 600f;
for (int num475 = 0; num475 < 200; num475++)
{
NPC npc = Main.npc[num475];
if (npc.CanBeChasedBy(projectile, false) && Collision.CanHit(projectile.Center, 1, 1, npc.Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses)
{
npcCenterX = npc.position.X + (float)(npc.width / 2);
npcCenterY = npc.position.Y + (float)(npc.height / 2);
float num478 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - npcCenterX) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - npcCenterY);
if (num478 < num474)
{
if (npc.position.X < num472)
{
npc.velocity.X += 0.05f;
}
else
{
npc.velocity.X -= 0.05f;
}
if (npc.position.Y < num473)
{
npc.velocity.Y += 0.05f;
}
else
{
npc.velocity.Y -= 0.05f;
}
}
}
}
}
public override Color? GetAlpha(Color lightColor)
{
return new Color(204, 255, 255, projectile.alpha);
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D tex = Main.projectileTexture[projectile.type];
spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, null, projectile.GetAlpha(lightColor), projectile.rotation, tex.Size() / 2f, projectile.scale, SpriteEffects.None, 0f);
return false;
}
}
}