using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
namespace JoshuasMod.Projectiles
{
public class SpacialRendProj : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Spacial Rend");
Main.RegisterItemAnimation(projectile.type, new DrawAnimationVertical(20, 12));
Main.projFrames[mod.ProjectileType("SpacialRendProj")] = 12; //"12" is the amount of frames there are in 1 loop.
}
public override void SetDefaults()
{
projectile.width = 78;
projectile.height = 68;
projectile.aiStyle = 75;
projectile.scale = 1.1f;
projectile.penetrate = -1;
projectile.friendly = true;
projectile.melee = true;
projectile.ownerHitCheck = true;
projectile.ignoreWater = true;
projectile.tileCollide = false;
}
public override void AI()
{
//This is the "Arkhalis" projectile code.
Player player = Main.player[projectile.owner];
float num = 1.57079637f;
Vector2 vector = player.RotatedRelativePoint(player.MountedCenter, true);
num = 0f;
if (projectile.spriteDirection == -1)
{
num = 3.14159265274f;
}
if (++projectile.frame >= Main.projFrames[projectile.type])
{
projectile.frame = 1;
}
projectile.soundDelay--;
if (projectile.soundDelay <=0)
{
Main.PlaySound(2, (int)projectile.Center.X, (int)projectile.Center.Y, 1);
projectile.soundDelay = 16;
}
if (Main.myPlayer == projectile.owner)
{
if (player.channel && !player.noItems && !player.CCed)
{
float scaleFactor6 = 1f;
if (player.inventory[player.selectedItem].shoot == projectile.type)
{
scaleFactor6 = player.inventory[player.selectedItem].shootSpeed * projectile.scale;
}
Vector2 vector13 = Main.MouseWorld - vector;
vector13.Normalize();
if (vector13.HasNaNs())
{
vector13 = Vector2.UnitX * (float)player.direction;
}
vector13 *= scaleFactor6;
if (vector13.X != projectile.velocity.X || vector13.Y != projectile.velocity.Y)
{
projectile.netUpdate = true;
}
projectile.velocity = vector13;
}
else
{
projectile.Kill();
}
}
Vector2 vector14 = projectile.Center + projectile.velocity * 3f;
Lighting.AddLight(vector14, 0.1f, 0.1f, 0.1f);
projectile.position = player.RotatedRelativePoint(player.MountedCenter, true) - projectile.Size / 2f;
projectile.rotation = projectile.velocity.ToRotation() + num;
projectile.spriteDirection = projectile.direction;
projectile.timeLeft = 2;
player.ChangeDir(projectile.direction);
player.heldProj = projectile.whoAmI;
player.itemTime = 2;
player.itemAnimation = 2;
player.itemRotation = (float)Math.Atan2((double)(projectile.velocity.Y * (float)projectile.direction), (double)(projectile.velocity.X * (float)projectile.direction));
//This is the dust used, it is the size of the projectile.
projectile.velocity.Y += projectile.ai[0];
for (int d = 0; d < 1; d++)
{
Dust.NewDust(projectile.position, projectile.width, projectile.height, 15, 0f, 0f, 150, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 0.85f);
}
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.OnFire, 5 * 60);
target.AddBuff(BuffID.Frostburn, 5 * 60);
target.AddBuff(BuffID.CursedInferno, 5 * 60);
target.AddBuff(BuffID.ShadowFlame, 5 * 60);
target.immune[projectile.owner] = 3;
}
}
}