Loot Tables - JBurlison/Pandaros.API GitHub Wiki

Loot tables are loosely tied to monsters via MonsterType.

Normal in game zombies have the monster type of "zombie". Settlers bosses have a monster type of "Boss".

There are 2 ways of creating a loot table. first is by inheriting from LootTable base class. Here is an example of the implementation with bosses.

    public class BossLoot : LootTable
    {
        public const string LootTableName = "Pandaros.Settlers.Monsters.Bosses";

        public override string name => LootTableName;

        public BossLoot()
        {
            LootPoolList.Add(new LootPoolEntry(SettlersBuiltIn.ItemTypes.MANA, 1, 20));
            MonsterTypes.Add("Boss");
        }
    }

Second is by inheriting the interface and implementing it yourself.

    public interface ILootTable
    {
        string name { get; }

        List<string> MonsterTypes { get; set; }

        List<LootPoolEntry> LootPoolList { get; }

        Dictionary<ushort, int> GetDrops(double luckModifier);
    }

The LootPoolEntry defines each item name, min number that can drop, max number that can drop and weight. Weight of 0 means it is guaranteed to drop.

Drop weight is a simple calculation that uses the killers luck. When a monster is killed a float roll is made from 0 to 1, then the luck modifier is added to it. each item is looped through adding its weight.

        public Dictionary<ushort, int> GetDrops(float luckModifier = 0)
        {
            var dic = new Dictionary<ushort, int>();

            float weightSum = 0;
            float roll = Pipliz.Random.NextFloat() + luckModifier;

            foreach (LootPoolEntry drop in LootPoolList)
            {
                weightSum += drop.Weight;

                if (roll > weightSum && ItemTypes.IndexLookup.StringLookupTable.TryGetItem(drop.Item, out ItemTypes.ItemType itemAction))
                {
                    dic[itemAction.GetRootParentType().ItemIndex] = Pipliz.Random.Next(drop.MinCount, drop.MaxCount + 1);
                }
            }

            return dic;
        }
⚠️ **GitHub.com Fallback** ⚠️