public void WriteConfig(String file) { DropReplacement replacement = new DropReplacement(); replacement.drops = new Dictionary<State, List<Drop>>(); List<Drop> drops = new List<Drop>(); drops.Add(new Drop { chance = 1.0f, high_stack = 99, low_stack = 1, itemID = 73 }); replacement.drops.Add(State.Normal, drops); LootReplacements.Add(3, replacement); using (var tw = new StreamWriter(file)) { tw.Write(JsonConvert.SerializeObject(LootReplacements, Formatting.Indented)); } }
public void WriteConfig(String file) { DropReplacement replacement = new DropReplacement(); replacement.drops = new Dictionary <State, List <Drop> >(); List <Drop> drops = new List <Drop>(); drops.Add(new Drop { chance = 1.0f, high_stack = 99, low_stack = 1, itemID = 73 }); replacement.drops.Add(State.Normal, drops); LootReplacements.Add(3, replacement); using (var tw = new StreamWriter(file)) { tw.Write(JsonConvert.SerializeObject(LootReplacements, Formatting.Indented)); } }
private void OnLootDrop(NpcLootDropEventArgs args) { //Debug print //Console.WriteLine("{0}[{1}]: ({2}, {3}) - Item:{4}", args.NPCID, args.NPCArrayIndex, args.X, args.Y, // args.ItemID); if (config.LootReplacements.ContainsKey(args.NpcId)) { DropReplacement repl = config.LootReplacements[args.NpcId]; if (Main.bloodMoon && repl.drops.ContainsKey(State.Bloodmoon)) { foreach (Drop d in repl.drops[State.Bloodmoon]) { double rng = random.NextDouble(); if (d.chance >= rng) { var item = TShock.Utils.GetItemById(d.itemID); int stack = random.Next(d.low_stack, d.high_stack + 1); Item.NewItem((int)args.Position.X, (int)args.Position.Y, item.width, item.height, d.itemID, stack, args.Broadcast, d.prefix); args.Handled = true; if (!repl.tryEachItem) { break; } } } } if (Main.eclipse && repl.drops.ContainsKey(State.Eclipse)) { foreach (Drop d in repl.drops[State.Eclipse]) { double rng = random.NextDouble(); if (d.chance >= rng) { var item = TShock.Utils.GetItemById(d.itemID); int stack = random.Next(d.low_stack, d.high_stack + 1); Item.NewItem((int)args.Position.X, (int)args.Position.Y, item.width, item.height, d.itemID, stack, args.Broadcast, d.prefix); args.Handled = true; if (!repl.tryEachItem) { break; } } } } if (Main.moonPhase == 0 && !Main.dayTime && repl.drops.ContainsKey(State.Fullmoon)) { foreach (Drop d in repl.drops[State.Fullmoon]) { double rng = random.NextDouble(); if (d.chance >= rng) { var item = TShock.Utils.GetItemById(d.itemID); int stack = random.Next(d.low_stack, d.high_stack + 1); Item.NewItem((int)args.Position.X, (int)args.Position.Y, item.width, item.height, d.itemID, stack, args.Broadcast, d.prefix); args.Handled = true; if (!repl.tryEachItem) { break; } } } } if (!Main.dayTime && repl.drops.ContainsKey(State.Night)) { foreach (Drop d in repl.drops[State.Night]) { double rng = random.NextDouble(); if (d.chance >= rng) { var item = TShock.Utils.GetItemById(d.itemID); int stack = random.Next(d.low_stack, d.high_stack + 1); Item.NewItem((int)args.Position.X, (int)args.Position.Y, item.width, item.height, d.itemID, stack, args.Broadcast, d.prefix); args.Handled = true; if (!repl.tryEachItem) { break; } } } } if (Main.dayTime && repl.drops.ContainsKey(State.Day)) { foreach (Drop d in repl.drops[State.Day]) { double rng = random.NextDouble(); if (d.chance >= rng) { var item = TShock.Utils.GetItemById(d.itemID); int stack = random.Next(d.low_stack, d.high_stack + 1); Item.NewItem((int)args.Position.X, (int)args.Position.Y, item.width, item.height, d.itemID, stack, args.Broadcast, d.prefix); args.Handled = true; if (!repl.tryEachItem) { break; } } } } if (repl.drops.ContainsKey(State.Normal)) { foreach (Drop d in repl.drops[State.Normal]) { double rng = random.NextDouble(); if (d.chance >= rng) { var item = TShock.Utils.GetItemById(d.itemID); int stack = random.Next(d.low_stack, d.high_stack + 1); Item.NewItem((int)args.Position.X, (int)args.Position.Y, item.width, item.height, d.itemID, stack, args.Broadcast, d.prefix); args.Handled = true; if (!repl.tryEachItem) { break; } } } } if (!repl.alsoDropDefaultLoot) { args.Handled = true; } } }