forked from Kalciphoz/kRPG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkRPG.cs
293 lines (266 loc) · 11.3 KB
/
kRPG.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using kRPG.Content.GFX;
using kRPG.Content.GUI.Base;
using kRPG.Content.Items.Glyphs;
using kRPG.Content.Items.Weapons.Melee;
using kRPG.Enums;
using kRPG.Packets;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using On.Terraria.ID;
using Terraria;
using Terraria.ModLoader;
using Terraria.UI;
using Terraria.ID;
using ItemID = Terraria.ID.ItemID;
// ReSharper disable StringLiteralTypo
namespace kRPG
{
public class kRPG : Mod
{
public kRPG()
{
Properties = new ModProperties { Autoload = true, AutoloadGores = true, AutoloadSounds = true };
Mod = this;
}
public static void LogMessage(string msg)
{
Debug.WriteLine("MESSAGE: " + msg);
ModLoader.GetMod(Constants.ModName).Logger.InfoFormat(msg);
}
public Texture2D[] InvSlot { get; set; } = new Texture2D[16];
public static kRPG Mod { get; set; }
public static bool PlayerEnteredWorld { get; set; } = false;
// public static Mod Overhaul { get; set; }
public bool DrawInterface()
{
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.UIScaleMatrix);
if (Main.netMode == NetmodeID.Server || Main.gameMenu) return true;
try
{
for (int i = 0; i < BaseGui.GuiElements.Count; i += 1)
{
BaseGui gui = BaseGui.GuiElements[i];
if (gui.PreDraw())
gui.Draw(Main.spriteBatch, Main.LocalPlayer);
}
}
catch (SystemException e)
{
LogMessage(e.ToString());
}
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.UIScaleMatrix);
return true;
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
Message msg = (Message)reader.ReadByte();
#if DEBUG
LogMessage($"Handling {msg}");
#endif
switch (msg)
{
//case Message.InitProjEleDmg:
// if (!Main.projectile.IndexInRange((int)tags[DataTag.projId])) break;
// Projectile p = Main.projectile[(int)tags[DataTag.projId]];
// try
// {
// kProjectile proj = p.GetGlobalProjectile<kProjectile>();
// proj.elementalDamage = new Dictionary<ELEMENT, int>()
// {
// { ELEMENT.FIRE, (int)tags[DataTag.fire] },
// { ELEMENT.COLD, (int)tags[DataTag.cold] },
// { ELEMENT.LIGHTNING, (int)tags[DataTag.lightning] },
// { ELEMENT.SHADOW, (int)tags[DataTag.shadow] }
// };
// }
// catch (SystemException e)
// {
// Main.NewText(e.ToString());
// }
// break;
case Message.NpcEleDmg:
NPCEleDmgPacket.Read(reader);
break;
case Message.PrefixNpc:
PrefixNPCPacket.Read(reader);
break;
case Message.SyncStats:
SyncStatsPacket.Read(reader);
break;
case Message.SyncLevel:
SyncLevelPacket.Read(reader);
kRPG.PlayerEnteredWorld = true;
break;
case Message.CreateProjectile:
CreateProjectilePacket.Read(reader);
break;
case Message.AddXp:
AddXPPacket.Read(reader);
break;
//case Message.SyncSpear:
// SyncSpearPacket.Read(reader);
// break;
case Message.SwordInit:
SwordInitPacket.Read(reader);
break;
case Message.StaffInit:
StaffInitPacket.Read(reader);
break;
case Message.BowInit:
BowInitPacket.Read(reader);
break;
case Message.SyncHit:
SyncHitPacket.Read(reader);
break;
case Message.SyncCritHit:
SyncCritHitPacket.Read(reader);
break;
}
}
public override void Load()
{
//Overhaul = ModLoader.GetMod("TerrariaOverhaul");
kConfig.Initialize();
if (Main.netMode != NetmodeID.Server)
{
GFX.LoadGfx();
InvSlot[0] = Main.inventoryBackTexture;
InvSlot[1] = Main.inventoryBack2Texture;
InvSlot[2] = Main.inventoryBack3Texture;
InvSlot[3] = Main.inventoryBack4Texture;
InvSlot[4] = Main.inventoryBack5Texture;
InvSlot[5] = Main.inventoryBack6Texture;
InvSlot[6] = Main.inventoryBack7Texture;
InvSlot[7] = Main.inventoryBack8Texture;
InvSlot[8] = Main.inventoryBack9Texture;
InvSlot[9] = Main.inventoryBack10Texture;
InvSlot[10] = Main.inventoryBack11Texture;
InvSlot[11] = Main.inventoryBack12Texture;
InvSlot[12] = Main.inventoryBack13Texture;
InvSlot[13] = Main.inventoryBack14Texture;
InvSlot[14] = Main.inventoryBack15Texture;
InvSlot[15] = Main.inventoryBack16Texture;
Main.inventoryBackTexture = GFX.ItemSlot;
Main.inventoryBack2Texture = GFX.ItemSlot;
Main.inventoryBack3Texture = GFX.ItemSlot;
Main.inventoryBack4Texture = GFX.ItemSlot;
Main.inventoryBack5Texture = GFX.ItemSlot;
Main.inventoryBack6Texture = GFX.ItemSlot;
Main.inventoryBack7Texture = GFX.ItemSlot;
Main.inventoryBack8Texture = GFX.ItemSlot;
Main.inventoryBack9Texture = GFX.ItemSlot;
Main.inventoryBack10Texture = GFX.FavouritedSlot;
Main.inventoryBack11Texture = GFX.ItemSlot;
Main.inventoryBack12Texture = GFX.ItemSlot;
Main.inventoryBack13Texture = GFX.ItemSlot;
Main.inventoryBack14Texture = GFX.SelectedSlot;
Main.inventoryBack15Texture = GFX.ItemSlot;
Main.inventoryBack16Texture = GFX.ItemSlot;
}
Main.player[Main.myPlayer].hbLocked = false;
SwordHilt.Initialize();
SwordBlade.Initialize();
SwordAccent.Initialize();
Staff.Initialize();
StaffGem.Initialize();
StaffOrnament.Initialize();
GlyphModifier.Initialize();
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
Mod MagicStorage = ModLoader.GetMod("MagicStorage");
MagicStorage?.ModifyInterfaceLayers(layers);
layers.Find(layer => layer.Name == "Vanilla: Resource Bars").Active = false;
layers[layers.FindIndex(layer => layer.Name == "Vanilla: Inventory")] = new LegacyGameInterfaceLayer(Constants.ModName, DrawInterface, InterfaceScaleType.UI);
layers.Find(layer => layer.Name == "Vanilla: Hotbar").Active = false;
}
public override void Unload()
{
Main.inventoryBackTexture = InvSlot[0];
Main.inventoryBack2Texture = InvSlot[1];
Main.inventoryBack3Texture = InvSlot[2];
Main.inventoryBack4Texture = InvSlot[3];
Main.inventoryBack5Texture = InvSlot[4];
Main.inventoryBack6Texture = InvSlot[5];
Main.inventoryBack7Texture = InvSlot[6];
Main.inventoryBack8Texture = InvSlot[7];
Main.inventoryBack9Texture = InvSlot[8];
Main.inventoryBack10Texture = InvSlot[9];
Main.inventoryBack11Texture = InvSlot[10];
Main.inventoryBack12Texture = InvSlot[11];
Main.inventoryBack13Texture = InvSlot[12];
Main.inventoryBack14Texture = InvSlot[13];
Main.inventoryBack15Texture = InvSlot[14];
Main.inventoryBack16Texture = InvSlot[15];
GFX.UnloadGfx();
SwordBlade.Unload();
SwordHilt.Unload();
SwordAccent.Unload();
StaffGem.Unload();
Staff.Unload();
StaffOrnament.Unload();
Main.instance.invBottom = 210;
}
#region UpdateCheck
public class VersionInfo
{
public string summary;
public string version;
}
//Mirsario's code in Mirsario's code style
public static void CheckForUpdates()
{
#pragma warning disable 162
try
{
string url = @"http://raw.githubusercontent.com/FairfieldTekLLC/kRPG/master/kRPG_VersionInfo.json";
WebClient client = new WebClient();
Version currentVersion = Mod.Version;
client.DownloadStringCompleted += (sender, e) =>
{
try
{
string text = e.Result;
VersionInfo versionInfo = JsonConvert.DeserializeObject<VersionInfo>(text);
Version latestVersion = new Version(versionInfo.version);
if (latestVersion > currentVersion)
{
//Public update available
Main.NewText("[c/cccccc:New version of] [c/ffdb00:KRPG] [c/cccccc:available]");
Main.NewTextMultiline("[c/cccccc:Summary:] " + versionInfo.summary, WidthLimit: 725);
Main.NewText("[c/cccccc:Get the update from Mod Browser]");
}
else if (latestVersion == currentVersion && new Version(kConfig.Stats.LastStartVersion) < currentVersion)
{
//After installing a public update
Main.NewText("[c/cccccc:KRPG is now up to date!]");
Main.NewTextMultiline("[c/cccccc:Summary changes:] " + versionInfo.summary, WidthLimit: 725);
}
kConfig.Stats.LastStartVersion = currentVersion.ToString();
kConfig.SaveStats();
}
catch
{
//
}
};
client.DownloadStringAsync(new Uri(url), url);
}
catch
{
//
}
#pragma warning restore 162
}
#endregion
}
}