Terraria 1.3.5.3 Source Code
This commit is contained in:
commit
4b21dac4b6
503 changed files with 409032 additions and 0 deletions
113
GameContent/Tile_Entities/TEItemFrame.cs
Normal file
113
GameContent/Tile_Entities/TEItemFrame.cs
Normal file
|
@ -0,0 +1,113 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TEItemFrame
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.GameContent.Tile_Entities
|
||||
{
|
||||
public class TEItemFrame : TileEntity
|
||||
{
|
||||
public Item item;
|
||||
|
||||
public static void Initialize() => TileEntity._NetPlaceEntity += new Action<int, int, int>(TEItemFrame.NetPlaceEntity);
|
||||
|
||||
public static void NetPlaceEntity(int x, int y, int type)
|
||||
{
|
||||
if (type != 1 || !TEItemFrame.ValidTile(x, y))
|
||||
return;
|
||||
NetMessage.SendData(86, number: TEItemFrame.Place(x, y), number2: ((float) x), number3: ((float) y));
|
||||
}
|
||||
|
||||
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 = (byte) 1;
|
||||
TileEntity.ByID[teItemFrame.ID] = (TileEntity) teItemFrame;
|
||||
TileEntity.ByPosition[teItemFrame.Position] = (TileEntity) teItemFrame;
|
||||
return teItemFrame.ID;
|
||||
}
|
||||
|
||||
public static int Hook_AfterPlacement(int x, int y, int type = 395, int style = 0, int direction = 1)
|
||||
{
|
||||
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: 1f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || tileEntity.type != (byte) 1)
|
||||
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) && tileEntity.type == (byte) 1 ? 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: " + this.item.ToString();
|
||||
|
||||
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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
360
GameContent/Tile_Entities/TELogicSensor.cs
Normal file
360
GameContent/Tile_Entities/TELogicSensor.cs
Normal file
|
@ -0,0 +1,360 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TELogicSensor
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// 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 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 = false;
|
||||
private static bool playerBoxFilled = false;
|
||||
public TELogicSensor.LogicCheckType logicCheck;
|
||||
public bool On;
|
||||
public int CountedData;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
TileEntity._UpdateStart += new Action(TELogicSensor.UpdateStartInternal);
|
||||
TileEntity._UpdateEnd += new Action(TELogicSensor.UpdateEndInternal);
|
||||
TileEntity._NetPlaceEntity += new Action<int, int, int>(TELogicSensor.NetPlaceEntity);
|
||||
}
|
||||
|
||||
public static void NetPlaceEntity(int x, int y, int type)
|
||||
{
|
||||
if (type != 2 || !TELogicSensor.ValidTile(x, y))
|
||||
return;
|
||||
int num = TELogicSensor.Place(x, y);
|
||||
((TELogicSensor) TileEntity.ByID[num]).FigureCheckState();
|
||||
NetMessage.SendData(86, number: num, number2: ((float) x), number3: ((float) y));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Wiring.blockPlayerTeleportationForOneIteration = false;
|
||||
TELogicSensor.tripPoints.Clear();
|
||||
foreach (int key in TELogicSensor.markedIDsForRemoval)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (TileEntity.ByID.TryGetValue(key, out tileEntity) && tileEntity.type == (byte) 2)
|
||||
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 = (byte) 2;
|
||||
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)
|
||||
{
|
||||
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: 2f);
|
||||
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) || tileEntity.type != (byte) 2)
|
||||
return;
|
||||
Wiring.blockPlayerTeleportationForOneIteration = ((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.PlayerAbove;
|
||||
if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.PlayerAbove && ((TELogicSensor) tileEntity).On)
|
||||
Wiring.HitSwitch((int) tileEntity.Position.X, (int) tileEntity.Position.Y);
|
||||
if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.Water && ((TELogicSensor) tileEntity).On)
|
||||
Wiring.HitSwitch((int) tileEntity.Position.X, (int) tileEntity.Position.Y);
|
||||
if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.Lava && ((TELogicSensor) tileEntity).On)
|
||||
Wiring.HitSwitch((int) tileEntity.Position.X, (int) tileEntity.Position.Y);
|
||||
if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.Honey && ((TELogicSensor) tileEntity).On)
|
||||
Wiring.HitSwitch((int) tileEntity.Position.X, (int) tileEntity.Position.Y);
|
||||
if (((TELogicSensor) tileEntity).logicCheck == TELogicSensor.LogicCheckType.Liquid && ((TELogicSensor) tileEntity).On)
|
||||
Wiring.HitSwitch((int) tileEntity.Position.X, (int) 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) && tileEntity.type == (byte) 2 ? 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,
|
||||
}
|
||||
}
|
||||
}
|
151
GameContent/Tile_Entities/TETrainingDummy.cs
Normal file
151
GameContent/Tile_Entities/TETrainingDummy.cs
Normal file
|
@ -0,0 +1,151 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.GameContent.Tile_Entities.TETrainingDummy
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// 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 = false;
|
||||
public int npc;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
TileEntity._UpdateStart += new Action(TETrainingDummy.ClearBoxes);
|
||||
TileEntity._NetPlaceEntity += new Action<int, int, int>(TETrainingDummy.NetPlaceEntity);
|
||||
}
|
||||
|
||||
public static void NetPlaceEntity(int x, int y, int type)
|
||||
{
|
||||
if (type != 0 || !TETrainingDummy.ValidTile(x, y))
|
||||
return;
|
||||
TETrainingDummy.Place(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 = (byte) 0;
|
||||
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)
|
||||
{
|
||||
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)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void Kill(int x, int y)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (!TileEntity.ByPosition.TryGetValue(new Point16(x, y), out tileEntity) || tileEntity.type != (byte) 0)
|
||||
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) && tileEntity.type == (byte) 0 ? 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue