コード例 #1
0
        private static void ValidateItemData()
        {
            ItemData ??= new Dictionary <string, ItemData>();
            List <string> tradeables = StoreDialog.GetTradeables().Select(t => t.defName).ToList();
            List <string> toCull     = ItemData.Keys.Where(dataKey => !tradeables.Contains(dataKey.CapitalizeFirst())).ToList();

            foreach (string defName in toCull)
            {
                ItemData.Remove(defName);
            }

            var builder = new StringBuilder();

            foreach (ThingDef item in tradeables.Where(t => !ItemData.ContainsKey(t)).Select(i => DefDatabase <ThingDef> .GetNamed(i)))
            {
                ModContentPack contentPack = item.modContentPack;

                var data = new ItemData
                {
                    Version        = Models.ItemData.CurrentVersion,
                    QuantityLimit  = -1,
                    IsStuffAllowed = true,
                    IsUsable       = GameHelper.GetDefaultUsability(item),
                    IsWearable     = true,
                    IsEquippable   = true
                };

                if (contentPack != null)
                {
                    data.Mod = contentPack.IsCoreMod ? "RimWorld" : contentPack.Name ?? "Unknown";
                }

                ItemData[item.defName] = data;

                try
                {
                    data.IsMelee  = item.IsMeleeWeapon;
                    data.IsRanged = item.IsRangedWeapon;
                    data.IsWeapon = item.IsWeapon;
                }
                catch (Exception e)
                {
                    builder.Append($"Failed to gather weapon data for item '{item.label ?? "Unknown"}' from mod '{item.TryGetModName()}'");
                    builder.AppendLine($" -- Exception: {e.GetType().Name}({e.Message ?? "No message"})");
                }
            }

            foreach (KeyValuePair <string, ItemData> pair in ItemData.Where(data => data.Value.Version < Models.ItemData.CurrentVersion))
            {
                string   defName = pair.Key;
                ItemData data    = pair.Value;

                ThingItem item = Items.Find(i => i.DefName?.Equals(defName) == true);

                data.IsUsable     = item?.Thing == null || GameHelper.GetDefaultUsability(item.Thing);
                data.IsWearable   = true;
                data.IsEquippable = true;
                data.Version      = Models.ItemData.CurrentVersion;
            }
        }
コード例 #2
0
        private static bool Prefix()
        {
            List <Item>   inventory    = StoreInventory.items;
            var           tradeables   = new HashSet <ThingDef>(StoreDialog.GetTradeables());
            List <string> tradeableIds = tradeables.Select(t => t.defName).ToList();

            if (Data.PawnKinds != null)
            {
                DisableKinds(inventory);
            }

            StoreInventory.items = inventory.Where(i => !string.IsNullOrEmpty(i.defname)).Where(i => tradeableIds.Contains(i.defname)).ToList();

            RemoveDanglingItems();
            FixNullItemNames(tradeables);

            List <ToolkitItem> items = PrepareItems(tradeables).ToList();

            if (TkSettings.Offload)
            {
                Task.Run(
                    async() =>
                {
                    await Data.SaveJsonAsync(new ItemList {
                        Items = items
                    }, Paths.ToolkitItemFilePath);
                    await Data.SaveItemDataAsync(Paths.ItemDataFilePath);
                }
                    )
                .ConfigureAwait(false);
            }
            else
            {
                Data.SaveJson(new ItemList {
                    Items = items
                }, Paths.ToolkitItemFilePath);
                Data.SaveItemData(Paths.ItemDataFilePath);
            }

            return(false);
        }
コード例 #3
0
 private static void ValidateItems()
 {
     Items = StoreDialog.GetTradeables().Select(t => new ThingItem {
         Thing = t
     }).ToList();
 }