/* PREPERATION FOR TEST SCENARIOS - DOES NOT CHANGE FUNCTIONALITY OF TESTED ITEMS */ public Dictionary <Item, int> GetRandomLootTest(float chance) { var results = new Dictionary <Item, int>(); var defaultTable = LootTableManager.GetLootTable(LootTable.Default); for (int i = 0; i < sampleSize; i++) { var table = new List <KeyValuePair <Item, float> >(defaultTable); var item = GetRandomLootTest(table, chance); if (results.ContainsKey(item)) { results[item] += 1; } else { results.Add(item, 1); } } if (results.ContainsKey(Item.Null)) { Assert.IsTrue(results[Item.Null] <= sampleSize * (1 - chance + errorMargin * 0.01f) && results[Item.Null] >= sampleSize * (1 - chance - errorMargin * 0.01f)); } else { results.Add(Item.Null, 0); Assert.IsTrue(true); } return(results); }
void Start() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); PopulateLootTableManager(); }
/* COPY OF CODE TO BE TESTED - MIGHT CHANGE FUNCTIONALITY OF TESTE ITEMS */ /* MAKE SURE THIS CODE IS ROUGHLY THE SAME AS THE TESTED ITEM */ public static Item GetRandomLootTest(List <KeyValuePair <Item, float> > items, float dropRate) { // Get the total value of all values var total = LootTableManager.GetTotalOfValues(items, 0, 0.0f); // Convert dropRate (in %) to a usable value in the context of 'items' var dropRateInContext = LootTableManager.GetDropRateInContext(dropRate, total); var temp = LootTableManager.ApplyDropRate(items, dropRateInContext); // Different from tested code due to use of UnityEngine.Random var itemNr = GetRandomItemNr(0.0, total + dropRateInContext); var chance = 0.0f; foreach (var item in temp) { if (itemNr >= chance && itemNr < item.Value + chance) { return(item.Key); } chance += item.Value; } return(Item.Null); }
protected override void Start() { base.Start(); _item = LootTableManager.GetRandomLoot(LootTable, DropChance); }
private void Awake() { _instance = this; LoadLootTableData(); }