Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
/home/travis/build/Jofairden/EvenMoreModifiers/LootModWorld.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using Terraria.ModLoader;
4 using Terraria.ModLoader.IO;
5 using Terraria.World.Generation;
6 
7 namespace Loot
8 {
12  public class LootModWorld : ModWorld
13  {
14  // The world has not initialized yet, when it is first updated
15  public static bool Initialized { get; internal set; }
16 
17  public override void Initialize()
18  {
19  Initialized = false;
20  }
21 
22  public override TagCompound Save()
23  {
24  return new TagCompound
25  {
26  {"initialized", Initialized}
27  };
28  }
29 
30  public override void Load(TagCompound tag)
31  {
32  try
33  {
34  Initialized = tag.GetBool("initialized");
35  }
36  catch (Exception e)
37  {
38  Loot.Logger.Error("Error on EMMWorld.Load", e);
39  }
40  }
41 
42  public override void PostUpdate()
43  {
44  if (Initialized)
45  {
46  return;
47  }
48 
49  Initialized = true;
50  //foreach (var chest in Main.chest.Where(chest => chest != null && chest.x > 0 && chest.y > 0))
51  //{
52  // WorldGenModifiersPass.GenerateModifiers(null, ModifierContextMethod.FirstLoad, chest.item.Where(x => !x.IsAir), chest);
53  //}
54  }
55 
56  // TODO hardmode task, generate better modifiers in new biomes etc.
57 
58  public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
59  {
60  //tasks.Add(new WorldGenModifiersPass("EvenMoreModifiers:WorldGenModifiersPass", 1));
61  }
62 
63  //internal sealed class WorldGenModifiersPass : GenPass
64  //{
65  // public WorldGenModifiersPass(string name, float loadWeight) : base(name, loadWeight)
66  // {
67  // }
68 
69  // // Attempt rolling modifiers on items
70  // internal static void GenerateModifiers(GenerationProgress progress, ModifierContextMethod method, IEnumerable<Item> items, object obj = null)
71  // {
72  // if (progress != null)
73  // {
74  // progress.Message = "Generating modifiers on generated items...";
75  // }
76 
77  // foreach (var item in items)
78  // {
79  // LootModItem itemInfo = LootModItem.GetInfo(item);
80  // ModifierPool pool = itemInfo.ModifierPool;
81  // UnifiedRandom rand = (Main.rand ?? WorldGen.genRand) ?? new UnifiedRandom();
82 
83  // if (itemInfo.HasRolled || pool != null)
84  // continue;
85 
86  // itemInfo.HasRolled = true;
87 
88  // if (rand != null && rand.NextBool())
89  // continue;
90 
91  // ModifierContext ctx = new ModifierContext
92  // {
93  // Method = method,
94  // Item = item,
95  // Strategy = RollingUtils.Strategies.Normal
96  // };
97 
98  // switch (obj)
99  // {
100  // case Chest chest:
101  // ctx.CustomData = new Dictionary<string, object>
102  // {
103  // {"chestData", new Tuple<int, int>(chest.x, chest.y)}
104  // };
105  // break;
106  // case Player player:
107  // ctx.Player = player;
108  // break;
109  // }
110 
111  // pool = itemInfo.RollNewPool(ctx, RollingUtils.Properties.WorldGen);
112  // pool?.ApplyModifiers(item);
113  // }
114  // }
115 
116  // public override void Apply(GenerationProgress progress)
117  // {
118  // Initialized = true;
119  // foreach (var chest in Main.chest.Where(chest => chest != null && chest.x > 0 && chest.y > 0))
120  // {
121  // GenerateModifiers(progress,
122  // ModifierContextMethod.WorldGeneration,
123  // chest.item.Where(x => x != null && !x.IsAir && x.IsModifierRollableItem()),
124  // chest);
125  // }
126  // }
127  //}
128  }
129 }
override void Initialize()
Definition: LootModWorld.cs:17
This class is responsible for generating modifiers when a world is being created. ...
Definition: LootModWorld.cs:12
override void Load(TagCompound tag)
Definition: LootModWorld.cs:30
override TagCompound Save()
Definition: LootModWorld.cs:22
override void ModifyWorldGenTasks(List< GenPass > tasks, ref float totalWeight)
Definition: LootModWorld.cs:58
override void PostUpdate()
Definition: LootModWorld.cs:42
static bool Initialized
Definition: LootModWorld.cs:15