Terraria 1.4.0.5 Source Code
This commit is contained in:
commit
05205f009e
1059 changed files with 563450 additions and 0 deletions
21
GameContent/Tile_Entities/DisplayDollSlot.cs
Normal file
21
GameContent/Tile_Entities/DisplayDollSlot.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.DisplayDollSlot
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public static class DisplayDollSlot
|
||||
{
|
||||
public const int Armor_Head = 0;
|
||||
public const int Armor_Shirt = 1;
|
||||
public const int Armor_Legs = 2;
|
||||
public const int Acc_1 = 3;
|
||||
public const int Acc_2 = 4;
|
||||
public const int Acc_3 = 5;
|
||||
public const int Acc_4 = 6;
|
||||
public const int Acc_5 = 7;
|
||||
public const int Count = 8;
|
||||
}
|
||||
}
|
15
GameContent/Tile_Entities/HatRackSlot.cs
Normal file
15
GameContent/Tile_Entities/HatRackSlot.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.HatRackSlot
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public static class HatRackSlot
|
||||
{
|
||||
public const int LeftHat = 0;
|
||||
public const int RightHat = 1;
|
||||
public const int Count = 2;
|
||||
}
|
||||
}
|
510
GameContent/Tile_Entities/TEDisplayDoll.cs
Normal file
510
GameContent/Tile_Entities/TEDisplayDoll.cs
Normal file
|
@ -0,0 +1,510 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TEDisplayDoll
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.IO;
|
||||
using Terraria.Audio;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.GameInput;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TEDisplayDoll : TileEntity
|
||||
{
|
||||
private static byte _myEntityID;
|
||||
private const int MyTileID = 470;
|
||||
private const int entityTileWidth = 2;
|
||||
private const int entityTileHeight = 3;
|
||||
private Player _dollPlayer;
|
||||
private Item[] _items;
|
||||
private Item[] _dyes;
|
||||
private static int accessoryTargetSlot = 3;
|
||||
|
||||
public TEDisplayDoll()
|
||||
{
|
||||
this._items = new Item[8];
|
||||
for (int index = 0; index < this._items.Length; ++index)
|
||||
this._items[index] = new Item();
|
||||
this._dyes = new Item[8];
|
||||
for (int index = 0; index < this._dyes.Length; ++index)
|
||||
this._dyes[index] = new Item();
|
||||
this._dollPlayer = new Player();
|
||||
this._dollPlayer.hair = 15;
|
||||
this._dollPlayer.skinColor = Color.White;
|
||||
this._dollPlayer.skinVariant = 10;
|
||||
}
|
||||
|
||||
public override void RegisterTileEntityID(int assignedID) => TEDisplayDoll._myEntityID = (byte) assignedID;
|
||||
|
||||
public override TileEntity GenerateInstance() => (TileEntity) new TEDisplayDoll();
|
||||
|
||||
public override void NetPlaceEntityAttempt(int x, int y) => NetMessage.SendData(86, number: TEDisplayDoll.Place(x, y), number2: ((float) x), number3: ((float) y));
|
||||
|
||||
public static int Place(int x, int y)
|
||||
{
|
||||
TEDisplayDoll teDisplayDoll = new TEDisplayDoll();
|
||||
teDisplayDoll.Position = new Point16(x, y);
|
||||
teDisplayDoll.ID = TileEntity.AssignNewID();
|
||||
teDisplayDoll.type = TEDisplayDoll._myEntityID;
|
||||
TileEntity.ByID[teDisplayDoll.ID] = (TileEntity) teDisplayDoll;
|
||||
TileEntity.ByPosition[teDisplayDoll.Position] = (TileEntity) teDisplayDoll;
|
||||
return teDisplayDoll.ID;
|
||||
}
|
||||
|
||||
public static int Hook_AfterPlacement(
|
||||
int x,
|
||||
int y,
|
||||
int type = 470,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
return TEDisplayDoll.Place(x, y - 2);
|
||||
NetMessage.SendTileSquare(Main.myPlayer, x, y - 1, 3);
|
||||
NetMessage.SendData(87, number: x, number2: ((float) (y - 2)), number3: ((float) TEDisplayDoll._myEntityID));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || (int) tileEntity.type != (int) TEDisplayDoll._myEntityID)
|
||||
return;
|
||||
TileEntity.ByID.Remove(tileEntity.ID);
|
||||
TileEntity.ByPosition.Remove(new Point16(x, y));
|
||||
}
|
||||
|
||||
public static int Find(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
return TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) && (int) tileEntity.type == (int) TEDisplayDoll._myEntityID ? tileEntity.ID : -1;
|
||||
}
|
||||
|
||||
public override void WriteExtraData(BinaryWriter writer, bool networkSend)
|
||||
{
|
||||
BitsByte bitsByte1 = (BitsByte) (byte) 0;
|
||||
bitsByte1[0] = !this._items[0].IsAir;
|
||||
bitsByte1[1] = !this._items[1].IsAir;
|
||||
bitsByte1[2] = !this._items[2].IsAir;
|
||||
bitsByte1[3] = !this._items[3].IsAir;
|
||||
bitsByte1[4] = !this._items[4].IsAir;
|
||||
bitsByte1[5] = !this._items[5].IsAir;
|
||||
bitsByte1[6] = !this._items[6].IsAir;
|
||||
bitsByte1[7] = !this._items[7].IsAir;
|
||||
BitsByte bitsByte2 = (BitsByte) (byte) 0;
|
||||
bitsByte2[0] = !this._dyes[0].IsAir;
|
||||
bitsByte2[1] = !this._dyes[1].IsAir;
|
||||
bitsByte2[2] = !this._dyes[2].IsAir;
|
||||
bitsByte2[3] = !this._dyes[3].IsAir;
|
||||
bitsByte2[4] = !this._dyes[4].IsAir;
|
||||
bitsByte2[5] = !this._dyes[5].IsAir;
|
||||
bitsByte2[6] = !this._dyes[6].IsAir;
|
||||
bitsByte2[7] = !this._dyes[7].IsAir;
|
||||
writer.Write((byte) bitsByte1);
|
||||
writer.Write((byte) bitsByte2);
|
||||
for (int index = 0; index < 8; ++index)
|
||||
{
|
||||
Item obj = this._items[index];
|
||||
if (!obj.IsAir)
|
||||
{
|
||||
writer.Write((short) obj.netID);
|
||||
writer.Write(obj.prefix);
|
||||
writer.Write((short) obj.stack);
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < 8; ++index)
|
||||
{
|
||||
Item dye = this._dyes[index];
|
||||
if (!dye.IsAir)
|
||||
{
|
||||
writer.Write((short) dye.netID);
|
||||
writer.Write(dye.prefix);
|
||||
writer.Write((short) dye.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadExtraData(BinaryReader reader, bool networkSend)
|
||||
{
|
||||
BitsByte bitsByte1 = (BitsByte) reader.ReadByte();
|
||||
BitsByte bitsByte2 = (BitsByte) reader.ReadByte();
|
||||
for (int key = 0; key < 8; ++key)
|
||||
{
|
||||
this._items[key] = new Item();
|
||||
Item obj = this._items[key];
|
||||
if (bitsByte1[key])
|
||||
{
|
||||
obj.netDefaults((int) reader.ReadInt16());
|
||||
obj.Prefix((int) reader.ReadByte());
|
||||
obj.stack = (int) reader.ReadInt16();
|
||||
}
|
||||
}
|
||||
for (int key = 0; key < 8; ++key)
|
||||
{
|
||||
this._dyes[key] = new Item();
|
||||
Item dye = this._dyes[key];
|
||||
if (bitsByte2[key])
|
||||
{
|
||||
dye.netDefaults((int) reader.ReadInt16());
|
||||
dye.Prefix((int) reader.ReadByte());
|
||||
dye.stack = (int) reader.ReadInt16();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() => this.Position.X.ToString() + "x " + (object) this.Position.Y + "y item: " + (object) this._items[0] + " " + (object) this._items[1] + " " + (object) this._items[2];
|
||||
|
||||
public static void Framing_CheckTile(int callX, int callY)
|
||||
{
|
||||
if (WorldGen.destroyObject)
|
||||
return;
|
||||
int num1 = callX;
|
||||
int num2 = callY;
|
||||
Tile tileSafely = Framing.GetTileSafely(callX, callY);
|
||||
int num3 = num1 - (int) tileSafely.frameX / 18 % 2;
|
||||
int y = num2 - (int) tileSafely.frameY / 18 % 3;
|
||||
bool flag = false;
|
||||
for (int index1 = num3; index1 < num3 + 2; ++index1)
|
||||
{
|
||||
for (int index2 = y; index2 < y + 3; ++index2)
|
||||
{
|
||||
Tile tile = Main.tile[index1, index2];
|
||||
if (!tile.active() || tile.type != (ushort) 470)
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (!WorldGen.SolidTileAllowBottomSlope(num3, y + 3) || !WorldGen.SolidTileAllowBottomSlope(num3 + 1, y + 3))
|
||||
flag = true;
|
||||
if (!flag)
|
||||
return;
|
||||
TEDisplayDoll.Kill(num3, y);
|
||||
if ((int) Main.tile[callX, callY].frameX / 72 != 1)
|
||||
Item.NewItem(num3 * 16, y * 16, 32, 48, 498);
|
||||
else
|
||||
Item.NewItem(num3 * 16, y * 16, 32, 48, 1989);
|
||||
WorldGen.destroyObject = true;
|
||||
for (int i = num3; i < num3 + 2; ++i)
|
||||
{
|
||||
for (int j = y; j < y + 3; ++j)
|
||||
{
|
||||
if (Main.tile[i, j].active() && Main.tile[i, j].type == (ushort) 470)
|
||||
WorldGen.KillTile(i, j);
|
||||
}
|
||||
}
|
||||
WorldGen.destroyObject = false;
|
||||
}
|
||||
|
||||
public void Draw(int tileLeftX, int tileTopY)
|
||||
{
|
||||
Player dollPlayer = this._dollPlayer;
|
||||
for (int index = 0; index < 8; ++index)
|
||||
{
|
||||
dollPlayer.armor[index] = this._items[index];
|
||||
dollPlayer.dye[index] = this._dyes[index];
|
||||
}
|
||||
dollPlayer.direction = -1;
|
||||
dollPlayer.Male = true;
|
||||
Tile tileSafely = Framing.GetTileSafely(tileLeftX, tileTopY);
|
||||
if ((int) tileSafely.frameX % 72 == 36)
|
||||
dollPlayer.direction = 1;
|
||||
if ((int) tileSafely.frameX / 72 == 1)
|
||||
dollPlayer.Male = false;
|
||||
dollPlayer.isDisplayDollOrInanimate = true;
|
||||
dollPlayer.ResetEffects();
|
||||
dollPlayer.ResetVisibleAccessories();
|
||||
dollPlayer.UpdateDyes();
|
||||
dollPlayer.DisplayDollUpdate();
|
||||
dollPlayer.UpdateSocialShadow();
|
||||
dollPlayer.PlayerFrame();
|
||||
Vector2 vector2 = new Vector2((float) (tileLeftX + 1), (float) (tileTopY + 3)) * 16f + new Vector2((float) (-dollPlayer.width / 2), (float) (-dollPlayer.height - 6));
|
||||
dollPlayer.position = vector2;
|
||||
dollPlayer.skinDyePacked = PlayerDrawHelper.PackShader((int) tileSafely.color(), PlayerDrawHelper.ShaderConfiguration.TilePaintID);
|
||||
Main.PlayerRenderer.DrawPlayer(Main.Camera, dollPlayer, dollPlayer.position, 0.0f, dollPlayer.fullRotationOrigin);
|
||||
}
|
||||
|
||||
public override void OnPlayerUpdate(Player player)
|
||||
{
|
||||
if (player.InInteractionRange(player.tileEntityAnchor.X, player.tileEntityAnchor.Y) && player.chest == -1 && player.talkNPC == -1)
|
||||
return;
|
||||
if (player.chest == -1 && player.talkNPC == -1)
|
||||
SoundEngine.PlaySound(11);
|
||||
player.tileEntityAnchor.Clear();
|
||||
Recipe.FindRecipes();
|
||||
}
|
||||
|
||||
public static void OnPlayerInteraction(Player player, int clickX, int clickY)
|
||||
{
|
||||
int x = clickX;
|
||||
int index = clickY;
|
||||
if ((int) Main.tile[x, index].frameX % 36 != 0)
|
||||
--x;
|
||||
int y1 = index - (int) Main.tile[x, index].frameY / 18;
|
||||
int id = TEDisplayDoll.Find(x, y1);
|
||||
if (id == -1)
|
||||
return;
|
||||
int y2 = y1 + 1;
|
||||
TEDisplayDoll.accessoryTargetSlot = 3;
|
||||
TileEntity.BasicOpenCloseInteraction(player, x, y2, id);
|
||||
}
|
||||
|
||||
public override void OnInventoryDraw(Player player, SpriteBatch spriteBatch)
|
||||
{
|
||||
if (Main.tile[player.tileEntityAnchor.X, player.tileEntityAnchor.Y].type != (ushort) 470)
|
||||
{
|
||||
player.tileEntityAnchor.Clear();
|
||||
Recipe.FindRecipes();
|
||||
}
|
||||
else
|
||||
this.DrawInner(player, spriteBatch);
|
||||
}
|
||||
|
||||
public override bool TryGetItemGamepadOverrideInstructions(
|
||||
Item[] inv,
|
||||
int context,
|
||||
int slot,
|
||||
out string instruction)
|
||||
{
|
||||
instruction = "";
|
||||
Item newItem = inv[slot];
|
||||
if (newItem.IsAir || newItem.favorited)
|
||||
return false;
|
||||
switch (context)
|
||||
{
|
||||
case 0:
|
||||
if (TEDisplayDoll.FitsDisplayDoll(newItem))
|
||||
{
|
||||
instruction = Lang.misc[76].Value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
if (Main.player[Main.myPlayer].ItemSpace(newItem).CanTakeItemToPersonalInventory)
|
||||
{
|
||||
instruction = Lang.misc[68].Value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GetItemGamepadInstructions(int slot = 0)
|
||||
{
|
||||
Item[] inv = this._items;
|
||||
int slot1 = slot;
|
||||
int context = 23;
|
||||
if (slot >= 8)
|
||||
{
|
||||
slot1 -= 8;
|
||||
inv = this._dyes;
|
||||
context = 25;
|
||||
}
|
||||
else if (slot >= 3)
|
||||
{
|
||||
inv = this._items;
|
||||
context = 24;
|
||||
}
|
||||
return ItemSlot.GetGamepadInstructions(inv, context, slot1);
|
||||
}
|
||||
|
||||
private void DrawInner(Player player, SpriteBatch spriteBatch)
|
||||
{
|
||||
Main.inventoryScale = 0.72f;
|
||||
this.DrawSlotPairSet(player, spriteBatch, 3, 0, 0.0f, 0.5f, 23);
|
||||
this.DrawSlotPairSet(player, spriteBatch, 5, 3, 3f, 0.5f, 24);
|
||||
}
|
||||
|
||||
private void DrawSlotPairSet(
|
||||
Player player,
|
||||
SpriteBatch spriteBatch,
|
||||
int slotsToShowLine,
|
||||
int slotsArrayOffset,
|
||||
float offsetX,
|
||||
float offsetY,
|
||||
int inventoryContextTarget)
|
||||
{
|
||||
Item[] items = this._items;
|
||||
for (int index1 = 0; index1 < slotsToShowLine; ++index1)
|
||||
{
|
||||
for (int index2 = 0; index2 < 2; ++index2)
|
||||
{
|
||||
int num1 = (int) (73.0 + ((double) index1 + (double) offsetX) * 56.0 * (double) Main.inventoryScale);
|
||||
int num2 = (int) ((double) Main.instance.invBottom + ((double) index2 + (double) offsetY) * 56.0 * (double) Main.inventoryScale);
|
||||
Item[] inv;
|
||||
int context;
|
||||
if (index2 == 0)
|
||||
{
|
||||
inv = this._items;
|
||||
context = inventoryContextTarget;
|
||||
}
|
||||
else
|
||||
{
|
||||
inv = this._dyes;
|
||||
context = 25;
|
||||
}
|
||||
if (Utils.FloatIntersect((float) Main.mouseX, (float) Main.mouseY, 0.0f, 0.0f, (float) num1, (float) num2, (float) TextureAssets.InventoryBack.Width() * Main.inventoryScale, (float) TextureAssets.InventoryBack.Height() * Main.inventoryScale) && !PlayerInput.IgnoreMouseInterface)
|
||||
{
|
||||
player.mouseInterface = true;
|
||||
ItemSlot.Handle(inv, context, index1 + slotsArrayOffset);
|
||||
}
|
||||
ItemSlot.Draw(spriteBatch, inv, context, index1 + slotsArrayOffset, new Vector2((float) num1, (float) num2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OverrideItemSlotHover(Item[] inv, int context = 0, int slot = 0)
|
||||
{
|
||||
Item obj = inv[slot];
|
||||
if (!obj.IsAir && !inv[slot].favorited && context == 0 && TEDisplayDoll.FitsDisplayDoll(obj))
|
||||
{
|
||||
Main.cursorOverride = 9;
|
||||
return true;
|
||||
}
|
||||
if (obj.IsAir || context != 23 && context != 24 && context != 25 || !Main.player[Main.myPlayer].ItemSpace(inv[slot]).CanTakeItemToPersonalInventory)
|
||||
return false;
|
||||
Main.cursorOverride = 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OverrideItemSlotLeftClick(Item[] inv, int context = 0, int slot = 0)
|
||||
{
|
||||
if (!ItemSlot.ShiftInUse)
|
||||
return false;
|
||||
if (Main.cursorOverride == 9 && context == 0)
|
||||
{
|
||||
Item obj = inv[slot];
|
||||
if (!obj.IsAir && !obj.favorited && TEDisplayDoll.FitsDisplayDoll(obj))
|
||||
return this.TryFitting(inv, context, slot);
|
||||
}
|
||||
if ((Main.cursorOverride != 8 || context != 23) && context != 24 && context != 25)
|
||||
return false;
|
||||
inv[slot] = Main.player[Main.myPlayer].GetItem(Main.myPlayer, inv[slot], GetItemSettings.InventoryEntityToPlayerInventorySettings);
|
||||
if (Main.netMode == 1)
|
||||
{
|
||||
if (context == 25)
|
||||
NetMessage.SendData(121, number: Main.myPlayer, number2: ((float) this.ID), number3: ((float) slot), number4: 1f);
|
||||
else
|
||||
NetMessage.SendData(121, number: Main.myPlayer, number2: ((float) this.ID), number3: ((float) slot));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool FitsDisplayDoll(Item item)
|
||||
{
|
||||
if (item.maxStack > 1)
|
||||
return false;
|
||||
return item.headSlot > 0 || item.bodySlot > 0 || item.legSlot > 0 || item.accessory;
|
||||
}
|
||||
|
||||
private bool TryFitting(Item[] inv, int context = 0, int slot = 0, bool justCheck = false)
|
||||
{
|
||||
Item obj = inv[slot];
|
||||
int index1 = -1;
|
||||
if (obj.headSlot > 0)
|
||||
index1 = 0;
|
||||
if (obj.bodySlot > 0)
|
||||
index1 = 1;
|
||||
if (obj.legSlot > 0)
|
||||
index1 = 2;
|
||||
if (obj.accessory)
|
||||
index1 = TEDisplayDoll.accessoryTargetSlot;
|
||||
if (index1 == -1)
|
||||
return false;
|
||||
if (justCheck)
|
||||
return true;
|
||||
if (obj.accessory)
|
||||
{
|
||||
++TEDisplayDoll.accessoryTargetSlot;
|
||||
if (TEDisplayDoll.accessoryTargetSlot >= 8)
|
||||
TEDisplayDoll.accessoryTargetSlot = 3;
|
||||
for (int index2 = 3; index2 < 8; ++index2)
|
||||
{
|
||||
if (this._items[index2].IsAir)
|
||||
{
|
||||
index1 = index2;
|
||||
TEDisplayDoll.accessoryTargetSlot = index2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int index3 = 3; index3 < 8; ++index3)
|
||||
{
|
||||
if (inv[slot].type == this._items[index3].type)
|
||||
index1 = index3;
|
||||
}
|
||||
}
|
||||
SoundEngine.PlaySound(7);
|
||||
Utils.Swap<Item>(ref this._items[index1], ref inv[slot]);
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(121, number: Main.myPlayer, number2: ((float) this.ID), number3: ((float) index1));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteItem(int itemIndex, BinaryWriter writer, bool dye)
|
||||
{
|
||||
Item dye1 = this._items[itemIndex];
|
||||
if (dye)
|
||||
dye1 = this._dyes[itemIndex];
|
||||
writer.Write((ushort) dye1.netID);
|
||||
writer.Write((ushort) dye1.stack);
|
||||
writer.Write(dye1.prefix);
|
||||
}
|
||||
|
||||
public void ReadItem(int itemIndex, BinaryReader reader, bool dye)
|
||||
{
|
||||
int Type = (int) reader.ReadUInt16();
|
||||
int num = (int) reader.ReadUInt16();
|
||||
int pre = (int) reader.ReadByte();
|
||||
Item dye1 = this._items[itemIndex];
|
||||
if (dye)
|
||||
dye1 = this._dyes[itemIndex];
|
||||
dye1.SetDefaults(Type);
|
||||
dye1.stack = num;
|
||||
dye1.Prefix(pre);
|
||||
}
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 470 && Main.tile[x, y].frameY == (short) 0 && (int) Main.tile[x, y].frameX % 36 == 0;
|
||||
|
||||
public void SetInventoryFromMannequin(int headFrame, int shirtFrame, int legFrame)
|
||||
{
|
||||
headFrame /= 100;
|
||||
shirtFrame /= 100;
|
||||
legFrame /= 100;
|
||||
if (headFrame >= 0 && headFrame < Item.headType.Length)
|
||||
this._items[0].SetDefaults(Item.headType[headFrame]);
|
||||
if (shirtFrame >= 0 && shirtFrame < Item.bodyType.Length)
|
||||
this._items[1].SetDefaults(Item.bodyType[shirtFrame]);
|
||||
if (legFrame < 0 || legFrame >= Item.legType.Length)
|
||||
return;
|
||||
this._items[2].SetDefaults(Item.legType[legFrame]);
|
||||
}
|
||||
|
||||
public static bool IsBreakable(int clickX, int clickY)
|
||||
{
|
||||
int x = clickX;
|
||||
int index = clickY;
|
||||
if ((int) Main.tile[x, index].frameX % 36 != 0)
|
||||
--x;
|
||||
int y = index - (int) Main.tile[x, index].frameY / 18;
|
||||
int key = TEDisplayDoll.Find(x, y);
|
||||
return key == -1 || !(TileEntity.ByID[key] as TEDisplayDoll).ContainsItems();
|
||||
}
|
||||
|
||||
public bool ContainsItems()
|
||||
{
|
||||
for (int index = 0; index < 8; ++index)
|
||||
{
|
||||
if (!this._items[index].IsAir || !this._dyes[index].IsAir)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
175
GameContent/Tile_Entities/TEFoodPlatter.cs
Normal file
175
GameContent/Tile_Entities/TEFoodPlatter.cs
Normal file
|
@ -0,0 +1,175 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TEFoodPlatter
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.IO;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ID;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TEFoodPlatter : TileEntity
|
||||
{
|
||||
private static byte _myEntityID;
|
||||
public Item item;
|
||||
|
||||
public override void RegisterTileEntityID(int assignedID) => TEFoodPlatter._myEntityID = (byte) assignedID;
|
||||
|
||||
public override void NetPlaceEntityAttempt(int x, int y) => TEFoodPlatter.NetPlaceEntity(x, y);
|
||||
|
||||
public static void NetPlaceEntity(int x, int y) => NetMessage.SendData(86, number: TEFoodPlatter.Place(x, y), number2: ((float) x), number3: ((float) y));
|
||||
|
||||
public override TileEntity GenerateInstance() => (TileEntity) new TEFoodPlatter();
|
||||
|
||||
public TEFoodPlatter() => this.item = new Item();
|
||||
|
||||
public static int Place(int x, int y)
|
||||
{
|
||||
TEFoodPlatter teFoodPlatter = new TEFoodPlatter();
|
||||
teFoodPlatter.Position = new Point16(x, y);
|
||||
teFoodPlatter.ID = TileEntity.AssignNewID();
|
||||
teFoodPlatter.type = TEFoodPlatter._myEntityID;
|
||||
TileEntity.ByID[teFoodPlatter.ID] = (TileEntity) teFoodPlatter;
|
||||
TileEntity.ByPosition[teFoodPlatter.Position] = (TileEntity) teFoodPlatter;
|
||||
return teFoodPlatter.ID;
|
||||
}
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y) => TEFoodPlatter.ValidTile(x, y);
|
||||
|
||||
public static int Hook_AfterPlacement(
|
||||
int x,
|
||||
int y,
|
||||
int type = 520,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
return TEFoodPlatter.Place(x, y);
|
||||
NetMessage.SendTileSquare(Main.myPlayer, x, y, 1);
|
||||
NetMessage.SendData(87, number: x, number2: ((float) y), number3: ((float) TEFoodPlatter._myEntityID));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || (int) tileEntity.type != (int) TEFoodPlatter._myEntityID)
|
||||
return;
|
||||
TileEntity.ByID.Remove(tileEntity.ID);
|
||||
TileEntity.ByPosition.Remove(new Point16(x, y));
|
||||
}
|
||||
|
||||
public static int Find(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
return TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) && (int) tileEntity.type == (int) TEFoodPlatter._myEntityID ? tileEntity.ID : -1;
|
||||
}
|
||||
|
||||
public static bool ValidTile(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 520 && Main.tile[x, y].frameY == (short) 0;
|
||||
|
||||
public override void WriteExtraData(BinaryWriter writer, bool networkSend)
|
||||
{
|
||||
writer.Write((short) this.item.netID);
|
||||
writer.Write(this.item.prefix);
|
||||
writer.Write((short) this.item.stack);
|
||||
}
|
||||
|
||||
public override void ReadExtraData(BinaryReader reader, bool networkSend)
|
||||
{
|
||||
this.item = new Item();
|
||||
this.item.netDefaults((int) reader.ReadInt16());
|
||||
this.item.Prefix((int) reader.ReadByte());
|
||||
this.item.stack = (int) reader.ReadInt16();
|
||||
}
|
||||
|
||||
public override string ToString() => this.Position.X.ToString() + "x " + (object) this.Position.Y + "y item: " + (object) this.item;
|
||||
|
||||
public void DropItem()
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
Item.NewItem((int) this.Position.X * 16, (int) this.Position.Y * 16, 16, 16, this.item.netID, pfix: ((int) this.item.prefix));
|
||||
this.item = new Item();
|
||||
}
|
||||
|
||||
public static void TryPlacing(int x, int y, int netid, int prefix, int stack)
|
||||
{
|
||||
WorldGen.RangeFrame(x, y, x + 1, y + 1);
|
||||
int key = TEFoodPlatter.Find(x, y);
|
||||
if (key == -1)
|
||||
{
|
||||
int number = Item.NewItem(x * 16, y * 16, 16, 16, 1);
|
||||
Main.item[number].netDefaults(netid);
|
||||
Main.item[number].Prefix(prefix);
|
||||
Main.item[number].stack = stack;
|
||||
NetMessage.SendData(21, number: number);
|
||||
}
|
||||
else
|
||||
{
|
||||
TEFoodPlatter teFoodPlatter = (TEFoodPlatter) TileEntity.ByID[key];
|
||||
if (teFoodPlatter.item.stack > 0)
|
||||
teFoodPlatter.DropItem();
|
||||
teFoodPlatter.item = new Item();
|
||||
teFoodPlatter.item.netDefaults(netid);
|
||||
teFoodPlatter.item.Prefix(prefix);
|
||||
teFoodPlatter.item.stack = stack;
|
||||
NetMessage.SendData(86, number: teFoodPlatter.ID, number2: ((float) x), number3: ((float) y));
|
||||
}
|
||||
}
|
||||
|
||||
public static void OnPlayerInteraction(Player player, int clickX, int clickY)
|
||||
{
|
||||
if (TEFoodPlatter.FitsFoodPlatter(player.inventory[player.selectedItem]) && !player.inventory[player.selectedItem].favorited)
|
||||
{
|
||||
player.GamepadEnableGrappleCooldown();
|
||||
TEFoodPlatter.PlaceItemInFrame(player, clickX, clickY);
|
||||
Recipe.FindRecipes();
|
||||
}
|
||||
else
|
||||
{
|
||||
int x = clickX;
|
||||
int y = clickY;
|
||||
int key = TEFoodPlatter.Find(x, y);
|
||||
if (key == -1 || ((TEFoodPlatter) TileEntity.ByID[key]).item.stack <= 0)
|
||||
return;
|
||||
player.GamepadEnableGrappleCooldown();
|
||||
WorldGen.KillTile(clickX, clickY, true);
|
||||
if (Main.netMode != 1)
|
||||
return;
|
||||
NetMessage.SendData(17, number2: ((float) x), number3: ((float) y), number4: 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool FitsFoodPlatter(Item i) => i.stack > 0 && ItemID.Sets.IsFood[i.type];
|
||||
|
||||
public static void PlaceItemInFrame(Player player, int x, int y)
|
||||
{
|
||||
int key = TEFoodPlatter.Find(x, y);
|
||||
if (key == -1)
|
||||
return;
|
||||
if (((TEFoodPlatter) TileEntity.ByID[key]).item.stack > 0)
|
||||
{
|
||||
WorldGen.KillTile(x, y, true);
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(17, number2: ((float) Player.tileTargetX), number3: ((float) y), number4: 1f);
|
||||
}
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(133, number: x, number2: ((float) y), number3: ((float) player.selectedItem), number4: ((float) player.whoAmI), number5: 1);
|
||||
else
|
||||
TEFoodPlatter.TryPlacing(x, y, player.inventory[player.selectedItem].netID, (int) player.inventory[player.selectedItem].prefix, 1);
|
||||
--player.inventory[player.selectedItem].stack;
|
||||
if (player.inventory[player.selectedItem].stack <= 0)
|
||||
{
|
||||
player.inventory[player.selectedItem].SetDefaults();
|
||||
Main.mouseItem.SetDefaults();
|
||||
}
|
||||
if (player.selectedItem == 58)
|
||||
Main.mouseItem = player.inventory[player.selectedItem].Clone();
|
||||
player.releaseUseItem = false;
|
||||
player.mouseInterface = true;
|
||||
WorldGen.RangeFrame(x, y, x + 1, y + 1);
|
||||
}
|
||||
}
|
||||
}
|
457
GameContent/Tile_Entities/TEHatRack.cs
Normal file
457
GameContent/Tile_Entities/TEHatRack.cs
Normal file
|
@ -0,0 +1,457 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TEHatRack
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.IO;
|
||||
using Terraria.Audio;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.GameInput;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TEHatRack : TileEntity
|
||||
{
|
||||
private static byte _myEntityID;
|
||||
private const int MyTileID = 475;
|
||||
private const int entityTileWidth = 3;
|
||||
private const int entityTileHeight = 4;
|
||||
private Player _dollPlayer;
|
||||
private Item[] _items;
|
||||
private Item[] _dyes;
|
||||
private static int hatTargetSlot;
|
||||
|
||||
public TEHatRack()
|
||||
{
|
||||
this._items = new Item[2];
|
||||
for (int index = 0; index < this._items.Length; ++index)
|
||||
this._items[index] = new Item();
|
||||
this._dyes = new Item[2];
|
||||
for (int index = 0; index < this._dyes.Length; ++index)
|
||||
this._dyes[index] = new Item();
|
||||
this._dollPlayer = new Player();
|
||||
this._dollPlayer.hair = 15;
|
||||
this._dollPlayer.skinColor = Color.White;
|
||||
this._dollPlayer.skinVariant = 10;
|
||||
}
|
||||
|
||||
public override void RegisterTileEntityID(int assignedID) => TEHatRack._myEntityID = (byte) assignedID;
|
||||
|
||||
public override TileEntity GenerateInstance() => (TileEntity) new TEHatRack();
|
||||
|
||||
public override void NetPlaceEntityAttempt(int x, int y) => NetMessage.SendData(86, number: TEHatRack.Place(x, y), number2: ((float) x), number3: ((float) y));
|
||||
|
||||
public static int Place(int x, int y)
|
||||
{
|
||||
TEHatRack teHatRack = new TEHatRack();
|
||||
teHatRack.Position = new Point16(x, y);
|
||||
teHatRack.ID = TileEntity.AssignNewID();
|
||||
teHatRack.type = TEHatRack._myEntityID;
|
||||
TileEntity.ByID[teHatRack.ID] = (TileEntity) teHatRack;
|
||||
TileEntity.ByPosition[teHatRack.Position] = (TileEntity) teHatRack;
|
||||
return teHatRack.ID;
|
||||
}
|
||||
|
||||
public static int Hook_AfterPlacement(
|
||||
int x,
|
||||
int y,
|
||||
int type = 475,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
return TEHatRack.Place(x - 1, y - 3);
|
||||
NetMessage.SendTileSquare(Main.myPlayer, x, y - 1, 5);
|
||||
NetMessage.SendData(87, number: (x - 1), number2: ((float) (y - 3)), number3: ((float) TEHatRack._myEntityID));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || (int) tileEntity.type != (int) TEHatRack._myEntityID)
|
||||
return;
|
||||
TileEntity.ByID.Remove(tileEntity.ID);
|
||||
TileEntity.ByPosition.Remove(new Point16(x, y));
|
||||
}
|
||||
|
||||
public static int Find(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
return TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) && (int) tileEntity.type == (int) TEHatRack._myEntityID ? tileEntity.ID : -1;
|
||||
}
|
||||
|
||||
public override void WriteExtraData(BinaryWriter writer, bool networkSend)
|
||||
{
|
||||
BitsByte bitsByte = (BitsByte) (byte) 0;
|
||||
bitsByte[0] = !this._items[0].IsAir;
|
||||
bitsByte[1] = !this._items[1].IsAir;
|
||||
bitsByte[2] = !this._dyes[0].IsAir;
|
||||
bitsByte[3] = !this._dyes[1].IsAir;
|
||||
writer.Write((byte) bitsByte);
|
||||
for (int index = 0; index < 2; ++index)
|
||||
{
|
||||
Item obj = this._items[index];
|
||||
if (!obj.IsAir)
|
||||
{
|
||||
writer.Write((short) obj.netID);
|
||||
writer.Write(obj.prefix);
|
||||
writer.Write((short) obj.stack);
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < 2; ++index)
|
||||
{
|
||||
Item dye = this._dyes[index];
|
||||
if (!dye.IsAir)
|
||||
{
|
||||
writer.Write((short) dye.netID);
|
||||
writer.Write(dye.prefix);
|
||||
writer.Write((short) dye.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadExtraData(BinaryReader reader, bool networkSend)
|
||||
{
|
||||
BitsByte bitsByte = (BitsByte) reader.ReadByte();
|
||||
for (int key = 0; key < 2; ++key)
|
||||
{
|
||||
this._items[key] = new Item();
|
||||
Item obj = this._items[key];
|
||||
if (bitsByte[key])
|
||||
{
|
||||
obj.netDefaults((int) reader.ReadInt16());
|
||||
obj.Prefix((int) reader.ReadByte());
|
||||
obj.stack = (int) reader.ReadInt16();
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < 2; ++index)
|
||||
{
|
||||
this._dyes[index] = new Item();
|
||||
Item dye = this._dyes[index];
|
||||
if (bitsByte[index + 2])
|
||||
{
|
||||
dye.netDefaults((int) reader.ReadInt16());
|
||||
dye.Prefix((int) reader.ReadByte());
|
||||
dye.stack = (int) reader.ReadInt16();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() => this.Position.X.ToString() + "x " + (object) this.Position.Y + "y item: " + (object) this._items[0] + " " + (object) this._items[1];
|
||||
|
||||
public static void Framing_CheckTile(int callX, int callY)
|
||||
{
|
||||
if (WorldGen.destroyObject)
|
||||
return;
|
||||
int num1 = callX;
|
||||
int num2 = callY;
|
||||
Tile tileSafely = Framing.GetTileSafely(callX, callY);
|
||||
int num3 = num1 - (int) tileSafely.frameX / 18 % 3;
|
||||
int y = num2 - (int) tileSafely.frameY / 18 % 4;
|
||||
bool flag = false;
|
||||
for (int index1 = num3; index1 < num3 + 3; ++index1)
|
||||
{
|
||||
for (int index2 = y; index2 < y + 4; ++index2)
|
||||
{
|
||||
Tile tile = Main.tile[index1, index2];
|
||||
if (!tile.active() || tile.type != (ushort) 475)
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (!WorldGen.SolidTileAllowBottomSlope(num3, y + 4) || !WorldGen.SolidTileAllowBottomSlope(num3 + 1, y + 4) || !WorldGen.SolidTileAllowBottomSlope(num3 + 2, y + 4))
|
||||
flag = true;
|
||||
if (!flag)
|
||||
return;
|
||||
TEHatRack.Kill(num3, y);
|
||||
Item.NewItem(num3 * 16, y * 16, 48, 64, 3977);
|
||||
WorldGen.destroyObject = true;
|
||||
for (int i = num3; i < num3 + 3; ++i)
|
||||
{
|
||||
for (int j = y; j < y + 4; ++j)
|
||||
{
|
||||
if (Main.tile[i, j].active() && Main.tile[i, j].type == (ushort) 475)
|
||||
WorldGen.KillTile(i, j);
|
||||
}
|
||||
}
|
||||
WorldGen.destroyObject = false;
|
||||
}
|
||||
|
||||
public void Draw(int tileLeftX, int tileTopY)
|
||||
{
|
||||
Player dollPlayer = this._dollPlayer;
|
||||
dollPlayer.direction = -1;
|
||||
dollPlayer.Male = true;
|
||||
if ((int) Framing.GetTileSafely(tileLeftX, tileTopY).frameX % 216 == 54)
|
||||
dollPlayer.direction = 1;
|
||||
dollPlayer.isDisplayDollOrInanimate = true;
|
||||
dollPlayer.isHatRackDoll = true;
|
||||
dollPlayer.armor[0] = this._items[0];
|
||||
dollPlayer.dye[0] = this._dyes[0];
|
||||
dollPlayer.ResetEffects();
|
||||
dollPlayer.ResetVisibleAccessories();
|
||||
dollPlayer.invis = true;
|
||||
dollPlayer.UpdateDyes();
|
||||
dollPlayer.DisplayDollUpdate();
|
||||
dollPlayer.PlayerFrame();
|
||||
Vector2 vector2_1 = new Vector2((float) tileLeftX + 1.5f, (float) (tileTopY + 4)) * 16f;
|
||||
dollPlayer.direction *= -1;
|
||||
Vector2 vector2_2 = new Vector2((float) (-dollPlayer.width / 2), (float) (-dollPlayer.height - 6)) + new Vector2((float) (dollPlayer.direction * 14), -2f);
|
||||
dollPlayer.position = vector2_1 + vector2_2;
|
||||
Main.PlayerRenderer.DrawPlayer(Main.Camera, dollPlayer, dollPlayer.position, 0.0f, dollPlayer.fullRotationOrigin);
|
||||
dollPlayer.armor[0] = this._items[1];
|
||||
dollPlayer.dye[0] = this._dyes[1];
|
||||
dollPlayer.ResetEffects();
|
||||
dollPlayer.ResetVisibleAccessories();
|
||||
dollPlayer.invis = true;
|
||||
dollPlayer.UpdateDyes();
|
||||
dollPlayer.DisplayDollUpdate();
|
||||
dollPlayer.skipAnimatingValuesInPlayerFrame = true;
|
||||
dollPlayer.PlayerFrame();
|
||||
dollPlayer.skipAnimatingValuesInPlayerFrame = false;
|
||||
dollPlayer.direction *= -1;
|
||||
Vector2 vector2_3 = new Vector2((float) (-dollPlayer.width / 2), (float) (-dollPlayer.height - 6)) + new Vector2((float) (dollPlayer.direction * 12), 16f);
|
||||
dollPlayer.position = vector2_1 + vector2_3;
|
||||
Main.PlayerRenderer.DrawPlayer(Main.Camera, dollPlayer, dollPlayer.position, 0.0f, dollPlayer.fullRotationOrigin);
|
||||
}
|
||||
|
||||
public override string GetItemGamepadInstructions(int slot = 0)
|
||||
{
|
||||
Item[] inv = this._items;
|
||||
int slot1 = slot;
|
||||
int context = 26;
|
||||
if (slot >= 2)
|
||||
{
|
||||
slot1 -= 2;
|
||||
inv = this._dyes;
|
||||
context = 27;
|
||||
}
|
||||
return ItemSlot.GetGamepadInstructions(inv, context, slot1);
|
||||
}
|
||||
|
||||
public override bool TryGetItemGamepadOverrideInstructions(
|
||||
Item[] inv,
|
||||
int context,
|
||||
int slot,
|
||||
out string instruction)
|
||||
{
|
||||
instruction = "";
|
||||
Item newItem = inv[slot];
|
||||
if (newItem.IsAir || newItem.favorited)
|
||||
return false;
|
||||
switch (context)
|
||||
{
|
||||
case 0:
|
||||
if (TEHatRack.FitsHatRack(newItem))
|
||||
{
|
||||
instruction = Lang.misc[76].Value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 26:
|
||||
case 27:
|
||||
if (Main.player[Main.myPlayer].ItemSpace(newItem).CanTakeItemToPersonalInventory)
|
||||
{
|
||||
instruction = Lang.misc[68].Value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void OnPlayerUpdate(Player player)
|
||||
{
|
||||
if (player.InInteractionRange(player.tileEntityAnchor.X, player.tileEntityAnchor.Y) && player.chest == -1 && player.talkNPC == -1)
|
||||
return;
|
||||
if (player.chest == -1 && player.talkNPC == -1)
|
||||
SoundEngine.PlaySound(11);
|
||||
player.tileEntityAnchor.Clear();
|
||||
Recipe.FindRecipes();
|
||||
}
|
||||
|
||||
public static void OnPlayerInteraction(Player player, int clickX, int clickY)
|
||||
{
|
||||
int index1 = clickX;
|
||||
int index2 = clickY;
|
||||
int x1 = index1 - (int) Main.tile[index1, index2].frameX % 54 / 18;
|
||||
int y1 = index2 - (int) Main.tile[x1, index2].frameY / 18;
|
||||
int id = TEHatRack.Find(x1, y1);
|
||||
if (id == -1)
|
||||
return;
|
||||
int y2 = y1 + 1;
|
||||
int x2 = x1 + 1;
|
||||
TileEntity.BasicOpenCloseInteraction(player, x2, y2, id);
|
||||
}
|
||||
|
||||
public override void OnInventoryDraw(Player player, SpriteBatch spriteBatch)
|
||||
{
|
||||
if (Main.tile[player.tileEntityAnchor.X, player.tileEntityAnchor.Y].type != (ushort) 475)
|
||||
{
|
||||
player.tileEntityAnchor.Clear();
|
||||
Recipe.FindRecipes();
|
||||
}
|
||||
else
|
||||
this.DrawInner(player, spriteBatch);
|
||||
}
|
||||
|
||||
private void DrawInner(Player player, SpriteBatch spriteBatch)
|
||||
{
|
||||
Main.inventoryScale = 0.72f;
|
||||
this.DrawSlotPairSet(player, spriteBatch, 2, 0, 3.5f, 0.5f, 26);
|
||||
}
|
||||
|
||||
private void DrawSlotPairSet(
|
||||
Player player,
|
||||
SpriteBatch spriteBatch,
|
||||
int slotsToShowLine,
|
||||
int slotsArrayOffset,
|
||||
float offsetX,
|
||||
float offsetY,
|
||||
int inventoryContextTarget)
|
||||
{
|
||||
Item[] items = this._items;
|
||||
for (int index1 = 0; index1 < slotsToShowLine; ++index1)
|
||||
{
|
||||
for (int index2 = 0; index2 < 2; ++index2)
|
||||
{
|
||||
int num1 = (int) (73.0 + ((double) index1 + (double) offsetX) * 56.0 * (double) Main.inventoryScale);
|
||||
int num2 = (int) ((double) Main.instance.invBottom + ((double) index2 + (double) offsetY) * 56.0 * (double) Main.inventoryScale);
|
||||
Item[] inv;
|
||||
int context;
|
||||
if (index2 == 0)
|
||||
{
|
||||
inv = this._items;
|
||||
context = inventoryContextTarget;
|
||||
}
|
||||
else
|
||||
{
|
||||
inv = this._dyes;
|
||||
context = 27;
|
||||
}
|
||||
if (Utils.FloatIntersect((float) Main.mouseX, (float) Main.mouseY, 0.0f, 0.0f, (float) num1, (float) num2, (float) TextureAssets.InventoryBack.Width() * Main.inventoryScale, (float) TextureAssets.InventoryBack.Height() * Main.inventoryScale) && !PlayerInput.IgnoreMouseInterface)
|
||||
{
|
||||
player.mouseInterface = true;
|
||||
ItemSlot.Handle(inv, context, index1 + slotsArrayOffset);
|
||||
}
|
||||
ItemSlot.Draw(spriteBatch, inv, context, index1 + slotsArrayOffset, new Vector2((float) num1, (float) num2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OverrideItemSlotHover(Item[] inv, int context = 0, int slot = 0)
|
||||
{
|
||||
Item obj = inv[slot];
|
||||
if (!obj.IsAir && !inv[slot].favorited && context == 0 && TEHatRack.FitsHatRack(obj))
|
||||
{
|
||||
Main.cursorOverride = 9;
|
||||
return true;
|
||||
}
|
||||
if (obj.IsAir || context != 26 && context != 27 || !Main.player[Main.myPlayer].ItemSpace(inv[slot]).CanTakeItemToPersonalInventory)
|
||||
return false;
|
||||
Main.cursorOverride = 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OverrideItemSlotLeftClick(Item[] inv, int context = 0, int slot = 0)
|
||||
{
|
||||
if (!ItemSlot.ShiftInUse)
|
||||
return false;
|
||||
if (Main.cursorOverride == 9 && context == 0)
|
||||
{
|
||||
Item obj = inv[slot];
|
||||
if (Main.cursorOverride == 9 && !obj.IsAir && !obj.favorited && context == 0 && TEHatRack.FitsHatRack(obj))
|
||||
return this.TryFitting(inv, context, slot);
|
||||
}
|
||||
if ((Main.cursorOverride != 8 || context != 23) && context != 26 && context != 27)
|
||||
return false;
|
||||
inv[slot] = Main.player[Main.myPlayer].GetItem(Main.myPlayer, inv[slot], GetItemSettings.InventoryEntityToPlayerInventorySettings);
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(124, number: Main.myPlayer, number2: ((float) this.ID), number3: ((float) slot));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool FitsHatRack(Item item) => item.maxStack <= 1 && item.headSlot > 0;
|
||||
|
||||
private bool TryFitting(Item[] inv, int context = 0, int slot = 0, bool justCheck = false)
|
||||
{
|
||||
if (!TEHatRack.FitsHatRack(inv[slot]))
|
||||
return false;
|
||||
if (justCheck)
|
||||
return true;
|
||||
int index1 = TEHatRack.hatTargetSlot;
|
||||
++TEHatRack.hatTargetSlot;
|
||||
for (int index2 = 0; index2 < 2; ++index2)
|
||||
{
|
||||
if (this._items[index2].IsAir)
|
||||
{
|
||||
index1 = index2;
|
||||
TEHatRack.hatTargetSlot = index2 + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int index3 = 0; index3 < 2; ++index3)
|
||||
{
|
||||
if (inv[slot].type == this._items[index3].type)
|
||||
index1 = index3;
|
||||
}
|
||||
if (TEHatRack.hatTargetSlot >= 2)
|
||||
TEHatRack.hatTargetSlot = 0;
|
||||
SoundEngine.PlaySound(7);
|
||||
Utils.Swap<Item>(ref this._items[index1], ref inv[slot]);
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(124, number: Main.myPlayer, number2: ((float) this.ID), number3: ((float) index1));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteItem(int itemIndex, BinaryWriter writer, bool dye)
|
||||
{
|
||||
Item dye1 = this._items[itemIndex];
|
||||
if (dye)
|
||||
dye1 = this._dyes[itemIndex];
|
||||
writer.Write((ushort) dye1.netID);
|
||||
writer.Write((ushort) dye1.stack);
|
||||
writer.Write(dye1.prefix);
|
||||
}
|
||||
|
||||
public void ReadItem(int itemIndex, BinaryReader reader, bool dye)
|
||||
{
|
||||
int Type = (int) reader.ReadUInt16();
|
||||
int num = (int) reader.ReadUInt16();
|
||||
int pre = (int) reader.ReadByte();
|
||||
Item dye1 = this._items[itemIndex];
|
||||
if (dye)
|
||||
dye1 = this._dyes[itemIndex];
|
||||
dye1.SetDefaults(Type);
|
||||
dye1.stack = num;
|
||||
dye1.Prefix(pre);
|
||||
}
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 475 && Main.tile[x, y].frameY == (short) 0 && (int) Main.tile[x, y].frameX % 54 == 0;
|
||||
|
||||
public static bool IsBreakable(int clickX, int clickY)
|
||||
{
|
||||
int index1 = clickX;
|
||||
int index2 = clickY;
|
||||
int x = index1 - (int) Main.tile[index1, index2].frameX % 54 / 18;
|
||||
int y = index2 - (int) Main.tile[x, index2].frameY / 18;
|
||||
int key = TEHatRack.Find(x, y);
|
||||
return key == -1 || !(TileEntity.ByID[key] as TEHatRack).ContainsItems();
|
||||
}
|
||||
|
||||
public bool ContainsItems()
|
||||
{
|
||||
for (int index = 0; index < 2; ++index)
|
||||
{
|
||||
if (!this._items[index].IsAir || !this._dyes[index].IsAir)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
182
GameContent/Tile_Entities/TEItemFrame.cs
Normal file
182
GameContent/Tile_Entities/TEItemFrame.cs
Normal file
|
@ -0,0 +1,182 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TEItemFrame
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.IO;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TEItemFrame : TileEntity
|
||||
{
|
||||
private static byte _myEntityID;
|
||||
public Item item;
|
||||
|
||||
public override void RegisterTileEntityID(int assignedID) => TEItemFrame._myEntityID = (byte) assignedID;
|
||||
|
||||
public override void NetPlaceEntityAttempt(int x, int y) => TEItemFrame.NetPlaceEntity(x, y);
|
||||
|
||||
public static void NetPlaceEntity(int x, int y) => NetMessage.SendData(86, number: TEItemFrame.Place(x, y), number2: ((float) x), number3: ((float) y));
|
||||
|
||||
public override TileEntity GenerateInstance() => (TileEntity) new TEItemFrame();
|
||||
|
||||
public TEItemFrame() => this.item = new Item();
|
||||
|
||||
public static int Place(int x, int y)
|
||||
{
|
||||
TEItemFrame teItemFrame = new TEItemFrame();
|
||||
teItemFrame.Position = new Point16(x, y);
|
||||
teItemFrame.ID = TileEntity.AssignNewID();
|
||||
teItemFrame.type = TEItemFrame._myEntityID;
|
||||
TileEntity.ByID[teItemFrame.ID] = (TileEntity) teItemFrame;
|
||||
TileEntity.ByPosition[teItemFrame.Position] = (TileEntity) teItemFrame;
|
||||
return teItemFrame.ID;
|
||||
}
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y) => TEItemFrame.ValidTile(x, y);
|
||||
|
||||
public static int Hook_AfterPlacement(
|
||||
int x,
|
||||
int y,
|
||||
int type = 395,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
return TEItemFrame.Place(x, y);
|
||||
NetMessage.SendTileSquare(Main.myPlayer, x, y, 2);
|
||||
NetMessage.SendData(87, number: x, number2: ((float) y), number3: ((float) TEItemFrame._myEntityID));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || (int) tileEntity.type != (int) TEItemFrame._myEntityID)
|
||||
return;
|
||||
TileEntity.ByID.Remove(tileEntity.ID);
|
||||
TileEntity.ByPosition.Remove(new Point16(x, y));
|
||||
}
|
||||
|
||||
public static int Find(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
return TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) && (int) tileEntity.type == (int) TEItemFrame._myEntityID ? tileEntity.ID : -1;
|
||||
}
|
||||
|
||||
public static bool ValidTile(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 395 && Main.tile[x, y].frameY == (short) 0 && (int) Main.tile[x, y].frameX % 36 == 0;
|
||||
|
||||
public override void WriteExtraData(BinaryWriter writer, bool networkSend)
|
||||
{
|
||||
writer.Write((short) this.item.netID);
|
||||
writer.Write(this.item.prefix);
|
||||
writer.Write((short) this.item.stack);
|
||||
}
|
||||
|
||||
public override void ReadExtraData(BinaryReader reader, bool networkSend)
|
||||
{
|
||||
this.item = new Item();
|
||||
this.item.netDefaults((int) reader.ReadInt16());
|
||||
this.item.Prefix((int) reader.ReadByte());
|
||||
this.item.stack = (int) reader.ReadInt16();
|
||||
}
|
||||
|
||||
public override string ToString() => this.Position.X.ToString() + "x " + (object) this.Position.Y + "y item: " + (object) this.item;
|
||||
|
||||
public void DropItem()
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
Item.NewItem((int) this.Position.X * 16, (int) this.Position.Y * 16, 32, 32, this.item.netID, pfix: ((int) this.item.prefix));
|
||||
this.item = new Item();
|
||||
}
|
||||
|
||||
public static void TryPlacing(int x, int y, int netid, int prefix, int stack)
|
||||
{
|
||||
WorldGen.RangeFrame(x, y, x + 2, y + 2);
|
||||
int key = TEItemFrame.Find(x, y);
|
||||
if (key == -1)
|
||||
{
|
||||
int number = Item.NewItem(x * 16, y * 16, 32, 32, 1);
|
||||
Main.item[number].netDefaults(netid);
|
||||
Main.item[number].Prefix(prefix);
|
||||
Main.item[number].stack = stack;
|
||||
NetMessage.SendData(21, number: number);
|
||||
}
|
||||
else
|
||||
{
|
||||
TEItemFrame teItemFrame = (TEItemFrame) TileEntity.ByID[key];
|
||||
if (teItemFrame.item.stack > 0)
|
||||
teItemFrame.DropItem();
|
||||
teItemFrame.item = new Item();
|
||||
teItemFrame.item.netDefaults(netid);
|
||||
teItemFrame.item.Prefix(prefix);
|
||||
teItemFrame.item.stack = stack;
|
||||
NetMessage.SendData(86, number: teItemFrame.ID, number2: ((float) x), number3: ((float) y));
|
||||
}
|
||||
}
|
||||
|
||||
public static void OnPlayerInteraction(Player player, int clickX, int clickY)
|
||||
{
|
||||
if (TEItemFrame.FitsItemFrame(player.inventory[player.selectedItem]) && !player.inventory[player.selectedItem].favorited)
|
||||
{
|
||||
player.GamepadEnableGrappleCooldown();
|
||||
TEItemFrame.PlaceItemInFrame(player, clickX, clickY);
|
||||
Recipe.FindRecipes();
|
||||
}
|
||||
else
|
||||
{
|
||||
int x = clickX;
|
||||
int y = clickY;
|
||||
if ((int) Main.tile[x, y].frameX % 36 != 0)
|
||||
--x;
|
||||
if ((int) Main.tile[x, y].frameY % 36 != 0)
|
||||
--y;
|
||||
int key = TEItemFrame.Find(x, y);
|
||||
if (key == -1 || ((TEItemFrame) TileEntity.ByID[key]).item.stack <= 0)
|
||||
return;
|
||||
player.GamepadEnableGrappleCooldown();
|
||||
WorldGen.KillTile(clickX, clickY, true);
|
||||
if (Main.netMode != 1)
|
||||
return;
|
||||
NetMessage.SendData(17, number2: ((float) x), number3: ((float) y), number4: 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool FitsItemFrame(Item i) => i.stack > 0;
|
||||
|
||||
public static void PlaceItemInFrame(Player player, int x, int y)
|
||||
{
|
||||
if ((int) Main.tile[x, y].frameX % 36 != 0)
|
||||
--x;
|
||||
if ((int) Main.tile[x, y].frameY % 36 != 0)
|
||||
--y;
|
||||
int key = TEItemFrame.Find(x, y);
|
||||
if (key == -1)
|
||||
return;
|
||||
if (((TEItemFrame) TileEntity.ByID[key]).item.stack > 0)
|
||||
{
|
||||
WorldGen.KillTile(x, y, true);
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(17, number2: ((float) Player.tileTargetX), number3: ((float) y), number4: 1f);
|
||||
}
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(89, number: x, number2: ((float) y), number3: ((float) player.selectedItem), number4: ((float) player.whoAmI), number5: 1);
|
||||
else
|
||||
TEItemFrame.TryPlacing(x, y, player.inventory[player.selectedItem].netID, (int) player.inventory[player.selectedItem].prefix, 1);
|
||||
--player.inventory[player.selectedItem].stack;
|
||||
if (player.inventory[player.selectedItem].stack <= 0)
|
||||
{
|
||||
player.inventory[player.selectedItem].SetDefaults();
|
||||
Main.mouseItem.SetDefaults();
|
||||
}
|
||||
if (player.selectedItem == 58)
|
||||
Main.mouseItem = player.inventory[player.selectedItem].Clone();
|
||||
player.releaseUseItem = false;
|
||||
player.mouseInterface = true;
|
||||
WorldGen.RangeFrame(x, y, x + 2, y + 2);
|
||||
}
|
||||
}
|
||||
}
|
379
GameContent/Tile_Entities/TELogicSensor.cs
Normal file
379
GameContent/Tile_Entities/TELogicSensor.cs
Normal file
|
@ -0,0 +1,379 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TELogicSensor
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TELogicSensor : TileEntity
|
||||
{
|
||||
private static byte _myEntityID;
|
||||
private static Dictionary<int, Rectangle> playerBox = new Dictionary<int, Rectangle>();
|
||||
private static List<Tuple<Point16, bool>> tripPoints = new List<Tuple<Point16, bool>>();
|
||||
private static List<int> markedIDsForRemoval = new List<int>();
|
||||
private static bool inUpdateLoop;
|
||||
private static bool playerBoxFilled;
|
||||
public TELogicSensor.LogicCheckType logicCheck;
|
||||
public bool On;
|
||||
public int CountedData;
|
||||
|
||||
public override void RegisterTileEntityID(int assignedID)
|
||||
{
|
||||
TELogicSensor._myEntityID = (byte) assignedID;
|
||||
TileEntity._UpdateStart += new Action(TELogicSensor.UpdateStartInternal);
|
||||
TileEntity._UpdateEnd += new Action(TELogicSensor.UpdateEndInternal);
|
||||
}
|
||||
|
||||
public override void NetPlaceEntityAttempt(int x, int y) => TELogicSensor.NetPlaceEntity(x, y);
|
||||
|
||||
public static void NetPlaceEntity(int x, int y)
|
||||
{
|
||||
int num = TELogicSensor.Place(x, y);
|
||||
((TELogicSensor) TileEntity.ByID[num]).FigureCheckState();
|
||||
NetMessage.SendData(86, number: num, number2: ((float) x), number3: ((float) y));
|
||||
}
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y) => TELogicSensor.ValidTile(x, y);
|
||||
|
||||
public override TileEntity GenerateInstance() => (TileEntity) new TELogicSensor();
|
||||
|
||||
private static void UpdateStartInternal()
|
||||
{
|
||||
TELogicSensor.inUpdateLoop = true;
|
||||
TELogicSensor.markedIDsForRemoval.Clear();
|
||||
TELogicSensor.playerBox.Clear();
|
||||
TELogicSensor.playerBoxFilled = false;
|
||||
TELogicSensor.FillPlayerHitboxes();
|
||||
}
|
||||
|
||||
private static void FillPlayerHitboxes()
|
||||
{
|
||||
if (TELogicSensor.playerBoxFilled)
|
||||
return;
|
||||
for (int key = 0; key < (int) byte.MaxValue; ++key)
|
||||
{
|
||||
if (Main.player[key].active)
|
||||
TELogicSensor.playerBox[key] = Main.player[key].getRect();
|
||||
}
|
||||
TELogicSensor.playerBoxFilled = true;
|
||||
}
|
||||
|
||||
private static void UpdateEndInternal()
|
||||
{
|
||||
TELogicSensor.inUpdateLoop = false;
|
||||
foreach (Tuple<Point16, bool> tripPoint in TELogicSensor.tripPoints)
|
||||
{
|
||||
Wiring.blockPlayerTeleportationForOneIteration = tripPoint.Item2;
|
||||
Wiring.HitSwitch((int) tripPoint.Item1.X, (int) tripPoint.Item1.Y);
|
||||
if (Main.netMode == 2)
|
||||
NetMessage.SendData(59, number: ((int) tripPoint.Item1.X), number2: ((float) tripPoint.Item1.Y));
|
||||
}
|
||||
Wiring.blockPlayerTeleportationForOneIteration = false;
|
||||
TELogicSensor.tripPoints.Clear();
|
||||
foreach (int key in TELogicSensor.markedIDsForRemoval)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (TileEntity.ByID.TryGetValue(key, out tileEntity) && (int) tileEntity.type == (int) TELogicSensor._myEntityID)
|
||||
TileEntity.ByID.Remove(key);
|
||||
TileEntity.ByPosition.Remove(tileEntity.Position);
|
||||
}
|
||||
TELogicSensor.markedIDsForRemoval.Clear();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
bool state = TELogicSensor.GetState((int) this.Position.X, (int) this.Position.Y, this.logicCheck, this);
|
||||
switch (this.logicCheck)
|
||||
{
|
||||
case TELogicSensor.LogicCheckType.Day:
|
||||
case TELogicSensor.LogicCheckType.Night:
|
||||
if (!this.On & state)
|
||||
this.ChangeState(true, true);
|
||||
if (!this.On || state)
|
||||
break;
|
||||
this.ChangeState(false, false);
|
||||
break;
|
||||
case TELogicSensor.LogicCheckType.PlayerAbove:
|
||||
case TELogicSensor.LogicCheckType.Water:
|
||||
case TELogicSensor.LogicCheckType.Lava:
|
||||
case TELogicSensor.LogicCheckType.Honey:
|
||||
case TELogicSensor.LogicCheckType.Liquid:
|
||||
if (this.On == state)
|
||||
break;
|
||||
this.ChangeState(state, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeState(bool onState, bool TripWire)
|
||||
{
|
||||
if (onState != this.On && !TELogicSensor.SanityCheck((int) this.Position.X, (int) this.Position.Y))
|
||||
return;
|
||||
Main.tile[(int) this.Position.X, (int) this.Position.Y].frameX = onState ? (short) 18 : (short) 0;
|
||||
this.On = onState;
|
||||
if (Main.netMode == 2)
|
||||
NetMessage.SendTileSquare(-1, (int) this.Position.X, (int) this.Position.Y, 1);
|
||||
if (!TripWire || Main.netMode == 1)
|
||||
return;
|
||||
TELogicSensor.tripPoints.Add(Tuple.Create<Point16, bool>(this.Position, this.logicCheck == TELogicSensor.LogicCheckType.PlayerAbove));
|
||||
}
|
||||
|
||||
public static bool ValidTile(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 423 && (int) Main.tile[x, y].frameY % 18 == 0 && (int) Main.tile[x, y].frameX % 18 == 0;
|
||||
|
||||
public TELogicSensor()
|
||||
{
|
||||
this.logicCheck = TELogicSensor.LogicCheckType.None;
|
||||
this.On = false;
|
||||
}
|
||||
|
||||
public static TELogicSensor.LogicCheckType FigureCheckType(
|
||||
int x,
|
||||
int y,
|
||||
out bool on)
|
||||
{
|
||||
on = false;
|
||||
if (!WorldGen.InWorld(x, y))
|
||||
return TELogicSensor.LogicCheckType.None;
|
||||
Tile tile = Main.tile[x, y];
|
||||
if (tile == null)
|
||||
return TELogicSensor.LogicCheckType.None;
|
||||
TELogicSensor.LogicCheckType type = TELogicSensor.LogicCheckType.None;
|
||||
switch ((int) tile.frameY / 18)
|
||||
{
|
||||
case 0:
|
||||
type = TELogicSensor.LogicCheckType.Day;
|
||||
break;
|
||||
case 1:
|
||||
type = TELogicSensor.LogicCheckType.Night;
|
||||
break;
|
||||
case 2:
|
||||
type = TELogicSensor.LogicCheckType.PlayerAbove;
|
||||
break;
|
||||
case 3:
|
||||
type = TELogicSensor.LogicCheckType.Water;
|
||||
break;
|
||||
case 4:
|
||||
type = TELogicSensor.LogicCheckType.Lava;
|
||||
break;
|
||||
case 5:
|
||||
type = TELogicSensor.LogicCheckType.Honey;
|
||||
break;
|
||||
case 6:
|
||||
type = TELogicSensor.LogicCheckType.Liquid;
|
||||
break;
|
||||
}
|
||||
on = TELogicSensor.GetState(x, y, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
public static bool GetState(
|
||||
int x,
|
||||
int y,
|
||||
TELogicSensor.LogicCheckType type,
|
||||
TELogicSensor instance = null)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TELogicSensor.LogicCheckType.Day:
|
||||
return Main.dayTime;
|
||||
case TELogicSensor.LogicCheckType.Night:
|
||||
return !Main.dayTime;
|
||||
case TELogicSensor.LogicCheckType.PlayerAbove:
|
||||
bool flag1 = false;
|
||||
Rectangle rectangle = new Rectangle(x * 16 - 32 - 1, y * 16 - 160 - 1, 82, 162);
|
||||
foreach (KeyValuePair<int, Rectangle> keyValuePair in TELogicSensor.playerBox)
|
||||
{
|
||||
if (keyValuePair.Value.Intersects(rectangle))
|
||||
{
|
||||
flag1 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return flag1;
|
||||
case TELogicSensor.LogicCheckType.Water:
|
||||
case TELogicSensor.LogicCheckType.Lava:
|
||||
case TELogicSensor.LogicCheckType.Honey:
|
||||
case TELogicSensor.LogicCheckType.Liquid:
|
||||
if (instance == null)
|
||||
return false;
|
||||
Tile tile = Main.tile[x, y];
|
||||
bool flag2 = true;
|
||||
if (tile == null || tile.liquid == (byte) 0)
|
||||
flag2 = false;
|
||||
if (!tile.lava() && type == TELogicSensor.LogicCheckType.Lava)
|
||||
flag2 = false;
|
||||
if (!tile.honey() && type == TELogicSensor.LogicCheckType.Honey)
|
||||
flag2 = false;
|
||||
if ((tile.honey() || tile.lava()) && type == TELogicSensor.LogicCheckType.Water)
|
||||
flag2 = false;
|
||||
if (!flag2 && instance.On)
|
||||
{
|
||||
if (instance.CountedData == 0)
|
||||
instance.CountedData = 15;
|
||||
else if (instance.CountedData > 0)
|
||||
--instance.CountedData;
|
||||
flag2 = instance.CountedData > 0;
|
||||
}
|
||||
return flag2;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void FigureCheckState()
|
||||
{
|
||||
this.logicCheck = TELogicSensor.FigureCheckType((int) this.Position.X, (int) this.Position.Y, out this.On);
|
||||
TELogicSensor.GetFrame((int) this.Position.X, (int) this.Position.Y, this.logicCheck, this.On);
|
||||
}
|
||||
|
||||
public static void GetFrame(int x, int y, TELogicSensor.LogicCheckType type, bool on)
|
||||
{
|
||||
Main.tile[x, y].frameX = on ? (short) 18 : (short) 0;
|
||||
switch (type)
|
||||
{
|
||||
case TELogicSensor.LogicCheckType.Day:
|
||||
Main.tile[x, y].frameY = (short) 0;
|
||||
break;
|
||||
case TELogicSensor.LogicCheckType.Night:
|
||||
Main.tile[x, y].frameY = (short) 18;
|
||||
break;
|
||||
case TELogicSensor.LogicCheckType.PlayerAbove:
|
||||
Main.tile[x, y].frameY = (short) 36;
|
||||
break;
|
||||
case TELogicSensor.LogicCheckType.Water:
|
||||
Main.tile[x, y].frameY = (short) 54;
|
||||
break;
|
||||
case TELogicSensor.LogicCheckType.Lava:
|
||||
Main.tile[x, y].frameY = (short) 72;
|
||||
break;
|
||||
case TELogicSensor.LogicCheckType.Honey:
|
||||
Main.tile[x, y].frameY = (short) 90;
|
||||
break;
|
||||
case TELogicSensor.LogicCheckType.Liquid:
|
||||
Main.tile[x, y].frameY = (short) 108;
|
||||
break;
|
||||
default:
|
||||
Main.tile[x, y].frameY = (short) 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SanityCheck(int x, int y)
|
||||
{
|
||||
if (Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 423)
|
||||
return true;
|
||||
TELogicSensor.Kill(x, y);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int Place(int x, int y)
|
||||
{
|
||||
TELogicSensor teLogicSensor = new TELogicSensor();
|
||||
teLogicSensor.Position = new Point16(x, y);
|
||||
teLogicSensor.ID = TileEntity.AssignNewID();
|
||||
teLogicSensor.type = TELogicSensor._myEntityID;
|
||||
TileEntity.ByID[teLogicSensor.ID] = (TileEntity) teLogicSensor;
|
||||
TileEntity.ByPosition[teLogicSensor.Position] = (TileEntity) teLogicSensor;
|
||||
return teLogicSensor.ID;
|
||||
}
|
||||
|
||||
public static int Hook_AfterPlacement(
|
||||
int x,
|
||||
int y,
|
||||
int type = 423,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
bool on;
|
||||
TELogicSensor.LogicCheckType type1 = TELogicSensor.FigureCheckType(x, y, out on);
|
||||
TELogicSensor.GetFrame(x, y, type1, on);
|
||||
if (Main.netMode == 1)
|
||||
{
|
||||
NetMessage.SendTileSquare(Main.myPlayer, x, y, 1);
|
||||
NetMessage.SendData(87, number: x, number2: ((float) y), number3: ((float) TELogicSensor._myEntityID));
|
||||
return -1;
|
||||
}
|
||||
int key = TELogicSensor.Place(x, y);
|
||||
((TELogicSensor) TileEntity.ByID[key]).FigureCheckState();
|
||||
return key;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || (int) tileEntity.type != (int) TELogicSensor._myEntityID)
|
||||
return;
|
||||
Wiring.blockPlayerTeleportationForOneIteration = ((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.PlayerAbove;
|
||||
bool flag = false;
|
||||
if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.PlayerAbove && ((TELogicSensor) tileEntity).On)
|
||||
flag = true;
|
||||
else if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.Water && ((TELogicSensor) tileEntity).On)
|
||||
flag = true;
|
||||
else if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.Lava && ((TELogicSensor) tileEntity).On)
|
||||
flag = true;
|
||||
else if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.Honey && ((TELogicSensor) tileEntity).On)
|
||||
flag = true;
|
||||
else if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.Liquid && ((TELogicSensor) tileEntity).On)
|
||||
flag = true;
|
||||
if (flag)
|
||||
{
|
||||
Wiring.HitSwitch((int) tileEntity.Position.X, (int) tileEntity.Position.Y);
|
||||
NetMessage.SendData(59, number: ((int) tileEntity.Position.X), number2: ((float) tileEntity.Position.Y));
|
||||
}
|
||||
Wiring.blockPlayerTeleportationForOneIteration = false;
|
||||
if (TELogicSensor.inUpdateLoop)
|
||||
{
|
||||
TELogicSensor.markedIDsForRemoval.Add(tileEntity.ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntity.ByPosition.Remove(new Point16(x, y));
|
||||
TileEntity.ByID.Remove(tileEntity.ID);
|
||||
}
|
||||
}
|
||||
|
||||
public static int Find(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
return TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) && (int) tileEntity.type == (int) TELogicSensor._myEntityID ? tileEntity.ID : -1;
|
||||
}
|
||||
|
||||
public override void WriteExtraData(BinaryWriter writer, bool networkSend)
|
||||
{
|
||||
if (networkSend)
|
||||
return;
|
||||
writer.Write((byte) this.logicCheck);
|
||||
writer.Write(this.On);
|
||||
}
|
||||
|
||||
public override void ReadExtraData(BinaryReader reader, bool networkSend)
|
||||
{
|
||||
if (networkSend)
|
||||
return;
|
||||
this.logicCheck = (TELogicSensor.LogicCheckType) reader.ReadByte();
|
||||
this.On = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override string ToString() => this.Position.X.ToString() + "x " + (object) this.Position.Y + "y " + (object) this.logicCheck;
|
||||
|
||||
public enum LogicCheckType
|
||||
{
|
||||
None,
|
||||
Day,
|
||||
Night,
|
||||
PlayerAbove,
|
||||
Water,
|
||||
Lava,
|
||||
Honey,
|
||||
Liquid,
|
||||
}
|
||||
}
|
||||
}
|
181
GameContent/Tile_Entities/TETeleportationPylon.cs
Normal file
181
GameContent/Tile_Entities/TETeleportationPylon.cs
Normal file
|
@ -0,0 +1,181 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TETeleportationPylon
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TETeleportationPylon : TileEntity
|
||||
{
|
||||
private static byte _myEntityID;
|
||||
private const int MyTileID = 597;
|
||||
private const int entityTileWidth = 3;
|
||||
private const int entityTileHeight = 4;
|
||||
|
||||
public override void RegisterTileEntityID(int assignedID) => TETeleportationPylon._myEntityID = (byte) assignedID;
|
||||
|
||||
public override TileEntity GenerateInstance() => (TileEntity) new TETeleportationPylon();
|
||||
|
||||
public override void NetPlaceEntityAttempt(int x, int y)
|
||||
{
|
||||
TeleportPylonType pylonType;
|
||||
if (!this.TryGetPylonTypeFromTileCoords(x, y, out pylonType))
|
||||
TETeleportationPylon.RejectPlacementFromNet(x, y);
|
||||
else if (Main.PylonSystem.HasPylonOfType(pylonType))
|
||||
TETeleportationPylon.RejectPlacementFromNet(x, y);
|
||||
else
|
||||
NetMessage.SendData(86, number: TETeleportationPylon.Place(x, y), number2: ((float) x), number3: ((float) y));
|
||||
}
|
||||
|
||||
public bool TryGetPylonType(out TeleportPylonType pylonType) => this.TryGetPylonTypeFromTileCoords((int) this.Position.X, (int) this.Position.Y, out pylonType);
|
||||
|
||||
private static void RejectPlacementFromNet(int x, int y)
|
||||
{
|
||||
WorldGen.KillTile(x, y);
|
||||
if (Main.netMode != 2)
|
||||
return;
|
||||
NetMessage.SendData(17, number2: ((float) x), number3: ((float) y));
|
||||
}
|
||||
|
||||
public static int Place(int x, int y)
|
||||
{
|
||||
TETeleportationPylon teleportationPylon = new TETeleportationPylon();
|
||||
teleportationPylon.Position = new Point16(x, y);
|
||||
teleportationPylon.ID = TileEntity.AssignNewID();
|
||||
teleportationPylon.type = TETeleportationPylon._myEntityID;
|
||||
TileEntity.ByID[teleportationPylon.ID] = (TileEntity) teleportationPylon;
|
||||
TileEntity.ByPosition[teleportationPylon.Position] = (TileEntity) teleportationPylon;
|
||||
Main.PylonSystem.RequestImmediateUpdate();
|
||||
return teleportationPylon.ID;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || (int) tileEntity.type != (int) TETeleportationPylon._myEntityID)
|
||||
return;
|
||||
TileEntity.ByID.Remove(tileEntity.ID);
|
||||
TileEntity.ByPosition.Remove(new Point16(x, y));
|
||||
Main.PylonSystem.RequestImmediateUpdate();
|
||||
}
|
||||
|
||||
public override string ToString() => this.Position.X.ToString() + "x " + (object) this.Position.Y + "y";
|
||||
|
||||
public static void Framing_CheckTile(int callX, int callY)
|
||||
{
|
||||
if (WorldGen.destroyObject)
|
||||
return;
|
||||
int num1 = callX;
|
||||
int num2 = callY;
|
||||
Tile tileSafely = Framing.GetTileSafely(callX, callY);
|
||||
int num3 = num1 - (int) tileSafely.frameX / 18 % 3;
|
||||
int y = num2 - (int) tileSafely.frameY / 18 % 4;
|
||||
int pylonStyleFromTile = TETeleportationPylon.GetPylonStyleFromTile(tileSafely);
|
||||
bool flag = false;
|
||||
for (int index1 = num3; index1 < num3 + 3; ++index1)
|
||||
{
|
||||
for (int index2 = y; index2 < y + 4; ++index2)
|
||||
{
|
||||
Tile tile = Main.tile[index1, index2];
|
||||
if (!tile.active() || tile.type != (ushort) 597)
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (!WorldGen.SolidTileAllowBottomSlope(num3, y + 4) || !WorldGen.SolidTileAllowBottomSlope(num3 + 1, y + 4) || !WorldGen.SolidTileAllowBottomSlope(num3 + 2, y + 4))
|
||||
flag = true;
|
||||
if (!flag)
|
||||
return;
|
||||
TETeleportationPylon.Kill(num3, y);
|
||||
int typeFromTileStyle = TETeleportationPylon.GetPylonItemTypeFromTileStyle(pylonStyleFromTile);
|
||||
Item.NewItem(num3 * 16, y * 16, 48, 64, typeFromTileStyle);
|
||||
WorldGen.destroyObject = true;
|
||||
for (int i = num3; i < num3 + 3; ++i)
|
||||
{
|
||||
for (int j = y; j < y + 4; ++j)
|
||||
{
|
||||
if (Main.tile[i, j].active() && Main.tile[i, j].type == (ushort) 597)
|
||||
WorldGen.KillTile(i, j);
|
||||
}
|
||||
}
|
||||
WorldGen.destroyObject = false;
|
||||
}
|
||||
|
||||
public static int GetPylonStyleFromTile(Tile tile) => (int) tile.frameX / 54;
|
||||
|
||||
public static int GetPylonItemTypeFromTileStyle(int style)
|
||||
{
|
||||
switch (style)
|
||||
{
|
||||
case 1:
|
||||
return 4875;
|
||||
case 2:
|
||||
return 4916;
|
||||
case 3:
|
||||
return 4917;
|
||||
case 4:
|
||||
return 4918;
|
||||
case 5:
|
||||
return 4919;
|
||||
case 6:
|
||||
return 4920;
|
||||
case 7:
|
||||
return 4921;
|
||||
case 8:
|
||||
return 4951;
|
||||
default:
|
||||
return 4876;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 597 && Main.tile[x, y].frameY == (short) 0 && (int) Main.tile[x, y].frameX % 54 == 0;
|
||||
|
||||
public static int PlacementPreviewHook_AfterPlacement(
|
||||
int x,
|
||||
int y,
|
||||
int type = 597,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
return TETeleportationPylon.Place(x - 1, y - 3);
|
||||
NetMessage.SendTileSquare(Main.myPlayer, x, y - 1, 5);
|
||||
NetMessage.SendData(87, number: (x - 1), number2: ((float) (y - 3)), number3: ((float) TETeleportationPylon._myEntityID));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int PlacementPreviewHook_CheckIfCanPlace(
|
||||
int x,
|
||||
int y,
|
||||
int type = 597,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
TeleportPylonType fromPylonTileStyle = TETeleportationPylon.GetPylonTypeFromPylonTileStyle(style);
|
||||
return Main.PylonSystem.HasPylonOfType(fromPylonTileStyle) ? 1 : 0;
|
||||
}
|
||||
|
||||
private bool TryGetPylonTypeFromTileCoords(int x, int y, out TeleportPylonType pylonType)
|
||||
{
|
||||
pylonType = TeleportPylonType.SurfacePurity;
|
||||
Tile tile = Main.tile[x, y];
|
||||
if (tile == null || !tile.active() || tile.type != (ushort) 597)
|
||||
return false;
|
||||
int pylonStyle = (int) tile.frameX / 54;
|
||||
pylonType = TETeleportationPylon.GetPylonTypeFromPylonTileStyle(pylonStyle);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static TeleportPylonType GetPylonTypeFromPylonTileStyle(int pylonStyle) => (TeleportPylonType) pylonStyle;
|
||||
|
||||
public static int Find(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
return TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) && (int) tileEntity.type == (int) TETeleportationPylon._myEntityID ? tileEntity.ID : -1;
|
||||
}
|
||||
}
|
||||
}
|
159
GameContent/Tile_Entities/TETrainingDummy.cs
Normal file
159
GameContent/Tile_Entities/TETrainingDummy.cs
Normal file
|
@ -0,0 +1,159 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TETrainingDummy
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TETrainingDummy : TileEntity
|
||||
{
|
||||
private static Dictionary<int, Rectangle> playerBox = new Dictionary<int, Rectangle>();
|
||||
private static bool playerBoxFilled;
|
||||
private static byte _myEntityID;
|
||||
public int npc;
|
||||
|
||||
public override void RegisterTileEntityID(int assignedID)
|
||||
{
|
||||
TETrainingDummy._myEntityID = (byte) assignedID;
|
||||
TileEntity._UpdateStart += new Action(TETrainingDummy.ClearBoxes);
|
||||
}
|
||||
|
||||
public override void NetPlaceEntityAttempt(int x, int y) => TETrainingDummy.NetPlaceEntity(x, y);
|
||||
|
||||
public static void NetPlaceEntity(int x, int y) => TETrainingDummy.Place(x, y);
|
||||
|
||||
public override TileEntity GenerateInstance() => (TileEntity) new TETrainingDummy();
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y) => TETrainingDummy.ValidTile(x, y);
|
||||
|
||||
public static void ClearBoxes()
|
||||
{
|
||||
TETrainingDummy.playerBox.Clear();
|
||||
TETrainingDummy.playerBoxFilled = false;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
Rectangle rectangle = new Rectangle(0, 0, 32, 48);
|
||||
rectangle.Inflate(1600, 1600);
|
||||
int x = rectangle.X;
|
||||
int y = rectangle.Y;
|
||||
if (this.npc != -1)
|
||||
{
|
||||
if (Main.npc[this.npc].active && Main.npc[this.npc].type == 488 && (double) Main.npc[this.npc].ai[0] == (double) this.Position.X && (double) Main.npc[this.npc].ai[1] == (double) this.Position.Y)
|
||||
return;
|
||||
this.Deactivate();
|
||||
}
|
||||
else
|
||||
{
|
||||
TETrainingDummy.FillPlayerHitboxes();
|
||||
rectangle.X = (int) this.Position.X * 16 + x;
|
||||
rectangle.Y = (int) this.Position.Y * 16 + y;
|
||||
bool flag = false;
|
||||
foreach (KeyValuePair<int, Rectangle> keyValuePair in TETrainingDummy.playerBox)
|
||||
{
|
||||
if (keyValuePair.Value.Intersects(rectangle))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
return;
|
||||
this.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
private static void FillPlayerHitboxes()
|
||||
{
|
||||
if (TETrainingDummy.playerBoxFilled)
|
||||
return;
|
||||
for (int key = 0; key < (int) byte.MaxValue; ++key)
|
||||
{
|
||||
if (Main.player[key].active)
|
||||
TETrainingDummy.playerBox[key] = Main.player[key].getRect();
|
||||
}
|
||||
TETrainingDummy.playerBoxFilled = true;
|
||||
}
|
||||
|
||||
public static bool ValidTile(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 378 && Main.tile[x, y].frameY == (short) 0 && (int) Main.tile[x, y].frameX % 36 == 0;
|
||||
|
||||
public TETrainingDummy() => this.npc = -1;
|
||||
|
||||
public static int Place(int x, int y)
|
||||
{
|
||||
TETrainingDummy teTrainingDummy = new TETrainingDummy();
|
||||
teTrainingDummy.Position = new Point16(x, y);
|
||||
teTrainingDummy.ID = TileEntity.AssignNewID();
|
||||
teTrainingDummy.type = TETrainingDummy._myEntityID;
|
||||
TileEntity.ByID[teTrainingDummy.ID] = (TileEntity) teTrainingDummy;
|
||||
TileEntity.ByPosition[teTrainingDummy.Position] = (TileEntity) teTrainingDummy;
|
||||
return teTrainingDummy.ID;
|
||||
}
|
||||
|
||||
public static int Hook_AfterPlacement(
|
||||
int x,
|
||||
int y,
|
||||
int type = 378,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
return TETrainingDummy.Place(x - 1, y - 2);
|
||||
NetMessage.SendTileSquare(Main.myPlayer, x - 1, y - 1, 3);
|
||||
NetMessage.SendData(87, number: (x - 1), number2: ((float) (y - 2)), number3: ((float) TETrainingDummy._myEntityID));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || (int) tileEntity.type != (int) TETrainingDummy._myEntityID)
|
||||
return;
|
||||
TileEntity.ByID.Remove(tileEntity.ID);
|
||||
TileEntity.ByPosition.Remove(new Point16(x, y));
|
||||
}
|
||||
|
||||
public static int Find(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
return TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) && (int) tileEntity.type == (int) TETrainingDummy._myEntityID ? tileEntity.ID : -1;
|
||||
}
|
||||
|
||||
public override void WriteExtraData(BinaryWriter writer, bool networkSend) => writer.Write((short) this.npc);
|
||||
|
||||
public override void ReadExtraData(BinaryReader reader, bool networkSend) => this.npc = (int) reader.ReadInt16();
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
int index = NPC.NewNPC((int) this.Position.X * 16 + 16, (int) this.Position.Y * 16 + 48, 488, 100);
|
||||
Main.npc[index].ai[0] = (float) this.Position.X;
|
||||
Main.npc[index].ai[1] = (float) this.Position.Y;
|
||||
Main.npc[index].netUpdate = true;
|
||||
this.npc = index;
|
||||
if (Main.netMode == 1)
|
||||
return;
|
||||
NetMessage.SendData(86, number: this.ID, number2: ((float) this.Position.X), number3: ((float) this.Position.Y));
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
if (this.npc != -1)
|
||||
Main.npc[this.npc].active = false;
|
||||
this.npc = -1;
|
||||
if (Main.netMode == 1)
|
||||
return;
|
||||
NetMessage.SendData(86, number: this.ID, number2: ((float) this.Position.X), number3: ((float) this.Position.Y));
|
||||
}
|
||||
|
||||
public override string ToString() => this.Position.X.ToString() + "x " + (object) this.Position.Y + "y npc: " + (object) this.npc;
|
||||
}
|
||||
}
|
239
GameContent/Tile_Entities/TEWeaponsRack.cs
Normal file
239
GameContent/Tile_Entities/TEWeaponsRack.cs
Normal file
|
@ -0,0 +1,239 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TEWeaponsRack
|
||||
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.IO;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ID;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TEWeaponsRack : TileEntity
|
||||
{
|
||||
private static byte _myEntityID;
|
||||
public Item item;
|
||||
private const int MyTileID = 471;
|
||||
|
||||
public TEWeaponsRack() => this.item = new Item();
|
||||
|
||||
public override void RegisterTileEntityID(int assignedID) => TEWeaponsRack._myEntityID = (byte) assignedID;
|
||||
|
||||
public override TileEntity GenerateInstance() => (TileEntity) new TEWeaponsRack();
|
||||
|
||||
public override void NetPlaceEntityAttempt(int x, int y) => TEWeaponsRack.NetPlaceEntity(x, y);
|
||||
|
||||
public static void NetPlaceEntity(int x, int y) => NetMessage.SendData(86, number: TEWeaponsRack.Place(x, y), number2: ((float) x), number3: ((float) y));
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y) => TEWeaponsRack.ValidTile(x, y);
|
||||
|
||||
public static bool ValidTile(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 471 && Main.tile[x, y].frameY == (short) 0 && (int) Main.tile[x, y].frameX % 54 == 0;
|
||||
|
||||
public static int Place(int x, int y)
|
||||
{
|
||||
TEWeaponsRack teWeaponsRack = new TEWeaponsRack();
|
||||
teWeaponsRack.Position = new Point16(x, y);
|
||||
teWeaponsRack.ID = TileEntity.AssignNewID();
|
||||
teWeaponsRack.type = TEWeaponsRack._myEntityID;
|
||||
TileEntity.ByID[teWeaponsRack.ID] = (TileEntity) teWeaponsRack;
|
||||
TileEntity.ByPosition[teWeaponsRack.Position] = (TileEntity) teWeaponsRack;
|
||||
return teWeaponsRack.ID;
|
||||
}
|
||||
|
||||
public static int Hook_AfterPlacement(
|
||||
int x,
|
||||
int y,
|
||||
int type = 471,
|
||||
int style = 0,
|
||||
int direction = 1,
|
||||
int alternate = 0)
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
return TEWeaponsRack.Place(x, y);
|
||||
NetMessage.SendTileSquare(Main.myPlayer, x, y, 5);
|
||||
NetMessage.SendData(87, number: x, number2: ((float) y), number3: ((float) TEWeaponsRack._myEntityID));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || (int) tileEntity.type != (int) TEWeaponsRack._myEntityID)
|
||||
return;
|
||||
TileEntity.ByID.Remove(tileEntity.ID);
|
||||
TileEntity.ByPosition.Remove(new Point16(x, y));
|
||||
}
|
||||
|
||||
public static int Find(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
return TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) && (int) tileEntity.type == (int) TEWeaponsRack._myEntityID ? tileEntity.ID : -1;
|
||||
}
|
||||
|
||||
public override void WriteExtraData(BinaryWriter writer, bool networkSend)
|
||||
{
|
||||
writer.Write((short) this.item.netID);
|
||||
writer.Write(this.item.prefix);
|
||||
writer.Write((short) this.item.stack);
|
||||
}
|
||||
|
||||
public override void ReadExtraData(BinaryReader reader, bool networkSend)
|
||||
{
|
||||
this.item = new Item();
|
||||
this.item.netDefaults((int) reader.ReadInt16());
|
||||
this.item.Prefix((int) reader.ReadByte());
|
||||
this.item.stack = (int) reader.ReadInt16();
|
||||
}
|
||||
|
||||
public override string ToString() => this.Position.X.ToString() + "x " + (object) this.Position.Y + "y item: " + (object) this.item;
|
||||
|
||||
public static void Framing_CheckTile(int callX, int callY)
|
||||
{
|
||||
int num1 = 3;
|
||||
int num2 = 3;
|
||||
if (WorldGen.destroyObject)
|
||||
return;
|
||||
int num3 = callX;
|
||||
int num4 = callY;
|
||||
Tile tileSafely = Framing.GetTileSafely(callX, callY);
|
||||
int x = num3 - (int) tileSafely.frameX / 18 % num1;
|
||||
int y = num4 - (int) tileSafely.frameY / 18 % num2;
|
||||
bool flag = false;
|
||||
for (int index1 = x; index1 < x + num1; ++index1)
|
||||
{
|
||||
for (int index2 = y; index2 < y + num2; ++index2)
|
||||
{
|
||||
Tile tile = Main.tile[index1, index2];
|
||||
if (!tile.active() || tile.type != (ushort) 471 || tile.wall == (ushort) 0)
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
return;
|
||||
Item.NewItem(x * 16, y * 16, 48, 48, 2699);
|
||||
WorldGen.destroyObject = true;
|
||||
int key = TEWeaponsRack.Find(x, y);
|
||||
if (key != -1)
|
||||
{
|
||||
TEWeaponsRack teWeaponsRack = (TEWeaponsRack) TileEntity.ByID[key];
|
||||
if (!teWeaponsRack.item.IsAir)
|
||||
teWeaponsRack.DropItem();
|
||||
}
|
||||
for (int i = x; i < x + num1; ++i)
|
||||
{
|
||||
for (int j = y; j < y + num2; ++j)
|
||||
{
|
||||
if (Main.tile[i, j].active() && Main.tile[i, j].type == (ushort) 471)
|
||||
WorldGen.KillTile(i, j);
|
||||
}
|
||||
}
|
||||
WorldGen.destroyObject = false;
|
||||
}
|
||||
|
||||
public void DropItem()
|
||||
{
|
||||
if (Main.netMode != 1)
|
||||
Item.NewItem((int) this.Position.X * 16, (int) this.Position.Y * 16, 32, 32, this.item.netID, pfix: ((int) this.item.prefix));
|
||||
this.item = new Item();
|
||||
}
|
||||
|
||||
public static void TryPlacing(int x, int y, int netid, int prefix, int stack)
|
||||
{
|
||||
WorldGen.RangeFrame(x, y, x + 3, y + 3);
|
||||
int key = TEWeaponsRack.Find(x, y);
|
||||
if (key == -1)
|
||||
{
|
||||
int number = Item.NewItem(x * 16, y * 16, 32, 32, 1);
|
||||
Main.item[number].netDefaults(netid);
|
||||
Main.item[number].Prefix(prefix);
|
||||
Main.item[number].stack = stack;
|
||||
NetMessage.SendData(21, number: number);
|
||||
}
|
||||
else
|
||||
{
|
||||
TEWeaponsRack teWeaponsRack = (TEWeaponsRack) TileEntity.ByID[key];
|
||||
if (teWeaponsRack.item.stack > 0)
|
||||
teWeaponsRack.DropItem();
|
||||
teWeaponsRack.item = new Item();
|
||||
teWeaponsRack.item.netDefaults(netid);
|
||||
teWeaponsRack.item.Prefix(prefix);
|
||||
teWeaponsRack.item.stack = stack;
|
||||
NetMessage.SendData(86, number: teWeaponsRack.ID, number2: ((float) x), number3: ((float) y));
|
||||
}
|
||||
}
|
||||
|
||||
public static void OnPlayerInteraction(Player player, int clickX, int clickY)
|
||||
{
|
||||
if (TEWeaponsRack.FitsWeaponFrame(player.inventory[player.selectedItem]) && !player.inventory[player.selectedItem].favorited)
|
||||
{
|
||||
player.GamepadEnableGrappleCooldown();
|
||||
TEWeaponsRack.PlaceItemInFrame(player, clickX, clickY);
|
||||
Recipe.FindRecipes();
|
||||
}
|
||||
else
|
||||
{
|
||||
int index1 = clickX;
|
||||
int index2 = clickY;
|
||||
int index3 = index1 - (int) Main.tile[index1, index2].frameX % 54 / 18;
|
||||
int num = index2 - (int) Main.tile[index3, index2].frameY % 54 / 18;
|
||||
int key = TEWeaponsRack.Find(index3, num);
|
||||
if (key == -1 || ((TEWeaponsRack) TileEntity.ByID[key]).item.stack <= 0)
|
||||
return;
|
||||
player.GamepadEnableGrappleCooldown();
|
||||
WorldGen.KillTile(index3, num, true);
|
||||
if (Main.netMode != 1)
|
||||
return;
|
||||
NetMessage.SendData(17, number2: ((float) index3), number3: ((float) num), number4: 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool FitsWeaponFrame(Item i)
|
||||
{
|
||||
if (!i.IsAir && (i.fishingPole > 0 || ItemID.Sets.CanBePlacedOnWeaponRacks[i.type]))
|
||||
return true;
|
||||
return i.damage > 0 && i.useStyle != 0 && i.stack > 0;
|
||||
}
|
||||
|
||||
private static void PlaceItemInFrame(Player player, int x, int y)
|
||||
{
|
||||
x -= (int) Main.tile[x, y].frameX % 54 / 18;
|
||||
y -= (int) Main.tile[x, y].frameY % 54 / 18;
|
||||
int key = TEWeaponsRack.Find(x, y);
|
||||
if (key == -1)
|
||||
return;
|
||||
if (((TEWeaponsRack) TileEntity.ByID[key]).item.stack > 0)
|
||||
{
|
||||
WorldGen.KillTile(x, y, true);
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(17, number2: ((float) Player.tileTargetX), number3: ((float) y), number4: 1f);
|
||||
}
|
||||
if (Main.netMode == 1)
|
||||
NetMessage.SendData(123, number: x, number2: ((float) y), number3: ((float) player.selectedItem), number4: ((float) player.whoAmI), number5: 1);
|
||||
else
|
||||
TEWeaponsRack.TryPlacing(x, y, player.inventory[player.selectedItem].netID, (int) player.inventory[player.selectedItem].prefix, 1);
|
||||
--player.inventory[player.selectedItem].stack;
|
||||
if (player.inventory[player.selectedItem].stack <= 0)
|
||||
{
|
||||
player.inventory[player.selectedItem].SetDefaults();
|
||||
Main.mouseItem.SetDefaults();
|
||||
}
|
||||
if (player.selectedItem == 58)
|
||||
Main.mouseItem = player.inventory[player.selectedItem].Clone();
|
||||
player.releaseUseItem = false;
|
||||
player.mouseInterface = true;
|
||||
WorldGen.RangeFrame(x, y, x + 3, y + 3);
|
||||
}
|
||||
|
||||
public static bool KillTileDropItem(Tile tileCache, int i, int j)
|
||||
{
|
||||
int key = TEWeaponsRack.Find(i - (int) tileCache.frameX % 54 / 18, j - (int) tileCache.frameY % 54 / 18);
|
||||
if (key == -1 || ((TEWeaponsRack) TileEntity.ByID[key]).item.stack <= 0)
|
||||
return false;
|
||||
((TEWeaponsRack) TileEntity.ByID[key]).DropItem();
|
||||
if (Main.netMode != 2)
|
||||
Main.LocalPlayer.InterruptItemUsageIfOverTile(471);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue