using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;
namespace CorruptionCandles.Tiles
{
public class CursedCandle : ModTile
{
public override void SetDefaults()
{
Main.tileFrameImportant[Type] = true;
TileObjectData.newTile.CopyFrom(TileObjectData.Style1xX);
TileObjectData.newTile.UsesCustomCanPlace = true;
TileObjectData.newTile.Height = 1;
TileObjectData.newTile.Width = 1;
TileObjectData.newTile.Origin = new Point16(0, 0);
TileObjectData.newTile.CoordinateHeights = new int[]{ 16, 16, 22 };
TileObjectData.addTile(Type);
AddMapEntry(new Color(0, 255, 0));
dustType = 1;
animationFrameHeight = 20;
disableSmartCursor = true;
drop = mod.ItemType("CursedCandle");
AddMapEntry(new Color(0, 255, 0), "Torch");
dustType = mod.DustType("Sparkle");
torch = true;
}
public override void NumDust(int i, int j, bool fail, ref int num)
{
num = Main.rand.Next(1, 3);
}
public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
{
Tile tile = Main.tile[i, j];
if (tile.frameX < 66)
{
r = 0.0f;
g = 1.0f;
b = 0.0f;
}
}
public override void NearbyEffects(int i, int j, bool closer)
{
if(closer)
{
Main.player[Main.myPlayer].AddBuff(mod.BuffType("CursedCandle"), 2);
}
}
public override void AnimateTile(ref int frame, ref int frameCounter)
{
frame = Main.tileFrame[TileID.WaterCandle];
frameCounter = Main.tileFrameCounter[TileID.WaterCandle];
}
public override void PostDraw(int i, int j, SpriteBatch spriteBatch)
{
ulong randSeed = Main.TileFrameSeed ^ (ulong)((long)j << 32 | (long)((ulong)i));
Color color = new Color(100, 100, 100, 0);
int frameX = Main.tile[i, j].frameX;
int frameY = Main.tile[i, j].frameY;
int width = 16;
int offsetY = 0;
int height = 20;
if (WorldGen.SolidTile(i, j - 1))
{
offsetY = 2;
if (WorldGen.SolidTile(i - 1, j + 1) || WorldGen.SolidTile(i + 1, j + 1))
{
offsetY = 4;
}
}
Vector2 zero = new Vector2(Main.offScreenRange, Main.offScreenRange);
if (Main.drawToScreen)
{
zero = Vector2.Zero;
}
for (int k = 0; k < 7; k++)
{
float x = (float)Utils.RandomInt(ref randSeed, -10, 11) * 0.15f;
float y = (float)Utils.RandomInt(ref randSeed, -10, 1) * 0.35f;
Main.spriteBatch.Draw(mod.GetTexture("Tiles/CursedCandle_Flame"), new Vector2((float)(i * 16 - (int)Main.screenPosition.X) - (width - 16f) / 2f + x, (float)(j * 16 - (int)Main.screenPosition.Y + offsetY) + y) + zero, new Rectangle(frameX, frameY, width, height), color, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
}
}
}
}