private static Point GetClosestMaterialPos(Creature c, RecipeComponent recipe, bool checkInventory) { int currentFloor = c.CurrentFloor; Point worldIndex = c.WorldIndex; Block[] blocks = currentFloor >= 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[currentFloor].Blocks : Program.WorldMap[worldIndex.X, worldIndex.Y].Blocks; int width = Program.WorldMap.TileWidth, height = Program.WorldMap.TileHeight; // check inventory if (checkInventory) { foreach (Item item in c.Inventory) { RecipeComponent itemC = item.ToComponent(); if (recipe.Equals(itemC)) { return(new Point()); } } } // check map for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (blocks[i * width + j] is Item item) { RecipeComponent itemC = item.ToComponent(); if (recipe.Equals(itemC)) { return(new Point(i, j)); } } else if (blocks[i * width + j] is Chest chest) { foreach (Item cItem in chest.Inventory) { RecipeComponent itemC = cItem.ToComponent(); if (recipe.Equals(itemC)) { return(new Point(i, j)); } } } } } return(null); }
internal static Point GetClosestMaterialPos(RecipeComponent recipe, bool checkInventory) { // check player inventory if (checkInventory) { foreach (Item item in Program.Player.Inventory) { RecipeComponent itemC = item.ToComponent(); if (recipe.Equals(itemC)) { return(new Point()); } } } // check map for (int i = 0; i < Program.WorldMap.LocalTile.Width; i++) { for (int j = 0; j < Program.WorldMap.LocalTile.Height; j++) { if (Program.WorldMap.LocalTile[i, j] is Item item) { RecipeComponent itemC = item.ToComponent(); if (recipe.Equals(itemC)) { return(new Point(i, j)); } } else if (Program.WorldMap.LocalTile[i, j] is Chest chest) { foreach (Item cItem in chest.Inventory) { RecipeComponent itemC = cItem.ToComponent(); if (recipe.Equals(itemC)) { return(new Point(i, j)); } } } } } return(null); }