-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPathOfModifiers.cs
208 lines (182 loc) · 7.76 KB
/
PathOfModifiers.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
using PathOfModifiers.Maps;
using PathOfModifiers.Maps.Generators;
using PathOfModifiers.Rarities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
namespace PathOfModifiers
{
public class PathOfModifiers : Mod
{
public static PathOfModifiers Instance { get; private set; }
public PathOfModifiers() { }
public override uint ExtraPlayerBuffSlots => 15;
public static List<Mod> registeredMods = new();
public static void RegisterMod(Mod mod)
{
registeredMods.Add(mod);
}
public struct PoMModData
{
public Dictionary<Type, int> affixItemMap;
public Affixes.Items.Affix[] affixesItem;
public Dictionary<Type, int> rarityItemMap;
public RarityItem[] raritiesItem;
public Dictionary<Type, int> affixNPCMap;
public Affixes.NPCs.Affix[] affixesNPC;
public Dictionary<Type, int> rarityNPCMap;
public RarityNPC[] raritiesNPC;
public Dictionary<Type, int> generatorMap;
public Generator[] generators;
public Dictionary<Type, int> mapMap;
public Map[] maps;
}
/// <summary>
/// Loads affixes and rarities from registered mods
/// </summary>
static PoMModData LoadData()
{
Dictionary<Type, int> affixItemMap = new();
List<Affixes.Items.Affix> affixItemList = new();
Dictionary<Type, int> rarityItemMap = new();
List<RarityItem> rarityItemList = new();
Dictionary<Type, int> affixNPCMap = new();
List<Affixes.NPCs.Affix> affixNPCList = new();
Dictionary<Type, int> rarityNPCMap = new();
List<RarityNPC> rarityNPCList = new();
Dictionary<Type, int> generatorMap = new();
List<Generator> generatorList = new();
Dictionary<Type, int> mapMap = new();
List<Map> mapList = new();
int affixItemIndex = 0;
int rarityItemIndex = 0;
int affixNPCIndex = 0;
int rarityNPCIndex = 0;
int mapIndex = 0;
int generatorIndex = 0;
Affixes.Items.Affix affixItem;
RarityItem rarityItem;
Affixes.NPCs.Affix affixNPC;
RarityNPC rarityNPC;
Generator generator;
Map map;
foreach (Mod mod in registeredMods)
{
var types = mod.Code.GetTypes().Where(t => t.IsClass && !t.IsAbstract);
foreach (Type t in types)
{
if (t.IsDefined(typeof(DisableAffix), false))
{
continue;
}
if (t.IsSubclassOf(typeof(Affixes.Items.Affix)) || t == typeof(Affixes.Items.Affix))
{
affixItem = (Affixes.Items.Affix)Activator.CreateInstance(t);
affixItem.mod = mod;
affixItemList.Add(affixItem);
affixItemMap.Add(t, affixItemIndex);
Instance.Logger.Debug($"Added item affix {t.FullName} with index {affixItemIndex} from mod {mod.Name}");
affixItemIndex++;
}
else if (t.IsSubclassOf(typeof(RarityItem)) && t != typeof(RarityItem))
{
rarityItem = (RarityItem)Activator.CreateInstance(t, mod);
rarityItemList.Add(rarityItem);
rarityItemMap.Add(t, rarityItemIndex);
Instance.Logger.Debug($"Added item rarity {t.FullName} with index {rarityItemIndex} from mod {mod.Name}");
rarityItemIndex++;
}
else if (t.IsSubclassOf(typeof(Affixes.NPCs.Affix)) || t == typeof(Affixes.NPCs.Affix))
{
affixNPC = (Affixes.NPCs.Affix)Activator.CreateInstance(t);
affixNPC.mod = mod;
affixNPCList.Add(affixNPC);
affixNPCMap.Add(t, affixNPCIndex);
Instance.Logger.Debug($"Added NPC affix {t.FullName} with index {affixNPCIndex} from mod {mod.Name}");
affixNPCIndex++;
}
else if (t.IsSubclassOf(typeof(RarityNPC)) && t != typeof(RarityNPC))
{
rarityNPC = (RarityNPC)Activator.CreateInstance(t);
rarityNPC.mod = mod;
rarityNPCList.Add(rarityNPC);
rarityNPCMap.Add(t, rarityNPCIndex);
Instance.Logger.Debug($"Added NPC rarity {t.FullName} with index {rarityNPCIndex} from mod {mod.Name}");
rarityNPCIndex++;
}
else if (t.IsSubclassOf(typeof(Generator)) && t != typeof(Generator))
{
generator = (Generator)Activator.CreateInstance(t);
generator.mod = mod;
generatorList.Add(generator);
generatorMap.Add(t, generatorIndex);
Instance.Logger.Debug($"Added generator {t.FullName} with index {generatorIndex} from mod {mod.Name}");
generatorIndex++;
}
else if (t.IsSubclassOf(typeof(Map)) && t != typeof(Map))
{
map = (Map)Activator.CreateInstance(t);
map.mod = mod;
map.Initialize();
mapList.Add(map);
mapMap.Add(t, mapIndex);
Instance.Logger.Debug($"Added map {t.FullName} with index {mapIndex} from mod {mod.Name}");
mapIndex++;
}
}
}
return new PoMModData
{
affixItemMap = affixItemMap,
affixesItem = affixItemList.ToArray(),
rarityItemMap = rarityItemMap,
raritiesItem = rarityItemList.ToArray(),
affixNPCMap = affixNPCMap,
affixesNPC = affixNPCList.ToArray(),
rarityNPCMap = rarityNPCMap,
raritiesNPC = rarityNPCList.ToArray(),
generatorMap = generatorMap,
generators = generatorList.ToArray(),
mapMap = mapMap,
maps = mapList.ToArray(),
};
}
public override void Load()
{
Instance = this;
ModNet.ModNet.Initialize();
RegisterMod(this);
}
public override void PostSetupContent()
{
DataManager.Load(LoadData());
ModContent.GetInstance<Affixes.Items.ItemItem>().PostLoad();
ModContent.GetInstance<Affixes.NPCs.NPCNPC>().PostLoad();
//if (Main.netMode != 2)
//{
// new ModifierForgeUI().Initialize();
// modifierForgeUI = new UserInterface();
// ModifierForgeUI.HideUI();
// new MapDeviceUI().Initialize();
// mapDeviceUI = new UserInterface();
// MapDeviceUI.HideUI();
//}
}
public override void Unload()
{
//modifierForgeUI = null;
//mapDeviceUI = null;
DataManager.Unload();
Instance = null;
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
ModNet.ModNet.HandlePacket(reader, whoAmI);
}
}
}