Droppin Phat Lootz

What’s the point of decimating your foes if its not followed by the immediately gratifying, dopamine-generating effect of collecting buffs and items from their pixelated remains?

I tried to approach this task by being as future-thinking and flexible as possible. Because I’m using scriptable objects as the basis of my architecture, why would this be any different? First I created a serialized LootDrops class

[Serializable]
public class LootDrops
{
    public GameObject item;       public bool guaranteed;
    [Range(1, 10)]
    public int dropRate = 5;
    public int dropAmount;
}

Each LootDrop contains the prefab to be dropped, wether it is guaranteed to drop or is reliant on its drop rate, and finally how many of this item have the potential to drop in a single instance.

public class LootTable : ScriptableObject
{
    public int minDrops;
    public int maxDrops;     [SerializeField] public LootDrops[] phatLootz;
}

With LootTable I can add as many items as I want to the phatLootz array and determine the minimum and maximum number of items which can potentially drop in a single instance. This is the object that gets added to my Enemy object and ultimately determines what drops. Here are some examples of some basic setups.

Screen Shot 2019-04-19 at 8.42.25 PM.png

I’ve got a handful of “Basic” DropTables I can put on the various simple enemies to make sure they drop some coins. In the basic example, when enemies using this table perish they’ll randomly select a number between 0 and 5 and loop through PhatLootz that many times, selecting items with a higher drop rate more frequently until their DropAmount hits 0 wherein they’re removed from the table.

The drop rate is handled by creating a list I’m calling weightedTable and creating an entry for each item for their drop rate. So in the Basic example, weightedTable has 10 coins and 1 Simple Health Potion and an item is pulled from this list at random.

The “Boss” example includes a Guaranteed drop which exempts itself from min/max drops and drop rate. Before a loop number is selected, both of those Basic Treasure Chests are going to drop, then it proceeds as usual. Here’s the Bolt macro handling all that logic.

It works as intended, but I’m sure all the list creation and looping is going to have an inevitable effect on performance when happening at a larger scale. Any advice on how to refine this process would be fantastic!

Evan Lemmons

Husband, father, musician, gamer.