void OnNpcLootDrop(NpcLootDropEventArgs e) { Item item = TShock.Utils.GetItemById(e.ItemId); bool precious = itemsToWatch.Contains(e.ItemId); // If new item is watched and roll-off is enabled if (rollOnLoot && precious) { // Build item manually since we will not let the game process the drop item.SetDefaults(e.ItemId, false); item.Prefix(e.Prefix); item.stack = e.Stack; // Add to roll off items itemsToRoll.Add(item); if (itemsToRoll.Count == 1) { TSPlayer.All.SendMessage(string.Format("Loot: {0} ({1}). Type /roll for this item", item.AffixName(), item.stack), Color.Pink); } else { TSPlayer.All.SendMessage(string.Format("{0} ({1}) added to loot roll queue.", item.AffixName(), item.stack), Color.LightPink); } e.Handled = true; } }
/// <summary> /// For Custom Loot /// </summary> /// <param name="args"></param> private void OnLootDrop(NpcLootDropEventArgs args) { CustomNPCVars npcvar = NPCManager.GetCustomNPCByIndex(args.NpcArrayIndex); if (npcvar == null || npcvar.droppedLoot) { return; } args.Handled = npcvar.customNPC.overrideBaseNPCLoot; //Check if monster has been customized if (npcvar.customNPC.customNPCLoots != null) { foreach (CustomNPCLoot obj in npcvar.customNPC.customNPCLoots) { if (obj.itemDropChance >= 100 || NPCManager.Chance(obj.itemDropChance)) { int pre = 0; if (obj.itemPrefix != null) { pre = obj.itemPrefix[rand.Next(obj.itemPrefix.Count)]; } Item.NewItem((int)npcvar.mainNPC.position.X, (int)npcvar.mainNPC.position.Y, npcvar.mainNPC.width, npcvar.mainNPC.height, obj.itemID, obj.itemStack, false, pre, false); } } } npcvar.isDead = true; npcvar.droppedLoot = true; npcvar.OnDeath(); }
private void OnDropLoot(NpcLootDropEventArgs eventArgs) { // Same conditions as above if ((Terraria.Main.npc[eventArgs.NpcArrayIndex].boss || eventArgs.NpcId == Terraria.ID.NPCID.DD2Betsy) && Terraria.Main.GameMode == 0 && eventArgs.NpcId != Terraria.ID.NPCID.CultistBoss) { eventArgs.Handled = true; // //Prevents the game from processing this event. This stops npcs from dropping loot with the NPCLootOld() method. Coins, hearts, mana stars, and health potions use a differnet method so they retain normal behavior. Loot is cancelled as we are replacing it with treasure bags. } }
private void LootHook(NpcLootDropEventArgs e) { if (e == null || e.ItemId != 367) { return; } Task.Factory.StartNew(() => UndoBox((int)e.Position.X, (int)e.Position.Y, e.Width, e.Height)).LogExceptions(); }
private void OnNpcLootDrop(NpcLootDropEventArgs args) { if (args.Handled) { return; } var customNpc = GetCustomNpc(Main.npc[args.NpcArrayIndex]); if (customNpc != null) { args.Handled = customNpc.Definition.ShouldOverrideLoot && !AllowedDrops[args.ItemId]; } }
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; } } }