drop helper WIP continued, needs documentation pass
This commit is contained in:
1 parent
8de31b88dd
commit
87381ab767
1 file changed
+303
-31
+303
-31
@@ -10,6 +10,7 @@ namespace CalamityMod
|
||||
{
|
||||
public class DropHelper
|
||||
{
|
||||
#region Extra Boss Bags
|
||||
/// <summary>
|
||||
/// The number of extra loot bags bosses drop when Revengeance Mode is active.
|
||||
/// </summary>
|
||||
@@ -29,11 +30,14 @@ namespace CalamityMod
|
||||
/// The number of extra loot bags bosses drop when Armageddon is active.
|
||||
/// </summary>
|
||||
public static int ArmageddonExtraBags = 5;
|
||||
#endregion
|
||||
|
||||
#region Defiled Drop Chance Boost
|
||||
/// <summary>
|
||||
/// This is the value that Defiled Rune boosts certain drop chances to (a decimal number <= 1.0).
|
||||
/// </summary>
|
||||
public static float DefiledChanceBoost = 0.05f;
|
||||
#endregion
|
||||
|
||||
#region Boss Bag Drop Helper
|
||||
/// <summary>
|
||||
@@ -95,7 +99,7 @@ namespace CalamityMod
|
||||
|
||||
return bagsDropped;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region NPC Item Drops 100% Chance
|
||||
/// <summary>
|
||||
@@ -107,7 +111,7 @@ namespace CalamityMod
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItem(NPC npc, int itemID, bool dropPerPlayer = false, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItem(NPC npc, int itemID, bool dropPerPlayer, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
int quantity;
|
||||
|
||||
@@ -153,11 +157,11 @@ namespace CalamityMod
|
||||
/// <param name="npc">The NPC which should drop the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to drop.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0. Defaults to 1.0.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemChance(NPC npc, int itemID, bool dropPerPlayer = false, float chance = 1f, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemChance(NPC npc, int itemID, bool dropPerPlayer, float chance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
// If you fail the roll to get the drop, stop immediately.
|
||||
if (Main.rand.NextFloat() > chance)
|
||||
@@ -171,11 +175,11 @@ namespace CalamityMod
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to drop.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0. Defaults to 1.0.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemChance(NPC npc, int itemID, float chance = 1f, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemChance(NPC npc, int itemID, float chance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return DropItemChance(npc, itemID, false, chance, minQuantity, maxQuantity);
|
||||
}
|
||||
@@ -188,11 +192,11 @@ namespace CalamityMod
|
||||
/// <param name="npc">The NPC which should drop the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to drop.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance. Defaults to 1.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemChance(NPC npc, int itemID, bool dropPerPlayer = false, int oneInXChance = 1, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemChance(NPC npc, int itemID, bool dropPerPlayer, int oneInXChance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
// If you fail the roll to get the drop, stop immediately.
|
||||
if (Main.rand.Next(oneInXChance) != 0)
|
||||
@@ -206,11 +210,11 @@ namespace CalamityMod
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to drop.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance. Defaults to 1.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemChance(NPC npc, int itemID, int oneInXChance = 1, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemChance(NPC npc, int itemID, int oneInXChance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return DropItemChance(npc, itemID, false, oneInXChance, minQuantity, maxQuantity);
|
||||
}
|
||||
@@ -227,7 +231,7 @@ namespace CalamityMod
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool dropPerPlayer = false, bool condition = true, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool dropPerPlayer, bool condition, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItem(npc, itemID, dropPerPlayer, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
@@ -241,7 +245,7 @@ namespace CalamityMod
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool condition = true, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool condition, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItem(npc, itemID, false, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
@@ -253,11 +257,11 @@ namespace CalamityMod
|
||||
/// <param name="itemID">The ID of the item(s) to drop.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0. Defaults to 1.0.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool dropPerPlayer = false, bool condition = true, float chance = 1f, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool dropPerPlayer, bool condition, float chance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItemChance(npc, itemID, dropPerPlayer, chance, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
@@ -268,11 +272,11 @@ namespace CalamityMod
|
||||
/// <param name="npc">The NPC which should drop the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to drop.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0. Defaults to 1.0.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool condition = true, float chance = 1f, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool condition, float chance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItemChance(npc, itemID, false, chance, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
@@ -284,11 +288,11 @@ namespace CalamityMod
|
||||
/// <param name="itemID">The ID of the item(s) to drop.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance. Defaults to 1.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool dropPerPlayer = false, bool condition = true, int oneInXChance = 1, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool dropPerPlayer, bool condition, int oneInXChance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItemChance(npc, itemID, dropPerPlayer, oneInXChance, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
@@ -299,11 +303,11 @@ namespace CalamityMod
|
||||
/// <param name="npc">The NPC which should drop the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to drop.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance. Defaults to 1.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to drop. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to drop. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items dropped.</returns>
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool condition = true, int oneInXChance = 1, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(NPC npc, int itemID, bool condition, int oneInXChance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItemChance(npc, itemID, false, oneInXChance, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
@@ -335,15 +339,15 @@ namespace CalamityMod
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawns a stack of one or more items for the given player.
|
||||
/// At a chance, spawns a stack of one or more items for the given player.
|
||||
/// </summary>
|
||||
/// <param name="p">The player which should receive the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to spawn.</param>
|
||||
/// <param name="chance">The chance that the items will spawn. A decimal number <= 1.0. Defaults to 1.0.</param>
|
||||
/// <param name="chance">The chance that the items will spawn. A decimal number <= 1.0.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to spawn. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to spawn. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items spawned.</returns>
|
||||
public static int DropItemChance(Player p, int itemID, float chance = 1f, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemChance(Player p, int itemID, float chance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
// If you fail the roll to get the drop, stop immediately.
|
||||
if (Main.rand.NextFloat() > chance)
|
||||
@@ -353,15 +357,15 @@ namespace CalamityMod
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawns a stack of one or more items for the given player.
|
||||
/// At a chance, spawns a stack of one or more items for the given player.
|
||||
/// </summary>
|
||||
/// <param name="p">The player which should receive the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to spawn.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will spawn is 1 in this number. For example, 5 gives a 1 in 5 chance. Defaults to 1.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will spawn is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to spawn. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to spawn. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items spawned.</returns>
|
||||
public static int DropItemChance(Player p, int itemID, int oneInXChance = 1, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemChance(Player p, int itemID, int oneInXChance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
// If you fail the roll to get the drop, stop immediately.
|
||||
if (Main.rand.Next(oneInXChance) != 0)
|
||||
@@ -381,7 +385,7 @@ namespace CalamityMod
|
||||
/// <param name="minQuantity">The minimum number of items to spawn. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to spawn. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items spawned.</returns>
|
||||
public static int DropItemCondition(Player p, int itemID, bool condition = true, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(Player p, int itemID, bool condition, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItem(p, itemID, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
@@ -392,11 +396,11 @@ namespace CalamityMod
|
||||
/// <param name="p">The player which should receive the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to spawn.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this spawn. If false, nothing is spawned.</param>
|
||||
/// <param name="chance">The chance that the items will spawn. A decimal number <= 1.0. Defaults to 1.0.</param>
|
||||
/// <param name="chance">The chance that the items will spawn. A decimal number <= 1.0.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to spawn. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to spawn. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items spawned.</returns>
|
||||
public static int DropItemCondition(Player p, int itemID, bool condition = true, float chance = 1f, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(Player p, int itemID, bool condition, float chance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItemChance(p, itemID, chance, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
@@ -407,14 +411,282 @@ namespace CalamityMod
|
||||
/// <param name="p">The player which should receive the item(s).</param>
|
||||
/// <param name="itemID">The ID of the item(s) to spawn.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this spawn. If false, nothing is spawned.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will spawn is 1 in this number. For example, 5 gives a 1 in 5 chance. Defaults to 1.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will spawn is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="minQuantity">The minimum number of items to spawn. Defaults to 1.</param>
|
||||
/// <param name="maxQuantity">The maximum number of items to spawn. Defaults to 0, meaning the minimum quantity is always used.</param>
|
||||
/// <returns>The number of items spawned.</returns>
|
||||
public static int DropItemCondition(Player p, int itemID, bool condition = true, int oneInXChance = 1, int minQuantity = 1, int maxQuantity = 0)
|
||||
public static int DropItemCondition(Player p, int itemID, bool condition, int oneInXChance, int minQuantity = 1, int maxQuantity = 0)
|
||||
{
|
||||
return condition ? DropItemChance(p, itemID, oneInXChance, minQuantity, maxQuantity) : 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region NPC Item Set Drops
|
||||
/// <summary>
|
||||
/// Chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSet(NPC npc, bool dropPerPlayer, params int[] itemIDs)
|
||||
{
|
||||
// Can't choose anything from an empty array.
|
||||
if (itemIDs is null || itemIDs.Length == 0)
|
||||
return false;
|
||||
|
||||
// Choose which item to drop.
|
||||
int itemID = Main.rand.Next(itemIDs);
|
||||
|
||||
// If the drop is supposed to be instanced, drop it as such.
|
||||
if (dropPerPlayer)
|
||||
{
|
||||
npc.DropItemInstanced(npc.position, npc.Size, itemID);
|
||||
}
|
||||
else
|
||||
{
|
||||
Item.NewItem(npc.Hitbox, itemID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chooses an item from an array and drops it from the given NPC.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSet(NPC npc, params int[] itemIDs)
|
||||
{
|
||||
return DropItemFromSet(npc, false, itemIDs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At a chance, chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSetChance(NPC npc, bool dropPerPlayer, float chance, params int[] itemIDs)
|
||||
{
|
||||
// If you fail the roll to get the drop, stop immediately.
|
||||
if (Main.rand.NextFloat() > chance)
|
||||
return false;
|
||||
|
||||
return DropItemFromSet(npc, dropPerPlayer, itemIDs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At a chance, chooses an item from an array and drops it from the given NPC.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSetChance(NPC npc, float chance, params int[] itemIDs)
|
||||
{
|
||||
return DropItemFromSetChance(npc, false, chance, itemIDs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At a chance, chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSetChance(NPC npc, bool dropPerPlayer, int oneInXChance, params int[] itemIDs)
|
||||
{
|
||||
// If you fail the roll to get the drop, stop immediately.
|
||||
if (Main.rand.Next(oneInXChance) != 0)
|
||||
return false;
|
||||
|
||||
return DropItemFromSet(npc, dropPerPlayer, itemIDs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At a chance, chooses an item from an array and drops it from the given NPC.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSetChance(NPC npc, int oneInXChance, params int[] itemIDs)
|
||||
{
|
||||
return DropItemFromSetChance(npc, false, oneInXChance, itemIDs);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region NPC Item Set Drops Conditional
|
||||
/// <summary>
|
||||
/// With a condition, chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
public static bool DropItemFromSetCondition(NPC npc, bool dropPerPlayer, bool condition, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSet(npc, dropPerPlayer, itemIDs) : false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With a condition, chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
public static bool DropItemFromSetCondition(NPC npc, bool condition, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSet(npc, false, itemIDs) : false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With a condition, chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
public static bool DropItemFromSetCondition(NPC npc, bool dropPerPlayer, bool condition, float chance, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSetChance(npc, dropPerPlayer, chance, itemIDs) : false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With a condition, chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="chance">The chance that the items will drop. A decimal number <= 1.0.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
public static bool DropItemFromSetCondition(NPC npc, bool condition, float chance, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSetChance(npc, false, chance, itemIDs) : false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With a condition, chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="dropPerPlayer">Whether the drop should be "instanced" (each player gets their own copy).</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
public static bool DropItemFromSetCondition(NPC npc, bool dropPerPlayer, bool condition, int oneInXChance, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSetChance(npc, dropPerPlayer, oneInXChance, itemIDs) : false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With a condition, chooses an item from an array and drops it from the given NPC. Optionally spawns one copy of this drop per player.
|
||||
/// </summary>
|
||||
/// <param name="npc">The NPC which should drop the item.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will drop is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
public static bool DropItemFromSetCondition(NPC npc, bool condition, int oneInXChance, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSetChance(npc, false, oneInXChance, itemIDs) : false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Player Item Set Spawns
|
||||
/// <summary>
|
||||
/// Chooses an item from an array and spawns it for the given player.
|
||||
/// </summary>
|
||||
/// <param name="p">The player which should receive the item.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSet(Player p, params int[] itemIDs)
|
||||
{
|
||||
// Can't choose anything from an empty array.
|
||||
if (itemIDs is null || itemIDs.Length == 0)
|
||||
return false;
|
||||
|
||||
// Choose which item to drop.
|
||||
int itemID = Main.rand.Next(itemIDs);
|
||||
|
||||
p.QuickSpawnItem(itemID);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At a chance, chooses an item from an array and spawns it for the given player.
|
||||
/// </summary>
|
||||
/// <param name="p">The player which should receive the item.</param>
|
||||
/// <param name="chance">The chance that the items will spawn. A decimal number <= 1.0.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSetChance(Player p, float chance, params int[] itemIDs)
|
||||
{
|
||||
// If you fail the roll to get the drop, stop immediately.
|
||||
if (Main.rand.NextFloat() > chance)
|
||||
return false;
|
||||
|
||||
return DropItemFromSet(p, itemIDs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At a chance, chooses an item from an array and spawns it for the given player.
|
||||
/// </summary>
|
||||
/// <param name="p">The player which should receive the item.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will spawn is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was dropped.</returns>
|
||||
public static bool DropItemFromSetChance(Player p, int oneInXChance, params int[] itemIDs)
|
||||
{
|
||||
// If you fail the roll to get the drop, stop immediately.
|
||||
if (Main.rand.Next(oneInXChance) != 0)
|
||||
return false;
|
||||
|
||||
return DropItemFromSet(p, itemIDs);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Player Item Set Spawns Conditional
|
||||
/// <summary>
|
||||
/// With a condition, chooses an item from an array and spawns it for the given player.
|
||||
/// </summary>
|
||||
/// <param name="p">The player which should receive the item.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was spawned.</returns>
|
||||
public static bool DropItemFromSetCondition(Player p, bool condition, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSet(p, itemIDs) : false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With a condition and at a chance, chooses an item from an array and spawns it for the given player.
|
||||
/// </summary>
|
||||
/// <param name="p">The player which should receive the item.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="chance">The chance that the items will spawn. A decimal number <= 1.0.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be dropped.</param>
|
||||
/// <returns>Whether an item was spawned.</returns>
|
||||
public static bool DropItemFromSetCondition(Player p, bool condition, float chance, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSetChance(p, chance, itemIDs) : false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With a condition and at a chance, chooses an item from an array and spawns it for the given player.
|
||||
/// </summary>
|
||||
/// <param name="p">The player which should receive the item.</param>
|
||||
/// <param name="condition">Any arbitrary Boolean condition to gate this drop. If false, nothing is dropped.</param>
|
||||
/// <param name="oneInXChance">The chance that the items will spawn is 1 in this number. For example, 5 gives a 1 in 5 chance.</param>
|
||||
/// <param name="itemIDs">The array of items to choose from. If it's null or empty, nothing will be spawned.</param>
|
||||
/// <returns>Whether an item was spawned.</returns>
|
||||
public static bool DropItemFromSetCondition(Player p, bool condition, int oneInXChance, params int[] itemIDs)
|
||||
{
|
||||
return condition ? DropItemFromSetChance(p, oneInXChance, itemIDs) : false;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user