using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace StylishCombat.Items
{
public class EvilLegacy : ModItem
{
private int lastGripX =- 1;
private int lastGripY = -1;
public override void SetDefaults()
{
item.name = "Evil Legacy";
item.width = 28;
item.height = 26;
item.toolTip = "Creates Grim Grip attach point at cursor location";
item.value = 50000;
item.rare = 4;
item.noMelee = true;
item.useTime = 20;
item.noUseGraphic = true;
item.melee = true;
item.damage = 30;
item.knockBack = 7f;
item.useStyle = 5;
item.shootSpeed = 11.5f;
item.shoot = 13;
item.useSound = 1;
item.useAnimation = 20;
}
public override void UpdateInventory(Player player) // <-- Here's the problem
{
if (player.controlHook && player.releaseHook)
{
Vector2 pos = Main.screenPosition;
pos.X += Main.mouseX;
pos.Y += player.gravDir == 1 ? Main.mouseY : Main.screenHeight - Main.mouseY;
int tileCheckX = (int)(pos.X / 16f);
int tileCheckY = (int)(pos.Y / 16f);
if(CheckTerrain(tileCheckX, tileCheckY) && Math.Sqrt(Math.Pow(pos.X - player.Center.X,2) + Math.Pow(pos.Y - player.Center.Y,2))/16f < 18f)
{
WorldGen.PlaceTile(tileCheckX, tileCheckY, mod.TileType("Grim Grip"), false, false, player.whoAmI, 0);
for(int k=0; k<5; k++)
{
int dust = Dust.NewDust(pos,3,3,113,0f,0f,0, default(Color), 1.5f);
Main.dust[dust].noGravity = true;
}
Main.PlaySound(2, (int)pos.X, (int)pos.Y, 44);
if((lastGripX != -1 && lastGripY != -1) && Main.tile[lastGripX, lastGripY].type == mod.TileType("Grim Grip"))
{
WorldGen.KillTile(lastGripX,lastGripY,false,false,true);
}
lastGripX = tileCheckX;
lastGripY = tileCheckY;
}
}
}
private bool CheckTerrain(int x, int y)
{
if((x > Main.maxTilesX) || (x < 0) || (y < 0) || (y > Main.maxTilesY)) return false;
for(int i = x - 1; i <= x + 1; i++)
{
if(i > Main.maxTilesX) i = Main.maxTilesX;
if(i < 0) i = 0;
for(int j = y - 1; j <= y + 2; j++)
{
if(j > Main.maxTilesY) j = Main.maxTilesY;
if(j < 0) j = 0;
if(Main.tile[i, j].type != 0)
{
return false;
}
}
}
return true;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient("Crystal Ball",1);
recipe.AddIngredient("Bone",50);
recipe.AddIngredient("Soul of Night",10);
recipe.AddTile(TileID.DemonAltar);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}