forked from GabeHasWon/VerdantMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.cs
129 lines (109 loc) · 4.58 KB
/
Helper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using Microsoft.Xna.Framework;
using System;
using System.Linq;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
namespace Verdant
{
public class Helper
{
public static int AnyTileRectangle(int i, int j, int w, int h)
{
int count = 0;
for (int l = i; l < i + w; ++l)
for (int k = j; k < j + h; ++k)
if (Framing.GetTileSafely(l, k).HasTile)
count++;
return count;
}
public static int NoTileRectangle(int i, int j, int w, int h)
{
int count = 0;
for (int l = i; l < i + w; ++l)
for (int k = j; k < j + h; ++k)
if (!Framing.GetTileSafely(l, k).HasTile)
count++;
return count;
}
public static int TileRectangle(int i, int j, int w, int h, params int[] types)
{
int count = 0;
for (int l = i; l < i + w; ++l)
for (int k = j; k < j + h; ++k)
if (Framing.GetTileSafely(l, k).HasTile && types.Any(x => x == Framing.GetTileSafely(l, k).TileType))
count++;
return count;
}
public static bool AreaClear(int i, int j, int w, int h) => AnyTileRectangle(i, j, w, h) == 0;
public static int WallRectangle(int i, int j, int w, int h)
{
int count = 0;
for (int l = i; l < i + w; ++l)
for (int k = j; k < j + h; ++k)
if (Main.tile[l, k].WallType != WallID.None)
count++;
return count;
}
public static bool WalledSquare(int i, int j, int w, int h) => WallRectangle(i, j, w, h) == w * h;
public static int WalledType(int i, int j, int w, int h, int type)
{
int count = 0;
for (int l = i; l < i + w; ++l)
for (int k = j; k < j + h; ++k)
if (Main.tile[l, k].WallType != WallID.None && Main.tile[l, k].WallType == type)
count++;
return count;
}
public static bool WalledSquareType(int i, int j, int w, int h, int type) => WallRectangle(i, j, w, h) == w * h && WalledType(i, j, w, h, type) == w * h;
public static int FindDown(Vector2 worldPos)
{
Point tPos = worldPos.ToTileCoordinates();
while (!Main.tile[tPos.X, tPos.Y].HasTile || !Main.tileSolid[Main.tile[tPos.X, tPos.Y].TileType])
{
tPos.Y++;
if (tPos.Y > Main.maxTilesY - 2)
return tPos.Y;
}
return tPos.Y;
}
public static int FindUpWithType(Point tilePos, params int[] validTileTypes)
{
while (!WorldGen.SolidTile(tilePos) || !validTileTypes.Contains(Main.tile[tilePos.X, tilePos.Y].TileType))
{
tilePos.Y--;
if (tilePos.Y <= -1)
return -1;
}
return tilePos.Y;
}
public static void ArmsTowardsMouse(Player p = null, Vector2? targetLoc = null)
{
if (p == null)
p = Main.LocalPlayer;
if (targetLoc == null)
targetLoc = Main.MouseWorld;
float radians = p.AngleTo(targetLoc.Value) + MathHelper.PiOver2;
radians = Math.Abs(radians);
int FrameSize = 56;
bool WithinAngle(float target) => Math.Abs(target - radians) < MathHelper.PiOver4;
if (WithinAngle(MathHelper.PiOver4) || radians < MathHelper.PiOver4)
p.bodyFrame.Y = FrameSize * 2;
else if (WithinAngle(MathHelper.PiOver2))
p.bodyFrame.Y = FrameSize * 3;
else if (WithinAngle(MathHelper.PiOver4 * 3))
p.bodyFrame.Y = FrameSize * 4;
else if (WithinAngle(MathHelper.PiOver2 * 3))
p.bodyFrame.Y = FrameSize * 3;
}
public static int SyncItem(IEntitySource source, Vector2 pos, int type, int stack = 1)
{
int newItem = Item.NewItem(source, pos, type, stack); // Create a new item in the world.
if (Main.netMode == NetmodeID.MultiplayerClient && newItem >= 0)
NetMessage.SendData(MessageID.SyncItem, -1, -1, null, newItem, 1f);
return newItem;
}
public static bool OnScreen(Rectangle rect) => rect.Intersects(new Rectangle(0, 0, Main.screenWidth, Main.screenHeight));
public static Point MouseTile() => (Main.MouseWorld / 16f).ToPoint();
}
}