public static bool CanSpoil(Item item) { var mymod = StarvationMod.Instance; if (!mymod.Config.FoodSpoilageEnabled) { return(false); } if (item.buffType == BuffID.WellFed && item.buffTime > 0) { return(true); } if (mymod.Config.FoodIngredientsAlsoSpoil) { IReadOnlySet <int> ingredients; if (EntityGroups.TryGetItemGroup("Any Food Ingredient", out ingredients) && ingredients.Contains(item.type)) { switch (item.type) { case ItemID.Pumpkin: case ItemID.BlinkrootSeeds: case ItemID.Hay: case ItemID.Mushroom: case ItemID.Bowl: break; default: return(true); } } } return(false); }
public ItemDefinition AttemptToLicenseRandomItem(Player player, out int savings) { var myplayer = player.GetModPlayer <LicensesPlayer>(); int targetRarity = WildcardLicenseItem.ComputeTargetRarityOfLicenseStackSize(this.item.stack); string grpName = "Any " + ItemRarityAttributeHelpers.RarityColorText[targetRarity] + " Tier"; IReadOnlySet <int> tierItems, equipments; EntityGroups.TryGetItemGroup(grpName, out tierItems); EntityGroups.TryGetItemGroup("Any Equipment", out equipments); IList <int> tierEquips = new List <int>(tierItems.Intersect(equipments)); int randItemType; ItemDefinition randItemDef; IDictionary <int, string> idsToNames = ItemAttributeHelpers.DisplayNamesToIds .ToLookup(kv => kv.Value) .ToDictionary(g => g.Key, g => g.First().Key); do { int count = tierEquips.Count(); if (count == 0) { savings = 0; return(null); } randItemType = tierEquips[Main.rand.Next(count)]; randItemDef = new ItemDefinition(randItemType); tierEquips.Remove(randItemType); } while(myplayer.LicensedItems.Contains(randItemDef)); var dummyItem = new Item(); dummyItem.SetDefaults(randItemType, true); int cost = WildcardLicenseItem.ComputeCost(dummyItem, out savings); Item selectedItem = player.inventory[PlayerItemHelpers.VanillaInventorySelectedSlot]; int selectedItemStack = selectedItem?.stack ?? 0; myplayer.LicenseItemByDefinition(randItemDef, true); ItemHelpers.ReduceStack(this.item, cost); // Failsafes: if (selectedItem.type == this.item.type) { int newStackSize = (selectedItemStack >= cost) ? (selectedItemStack - cost) : 0; selectedItem.stack = newStackSize; Main.mouseItem.stack = newStackSize; if (selectedItem.stack == 0) { selectedItem.active = false; } if (Main.mouseItem.stack == 0) { Main.mouseItem.active = false; } } return(randItemDef); }