private static void transformObject(NetObjectList <Item> items, SObject item, CustomCropsDecayData data) { if (data.decayDays.TryGetValue(item.Quality, out int decayDays)) { if (item is ColoredObject coloredObject) { ColoredCropWithDecay crop = ColoredCropWithDecay.copyFrom(coloredObject); crop.decayDays = decayDays; for (int i = 0; i < items.Count; i++) { if (items[i] == item) { items[i] = crop; } } } else { CropWithDecay crop = CropWithDecay.copyFrom(item); crop.decayDays = decayDays; for (int i = 0; i < items.Count; i++) { if (items[i] == item) { items[i] = crop; } } } } }
private static void ReplaceInLocationChests(GameLocation location) { var objects = location.objects.Values; for (int j = 0; j < objects.Count(); j++) { var o = objects.ToList()[j]; if (o is Chest chest) { NetObjectList <Item> items = chest.items; for (int k = 0; k < items.Count; k++) { ReplaceIfOldItem(items, k); } } if (o.heldObject.Value is Chest autoGrabber) { NetObjectList <Item> items = autoGrabber.items; for (int k = 0; k < items.Count; k++) { ReplaceIfOldItem(items, k); } } } }
public bool ReceiveItems(NetObjectList <Item> chest, int needed, string type) { if (needed == 0) { return(true); } List <int> items; if (!JunimoPaymentsToday.TryGetValue(type, out items)) { items = new List <int>(); JunimoPaymentsToday[type] = items; } int paidSoFar = items.Count(); if (paidSoFar == needed) { return(true); } foreach (int i in Enumerable.Range(paidSoFar, needed)) { Item foundItem = chest.FirstOrDefault(item => item.getCategoryName() == type); if (foundItem != null) { items.Add(foundItem.ParentSheetIndex); Util.ReduceItemCount(chest, foundItem); } } return(items.Count() == needed); }
public void AddItems(NetObjectList <Item> items) { foreach (var item in items) { chest.addItem(item); } }
private void Transfer(bool keyPressed) { IList <Item> PlayerInventory = Game1.player.Items; if (keyPressed) { Chest OpenChest = GetOpenChest(); if (OpenChest == null) { return; } if (OpenChest.isEmpty()) { return; } NetObjectList <Item> OpenChestItems = OpenChest.items; foreach (Item chestItem in OpenChestItems) { foreach (Item playerItem in PlayerInventory) { if (playerItem != null) { if (playerItem.canStackWith(chestItem)) { OpenChest.grabItemFromInventory(playerItem, Game1.player); break; } } } } } }
internal void ReplaceOldTools(object sender, EventArgs e) { NetObjectList <Item> inventory = Game1.player.items; for (int i = 0; i < inventory.Count; i++) { ReplaceIfOldItem(inventory, i); } IList <GameLocation> locations = Game1.locations; for (int i = 0; i < locations.Count; i++) { var location = locations[i]; ReplaceInLocationChests(location); if (location is BuildableGameLocation bgl) { foreach (Building b in bgl.buildings) { if (b.indoors.Value is GameLocation gl) { ReplaceInLocationChests(gl); } } ; } } }
private static bool Chest_addItem_Prefix(Chest __instance, Item item, ref Item __result) { DataAccess DataAccess = DataAccess.GetDataAccess(); List <Node> nodes = DataAccess.LocationNodes[Game1.currentLocation]; Node node = nodes.Find(n => n.Position.Equals(__instance.tileLocation)); if (node is FilterPipeNode) { item.resetState(); __instance.clearNulls(); NetObjectList <Item> item_list = __instance.items; if (__instance.SpecialChestType == Chest.SpecialChestTypes.MiniShippingBin || __instance.SpecialChestType == Chest.SpecialChestTypes.JunimoChest) { item_list = __instance.GetItemsForPlayer(Game1.player.UniqueMultiplayerID); } if (!item_list.Any(x => x.Name.Equals(item.Name))) { if (item_list.Count < __instance.GetActualCapacity()) { item_list.Add(item.getOne()); __result = null; } else { __result = item; } } return(false); } return(true); }
/*** * Modified from CraftingRecipes.consumeIngredients ***/ /// <summary> /// Selects the ingredients for the recipe from player inventory and/or fridge. /// </summary> /// <returns>The ingredients.</returns> /// <param name="recipe">Recipe.</param> private List <Ingredient> SelectIngredients(CraftingRecipe recipe) { Util.Monitor.VerboseLog($"Selecting items: "); List <Ingredient> selected = new List <Ingredient>(); Dictionary <int, int> recipeList = Util.Helper.Reflection.GetField <Dictionary <int, int> >(recipe, "recipeList").GetValue(); NetObjectList <Item> playerItemList = Game1.player.items; Util.Monitor.VerboseLog($"Looking in inventory"); for (int ingredientIdx = recipeList.Count - 1; ingredientIdx >= 0; ingredientIdx--) { int ingredientID = recipeList.Keys.ElementAt(ingredientIdx); int ingredientAmt = recipeList[ingredientID]; bool ingredientDone = false; for (int itemIdx = playerItemList.Count - 1; itemIdx >= 0; itemIdx--) { Item playerItem = playerItemList[itemIdx]; if (playerItem != null && playerItem is SObject playerObject && !(playerItem as SObject).bigCraftable && (playerItem.parentSheetIndex == ingredientID || playerItem.Category == ingredientID)) { Util.Monitor.VerboseLog($"Selected {playerObject.Stack} {playerObject.DisplayName} (quality {playerObject.Quality})"); recipeList[ingredientID] -= playerItem.Stack; selected.Add(new Ingredient(playerItemList, itemIdx, ingredientAmt)); if (recipeList[ingredientID] <= 0) { recipeList[ingredientID] = ingredientAmt; ingredientDone = true; break; } } } if (recipe.isCookingRecipe && !ingredientDone && Game1.currentLocation is FarmHouse farmHouse) { Util.Monitor.VerboseLog($"Looking in fridge"); NetObjectList <Item> fridgeItemList = farmHouse.fridge.Value.items; for (int itemIdx = fridgeItemList.Count - 1; itemIdx >= 0; itemIdx--) { Item fridgeItem = fridgeItemList[itemIdx]; if (fridgeItem != null && fridgeItem is SObject fridgeObject && (fridgeItem.parentSheetIndex == ingredientID || fridgeItem.Category == ingredientID)) { Util.Monitor.VerboseLog($"Selected {fridgeObject.Stack} {fridgeObject.DisplayName} with quality {fridgeObject.Quality}"); recipeList[ingredientID] -= fridgeItem.Stack; selected.Add(new Ingredient(fridgeItemList, itemIdx, ingredientAmt)); if (recipeList[ingredientID] <= 0) { recipeList[ingredientID] = ingredientAmt; ingredientDone = true; break; } } } } } return(selected); }
private void Harvest(GameLocation greenhouse) { IsHarvesting = true; currentHarvestingMap = greenhouse; try { var chests = GetChests(greenhouse).ToArray(); if (!chests.Any()) { Monitor.Log($"To enable auto harvesting in {greenhouse.Name}, place a chest on the map", LogLevel.Info); return; } var items = Game1.player.items; int maxItems = Game1.player.MaxItems; Game1.player.MaxItems = chests.Length * Chest.capacity; var objects = new NetObjectList <Item>(); for (int i = 0; i < Game1.player.MaxItems * 10; i++) { objects.Add(null); } Helper.Reflection.GetField <NetObjectList <Item> >(Game1.player, "items").SetValue(objects); foreach (var terrains in greenhouse.terrainFeatures) { foreach (var terrain in terrains) { if (terrain.Value is HoeDirt dirt) { AttemptHarvest(greenhouse, dirt, terrain); } } } foreach (var item in objects) { AttemptToAddToChest(chests, item, greenhouse); } CollectDebris(chests, greenhouse); Game1.player.MaxItems = maxItems; Helper.Reflection.GetField <NetObjectList <Item> >(Game1.player, "items").SetValue(items); CollectDebris(chests, greenhouse); } catch (Exception e) { Monitor.Log(e.ToString(), LogLevel.Error); } IsHarvesting = false; currentHarvestingMap = null; }
public Filter(int capacity) { items = new NetObjectList <Item>(); message = "Filter"; Capacity = capacity; //Generate cols and rows based on capacity Cols = 9; Rows = 1; }
public override bool CanRecieveItems() { bool canReceive = false; NetObjectList <Item> itemList = GetItemList(); if (itemList.Count < Chest.GetActualCapacity()) { canReceive = true; } return(canReceive); }
public void UpdateHutContainsItemCategory(Guid id, int itemCategory) { JunimoHut hut = Util.GetHutFromId(id); NetObjectList <Item> chest = hut.output.Value.items; if (!ItemsInHuts.ContainsKey(id)) { ItemsInHuts.Add(id, new Dictionary <int, bool>()); } ItemsInHuts[id][itemCategory] = chest.Any(item => item.category == itemCategory); }
/* * Modified from CraftingRecipes.consumeIngredients */ private List <Ingredient> SelectIngredients(CraftingRecipe recipe) { List <Ingredient> selected = new List <Ingredient>(); Dictionary <int, int> recipeList = QualityProducts.Instance.Helper.Reflection.GetField <Dictionary <int, int> >(recipe, "recipeList").GetValue(); NetObjectList <Item> playerItemList = Game1.player.items; for (int ingredientIdx = recipeList.Count - 1; ingredientIdx >= 0; ingredientIdx--) { int ingredientID = recipeList.Keys.ElementAt(ingredientIdx); int ingredientAmt = recipeList[ingredientID]; bool ingredientDone = false; for (int itemIdx = playerItemList.Count - 1; itemIdx >= 0; itemIdx--) { Item playerItem = playerItemList[itemIdx]; if (playerItem != null && playerItem is SObject && !(bool)(playerItem as SObject).bigCraftable && (playerItem.parentSheetIndex == ingredientID || playerItem.Category == ingredientID)) { recipeList[ingredientID] -= playerItem.Stack; selected.Add(new Ingredient(playerItemList, itemIdx, ingredientAmt)); if (recipeList[ingredientID] <= 0) { recipeList[ingredientID] = ingredientAmt; ingredientDone = true; break; } } } if (recipe.isCookingRecipe && !ingredientDone && Game1.currentLocation is FarmHouse farmHouse) { NetObjectList <Item> fridgeItemList = farmHouse.fridge.Value.items; for (int itemIdx = fridgeItemList.Count - 1; itemIdx >= 0; itemIdx--) { Item fridgeItem = fridgeItemList[itemIdx]; if (fridgeItem != null && fridgeItem is SObject && (fridgeItem.parentSheetIndex == ingredientID || fridgeItem.Category == ingredientID)) { recipeList[ingredientID] -= fridgeItem.Stack; selected.Add(new Ingredient(fridgeItemList, itemIdx, ingredientAmt)); if (recipeList[ingredientID] <= 0) { recipeList[ingredientID] = ingredientAmt; ingredientDone = true; break; } } } } } return(selected); }
public override bool IsEmpty() { bool isEmpty = false; NetObjectList <Item> itemList = GetItemList(); if (itemList.Count < 1) { isEmpty = true; } return(isEmpty); }
public ShippingBinContainerNode(Vector2 position, GameLocation location, StardewValley.Object obj, Building building) : base(position, location, obj) { Name = building.buildingType.ToString(); if (building is ShippingBin) { ShippingBin = (ShippingBin)building; } Farm = Game1.getFarm(); Filter = new NetObjectList <Item>(); Type = "ShippingBin"; }
public bool ReceivePaymentItems(JunimoHut hut) { Farm farm = Game1.getFarm(); NetObjectList <Item> chest = hut.output.Value.items; bool paidForage = ReceiveItems(chest, Payment.DailyWage.ForagedItems, "Forage"); bool paidFlowers = ReceiveItems(chest, Payment.DailyWage.Flowers, "Flower"); bool paidFruit = ReceiveItems(chest, Payment.DailyWage.Fruit, "Fruit"); bool paidWine = ReceiveItems(chest, Payment.DailyWage.Wine, "Artisan Goods"); return(paidForage && paidFlowers && paidFruit && paidWine); }
public static void ReduceItemCount(NetObjectList <Item> chest, Item item) { if (Config.FunChanges.InfiniteJunimoInventory) { return; } item.Stack--; if (item.Stack == 0) { chest.Remove(item); } }
private Item matchingItemInChest(Item sourceItem, NetObjectList <Item> items) { foreach (Item item in items) { //weirdly, this is an equals check //if (sourceItem.canStackWith(item) && (item.Stack - stackSizeOffset) < item.maximumStackSize() && item.Stack - stackSizeOffset > 0) if (sourceItem.canStackWith(item) && item.Stack < item.maximumStackSize() && item != sourceItem) { return(item); } } return(null); }
private static void chestItemChanged(NetObjectList <Item> items, SObject item) { if (cropsById.TryGetValue(item.ParentSheetIndex, out CustomCropsDecayData data)) { transformObject(items, item, data); } else if (cropsByName.TryGetValue(item.name, out data)) { transformObject(items, item, data); } else if (cropsByCategory.TryGetValue(item.Category, out data)) { transformObject(items, item, data); } }
/// <summary> /// Add an object to a netList of items. /// </summary> /// <param name="inventory"></param> /// <param name="I"></param> /// <returns></returns> public static bool addItemToOtherInventory(NetObjectList <Item> inventory, Item I) { if (I == null) { return(false); } if (isInventoryFull(inventory) == false) { if (inventory == null) { return(false); } if (inventory.Count == 0) { inventory.Add(I); return(true); } for (int i = 0; i < inventory.Capacity; i++) { // Log.AsyncC("OK????"); foreach (var v in inventory) { if (inventory.Count == 0) { addItemToOtherInventory(inventory, I); return(true); } if (v == null) { continue; } if (v.canStackWith(I)) { v.addToStack(I.getStack()); return(true); } } } inventory.Add(I); return(true); } else { return(false); } }
public override NetObjectList <Item> UpdateFilter(NetObjectList <Item> filteredItems) { Filter = new NetObjectList <Item>(); if (filteredItems == null) { Filter.Add(Farm.lastItemShipped); } else { foreach (Item item in filteredItems.ToList()) { Filter.Add(item); } } return(Filter); }
/// <summary> /// Checks whether or not the net inventory list is full of items. /// </summary> /// <param name="inventory"></param> /// <param name="logInfo"></param> /// <returns></returns> public static bool isInventoryFull(NetObjectList <Item> inventory, bool logInfo = false) { if (logInfo) { ModCore.ModMonitor.Log("size " + inventory.Count); ModCore.ModMonitor.Log("max " + inventory.Capacity); } if (inventory.Count == inventory.Capacity) { return(true); } else { return(false); } }
public override bool CanStackItem(Item item) { bool canStack = false; NetObjectList <Item> itemList = GetItemList(); if (itemList.Any(i => i.ParentSheetIndex.Equals(item.ParentSheetIndex))) { foreach (Item i in itemList.ToList()) { if (i.ParentSheetIndex == item.ParentSheetIndex && i.canStackWith(item)) { canStack = true; } } } return(canStack); }
private static void ReplaceIfOldItem(NetObjectList <Item> items, int i) { Item item = items[i]; if (item != null) { if (item.Name.Contains("ButcherMod.MeatCleaver")) { items[i] = new MeatCleaver(); AnimalHusbandryModEntery.monitor.Log($"An older version of the MeatCleaver found. Replacing it with the new one.", LogLevel.Debug); } else if (item.Name.Contains("ButcherMod.tools.InseminationSyringe")) { items[i] = new InseminationSyringe(); AnimalHusbandryModEntery.monitor.Log($"An older version of the InseminationSyringe found. Replacing it with the new one.", LogLevel.Debug); } } }
/// <summary> /// Loads warps for GameLocation /// </summary> private void LoadWarps() { this.GetLocation(); IList <string> warpNames = new List <string>(); NetObjectList <Warp> warps = this._location.warps; foreach (Warp warp in warps) { if (!warpNames.Contains(warp.TargetName)) { this._warps.Add(warp); warpNames.Add(warp.TargetName); } } this._warpsLoaded = true; }
public override bool CanStackItems() { bool canStack = false; NetObjectList <Item> itemList = GetItemList(); int index = itemList.Count - 1; while (index >= 0 && !canStack) { if (itemList[index] != null) { if (itemList[index].getRemainingStackSpace() > 0) { canStack = true; } } index--; } return(canStack); }
public override NetObjectList <Item> UpdateFilter(NetObjectList <Item> filteredItems) { Filter = new NetObjectList <Item>(); if (filteredItems == null) { NetObjectList <Item> itemList = GetItemList(); foreach (Item item in itemList.ToList()) { Filter.Add(item); } } else { foreach (Item item in filteredItems.ToList()) { Filter.Add(item); } } return(Filter); }
/// <summary>Get whether the mill's input bin is full.</summary> private bool InputFull() { NetObjectList <Item?>?slots = this.Input.items; // free slots if (slots.Count < Chest.capacity) { return(false); } // free space in stacks foreach (Item?slot in slots) { if (slot == null || slot.Stack < this.GetMaxInputStackSize(slot)) { return(false); } } return(true); }
private bool UseItemAbility(Guid id, Vector2 pos, int itemCategory, Func <Vector2, int, bool> useItem) { JunimoHut hut = Util.GetHutFromId(id); NetObjectList <Item> chest = hut.output.Value.items; Item foundItem = chest.FirstOrDefault(item => item.Category == itemCategory); if (foundItem == null) { return(false); } bool success = useItem(pos, foundItem.ParentSheetIndex); if (success) { Util.ReduceItemCount(chest, foundItem); UpdateHutItems(id); } return(success); }
public Item TryExtractItem(ContainerNode input, NetObjectList <Item> itemList, int index, int flux) { //Exception for multiple thread collisions Item source = itemList[index]; Item tosend = null; if (source is SObject) { SObject obj = (SObject)source; SObject tosendObject = (SObject)tosend; if (input.CanRecieveItem(source) && !IsEmpty()) { if (obj.Stack <= flux) { tosendObject = obj; itemList.RemoveAt(index); } else { obj.stack.Value -= flux; tosendObject = (SObject)obj.getOne(); tosendObject.stack.Value = flux; } Chest.clearNulls(); return(tosendObject); } } else if (source is Tool) { Tool tool = (Tool)source; Tool tosendTool = (Tool)tosend; if (input.CanRecieveItem(tool)) { tosendTool = tool; itemList.RemoveAt(index); } Chest.clearNulls(); return(tosendTool); } return(null); }