using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TAPI;
using Terraria;
namespace MaxsMod.Projectiles
{
public class CopperLanceProj : ModProjectile
{
public override void AI()
{
projectile.light = 0.9f;
int DustID = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y + 2f), projectile.width, projectile.height, 24, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default(Color), 0.5f);
Main.player[projectile.owner].direction = projectile.direction; //Make's the owner face the direction the spear
Main.player[projectile.owner].heldProj = projectile.whoAmI;
Main.player[projectile.owner].itemTime = Main.player[projectile.owner].itemAnimation;
projectile.position.X = Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) - (float)(projectile.width / 2);
projectile.position.Y = Main.player[projectile.owner].position.Y + (float)(Main.player[projectile.owner].height / 2) - (float)(projectile.height / 2);
projectile.position += projectile.velocity * projectile.ai[0];
if (projectile.ai[0] == 0f)
{
projectile.ai[0] = 3f;
projectile.netUpdate = true;
}
if (Main.player[projectile.owner].itemAnimation < Main.player[projectile.owner].itemAnimationMax / 3)
{
projectile.ai[0] -= 1.1f; //How far back it goes
if (projectile.localAI[0] == 0f && Main.myPlayer == projectile.owner)
{
projectile.localAI[0] = 1f;
if (Collision.CanHit(Main.player[projectile.owner].position, Main.player[projectile.owner].width, Main.player[projectile.owner].height, new Vector2(projectile.center().X + projectile.velocity.X * projectile.ai[0], projectile.center().Y + projectile.velocity.Y * projectile.ai[0]), projectile.width, projectile.height)) //The if statement to make a projectile after the spear point reaaches it's max distance; you can remove the if statements and the things it contains to make it a normal spear
{
Projectile.NewProjectile(projectile.center().X + projectile.velocity.X , projectile.center().Y + projectile.velocity.Y , projectile.velocity.X * 1.5f, projectile.velocity.Y * 1.5f, "COFP:MiniAncientSpear", projectile.damage , projectile.knockBack * 0.85f, projectile.owner, 0f, 0f); //Spawning the projectile
}
}
}
else
{
projectile.ai[0] += 0.75f; //How Far It Goes
}
if (Main.player[projectile.owner].itemAnimation == 0)
{
projectile.Kill(); //Kills projectile after it is done
}
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2.355f; //Rotates the spear based on where you shoot
if (projectile.spriteDirection == -1)
{
projectile.rotation -= 1.57f;
}
}
}
}