-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMapAssist.cs
205 lines (177 loc) · 6.93 KB
/
MapAssist.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using IL.Terraria.World.Generation; /// To prevent corruption searching lag in the future
using System;
using Terraria.ModLoader;
using Terraria.Utilities;
using ReLogic.Graphics;
/*
Ye fabled Crash regaurding the Map. Unsure if fixed now but just in case it isnt:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.get_Item(Int32 index)
at BossAssist.MapAssist.DrawIcons() in C:\Users\TurtleShark's Bros\Documents\My Games\Terraria\ModLoader\Mod Sources\BossAssist\BossLogUI.cs:line 86
at BossAssist.MapAssist.DrawFullscreenMap() in C:\Users\TurtleShark's Bros\Documents\My Games\Terraria\ModLoader\Mod Sources\BossAssist\BossLogUI.cs:line 78
at BossAssist.BossAssist.PostDrawFullscreenMap(String& mouseText) in C:\Users\TurtleShark's Bros\Documents\My Games\Terraria\ModLoader\Mod Sources\BossAssist\DataManager.cs:line 157
at Terraria.ModLoader.ModHooks.PostDrawFullscreenMap(String& mouseText)
at Terraria.Main.DrawMap()
at Terraria.Main.do_Draw(GameTime gameTime)
at Terraria.Main.DoDraw(GameTime gameTime)
*/
namespace BossAssist
{
public static class MapAssist
{
#region [Item Drawing]
public static List<Vector2> whitelistPos;
public static List<int> whitelistType;
internal static void FullMapInitialize()
{
whitelistPos = new List<Vector2>();
whitelistType = new List<int>();
//tilePos = new Vector2();
//shouldDraw = false;
}
public static void DrawFullscreenMap()
{
UpdateMapLocations();
DrawIcons();
}
private static void UpdateMapLocations()
{
whitelistPos.Clear();
whitelistType.Clear();
foreach (Item item in Main.item)
{
if (!item.active) continue;
if (IsWhiteListItem(item))
{
whitelistPos.Add(item.Center);
whitelistType.Add(item.type);
}
}
}
private static void DrawIcons()
{
foreach (Vector2 item in whitelistPos)
{
Texture2D drawTexture = Main.itemTexture[whitelistType[whitelistPos.IndexOf(item)]];
Vector2 drawPosition = CalculateDrawPos(new Vector2(item.X / 16, item.Y / 16));
if (WhiteListType(whitelistType[whitelistPos.IndexOf(item)]) == 1 && !BossAssist.ClientConfig.FragmentsBool) continue;
if (WhiteListType(whitelistType[whitelistPos.IndexOf(item)]) == 2 && !BossAssist.ClientConfig.ScalesBool) continue;
DrawTextureOnMap(drawTexture, drawPosition);
}
}
private static Vector2 CalculateDrawPos(Vector2 tilePos)
{
Vector2 halfScreen = new Vector2(Main.screenWidth / 2, Main.screenHeight / 2);
Vector2 relativePos = tilePos - Main.mapFullscreenPos;
relativePos *= Main.mapFullscreenScale / 16;
relativePos = relativePos * 16 + halfScreen;
Vector2 drawPosition = new Vector2((int)relativePos.X, (int)relativePos.Y);
return drawPosition;
}
private static void DrawTextureOnMap(Texture2D texture, Vector2 drawPosition)
{
Rectangle drawPos = new Rectangle((int)drawPosition.X, (int)drawPosition.Y, texture.Width, texture.Height);
Vector2 originLoc = new Vector2(texture.Width / 2, texture.Height / 2);
Main.spriteBatch.Draw(texture, drawPos, null, Color.White, 0f, originLoc, SpriteEffects.None, 0f);
}
public static bool IsWhiteListItem(Item item)
{
if (item.consumable && item.Name == "Treasure Bag" && item.expert) return true;
if (item.rare == 9 && item.damage <= 0 && item.Name.Contains("Fragment")) return true;
if (item.type == ItemID.ShadowScale || item.type == ItemID.TissueSample) return true;
return false;
}
public static int WhiteListType(int type)
{
Item item = new Item();
item.SetDefaults(type);
if (item.consumable && item.Name == "Treasure Bag" && item.expert) return 0;
if (item.rare == 9 && item.damage <= 0 && item.Name.Contains("Fragment")) return 1;
if (item.type == ItemID.ShadowScale || item.type == ItemID.TissueSample) return 2;
return -1;
}
#endregion
/*
#region EvilFinder
public static Vector2 tilePos;
public static bool shouldDraw = false;
public static int evilType = 0;
public static void DrawNearestEvil(Vector2 pos)
{
if (pos == new Vector2(0, 0) || evilType == 0) return;
Texture2D drawTexture = null;
if (evilType == 1) drawTexture = Main.itemTexture[ItemID.CorruptFishingCrate];
else if (evilType == 2) drawTexture = Main.itemTexture[ItemID.CrimsonFishingCrate];
Vector2 drawPosition = CalculateDrawPos(pos);
DrawTextureOnMap(drawTexture, drawPosition);
}
public static int ValidEvilTile(int type)
{
List<int> validCrimsonTiles = new List<int>()
{
TileID.CrimsonHardenedSand,
TileID.Crimsand,
TileID.CrimsonSandstone,
TileID.Crimstone,
TileID.CrimtaneThorns,
TileID.FleshIce,
TileID.FleshGrass
};
List<int> validCorruptionTiles = new List<int>()
{
TileID.Ebonstone,
TileID.Ebonsand,
TileID.CorruptGrass,
TileID.CorruptIce,
TileID.CorruptHardenedSand,
TileID.CorruptThorns,
TileID.CorruptSandstone,
};
if (validCorruptionTiles.Contains(type)) return 1;
if (validCrimsonTiles.Contains(type)) return 2;
return 0;
}
public static void LocateNearestEvil()
{
shouldDraw = false;
tilePos = new Vector2(0, 0);
float tileDistance = float.MaxValue;
Vector2 nearestTile = new Vector2(0, 0);
for (int x = (int)(Main.leftWorld / 16); x < (int)(Main.rightWorld / 16); x++)
{
for (int y = (int)(Main.topWorld / 16); y < (int)(Main.bottomWorld / 16); y++)
{
if (x >= Main.LocalPlayer.position.X) break;
if (!Main.tile[x, y].active() || ValidEvilTile(Main.tile[x, y].type) == 0) continue;
float currentTileDistance = Vector2.Distance(new Vector2(x, y).ToWorldCoordinates(), Main.LocalPlayer.Center);
if (currentTileDistance < tileDistance)
{
tileDistance = currentTileDistance;
nearestTile = new Vector2(x, y);
evilType = ValidEvilTile(Main.tile[x, y].type);
}
}
}
if (tileDistance != float.MaxValue)
{
tilePos = nearestTile;
shouldDraw = true;
}
else
{
shouldDraw = false;
tilePos = new Vector2(0, 0);
evilType = 0;
}
}
#endregion
*/
}
}