using System;
using System.Collections.Generic;
using CalamityMod.Items.Accessories;
using CalamityMod.NPCs.SulphurousSea;
using CalamityMod.Items.Potions;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.GameContent.ItemDropRules;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.Utilities;
namespace CalamityMod
{
#region Fraction Struct (thanks Yorai)
public struct Fraction
{
internal readonly int numerator;
internal readonly int denominator;
public Fraction(int n, int d)
{
numerator = n < 0 ? 0 : n;
denominator = d <= 0 ? 1 : d;
}
public static implicit operator float(Fraction f) => f.numerator / (float)f.denominator;
}
#endregion
#region Weighted Item Stack Struct
public struct WeightedItemStack
{
public const float DefaultWeight = 1f;
public const float MinisiculeWeight = 1E-6f;
internal int itemID;
internal float weight;
internal int minQuantity;
internal int maxQuantity;
internal WeightedItemStack(int id, float w)
{
itemID = id;
weight = w;
minQuantity = 1;
maxQuantity = 1;
}
internal WeightedItemStack(int id, float w, int quantity)
{
itemID = id;
weight = w;
minQuantity = quantity;
maxQuantity = quantity;
}
internal WeightedItemStack(int id, float w, int min, int max)
{
itemID = id;
weight = w;
minQuantity = min;
maxQuantity = max;
}
internal int ChooseQuantity(UnifiedRandom rng) => rng.Next(minQuantity, maxQuantity + 1);
// Allow for implicitly casting integer item IDs into weighted item stacks.
// Stack size is assumed to be 1. Weight is assumed to be default.
public static implicit operator WeightedItemStack(int id)
{
return new WeightedItemStack(id, DefaultWeight, 1);
}
}
#endregion
public static class DropHelper
{
#region Global Drop Chances
///
/// Weapons in Normal Mode typically have a 1 in X chance of dropping, where X is this variable.
///
public const int NormalWeaponDropRateInt = 4;
///
/// Weapons in Normal Mode typically have this chance to drop, measured out of 1.0.
///
public const float NormalWeaponDropRateFloat = 0.25f;
///
/// Weapons in Normal Mode typically have this chance to drop (as a DropHelper Fraction).
///
public static readonly Fraction NormalWeaponDropRateFraction = new(1, NormalWeaponDropRateInt);
///
/// Weapons in Expert Mode typically have a 1 in X chance of dropping, where X is this variable.
///
public const int BagWeaponDropRateInt = 3;
///
/// Weapons in Expert Mode typically have this chance to drop, measured out of 1.0.
///
public const float BagWeaponDropRateFloat = 0.3333333f;
///
/// Weapons in Expert Mode typically have this chance to drop (as a DropHelper Fraction).
///
public static readonly Fraction BagWeaponDropRateFraction = new(1, BagWeaponDropRateInt);
#endregion
#region Bestiary Text
public static string FirstKillText = "Drops only on the first kill";
public static string MechBossText = "Drops on the first kill of the final Mechanical Boss";
public static string CynosureText = "Drops once you have defeated both Draedon and Calamitas";
public static string ProvidenceHallowText = "Drops if Providence was summoned in the Hallow\nor if Providence is only attacked during nighttime";
public static string ProvidenceUnderworldText = "Drops if Providence was summoned in the Underworld\nor if Providence is only attacked during nighttime";
public static string ProvidenceNightText = "Drops if Providence is only attacked during nighttime";
public static string ProvidenceChallengeText = $"Drops if Providence was defeated only with the [i:{ModContent.ItemType()}] Profaned Soul Artifact\nThis is an Expert Mode drop rate";
#endregion
#region Block Drops
private static int[] AllLoadedItemIDs = null;
///
/// Adds the specified items to TML's blockLoot list. Items on the list cannot spawn in the world via any means.
/// You should only use this function in the following places:
/// - ModNPC.PreKill and GlobalNPC.PreKill
/// - ModNPC.OnKill and GlobalNPC.OnKill
/// This function is intended to block items from dropping from NPCs based on TEMPORARY CONDITIONS.
/// If you want to permanently remove a drop from an NPC, this is not the function you want.
/// In those cases, use GlobalNPC.ModifyLoot, an if statement for that NPC, and loot.Remove or loot.RemoveWhere.
/// This will ensure that the drops are removed from the bestiary as well.
///
/// The item IDs to prevent from spawning.
public static void BlockDrops(params int[] itemIDs)
{
foreach (int itemID in itemIDs)
NPCLoader.blockLoot.Add(itemID);
}
///
/// Blocks every possible item in the game from dropping. This is the extreme version of BlockDrops.
/// Please read the usage notes on BlockDrops.
/// This function intentionally still allows hearts and mana stars to drop. If you also want to block those, block them separately.
///
/// The item IDs to still allow to drop.
public static void BlockEverything(params int[] exceptions)
{
// This solution is legitimately brain damaged but it works for now
// At least it's cached...
if (AllLoadedItemIDs is null)
{
AllLoadedItemIDs = new int[ItemLoader.ItemCount];
for (int i = 0; i < ItemLoader.ItemCount; ++i)
AllLoadedItemIDs[i] = i;
}
// Apply exceptions
int[] withSomeExceptions = new int[ItemLoader.ItemCount];
AllLoadedItemIDs.CopyTo(withSomeExceptions, 0);
withSomeExceptions[ItemID.Heart] = ItemID.RedPotion;
withSomeExceptions[ItemID.Star] = ItemID.RedPotion;
foreach (int itemID in exceptions)
withSomeExceptions[itemID] = ItemID.RedPotion;
BlockDrops(withSomeExceptions);
}
#endregion
#region Specific Drop Helpers
// Code copied from Player.QuickSpawnClonedItem, which was added by TML.
///
/// Clones the given item and spawns it into the world at the given position. You can also customize stack count as necessary.
/// The default stack count of -1 makes it copy the stack count of the given item.
///
/// The item to clone and spawn.
/// Where the item should be spawned.
/// The stack count to use. Leave at -1 to use the stack of the item parameter.
/// The spawned clone of the item. NEVER equal to the input item.
public static Item DropItemClone(IEntitySource src, Item item, Vector2 position, int stack = -1)
{
int index = Item.NewItem(src, position, item.type, stack, false, -1, false, false);
Item theClone = Main.item[index] = item.Clone();
theClone.whoAmI = index;
theClone.position = position;
if (stack != -1)
theClone.stack = stack;
// If in multiplayer, broadcast that this item was spawned.
if (Main.netMode == NetmodeID.MultiplayerClient)
NetMessage.SendData(MessageID.SyncItem, -1, -1, null, index, 1f);
return theClone;
}
///
/// Finds the worm segment nearest to an NPC's target by combing the NPC array for the closest NPC that is one of the specified types.
/// Return the specified NPC's index if no matching worm segment was found.
///
/// The NPC whose target is used for distance comparisons.
/// An array (or multiple parameters) of NPC IDs which are the worm segments to look for.
/// An index in the NPC array of the closest worm segment, or the specified NPC's index.
public static int FindClosestWormSegment(NPC wormHead, params int[] wormSegmentIDs)
{
List idsToCheck = new List(wormSegmentIDs);
Vector2 playerPos = Main.player[wormHead.target].Center;
int r = wormHead.whoAmI;
float minDist = 1E+06f;
for (int i = 0; i < Main.npc.Length; ++i)
{
NPC n = Main.npc[i];
if (n != null && n.active && idsToCheck.Contains(n.type))
{
float dist = (n.Center - playerPos).Length();
if (dist < minDist)
{
minDist = dist;
r = i;
}
}
}
return r;
}
///
/// Shorthand for shorthand: Registers an item to drop per-player on the specified condition.
/// Intended for lore items, but can be used generally for instanced drops.
///
/// The ILoot interface for the loot table.
/// A lambda which evaluates in real-time to the condition that needs to be checked.
/// The item ID to drop.
/// Whether drops registered with this condition appear in the Bestiary. Defaults to true.
/// The description of this condition in the Bestiary. Defaults to null.
/// A LeadingConditionRule which you can attach more PerPlayer or other rules to as you want.
public static LeadingConditionRule AddConditionalPerPlayer(this ILoot loot, Func lambda, int itemID, bool ui = true, string desc = null)
{
LeadingConditionRule lcr = new(If(lambda, ui, desc));
lcr.Add(PerPlayer(itemID));
loot.Add(lcr);
return lcr;
}
///
/// Shorthand for shorthand: Registers an item to drop per-player on the specified condition.
/// Intended for lore items, but can be used generally for instanced drops.
///
/// The ILoot interface for the loot table.
/// A lambda which evaluates in real-time to the condition that needs to be checked.
/// The item ID to drop.
/// Whether drops registered with this condition appear in the Bestiary. Defaults to true.
/// The description of this condition in the Bestiary. Defaults to null.
/// A LeadingConditionRule which you can attach more PerPlayer or other rules to as you want.
public static LeadingConditionRule AddConditionalPerPlayer(this ILoot loot, Func lambda, int itemID, bool ui = true, string desc = null)
{
LeadingConditionRule lcr = new(If(lambda, ui, desc));
lcr.Add(PerPlayer(itemID));
loot.Add(lcr);
return lcr;
}
public static DropBasedOnExpertMode NormalVsExpertQuantity(int itemID, int dropRateInt, int minNormal, int maxNormal, int minExpert, int maxExpert)
{
IItemDropRule normalRule = ItemDropRule.Common(itemID, dropRateInt, minNormal, maxNormal);
IItemDropRule expertRule = ItemDropRule.Common(itemID, dropRateInt, minExpert, maxExpert);
return new DropBasedOnExpertMode(normalRule, expertRule);
}
///
/// Adds the Revengeance Mode bag accessories to the given loot table.
///
/// The ILoot interface for the loot table.
public static void AddRevBagAccessories(this ILoot loot)
{
var lcr = new LeadingConditionRule(If(() => CalamityWorld.revenge));
lcr.Add(new OneFromOptionsDropRule(20, 1, ModContent.ItemType(), ModContent.ItemType(), ModContent.ItemType()));
loot.Add(lcr);
}
///
/// Adds all the common potions for fishing crates, alongside scaling mana and regen potions
///
/// The ILoot interface for the loot table.
public static void AddCratePotionRules(this ILoot loot)
{
loot.Add(ItemID.ObsidianSkinPotion, 10, 1, 3);
loot.Add(ItemID.SwiftnessPotion, 10, 1, 3);
loot.Add(ItemID.IronskinPotion, 10, 1, 3);
loot.Add(ItemID.NightOwlPotion, 10, 1, 3);
loot.Add(ItemID.ShinePotion, 10, 1, 3);
loot.Add(ItemID.MiningPotion, 10, 1, 3);
loot.Add(ItemID.HeartreachPotion, 10, 1, 3);
loot.Add(ItemID.TrapsightPotion, 10, 1, 3); // Dangersense Potion
// Define all the loot rules for the potion types
var supremePots = new OneFromOptionsNotScaledWithLuckDropRule(1, 1, ModContent.ItemType(), ModContent.ItemType());
var superPots = new OneFromOptionsNotScaledWithLuckDropRule(1, 1, ItemID.SuperHealingPotion, ItemID.SuperManaPotion);
var greaterPots = new OneFromOptionsNotScaledWithLuckDropRule(1, 1, ItemID.GreaterHealingPotion, ItemID.GreaterManaPotion);
var regularPots = new OneFromOptionsNotScaledWithLuckDropRule(1, 1, ItemID.HealingPotion, ItemID.ManaPotion);
var lesserPots = new OneFromOptionsNotScaledWithLuckDropRule(1, 1, ItemID.LesserHealingPotion, ItemID.LesserManaPotion);
// Chained LeadingConditionRules achieve the equivalent of "if killed X, else if killed Y, else if killed Z, else..."
var lcrSupremePotion = loot.DefineConditionalDropSet(() => DownedBossSystem.downedDoG);
var lcrSuperPotion = new LeadingConditionRule(If(() => DownedBossSystem.downedProvidence));
var lcrGreaterPotion = new LeadingConditionRule(If(() => NPC.downedMechBossAny));
var lcrRegularPotion = new LeadingConditionRule(If(() => NPC.downedBoss3));
// Actually chain all the LCRs together
lcrSupremePotion.Add(supremePots);
lcrSupremePotion.OnFailedConditions(lcrSuperPotion);
lcrSuperPotion.Add(superPots);
lcrSuperPotion.OnFailedConditions(lcrGreaterPotion);
lcrGreaterPotion.Add(greaterPots);
lcrGreaterPotion.OnFailedConditions(lcrRegularPotion);
lcrRegularPotion.Add(regularPots);
lcrRegularPotion.OnFailedConditions(lesserPots);
}
#endregion
#region Recursive Drop Rate Mutator
private static int RecursivelyMutateDropRate(this IItemDropRule rule, int itemID, int newNumerator, int newDenominator)
{
if (rule is CommonDrop drop && drop.itemId == itemID)
{
drop.chanceNumerator = newNumerator;
drop.chanceDenominator = newDenominator;
return 1;
}
else if (rule is ItemDropWithConditionRule conditionalDrop && conditionalDrop.itemId == itemID)
{
conditionalDrop.chanceNumerator = newNumerator;
conditionalDrop.chanceDenominator = newDenominator;
return 1;
}
else if (rule is DropBasedOnExpertMode expertDrop)
{
int normalChanges = RecursivelyMutateDropRate(expertDrop.ruleForNormalMode, itemID, newNumerator, newDenominator);
int expertChanges = RecursivelyMutateDropRate(expertDrop.ruleForExpertMode, itemID, newNumerator, newDenominator);
return normalChanges + expertChanges;
}
else if (rule is DropBasedOnMasterMode masterDrop)
{
int defaultChanges = RecursivelyMutateDropRate(masterDrop.ruleForDefault, itemID, newNumerator, newDenominator);
int masterChanges = RecursivelyMutateDropRate(masterDrop.ruleForMasterMode, itemID, newNumerator, newDenominator);
return defaultChanges + masterChanges;
}
return 0;
}
#endregion
#region Lambda Drop Rule Condition
// This class serves as a vanilla drop rule condition that is based on completely arbitrary code.
// Create these using the function DropHelper.If as needed.
internal class LambdaDropRuleCondition : IItemDropRuleCondition
{
private readonly Func conditionLambda;
private readonly bool visibleInUI;
private readonly string description;
internal LambdaDropRuleCondition(Func lambda, bool ui = true, string desc = null)
{
conditionLambda = lambda;
visibleInUI = ui;
description = desc;
}
public bool CanDrop(DropAttemptInfo info) => conditionLambda(info);
public bool CanShowItemDropInUI() => visibleInUI;
public string GetConditionDescription() => description;
}
internal class LambdaDropRuleCondition2 : IItemDropRuleCondition
{
private readonly Func conditionLambda;
private readonly Func visibleInUI;
private readonly string description;
internal LambdaDropRuleCondition2(Func lambda, Func ui, string desc = null)
{
conditionLambda = lambda;
visibleInUI = ui;
description = desc;
}
public bool CanDrop(DropAttemptInfo info) => conditionLambda(info);
public bool CanShowItemDropInUI() => visibleInUI();
public string GetConditionDescription() => description;
}
internal class LambdaDropRuleCondition3 : IItemDropRuleCondition
{
private readonly Func conditionLambda;
private readonly Func visibleInUI;
private readonly Func description;
internal LambdaDropRuleCondition3(Func lambda, Func ui, Func desc)
{
conditionLambda = lambda;
visibleInUI = ui;
description = desc;
}
public bool CanDrop(DropAttemptInfo info) => conditionLambda(info);
public bool CanShowItemDropInUI() => visibleInUI();
public string GetConditionDescription() => description();
}
///
/// Creates a new LambdaDropRuleCondition which executes the code of your choosing to decide whether this item drop should occur.
/// This version of "If" does NOT use the DropAttemptInfo struct that is available.
/// This lets you write simpler lambdas that do not need the context, e.g. just checking if a boss is dead.
///
/// Lambda function which evaluates to true or false, deciding whether the item should drop. () => {CodeHere}
/// The LambdaDropRuleCondition produced.
public static IItemDropRuleCondition If(Func lambda) => new LambdaDropRuleCondition((_) => lambda());
///
/// Creates a new LambdaDropRuleCondition which executes the code of your choosing to decide whether this item drop should occur.
/// This version of "If" does NOT use the DropAttemptInfo struct that is available.
/// This lets you write simpler lambdas that do not need the context, e.g. just checking if a boss is dead.
///
/// Lambda function which evaluates to true or false, deciding whether the item should drop. () => {CodeHere}
/// Whether drops registered with this condition appear in the Bestiary. Defaults to true.
/// The description of this condition in the Bestiary. Defaults to null.
/// The LambdaDropRuleCondition produced.
public static IItemDropRuleCondition If(Func lambda, bool ui = true, string desc = null)
{
bool LambdaInfoWrapper(DropAttemptInfo _) => lambda();
return new LambdaDropRuleCondition(LambdaInfoWrapper, ui, desc);
}
public static IItemDropRuleCondition If(Func lambda, Func ui, string desc = null)
{
bool LambdaInfoWrapper(DropAttemptInfo _) => lambda();
return new LambdaDropRuleCondition2(LambdaInfoWrapper, ui, desc);
}
public static IItemDropRuleCondition If(Func lambda, Func ui, Func desc)
{
bool LambdaInfoWrapper(DropAttemptInfo _) => lambda();
return new LambdaDropRuleCondition3(LambdaInfoWrapper, ui, desc);
}
///
/// Creates a new LambdaDropRuleCondition which executes the code of your choosing to decide whether this item drop should occur.
/// This version of "If" DOES use the DropAttemptInfo struct, and thus the provided lambda requires 1 argument.
///
/// Lambda function which evaluates to true or false, deciding whether the item should drop. (info) => {CodeHere}
/// The LambdaDropRuleCondition produced.
public static IItemDropRuleCondition If(Func lambda) => new LambdaDropRuleCondition(lambda);
///
/// Creates a new LambdaDropRuleCondition which executes the code of your choosing to decide whether this item drop should occur.
/// This version of "If" DOES use the DropAttemptInfo struct, and thus the provided lambda requires 1 argument.
///
/// Lambda function which evaluates to true or false, deciding whether the item should drop. (info) => {CodeHere}
/// Whether drops registered with this condition appear in the Bestiary. Defaults to true.
/// The description of this condition in the Bestiary. Defaults to null.
/// The LambdaDropRuleCondition produced.
public static IItemDropRuleCondition If(Func lambda, bool ui = true, string desc = null)
{
return new LambdaDropRuleCondition(lambda, ui, desc);
}
public static IItemDropRuleCondition If(Func lambda, Func ui, string desc = null)
{
return new LambdaDropRuleCondition2(lambda, ui, desc);
}
public static IItemDropRuleCondition If(Func lambda, Func ui, Func desc)
{
return new LambdaDropRuleCondition3(lambda, ui, desc);
}
#endregion
#region Drop Rule Conditions
public static IItemDropRuleCondition HallowedBarsCondition = If((info) =>
{
// If the Early Hardmode Progression Rework is not enabled, then Hallowed Bars can always drop from Mechanical Bosses.
if (!CalamityConfig.Instance.EarlyHardmodeProgressionRework)
return true;
// If the Early Hardmode Progression Rework is enabled, then all 3 Mechanical Bosses must be defeated for Hallowed Bars to drop.
return NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3;
});
public static IItemDropRuleCondition GoldSetBonusGoldCondition = If((info) =>
{
// Gold coins "from normal enemies" do not drop from the following:
// 1 - NPCs spawned from statues
// 2 - NPCs with no contact damage (bosses are NOT excepted, since they hit the other rule)
// 3 - Very weak NPCs: those with 5 or less max health.
NPC npc = info.npc;
if (npc.SpawnedFromStatue || npc.damage <= 5 || npc.lifeMax <= 5)
return false;
// If the drop info doesn't have a player, then find the closest player to the NPC and use that player instead.
Player p = info.player;
if (p is null || !p.active)
p = Main.player[Player.FindClosest(npc.position, npc.width, npc.height)];
// With the player identified, return whether or not they have the full Gold Armor set equipped.
return p.Calamity().goldArmorGoldDrops;
});
public static IItemDropRuleCondition GoldSetBonusBossCondition = If((info) =>
{
// Gold coins "from from bosses"
NPC npc = info.npc;
if (!npc.boss)
return false;
// If the drop info doesn't have a player, then find the closest player to the NPC and use that player instead.
Player p = info.player;
if (p is null || !p.active)
p = Main.player[Player.FindClosest(npc.position, npc.width, npc.height)];
// With the player identified, return whether or not they have the full Gold Armor set equipped.
return p.Calamity().goldArmorGoldDrops;
});
public static IItemDropRuleCondition TarragonSetBonusHeartCondition = If((info) =>
{
// Tarragon hearts do not drop from the following:
// 1 - NPCs spawned from statues
// 2 - NPCs with no contact damage, unless they are bosses.
// 3 - Very weak NPCs (for postML), i.e. those with less than 100 max health.
NPC npc = info.npc;
if (npc.SpawnedFromStatue || (npc.damage <= 5 && !npc.boss) || npc.lifeMax <= 100)
return false;
// If the drop info doesn't have a player, then find the closest player to the NPC and use that player instead.
Player p = info.player;
if (p is null || !p.active)
p = Main.player[Player.FindClosest(npc.position, npc.width, npc.height)];
// With the player identified, return whether or not they have the full Tarragon Armor set equipped.
return p.Calamity().tarraSet;
});
internal const float TrasherEatDistance = 96f;
public static IItemDropRuleCondition AnglerFedToTrasherCondition = If((info) =>
{
bool trasherNearby = false;
for (int i = 0; i < Main.maxNPCs; ++i)
{
NPC nearby = Main.npc[i];
if (nearby is null || !nearby.active || nearby.type != ModContent.NPCType())
continue;
if (info.npc.Distance(nearby.Center) < TrasherEatDistance)
{
trasherNearby = true;
break;
}
}
return trasherNearby;
});
// The text is a separate rule so it doesn't show up on the non-Trasher Fishing Rod drop which only occurs if the Angler is not fed to a Trasher
public static IItemDropRuleCondition TrasherText = If((info) => true, true, "Drops if fed to a Trasher");
public static IItemDropRuleCondition RevNoMaster = If((info) => !Main.masterMode && CalamityWorld.revenge, () => !Main.masterMode && CalamityWorld.revenge, "This is a Revengeance Mode drop rate");
public static IItemDropRuleCondition RevAndMaster = If((info) => Main.masterMode || CalamityWorld.revenge, () => Main.masterMode || CalamityWorld.revenge, () =>
{
return Main.masterMode ? Language.GetTextValue("Bestiary_ItemDropConditions.IsMasterMode") : "This is a Revengeance Mode drop rate";
});
#region Boss Defeat Conditionals
public static IItemDropRuleCondition PostKS(bool ui = true) => If(() => NPC.downedSlimeKing, ui, "Drops after defeating King Slime");
public static IItemDropRuleCondition PostDS(bool ui = true) => If(() => DownedBossSystem.downedDesertScourge, ui, "Drops after defeating the Desert Scourge");
public static IItemDropRuleCondition PostEoC(bool ui = true) => If(() => NPC.downedBoss1, ui, "Drops after defeating the Eye of Cthulhu");
public static IItemDropRuleCondition PostCrab(bool ui = true) => If(() => DownedBossSystem.downedCrabulon, ui, "Drops after defeating Crabulon");
public static IItemDropRuleCondition PostEvil1(bool ui = true) => If(() => NPC.downedBoss2, ui, "Drops after defeating the " + (WorldGen.crimson ? "Brain of Cthulhu" : "Eater of Worlds"));
public static IItemDropRuleCondition PostHM(bool ui = true) => If(() => DownedBossSystem.downedHiveMind, ui, "Drops after defeating the Hive Mind");
public static IItemDropRuleCondition PostPerfs(bool ui = true) => If(() => DownedBossSystem.downedPerforator, ui, "Drops after defeating the Perforators");
public static IItemDropRuleCondition PostEvil2(bool ui = true) => If(() => DownedBossSystem.downedHiveMind || DownedBossSystem.downedPerforator, ui, "Drops after defeating the " + (WorldGen.crimson ? "Perforators" : "Hive Mind"));
public static IItemDropRuleCondition PostQB(bool ui = true) => If(() => NPC.downedQueenBee, ui, "Drops after defeating the Queen Bee");
public static IItemDropRuleCondition PostDeer(bool ui = true) => If(() => NPC.downedDeerclops, ui, "Drops after defeating Deerclops");
public static IItemDropRuleCondition PostSkele(bool ui = true) => If(() => NPC.downedBoss3, ui, "Drops after defeating Skeletron");
public static IItemDropRuleCondition PostSG(bool ui = true) => If(() => DownedBossSystem.downedSlimeGod, ui, "Drops after defeating the Slime God");
public static IItemDropRuleCondition Hardmode(bool ui = true) => If(() => Main.hardMode, ui, "Drops in Hardmode");
public static IItemDropRuleCondition PostQS(bool ui = true) => If(() => NPC.downedQueenSlime, ui, "Drops after defeating Queen Slime");
public static IItemDropRuleCondition PostCryo(bool ui = true) => If(() => DownedBossSystem.downedCryogen, ui, "Drops after defeating Cryogen");
public static IItemDropRuleCondition PostAS(bool ui = true) => If(() => DownedBossSystem.downedAquaticScourge, ui, "Drops after defeating the Aquatic Scourge");
public static IItemDropRuleCondition PostBrim(bool ui = true) => If(() => DownedBossSystem.downedBrimstoneElemental, ui, "Drops after defeating the Brimstone Elemental");
public static IItemDropRuleCondition PostDest(bool ui = true) => If(() => NPC.downedMechBoss1, ui, "Drops after defeating the Destroyer");
public static IItemDropRuleCondition PostTwins(bool ui = true) => If(() => NPC.downedMechBoss2, ui, "Drops after defeating the Twins");
public static IItemDropRuleCondition PostSP(bool ui = true) => If(() => NPC.downedMechBoss3, ui, "Drops after defeating Skeletron Prime");
public static IItemDropRuleCondition Post1Mech(bool ui = true) => If(() => NPC.downedMechBossAny, ui, "Drops after defeating a Mechanical Boss");
public static IItemDropRuleCondition Post3Mechs(bool ui = true) => If(() => NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3, ui, "Drops after defeating all three Mechanical Bosses");
public static IItemDropRuleCondition PostCal(bool ui = true) => If(() => DownedBossSystem.downedCalamitasClone, ui, "Drops after defeating Calamitas Clone");
public static IItemDropRuleCondition PostPlant(bool ui = true) => If(() => NPC.downedPlantBoss, ui, "Drops after defeating Plantera");
public static IItemDropRuleCondition PostCalPlant(bool ui = true) => If(() => DownedBossSystem.downedCalamitasClone || NPC.downedPlantBoss, ui, "Drops after defeating Calamitas or Plantera");
public static IItemDropRuleCondition PostLevi(bool ui = true) => If(() => DownedBossSystem.downedLeviathan, ui, "Drops after defeating the Leviathan and Anahita");
public static IItemDropRuleCondition PostAureus(bool ui = true) => If(() => DownedBossSystem.downedAstrumAureus, ui, "Drops after defeating Astrum Aureus");
public static IItemDropRuleCondition PostGolem(bool ui = true) => If(() => NPC.downedGolemBoss, ui, "Drops after defeating Golem");
public static IItemDropRuleCondition PostPBG(bool ui = true) => If(() => DownedBossSystem.downedPlaguebringer, ui, "Drops after defeating the Plaguebringer Goliath");
public static IItemDropRuleCondition PostEoL(bool ui = true) => If(() => NPC.downedEmpressOfLight, ui, "Drops after defeating the Empress of Light");
public static IItemDropRuleCondition PostFish(bool ui = true) => If(() => NPC.downedFishron, ui, "Drops after defeating Duke Fishron");
public static IItemDropRuleCondition PostRav(bool ui = true) => If(() => DownedBossSystem.downedRavager, ui, "Drops after defeating the Ravager");
public static IItemDropRuleCondition PostLC(bool ui = true) => If(() => NPC.downedAncientCultist, ui, "Drops after defeating the Lunatic Cultist");
public static IItemDropRuleCondition PostAD(bool ui = true) => If(() => DownedBossSystem.downedAstrumDeus, ui, "Drops after defeating Astrum Deus");
public static IItemDropRuleCondition PostML(bool ui = true) => If(() => NPC.downedMoonlord, ui, "Drops after defeating the Moon Lord");
public static IItemDropRuleCondition PostGuard(bool ui = true) => If(() => DownedBossSystem.downedGuardians, ui, "Drops after defeating the Profaned Guardian");
public static IItemDropRuleCondition PostBirb(bool ui = true) => If(() => DownedBossSystem.downedDragonfolly, ui, "Drops after defeating the Dragonfolly");
public static IItemDropRuleCondition PostProv(bool ui = true) => If(() => DownedBossSystem.downedProvidence, ui, "Drops after defeating Providence");
public static IItemDropRuleCondition PostSig(bool ui = true) => If(() => DownedBossSystem.downedSignus, ui, "Drops after defeating Signus");
public static IItemDropRuleCondition PostSW(bool ui = true) => If(() => DownedBossSystem.downedStormWeaver, ui, "Drops after defeating the Storm Weaver");
public static IItemDropRuleCondition PostCV(bool ui = true) => If(() => DownedBossSystem.downedCeaselessVoid, ui, "Drops after defeating the Ceaseless Void");
public static IItemDropRuleCondition PostPolter(bool ui = true) => If(() => DownedBossSystem.downedPolterghast, ui, "Drops after defeating the Polterghast");
public static IItemDropRuleCondition PostOD(bool ui = true) => If(() => DownedBossSystem.downedBoomerDuke, ui, "Drops after defeating the Old Duke");
public static IItemDropRuleCondition PostDoG(bool ui = true) => If(() => DownedBossSystem.downedDoG, ui, "Drops after defeating the Devourer of Gods");
public static IItemDropRuleCondition PostYharon(bool ui = true) => If(() => DownedBossSystem.downedYharon, ui, "Drops after defeating Yharon");
public static IItemDropRuleCondition PostExos(bool ui = true) => If(() => DownedBossSystem.downedExoMechs, ui, "Drops after defeating the Exo Mechs");
public static IItemDropRuleCondition PostSCal(bool ui = true) => If(() => DownedBossSystem.downedCalamitas, ui, "Drops after defeating Calamitas");
public static IItemDropRuleCondition PostAEW(bool ui = true) => If(() => DownedBossSystem.downedAdultEidolonWyrm, ui, "Drops after defeating the Adult Eidolon Wyrm");
public static IItemDropRuleCondition PostClam(bool ui = true) => If(() => DownedBossSystem.downedCLAM, ui, "Drops after defeating the Giant Clam");
public static IItemDropRuleCondition PostClamHM(bool ui = true) => If(() => DownedBossSystem.downedCLAMHardMode, ui, "Drops after defeating the Giant Clam in Hardmode");
public static IItemDropRuleCondition PostGSS(bool ui = true) => If(() => DownedBossSystem.downedGSS, ui, "Drops after defeating the Great Sand Shark");
public static IItemDropRuleCondition PostBetsy(bool ui = true) => If(() => DownedBossSystem.downedBetsy, ui, "Drops after defeating Betsy");
public static IItemDropRuleCondition PostT1AR(bool ui = true) => If(() => DownedBossSystem.downedEoCAcidRain, ui, "Drops after defeating the first tier of Acid Rain");
public static IItemDropRuleCondition PostT2AR(bool ui = true) => If(() => DownedBossSystem.downedAquaticScourgeAcidRain, ui, "Drops after defeating the second tier of Acid Rain");
#endregion
#endregion
#region Leading Condition Rule Extensions
///
/// Adds any given drop rule as a chained rule to the given LeadingConditionRule.
///
/// The LeadingConditionRule which should have another drop rule registered as one of its chains.
/// The drop rule which should occur given this leading condition.
/// Set to true for this drop to not appear in the Bestiary.
/// The LeadingConditionRule (first parameter).
public static IItemDropRule Add(this LeadingConditionRule mainRule, IItemDropRule chainedRule, bool hideLootReport = false)
{
return mainRule.OnSuccess(chainedRule, hideLootReport);
}
///
/// Shorthand to add a simple drop to the given LeadingConditionRule.
///
/// The LeadingConditionRule which should drop this item as one of its chains.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Set to true for this drop to not appear in the Bestiary.
/// The LeadingConditionRule (first parameter).
public static IItemDropRule Add(this LeadingConditionRule mainRule, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1, bool hideLootReport = false)
{
return mainRule.OnSuccess(ItemDropRule.Common(itemID, dropRateInt, minQuantity, maxQuantity), hideLootReport);
}
///
/// Shorthand to add a simple drop to the given LeadingConditionRule using a Fraction drop rate.
///
/// The LeadingConditionRule which should drop this item as one of its chains.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Set to true for this drop to not appear in the Bestiary.
/// The LeadingConditionRule (first parameter).
public static IItemDropRule Add(this LeadingConditionRule mainRule, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1, bool hideLootReport = false)
{
return mainRule.OnSuccess(new CommonDrop(itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator), hideLootReport);
}
///
/// Shorthand to add an arbitrary conditional drop to the given LeadingConditionRule.
///
/// The LeadingConditionRule which should drop this item as one of its chains.
/// A lambda which evaluates in real-time to the condition that needs to be checked.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Set to true for this drop to not appear in the Bestiary.
/// The description of this condition in the Bestiary. Defaults to null.
/// The item drop rule registered.
public static IItemDropRule AddIf(this LeadingConditionRule mainRule, Func lambda, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1, bool hideLootReport = false, string desc = null)
{
return mainRule.OnSuccess(ItemDropRule.ByCondition(If(lambda, true, desc), itemID, dropRateInt, minQuantity, maxQuantity), hideLootReport);
}
///
/// Shorthand to add an arbitrary conditional drop to the given LeadingConditionRule using a Fraction drop rate.
///
/// The LeadingConditionRule which should drop this item as one of its chains.
/// A lambda which evaluates in real-time to the condition that needs to be checked.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Set to true for this drop to not appear in the Bestiary.
/// The description of this condition in the Bestiary. Defaults to null.
/// The item drop rule registered.
public static IItemDropRule AddIf(this LeadingConditionRule mainRule, Func lambda, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1, bool hideLootReport = false, string desc = null)
{
return mainRule.OnSuccess(ItemDropRule.ByCondition(If(lambda, true, desc), itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator), hideLootReport);
}
///
/// Shorthand to add an arbitrary conditional drop to the given LeadingConditionRule.
/// This version requires a lambda which uses DropAttemptInfo.
///
/// The LeadingConditionRule which should drop this item as one of its chains.
/// A lambda which takes a DropAttemptInfo struct and evaluates in real-time to the condition that needs to be checked.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Set to true for this drop to not appear in the Bestiary.
/// The description of this condition in the Bestiary. Defaults to null.
/// The item drop rule registered.
public static IItemDropRule AddIf(this LeadingConditionRule mainRule, Func lambda, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1, bool hideLootReport = false, string desc = null)
{
return mainRule.OnSuccess(ItemDropRule.ByCondition(If(lambda, true, desc), itemID, dropRateInt, minQuantity, maxQuantity), hideLootReport);
}
///
/// Shorthand to add an arbitrary conditional drop to the given LeadingConditionRule using a Fraction drop rate.
/// This version requires a lambda which uses DropAttemptInfo.
///
/// The LeadingConditionRule which should drop this item as one of its chains.
/// A lambda which takes a DropAttemptInfo struct and evaluates in real-time to the condition that needs to be checked.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Set to true for this drop to not appear in the Bestiary.
/// The description of this condition in the Bestiary. Defaults to null.
/// The item drop rule registered.
public static IItemDropRule AddIf(this LeadingConditionRule mainRule, Func lambda, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1, bool hideLootReport = false, string desc = null)
{
return mainRule.OnSuccess(ItemDropRule.ByCondition(If(lambda, true, desc), itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator), hideLootReport);
}
///
/// Adds any given drop rule as a chained rule to the given LeadingConditionRule.
///
/// The LeadingConditionRule which should have another drop rule registered as one of its chains.
/// The drop rule which should occur given this leading condition.
/// Set to true for this drop to not appear in the Bestiary.
/// The LeadingConditionRule (first parameter).
public static IItemDropRule AddFail(this LeadingConditionRule mainRule, IItemDropRule chainedRule, bool hideLootReport = false)
{
return mainRule.OnFailedConditions(chainedRule, hideLootReport);
}
///
/// Shorthand to add a simple drop to the given LeadingConditionRule.
///
/// The LeadingConditionRule which should drop this item as one of its chains.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Set to true for this drop to not appear in the Bestiary.
/// The LeadingConditionRule (first parameter).
public static IItemDropRule AddFail(this LeadingConditionRule mainRule, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1, bool hideLootReport = false)
{
return mainRule.OnFailedConditions(ItemDropRule.Common(itemID, dropRateInt, minQuantity, maxQuantity), hideLootReport);
}
///
/// Shorthand to add a simple drop to the given LeadingConditionRule using a Fraction drop rate.
///
/// The LeadingConditionRule which should drop this item as one of its chains.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Set to true for this drop to not appear in the Bestiary.
/// The LeadingConditionRule (first parameter).
public static IItemDropRule AddFail(this LeadingConditionRule mainRule, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1, bool hideLootReport = false)
{
return mainRule.OnFailedConditions(new CommonDrop(itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator), hideLootReport);
}
#endregion
#region ILoot Extensions
///
/// Shorthand to add a simple drop to a loot table.
///
/// The ILoot interface for the loot table.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// The item drop rule registered.
public static IItemDropRule Add(this ILoot loot, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1)
{
return loot.Add(ItemDropRule.Common(itemID, dropRateInt, minQuantity, maxQuantity));
}
///
/// Shorthand to add a simple drop to a loot table using a Fraction drop rate.
///
/// The ILoot interface for the loot table.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// The item drop rule registered.
public static IItemDropRule Add(this ILoot loot, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1)
{
return loot.Add(new CommonDrop(itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator));
}
///
/// Shorthand to add an arbitrary conditional drop to a loot table.
///
/// The ILoot interface for the loot table.
/// An IItemDropRuleCondition which encapsulates the condition which needs to be checked in real-time.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// The item drop rule registered.
public static IItemDropRule AddIf(this ILoot loot, IItemDropRuleCondition cond, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1)
{
return loot.Add(ItemDropRule.ByCondition(cond, itemID, dropRateInt, minQuantity, maxQuantity));
}
///
/// Shorthand to add an arbitrary conditional drop to a loot table using a Fraction drop rate.
///
/// The ILoot interface for the loot table.
/// An IItemDropRuleCondition which encapsulates the condition which needs to be checked in real-time.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// The item drop rule registered.
public static IItemDropRule AddIf(this ILoot loot, IItemDropRuleCondition cond, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1)
{
return loot.Add(ItemDropRule.ByCondition(cond, itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator));
}
///
/// Shorthand to add an arbitrary conditional drop to a loot table.
///
/// The ILoot interface for the loot table.
/// A lambda which evaluates in real-time to the condition that needs to be checked.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Whether drops registered with this condition appear in the Bestiary. Defaults to true.
/// The description of this condition in the Bestiary. Defaults to null.
/// The item drop rule registered.
public static IItemDropRule AddIf(this ILoot loot, Func lambda, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1, bool ui = true, string desc = null)
{
return loot.Add(ItemDropRule.ByCondition(If(lambda, ui, desc), itemID, dropRateInt, minQuantity, maxQuantity));
}
///
/// Shorthand to add an arbitrary conditional drop to a loot table using a Fraction drop rate.
///
/// The ILoot interface for the loot table.
/// A lambda which evaluates in real-time to the condition that needs to be checked.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Whether drops registered with this condition appear in the Bestiary. Defaults to true.
/// The description of this condition in the Bestiary. Defaults to null.
/// The item drop rule registered.
public static IItemDropRule AddIf(this ILoot loot, Func lambda, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1, bool ui = true, string desc = null)
{
return loot.Add(ItemDropRule.ByCondition(If(lambda, ui, desc), itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator));
}
///
/// Shorthand to add an arbitrary conditional drop to a loot table.
/// This version requires a lambda which uses DropAttemptInfo.
///
/// The ILoot interface for the loot table.
/// A lambda which takes a DropAttemptInfo struct and evaluates in real-time to the condition that needs to be checked.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Whether drops registered with this condition appear in the Bestiary. Defaults to true.
/// The description of this condition in the Bestiary. Defaults to null.
/// The item drop rule registered.
public static IItemDropRule AddIf(this ILoot loot, Func lambda, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1, bool ui = true, string desc = null)
{
return loot.Add(ItemDropRule.ByCondition(If(lambda, ui, desc), itemID, dropRateInt, minQuantity, maxQuantity));
}
///
/// Shorthand to add an arbitrary conditional drop to a loot table using a Fraction drop rate.
/// This version requires a lambda which uses DropAttemptInfo.
///
/// The ILoot interface for the loot table.
/// A lambda which takes a DropAttemptInfo struct and evaluates in real-time to the condition that needs to be checked.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// Whether drops registered with this condition appear in the Bestiary. Defaults to true.
/// The description of this condition in the Bestiary. Defaults to null.
/// The item drop rule registered.
public static IItemDropRule AddIf(this ILoot loot, Func lambda, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1, bool ui = true, string desc = null)
{
return loot.Add(ItemDropRule.ByCondition(If(lambda, ui, desc), itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator));
}
///
/// Shorthand to add a simple normal-only drop to a loot table.
///
/// The ILoot interface for the loot table.
/// The item to drop.
/// The chance that the item will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// The item drop rule registered.
public static IItemDropRule AddNormalOnly(this ILoot loot, int itemID, int dropRateInt = 1, int minQuantity = 1, int maxQuantity = 1)
{
return loot.Add(ItemDropRule.ByCondition(new Conditions.NotExpert(), itemID, dropRateInt, minQuantity, maxQuantity));
}
///
/// Shorthand to add a simple normal-only drop to a loot table.
///
/// The ILoot interface for the loot table.
/// The item to drop.
/// The chance that the item will drop as a DropHelper Fraction.
/// The minimum number of items to drop. Defaults to 1.
/// The maximum number of items to drop. Defaults to 1.
/// The item drop rule registered.
public static IItemDropRule AddNormalOnly(this ILoot loot, int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1)
{
return loot.Add(ItemDropRule.ByCondition(new Conditions.NotExpert(), itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator));
}
///
/// Shorthand to add an arbitrary drop rule as a normal-only drop to a loot table.
///
/// The ILoot interface for the loot table.
/// The IItemDropRule to add.
public static void AddNormalOnly(this ILoot loot, IItemDropRule rule)
{
LeadingConditionRule normalOnly = loot.DefineNormalOnlyDropSet();
normalOnly.Add(rule);
}
///
/// Registers a LeadingConditionRule for a loot table and returns it so you can add drops to that rule.
///
/// The ILoot interface for the loot table.
/// The condition behind which you want to gate several drop rules.
/// The LeadingConditionRule which encapsulates the given condition.
public static LeadingConditionRule DefineConditionalDropSet(this ILoot loot, IItemDropRuleCondition condition)
{
LeadingConditionRule rule = new LeadingConditionRule(condition);
loot.Add(rule);
return rule;
}
///
/// Shorthand for registering a LeadingConditionRule using DropHelper.If.
/// This version does NOT use the DropAttemptInfo struct that is available.
///
/// The ILoot interface for the loot table.
/// A lambda which evaluates in real-time to the condition that needs to be checked.
/// The LeadingConditionRule which encapsulates the given lambda.
public static LeadingConditionRule DefineConditionalDropSet(this ILoot loot, Func lambda) => loot.DefineConditionalDropSet(If(lambda));
///
/// Shorthand for registering a LeadingConditionRule using DropHelper.If.
/// This version DOES use the DropAttemptInfo struct, and thus the provided lambda requires 1 argument.
///
/// The ILoot interface for the loot table.
/// A lambda which evaluates in real-time to the condition that needs to be checked.
/// The LeadingConditionRule which encapsulates the given lambda.
public static LeadingConditionRule DefineConditionalDropSet(this ILoot loot, Func lambda) => loot.DefineConditionalDropSet(If(lambda));
///
/// Shorthand for shorthand: Registers a Normal Mode only LeadingConditionRule for a loot table and returns it to you.
///
/// The ILoot interface for the loot table.
/// A Normal Mode only LeadingConditionRule.
public static LeadingConditionRule DefineNormalOnlyDropSet(this ILoot loot) => loot.DefineConditionalDropSet(new Conditions.NotExpert());
///
/// This function does its best to replace all instances of the given item in the given loot table's entries with the specified chance.
/// It tries to affect as many types of drop rule as possible.
///
/// The ILoot interface for the loot table.
/// The item to drop.
/// The new numerator to use.
/// The new denominator to use.
/// Whether or not to include global loot rules. Defaults to false. Generally, you should leave this as false.
/// The number of changes made.
public static int ChangeDropRate(this ILoot loot, int itemID, int newNumerator, int newDenominator, bool includeGlobalDrops = false)
{
int numChanges = 0;
var rules = loot.Get(includeGlobalDrops);
foreach (IItemDropRule rule in rules)
rule.RecursivelyMutateDropRate(itemID, newNumerator, newDenominator);
return numChanges;
}
///
/// This function does its best to replace all instances of the given item in the given loot table's entries with the specified chance.
/// It tries to affect as many types of drop rule as possible.
///
/// The ILoot interface for the loot table.
/// The item to drop.
/// The new drop rate to use, as a DropHelper Fraction.
/// Whether or not to include global loot rules. Defaults to false. Generally, you should leave this as false.
/// The number of changes made.
public static int ChangeDropRate(this ILoot loot, int itemID, Fraction dropRate, bool includeGlobalDrops = false)
{
return loot.ChangeDropRate(itemID, dropRate.numerator, dropRate.denominator, includeGlobalDrops);
}
#endregion
#region "Calamity Style" Drop Rule
///
/// Also known as the "Calamity Style" drop rule.
/// Every item in the list has the given chance to drop individually.
/// If no items drop, then one of them is forced to drop, chosen at random.
///
public class AllOptionsAtOnceWithPityDropRule : IItemDropRule
{
public WeightedItemStack[] stacks;
public Fraction dropRate;
public bool usesLuck;
public List ChainedRules { get; set; }
public AllOptionsAtOnceWithPityDropRule(Fraction dropRate, bool luck, params WeightedItemStack[] stacks)
{
this.dropRate = dropRate;
this.stacks = stacks;
usesLuck = luck;
ChainedRules = new List();
}
public AllOptionsAtOnceWithPityDropRule(Fraction dropRate, bool luck, params int[] itemIDs)
{
this.dropRate = dropRate;
stacks = new WeightedItemStack[itemIDs.Length];
for (int i = 0; i < stacks.Length; ++i)
stacks[i] = itemIDs[i]; // implicit conversion operator
usesLuck = luck;
ChainedRules = new List();
}
public bool CanDrop(DropAttemptInfo info) => true;
public ItemDropAttemptResult TryDroppingItem(DropAttemptInfo info)
{
bool droppedAnything = false;
// Roll for each drop individually.
foreach (WeightedItemStack stack in stacks)
{
bool rngRoll = usesLuck ? info.player.RollLuck(dropRate.denominator) < dropRate.numerator : info.rng.NextFloat() < dropRate;
droppedAnything |= rngRoll;
if (rngRoll)
CommonCode.DropItem(info, stack.itemID, stack.ChooseQuantity(info.rng));
}
// If everything fails to drop, force drop one item from the set.
if (!droppedAnything)
{
WeightedItemStack stack = info.rng.NextFromList(stacks);
CommonCode.DropItem(info, stack.itemID, stack.ChooseQuantity(info.rng));
}
// Calamity style drops cannot fail. You will always get at least one item.
ItemDropAttemptResult result = default;
result.State = ItemDropAttemptResultState.Success;
return result;
}
public void ReportDroprates(List drops, DropRateInfoChainFeed ratesInfo)
{
int numDrops = stacks.Length;
float rawDropRate = dropRate;
// Combinatorics:
// OPTION 1: [The item drops = Raw Drop Rate]
// +
// OPTION 2: [ALL items fail to drop = (1-x)^n] * [This item is chosen as pity = 1/n]
float dropRateWithPityRoll = rawDropRate + (float)(Math.Pow(1f - rawDropRate, numDrops) * (1f / numDrops));
float dropRateAdjustedForParent = dropRateWithPityRoll * ratesInfo.parentDroprateChance;
// Report the drop rate of each individual item. This calculation includes the fact that each individual item can be guaranteed as pity.
foreach (WeightedItemStack stack in stacks)
drops.Add(new DropRateInfo(stack.itemID, stack.minQuantity, stack.maxQuantity, dropRateAdjustedForParent, ratesInfo.conditions));
Chains.ReportDroprates(ChainedRules, rawDropRate, drops, ratesInfo);
}
}
public static IItemDropRule CalamityStyle(Fraction dropRateForEachItem, params WeightedItemStack[] stacks) => CalamityStyle(dropRateForEachItem, true, stacks);
public static IItemDropRule CalamityStyle(Fraction dropRateForEachItem, bool luck, params WeightedItemStack[] stacks)
{
return new AllOptionsAtOnceWithPityDropRule(dropRateForEachItem, luck, stacks);
}
public static IItemDropRule CalamityStyle(Fraction dropRateForEachItem, params int[] itemIDs) => CalamityStyle(dropRateForEachItem, true, itemIDs);
public static IItemDropRule CalamityStyle(Fraction dropRateForEachItem, bool luck, params int[] itemIDs)
{
return new AllOptionsAtOnceWithPityDropRule(dropRateForEachItem, luck, itemIDs);
}
#endregion
#region Per Player Drop Rule
public class PerPlayerDropRule : CommonDrop
{
// Default instanced drops are protected for 15 minutes, because they are used for boss bags.
// You can customize this duration as you see fit. Calamity defaults it to 5 minutes.
private const int DefaultDropProtectionTime = 18000; // 5 minutes
private int protectionTime;
public PerPlayerDropRule(int itemID, int denominator, int minQuantity = 1, int maxQuantity = 1, int numerator = 1, int protectFrames = DefaultDropProtectionTime)
: base(itemID, denominator, minQuantity, maxQuantity, numerator)
{
protectionTime = protectFrames;
}
public PerPlayerDropRule(int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1)
: base(itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator)
{
protectionTime = DefaultDropProtectionTime;
}
// Overriding CanDrop is unnecessary. This drop rule has no condition.
// If you want to use a condition with PerPlayerDropRule, use DropHelper.If
public override ItemDropAttemptResult TryDroppingItem(DropAttemptInfo info)
{
ItemDropAttemptResult result = default;
if (info.rng.Next(chanceDenominator) < chanceNumerator)
{
int stack = info.rng.Next(amountDroppedMinimum, amountDroppedMaximum + 1);
TryDropInternal(info, itemId, stack);
result.State = ItemDropAttemptResultState.Success;
return result;
}
result.State = ItemDropAttemptResultState.FailedRandomRoll;
return result;
}
// The contents of this method are more or less copied from CommonCode.DropItemLocalPerClientAndSetNPCMoneyTo0
private void TryDropInternal(DropAttemptInfo info, int itemId, int stack)
{
if (itemId <= 0 || itemId >= ItemLoader.ItemCount)
return;
// If server-side, then the item must be spawned for each client individually.
if (Main.netMode == NetmodeID.Server)
{
NPC npc = info.npc;
int idx = Item.NewItem(npc.GetSource_Loot(), npc.Center, itemId, stack, true, -1);
Main.timeItemSlotCannotBeReusedFor[idx] = protectionTime;
for (int i = 0; i < Main.maxPlayers; ++i)
if (Main.player[i].active)
NetMessage.SendData(MessageID.InstancedItem, i, -1, null, idx);
Main.item[idx].active = false;
}
// Otherwise just drop the item.
else
CommonCode.DropItem(info, itemId, stack);
}
}
public static IItemDropRule PerPlayer(int itemID, int denominator = 1, int minQuantity = 1, int maxQuantity = 1, int numerator = 1)
{
return new PerPlayerDropRule(itemID, denominator, minQuantity, maxQuantity, numerator);
}
public static IItemDropRule PerPlayer(int itemID, Fraction dropRate, int minQuantity = 1, int maxQuantity = 1)
{
return PerPlayer(itemID, dropRate.denominator, minQuantity, maxQuantity, dropRate.numerator);
}
#endregion
}
}