-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMechThrowverhaul.cs
More file actions
88 lines (75 loc) · 3.05 KB
/
MechThrowverhaul.cs
File metadata and controls
88 lines (75 loc) · 3.05 KB
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
using MechThrowverhaul.Items;
using MechThrowverhaul.UI;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ModLoader;
using Terraria.UI;
using Terraria.ID;
namespace MechThrowverhaul
{
public class MechThrowverhaul : Mod
{
internal ManufacturingTableUI ManufacturingTableUI;
internal UserInterface ManufacturingTableUserInterface;
public override void Load()
{
if (!Main.dedServ)
{
ManufacturingTableUI = new ManufacturingTableUI();
ManufacturingTableUI.Activate();
ManufacturingTableUserInterface = new UserInterface();
ManufacturingTableUserInterface.SetState(ManufacturingTableUI);
ModContent.GetInstance<MechThrowverhaul>().ManufacturingTableUserInterface.SetState(null);
}
}
public override void UpdateUI(GameTime gameTime)
{
ManufacturingTableUserInterface?.Update(gameTime);
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int InventoryIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Inventory"));
if (InventoryIndex != -1)
{
layers.Insert(InventoryIndex, new LegacyGameInterfaceLayer(
"MechThrowverhaul: ManufacturingTable",
delegate
{
ManufacturingTableUserInterface.Draw(Main.spriteBatch, new GameTime());
return true;
},
InterfaceScaleType.UI)
);
}
}
// Experimental system to automatically adjust recipes for throwverhauled weapons
public override void PostAddRecipes()
{
RecipeFinder finder = new RecipeFinder(); // make a new RecipeFinder
foreach (Recipe recipe in finder.SearchRecipes()) // loop every recipe found by the finder
{
ThrowingWeapons throwItem = recipe.createItem.GetGlobalItem<ThrowingWeapons>();
if (throwItem.throwverhauled)
{
RecipeEditor editor = new RecipeEditor(recipe); // for the currently looped recipe, make a new RecipeEditor
double multiplicand = throwItem.maxStack / recipe.createItem.stack;
if (multiplicand <= 0) multiplicand = 1;
recipe.createItem.stack = throwItem.maxStack;
foreach (Item item in recipe.requiredItem)
{
item.stack = (int)Math.Round(item.stack * multiplicand);
}
}
foreach (Item item in recipe.requiredItem)
{
if (item.type != ItemID.None && item.GetGlobalItem<ThrowingWeapons>().throwverhauled)
{
item.stack = 1;
}
}
}
}
}
}