LootStoreItemList EqualChanced = new LootStoreItemList(); // Zero chances - every entry takes the same chance LootStoreItem Roll(Loot loot, ushort lootMode) { LootStoreItemList possibleLoot = ExplicitlyChanced; possibleLoot.RemoveAll(new LootGroupInvalidSelector(loot, lootMode).Check); if (!possibleLoot.Empty()) // First explicitly chanced entries are checked { float roll = (float)RandomHelper.randChance(); foreach (var item in possibleLoot) // check each explicitly chanced entry in the template and modify its chance based on quality. { if (item.chance >= 100.0f) return item; roll -= item.chance; if (roll < 0) return item; } } possibleLoot = EqualChanced; possibleLoot.RemoveAll(new LootGroupInvalidSelector(loot, lootMode).Check); if (!possibleLoot.Empty()) // If nothing selected yet - an item is taken from equal-chanced part return possibleLoot.SelectRandom(); return null; // Empty drop from the group }
public bool addConditionItem(Condition cond) { if (cond == null || !cond.isLoaded())//should never happen, checked at loading { Log.outError(LogFilter.Loot, "LootTemplate.addConditionItem: condition is null"); return(false); } if (!Entries.Empty()) { foreach (var i in Entries) { if (i.itemid == cond.SourceEntry) { i.conditions.Add(cond); return(true); } } } if (!Groups.Empty()) { foreach (var group in Groups.Values) { if (group == null) { continue; } LootStoreItemList itemList = group.GetExplicitlyChancedItemList(); if (!itemList.Empty()) { foreach (var i in itemList) { if (i.itemid == cond.SourceEntry) { i.conditions.Add(cond); return(true); } } } itemList = group.GetEqualChancedItemList(); if (!itemList.Empty()) { foreach (var i in itemList) { if (i.itemid == cond.SourceEntry) { i.conditions.Add(cond); return(true); } } } } } return(false); }