Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
LootEssenceWorld.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using Terraria;
3 using Terraria.ModLoader;
4 using Terraria.ModLoader.IO;
5 
6 namespace Loot.Soulforging
7 {
8  internal class LootEssenceWorld : ModWorld
9  {
10  public HashSet<int> UnlockedCubes = new HashSet<int>();
11  // TODO for now default unlocked, until souls are implemented
12  public bool SoulforgingUnlocked = true;
13 
14  public void UnlockCube(int type)
15  {
16  UnlockedCubes.Add(type);
17  }
18 
19  public bool IsCubeUnlocked(int type)
20  {
21  return UnlockedCubes.Contains(type);
22  }
23 
24  public override TagCompound Save()
25  {
26  var items = new Dictionary<string, List<string>>();
27  foreach (var type in UnlockedCubes)
28  {
29  var item = new Item();
30  item.SetDefaults(type);
31  if (!items.ContainsKey(item.modItem.mod.Name)) items.Add(item.modItem.mod.Name, new List<string>());
32  items[item.modItem.mod.Name].Add(item.modItem.Name);
33  }
34  var tc = new TagCompound();
35  foreach (string mod in items.Keys)
36  {
37  tc.Add(mod, items[mod]);
38  }
39  return new TagCompound
40  {
41  {"UnlockedCubes", tc},
42  {"SoulforgingUnlocked", SoulforgingUnlocked}
43  };
44  }
45 
46  public override void Load(TagCompound tag)
47  {
48  foreach (var kvp in tag.GetCompound("UnlockedCubes"))
49  {
50  var mod = kvp.Key;
51  var items = kvp.Value as List<string>;
52  items.ForEach(item =>
53  {
54  UnlockedCubes.Add(ModLoader.GetMod(mod).ItemType(item));
55  });
56  }
57  SoulforgingUnlocked = tag.GetBool("SoulforgingUnlocked");
58  }
59  }
60 }