// Updates the internal probability matrix and optionally logs the result
// Updates the internal probability matrix and optionally logs the result
private void UpdateInternals(bool doLog) {
private void UpdateInternals(bool doLog) {
Log("Updating internals ...");
Log("Updating internals ...");
originalItems = new List<ItemDefinition>(ItemManager.itemList);
originalItems = new List<ItemDefinition>(ItemManager.itemList);
originalBlueprints = new List<ItemBlueprint>(ItemManager.bpList);
originalBlueprints = new List<ItemBlueprint>(ItemManager.bpList);
if (originalItems.Count < 20 || originalBlueprints.Count < 10) {
if (originalItems.Count < 20 || originalBlueprints.Count < 10) {
Error("Resources did not contain a sane amount of items and/or blueprints: " + originalItems.Count +
Error("Resources did not contain a sane amount of items and/or blueprints: " + originalItems.Count +
" / " + originalBlueprints.Count);
" / " + originalBlueprints.Count);
return;
return;
}
}
if (doLog)
if (doLog)
Log("There are " + originalItems.Count + " items and " + originalBlueprints.Count + " blueprints in the game.");
Log("There are " + originalItems.Count + " items and " + originalBlueprints.Count + " blueprints in the game.");
for (var i = 0; i < 4; ++i) {
for (var i = 0; i < 4; ++i) {
items[i] = new List<string>();
items[i] = new List<string>();
blueprints[i] = new List<string>();
blueprints[i] = new List<string>();
}
}
totalItems = 0;
totalItems = 0;
totalBlueprints = 0;
totalBlueprints = 0;
var allItems = ItemManager.GetItemDefinitions();
var allItems = ItemManager.GetItemDefinitions();
if (allItems == null || allItems.Count < 20) {
if (allItems == null || allItems.Count < 20) {
Error("ItemManager did not return a sane amount of items. Is the game broken?");
Error("ItemManager did not return a sane amount of items. Is the game broken?");
return;
return;
}
}
var notExistingItems = 0;
var notExistingItems = 0;
var notExistingBlueprints = 0;
var notExistingBlueprints = 0;
var itemsWithNoRarity = 0;
var itemsWithNoRarity = 0;
foreach (var item in allItems) {
foreach (var item in allItems) {
#if DEBUG
Log("ItemShortName:" + item.shortname);
#endif
if (neverDropped.Contains(item.shortname))
if (neverDropped.Contains(item.shortname))
continue;
continue;
int index = RarityIndex(item.rarity);
int index = RarityIndex(item, rarityOverrides);
if (index >= 0) {
if (index >= 0) {
if (ItemExists(item.shortname)) {
if (ItemExists(item.shortname)) {
if (!itemBlacklist.Contains(item.shortname)) {
if (!itemBlacklist.Contains(item.shortname)) {
items[index].Add(item.shortname);
items[index].Add(item.shortname);
++totalItems;
++totalItems;
}
}
} else ++notExistingItems;
} else ++notExistingItems;
if (BlueprintExists(item.shortname)) {
if (BlueprintExists(item.shortname)) {
if (blueprintsNeverDropped.Contains(item.shortname))
if (blueprintsNeverDropped.Contains(item.shortname))
continue;
continue;
if (!blueprintBlacklist.Contains(item.shortname)) {
if (!blueprintBlacklist.Contains(item.shortname)) {
blueprints[index].Add(item.shortname);
blueprints[index].Add(item.shortname);
++totalBlueprints;
++totalBlueprints;
}
}
} else ++notExistingBlueprints;
} else ++notExistingBlueprints;
} else ++itemsWithNoRarity;
} else {
#if DEBUG
// Will occasionally get these for new items. Should default some in json or hardcode (i.e. blueprint fragments, etc)
Warn("Item has no rarity: " + item.shortname);
#endif
++itemsWithNoRarity;
}
}
}
if (totalItems < 20 || totalBlueprints < 10) {
if (totalItems < 20 || totalBlueprints < 10) {
Error("Failed to categorize items: "+notExistingItems+" items and "+notExistingBlueprints+" blueprints did not exist and "+itemsWithNoRarity+" items had no rarity");
Error("Failed to categorize items: "+notExistingItems+" items and "+notExistingBlueprints+" blueprints did not exist and "+itemsWithNoRarity+" items had no rarity");
if (itemsWithNoRarity > 10)
if (itemsWithNoRarity > 10)
Error("THIS IS MOST LIKELY CAUSED BY A MISCONFIGURED (OR BROKEN) PLUGIN THAT MODIFIES ITEMS!");
Error("THIS IS MOST LIKELY CAUSED BY A MISCONFIGURED (OR BROKEN) PLUGIN THAT MODIFIES ITEMS!");
else
else
Error("PLEASE REPORT THIS ON THE DEDICATED DISCUSSION THREAD! http://oxidemod.org/threads/betterloot.7063");
Error("PLEASE REPORT THIS ON THE DEDICATED DISCUSSION THREAD! http://oxidemod.org/threads/betterloot.7063");
return;
return;
}
}
if (doLog)
if (doLog)
Log("We are going to use " + totalItems + " items and " + totalBlueprints + " blueprints of them.");
Log("We are going to use " + totalItems + " items and " + totalBlueprints + " blueprints of them.");
Log(string.Format("There is a {0:0.000}% chance to get one of {1} " + RarityName(i) + " items (w={2}, {3}/{4}).", prob, items[i].Count, ItemWeight(baseItemRarity, i), itemWeights[i], totalItemWeight));
Log(string.Format("There is a {0:0.000}% chance to get one of {1} " + RarityName(i) + " items (w={2}, {3}/{4}).", prob, items[i].Count, ItemWeight(baseItemRarity, i), itemWeights[i], totalItemWeight));
Log(string.Format("There is a {0:0.000}% chance to get one of {1} " + RarityName(i) + " blueprints (w={2}, {3}/{4}).", prob, blueprints[i].Count, ItemWeight(baseBlueprintRarity, i), blueprintWeights[i], totalBlueprintWeight));
Log(string.Format("There is a {0:0.000}% chance to get one of {1} " + RarityName(i) + " blueprints (w={2}, {3}/{4}).", prob, blueprints[i].Count, ItemWeight(baseBlueprintRarity, i), blueprintWeights[i], totalBlueprintWeight));
total += prob;
total += prob;
}
}
// Log("Total chance: " + total + "% == 100%");
// Log("Total chance: " + total + "% == 100%");
}
}
// Update containers accordingly
// Update containers accordingly
var containers = UnityEngine.Object.FindObjectsOfType<LootContainer>();
var containers = UnityEngine.Object.FindObjectsOfType<LootContainer>();