示例#1
0
        // Disable field making for totalCollected and highestCollected for custom items
        private static void PerItemStatDefOnRegisterStatDefs(On.RoR2.Stats.PerItemStatDef.orig_RegisterStatDefs orig)
        {
            var instancesList = typeof(PerItemStatDef).GetFieldValue <List <PerItemStatDef> >("instancesList");

            foreach (PerItemStatDef perItemStatDef in instancesList)
            {
                var prefix       = perItemStatDef.GetFieldValue <string>("prefix");
                var recordType   = perItemStatDef.GetFieldValue <StatRecordType>("recordType");
                var dataType     = perItemStatDef.GetFieldValue <StatDataType>("dataType");
                var keyToStatDef = ItemCatalog.GetPerItemBuffer <StatDef>();
                perItemStatDef.SetFieldValue("keyToStatDef", keyToStatDef);

                foreach (ItemIndex itemIndex in ItemCatalog.allItems)
                {
                    if ((int)itemIndex >= OriginalItemCount)
                    {
                        continue;
                    }
                    ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex);
                    StatDef statDef = StatDef.Register(prefix + "." + itemDef.name, recordType, dataType, 0.0);
                    keyToStatDef[(int)itemIndex] = statDef;
                }
            }
        }