mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
metal working station and recipes
This commit is contained in:
@@ -577,7 +577,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
* For each ingredient of the recipe, returns list of (ingredient, how many the player has the ingredient, how many the recipe wants)
|
||||
*/
|
||||
fun recipeToIngredientRecord(inventory: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List<String>): List<RecipeIngredientRecord> {
|
||||
val hasStation = if (recipe.workbench.isBlank()) true else nearbyCraftingStations.contains(recipe.workbench)
|
||||
val hasStation = if (recipe.workbench.isBlank()) true else nearbyCraftingStations.containsAll(recipe.workbench.split(','))
|
||||
return recipe.ingredients.map { ingredient ->
|
||||
val selectedItem = getItemForIngredient(inventory, ingredient)
|
||||
val howManyPlayerHas = inventory.searchByID(selectedItem)?.qty ?: 0L
|
||||
|
||||
@@ -61,7 +61,11 @@ class UIItemCraftingCandidateGrid(
|
||||
}
|
||||
|
||||
private fun isCraftable(player: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List<String>): Boolean {
|
||||
return UICrafting.recipeToIngredientRecord(player, recipe, nearbyCraftingStations).none { it.howManyPlayerHas <= 0L || !it.craftingStationAvailable }
|
||||
// printdbg(this, "Is this recipe craftable? $recipe")
|
||||
return UICrafting.recipeToIngredientRecord(player, recipe, nearbyCraftingStations).none {
|
||||
// printdbg(this, " considering ingredient ${it.selectedItem}, ${it.howManyRecipeWants} is required and got ${it.howManyPlayerHas}; crafting station available? ${it.craftingStationAvailable}")
|
||||
it.howManyPlayerHas <= 0L || !it.craftingStationAvailable
|
||||
}
|
||||
}
|
||||
|
||||
override fun scrollItemPage(relativeAmount: Int) {
|
||||
@@ -74,21 +78,31 @@ class UIItemCraftingCandidateGrid(
|
||||
private var currentFilter1 = arrayOf("")
|
||||
|
||||
override fun rebuild(filter: Array<String>) {
|
||||
// printdbg(this, "Rebuilding crafting candidate with following filters: ${filter.joinToString()}")
|
||||
currentFilter1 = filter
|
||||
|
||||
// filtering policy: if the player have all the ingredient item (regardless of the amount!), make the recipe visible
|
||||
craftingRecipes.clear()
|
||||
CraftingRecipeCodex.props.forEach { (_, recipes) ->
|
||||
recipes.forEach {
|
||||
if (isCraftable((parentUI as UICrafting).getPlayerInventory(), it, (parentUI as UICrafting).nearbyCraftingStations)) craftingRecipes.add(it)
|
||||
if (isCraftable((parentUI as UICrafting).getPlayerInventory(), it, (parentUI as UICrafting).nearbyCraftingStations)) {
|
||||
craftingRecipes.add(it)
|
||||
}
|
||||
else {
|
||||
// printdbg(this, " Skipping $recipes: insufficient ingredients")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recipesSortList.clear() // kinda like the output list
|
||||
|
||||
craftingRecipes.forEach {
|
||||
if ((filter.contains((ItemCodex[it.product]?.inventoryCategory ?: throw IllegalArgumentException("Unknown item: ${it.product}"))) || filter[0] == UIItemInventoryCatBar.CAT_ALL))
|
||||
if (
|
||||
filter.contains((ItemCodex[it.product]?.inventoryCategory ?: throw IllegalArgumentException("Unknown item: ${it.product}"))) ||
|
||||
filter[0] == UIItemInventoryCatBar.CAT_ALL
|
||||
) {
|
||||
recipesSortList.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
// map sortList to item list
|
||||
|
||||
Reference in New Issue
Block a user