200 lines
5.2 KiB
C#
200 lines
5.2 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.DataStructures;
|
|
using Terraria.Enums;
|
|
using Terraria.ID;
|
|
using Terraria.Localization;
|
|
using Terraria.ModLoader;
|
|
using Terraria.ObjectData;
|
|
|
|
namespace CalamityMod.Tiles
|
|
{
|
|
public class ProfanedChest : ModTile
|
|
{
|
|
public override void SetDefaults()
|
|
{
|
|
Main.tileSpelunker[Type] = true;
|
|
Main.tileContainer[Type] = true;
|
|
Main.tileShine2[Type] = true;
|
|
Main.tileShine[Type] = 1200;
|
|
Main.tileFrameImportant[Type] = true;
|
|
Main.tileNoAttach[Type] = true;
|
|
Main.tileValue[Type] = 500;
|
|
TileID.Sets.HasOutlines[Type] = true;
|
|
TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2);
|
|
TileObjectData.newTile.Origin = new Point16(0, 1);
|
|
TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 };
|
|
TileObjectData.newTile.HookCheck = new PlacementHook(new Func<int, int, int, int, int, int>(Chest.FindEmptyChest), -1, 0, true);
|
|
TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(new Func<int, int, int, int, int, int>(Chest.AfterPlacement_Hook), -1, 0, false);
|
|
TileObjectData.newTile.AnchorInvalidTiles = new int[] { 127 };
|
|
TileObjectData.newTile.StyleHorizontal = true;
|
|
TileObjectData.newTile.LavaDeath = false;
|
|
TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0);
|
|
TileObjectData.addTile(Type);
|
|
ModTranslation name = CreateMapEntryName();
|
|
name.SetDefault("Profaned Chest");
|
|
AddMapEntry(new Color(200, 200, 200), name, MapChestName);
|
|
disableSmartCursor = true;
|
|
adjTiles = new int[] { TileID.Containers };
|
|
chest = "Profaned Chest";
|
|
chestDrop = mod.ItemType("ProfanedChest");
|
|
}
|
|
|
|
public override bool HasSmartInteract()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public string MapChestName(string name, int i, int j)
|
|
{
|
|
int left = i;
|
|
int top = j;
|
|
Tile tile = Main.tile[i, j];
|
|
if (tile.frameX % 36 != 0)
|
|
{
|
|
left--;
|
|
}
|
|
if (tile.frameY != 0)
|
|
{
|
|
top--;
|
|
}
|
|
int chest = Chest.FindChest(left, top);
|
|
if (Main.chest[chest].name == "")
|
|
{
|
|
return name;
|
|
}
|
|
else
|
|
{
|
|
return name + ": " + Main.chest[chest].name;
|
|
}
|
|
}
|
|
|
|
public override void NumDust(int i, int j, bool fail, ref int num)
|
|
{
|
|
num = 1;
|
|
}
|
|
|
|
public override void KillMultiTile(int i, int j, int frameX, int frameY)
|
|
{
|
|
Item.NewItem(i * 16, j * 16, 32, 32, chestDrop);
|
|
Chest.DestroyChest(i, j);
|
|
}
|
|
|
|
public override void RightClick(int i, int j)
|
|
{
|
|
Player player = Main.LocalPlayer;
|
|
Tile tile = Main.tile[i, j];
|
|
Main.mouseRightRelease = false;
|
|
int left = i;
|
|
int top = j;
|
|
if (tile.frameX % 36 != 0)
|
|
{
|
|
left--;
|
|
}
|
|
if (tile.frameY != 0)
|
|
{
|
|
top--;
|
|
}
|
|
if (player.sign >= 0)
|
|
{
|
|
Main.PlaySound(SoundID.MenuClose);
|
|
player.sign = -1;
|
|
Main.editSign = false;
|
|
Main.npcChatText = "";
|
|
}
|
|
if (Main.editChest)
|
|
{
|
|
Main.PlaySound(SoundID.MenuTick);
|
|
Main.editChest = false;
|
|
Main.npcChatText = "";
|
|
}
|
|
if (player.editedChestName)
|
|
{
|
|
NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0);
|
|
player.editedChestName = false;
|
|
}
|
|
if (Main.netMode == 1)
|
|
{
|
|
if (left == player.chestX && top == player.chestY && player.chest >= 0)
|
|
{
|
|
player.chest = -1;
|
|
Recipe.FindRecipes();
|
|
Main.PlaySound(SoundID.MenuClose);
|
|
}
|
|
else
|
|
{
|
|
NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0);
|
|
Main.stackSplit = 600;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int chest = Chest.FindChest(left, top);
|
|
if (chest >= 0)
|
|
{
|
|
Main.stackSplit = 600;
|
|
if (chest == player.chest)
|
|
{
|
|
player.chest = -1;
|
|
Main.PlaySound(SoundID.MenuClose);
|
|
}
|
|
else
|
|
{
|
|
player.chest = chest;
|
|
Main.playerInventory = true;
|
|
Main.recBigList = false;
|
|
player.chestX = left;
|
|
player.chestY = top;
|
|
Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick);
|
|
}
|
|
Recipe.FindRecipes();
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void MouseOver(int i, int j)
|
|
{
|
|
Player player = Main.LocalPlayer;
|
|
Tile tile = Main.tile[i, j];
|
|
int left = i;
|
|
int top = j;
|
|
if (tile.frameX % 36 != 0)
|
|
{
|
|
left--;
|
|
}
|
|
if (tile.frameY != 0)
|
|
{
|
|
top--;
|
|
}
|
|
int chest = Chest.FindChest(left, top);
|
|
player.showItemIcon2 = -1;
|
|
if (chest < 0)
|
|
{
|
|
player.showItemIconText = Language.GetTextValue("LegacyChestType.0");
|
|
}
|
|
else
|
|
{
|
|
player.showItemIconText = Main.chest[chest].name.Length > 0 ? Main.chest[chest].name : "Profaned Chest";
|
|
if (player.showItemIconText == "Profaned Chest")
|
|
{
|
|
player.showItemIcon2 = mod.ItemType("ProfanedChest");
|
|
player.showItemIconText = "";
|
|
}
|
|
}
|
|
player.noThrow = 2;
|
|
player.showItemIcon = true;
|
|
}
|
|
|
|
public override void MouseOverFar(int i, int j)
|
|
{
|
|
MouseOver(i, j);
|
|
Player player = Main.LocalPlayer;
|
|
if (player.showItemIconText == "")
|
|
{
|
|
player.showItemIcon = false;
|
|
player.showItemIcon2 = 0;
|
|
}
|
|
}
|
|
}
|
|
} |