/
MagicalThings.cs
352 lines (317 loc) · 13.9 KB
/
MagicalThings.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
using System;
using System.Collections.Generic;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using Terraria.ModLoader.IO;
using Microsoft.Xna.Framework.Graphics;
using Terraria.Localization;
using MagicalThings.Buffs;
namespace MagicalThings
{
public class MagicalThings : Mod
{
public static bool AllowShoesInAccessorySlots = true;
public static bool ShoeSlotlocation = true;
//public const string SHOE_SLOT_BACK_TEX = "ShoeSlotBackground";
public const string ShoeSlotBackTex = "ShoeSlotBackground";
//public static readonly MagicalThingsConfig Config = new ModConfig("MagicalThings");
private static List<Func<bool>> RightClickOverrides;
internal static MagicalThings instance;
public MagicalThings()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true,
AutoloadBackgrounds = true //changed
};
//Config.Add(AllowShoesInAccessorySlots, true);
//Config.Add(ShoeSlotlocation, 2);
//Config.Load();
//TerraUI.Utilities.UIUtils.Mod = this;
//TerraUI.Utilities.UIUtils.Subdirectory = "TerraUI";
}
#region Load-Unload Sprite Draws
public override void Load()
{
instance = this;
if (!Main.dedServ)
{
AddMusicBox(GetSoundSlot(SoundType.Music, "Sounds/Music/Enkryption"), ItemType("EnkryptionMusicBox"), TileType("EnkryptionMusicBox"));
AddMusicBox(GetSoundSlot(SoundType.Music, "Sounds/Music/BlueMoon"), ItemType("BlueMoonMusicBox"), TileType("BlueMoonMusicBox"));
AddEquipTexture(null, EquipType.Legs, "GreatWizardRobes_Legs", "MagicalThings/Items/Armor/GreatWizard/GreatWizardRobes_Legs");
}
RightClickOverrides = new List<Func<bool>>();
}
public override void Unload()
{
instance = null;
if (RightClickOverrides != null)
{
RightClickOverrides.Clear();
RightClickOverrides = null;
}
}
public override object Call(params object[] args)
{
try
{
string keyword = args[0] as string;
if (string.IsNullOrEmpty(keyword))
{
return null;
}
switch (keyword)
{
case "add":
case "remove":
// shoeSlot.Call(/* "add" or "remove" */, /* func<bool> returns true to cancel/false to continue */);
// These two should be called in PostSetupContent
Func<bool> func = args[1] as Func<bool>;
if (func == null) return null;
if (keyword == "add")
{
RightClickOverrides.Add(func);
}
else if (keyword == "remove")
{
RightClickOverrides.Remove(func);
}
break;
case "getEquip":
case "getVanity":
case "getVisible":
/* Can't use these three in PostSetupContent because EquipShoeSlot is a field in MagicalPlayer, but
* that's not initialized yet, hence why I couldn't make some sort of delegate as an argument
* that assigned it */
// Item shoeItem = (Item)shoeSlot.Call(/* "getEquip"/"getVanity"/"getVisible" */, player.whoAmI);
// These three should be called on demand
int whoAmI = Convert.ToInt32(args[1]);
MagicalPlayer mmp = Main.player[whoAmI].GetModPlayer<MagicalPlayer>();
if (keyword == "getEquip")
{
return mmp.EquipShoeSlot.Item;
}
else if (keyword == "getVanity")
{
return mmp.VanityShoeSlot.Item;
}
// Returns the item that is responsible for the shoes to display on the player (at all times or during flight)
else if (keyword == "getVisible")
{
if (mmp.VanityShoeSlot.Item.shoeSlot > 0)
{
return mmp.VanityShoeSlot.Item;
}
else
{
return mmp.EquipShoeSlot.Item;
}
}
break;
}
}
catch
{
return null;
}
return null;
#region Old
//string keyword = args[0] as string;
//Func<bool> func = args[1] as Func<bool>;
//if (string.IsNullOrEmpty(keyword) || func == null)
//{
// return null;
//}
//keyword = keyword.ToLower();
//if (keyword == "add")
//{
// RightClickOverrides.Add(func);
//}
//else if (keyword == "remove")
//{
// RightClickOverrides.Remove(func);
//}
//return null;
#endregion
}
public override void PostDrawInterface(SpriteBatch spriteBatch)
{
//MagicalPlayer mpp = Main.player[Main.myPlayer].GetModPlayer<MagicalPlayer>();
MagicalPlayer mpp = Main.LocalPlayer.GetModPlayer<MagicalPlayer>();
mpp.Draw(spriteBatch);
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
PacketMessageType message = (PacketMessageType)reader.ReadByte();
byte player = reader.ReadByte();
MagicalPlayer modPlayer = Main.player[player].GetModPlayer<MagicalPlayer>();
switch (message)
{
case PacketMessageType.All:
modPlayer.EquipShoeSlot.Item = ItemIO.Receive(reader);
modPlayer.VanityShoeSlot.Item = ItemIO.Receive(reader);
modPlayer.ShoeDyeSlot.Item = ItemIO.Receive(reader);
if (Main.netMode == NetmodeID.Server)
{
ModPacket packet = GetPacket();
packet.Write((byte)PacketMessageType.All);
packet.Write(player);
ItemIO.Send(modPlayer.EquipShoeSlot.Item, packet);
ItemIO.Send(modPlayer.VanityShoeSlot.Item, packet);
ItemIO.Send(modPlayer.ShoeDyeSlot.Item, packet);
packet.Send(-1, whoAmI);
}
break;
case PacketMessageType.EquipShoeSlot:
modPlayer.EquipShoeSlot.Item = ItemIO.Receive(reader);
if (Main.netMode == NetmodeID.Server)
{
modPlayer.SendSingleItemPacket(PacketMessageType.EquipShoeSlot, modPlayer.EquipShoeSlot.Item, -1, whoAmI);
}
break;
case PacketMessageType.VanityShoeSlot:
modPlayer.VanityShoeSlot.Item = ItemIO.Receive(reader);
if (Main.netMode == NetmodeID.Server)
{
modPlayer.SendSingleItemPacket(PacketMessageType.VanityShoeSlot, modPlayer.VanityShoeSlot.Item, -1, whoAmI);
}
break;
case PacketMessageType.ShoeDyeSlot:
modPlayer.ShoeDyeSlot.Item = ItemIO.Receive(reader);
if (Main.netMode == NetmodeID.Server)
{
modPlayer.SendSingleItemPacket(PacketMessageType.ShoeDyeSlot, modPlayer.ShoeDyeSlot.Item, -1, whoAmI);
}
break;
default:
Logger.InfoFormat("Magical Things: Unknown message type: ", DisplayName);
//ErrorLogger.Log("Magical Things: Unknown message type: " + message);
break;
}
}
public static bool OverrideRightClick()
{
foreach (var func in RightClickOverrides)
{
if (func())
{
return true;
}
}
return false;
}
#endregion
#region Recipe Groups
public override void AddRecipeGroups()
{
#region Tier 7 Classes
// Creates a new recipe group
RecipeGroup group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Tier 7 Mage Class" + Lang.GetItemNameValue(ItemType("Tier 7 Mage Class")), new int[]
{
ItemType("HellMarkTome"),
ItemType("HellBurstStaff"),
ItemType("BookOfSpellsV6"),
ItemType("UnholyStorm")
});
// Registers the new recipe group with the specified name
RecipeGroup.RegisterGroup("MagicalThings:Tier 7 Mage Class", group);
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Tier 7 Ninja Class" + Lang.GetItemNameValue(ItemType("Tier 7 Ninja Class")), new int[]
{
ItemType("HellfireKunai"),
ItemType("BurningBloodDagger")
});
RecipeGroup.RegisterGroup("MagicalThings:Tier 7 Ninja Class", group);
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Tier 7 Ranger Class" + Lang.GetItemNameValue(ItemType("Tier 7 Ranger Class")), new int[]
{
ItemType("NightmareBow"),
ItemType("DarkBlaster")
});
RecipeGroup.RegisterGroup("MagicalThings:Tier 7 Ranger Class", group);
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Tier 7 Summoner Class" + Lang.GetItemNameValue(ItemType("Tier 7 Summoner Class")), new int[]
{
ItemType("FlameSkullLamp"),
ItemType("BrokenLance")
});
RecipeGroup.RegisterGroup("MagicalThings:Tier 7 Summoner Class", group);
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Tier 7 Melee Class" + Lang.GetItemNameValue(ItemType("Tier 7 Melee Class")), new int[]
{
ItemType("HellfireSword"),
ItemType("DarkFlail"),
ItemType("HellfireBident"),
ItemType("DarkThrow")
});
RecipeGroup.RegisterGroup("MagicalThings:Tier 7 Melee Class", group);
#endregion
#region Bar Groups
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Demonite Bar", new int[]
{
ItemID.DemoniteBar,
ItemID.CrimtaneBar
});
RecipeGroup.RegisterGroup("MagicalThings:Demonite Bar", group);
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Cobalt Bar", new int[]
{
ItemID.CobaltBar,
ItemID.PalladiumBar
});
RecipeGroup.RegisterGroup("MagicalThings:Cobalt Bar", group);
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Mythril Bar", new int[]
{
ItemID.MythrilBar,
ItemID.OrichalcumBar
});
RecipeGroup.RegisterGroup("MagicalThings:Mythril Bar", group);
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Adamantite Bar", new int[]
{
ItemID.AdamantiteBar,
ItemID.TitaniumBar
});
RecipeGroup.RegisterGroup("MagicalThings:Adamantite Bar", group);
#endregion
#region Boot Groups
group = new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " Hermes Boots", new int[]
{
ItemID.HermesBoots,
ItemID.FlurryBoots,
ItemID.SailfishBoots,
ItemType("MercuryBoots")
});
RecipeGroup.RegisterGroup("MagicalThings:Hermes Boots", group);
#endregion
}
#endregion
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(this);
recipe.AddIngredient(null, "MercuryBoots", 1);
recipe.AddIngredient(ItemID.RocketBoots, 1);
recipe.AddTile(TileID.TinkerersWorkbench);
recipe.SetResult(ItemID.SpectreBoots, 1);
recipe.AddRecipe();
//Added to normal recipe section
// recipe = new ModRecipe(this);
// recipe.AddIngredient(ItemID.PalladiumBar, 10);
// recipe.AddIngredient(ItemID.SoulofNight, 2);
// recipe.AddTile(TileID.MythrilAnvil);
// recipe.SetResult(null, "Twinkle", 1);
// recipe.AddRecipe();
}
public override void UpdateMusic(ref int music, ref MusicPriority priority)
{
if (Main.myPlayer == -1 || Main.gameMenu || !Main.LocalPlayer.active)
{
return;
}
if (Main.LocalPlayer.HasBuff(ModContent.BuffType<SantaNK2Buff>()))
{
music = MusicID.FrostMoon;
priority = MusicPriority.Environment;
}
}
}
}