mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
not craftable items (due to lack of items) are filtered on crafting recipe list
This commit is contained in:
@@ -90,7 +90,9 @@ object PlayerBuilderSigrid {
|
||||
inventory.add("item@basegame:12", 16) // copper sledgehammer
|
||||
inventory.add("item@basegame:4", 16) // iron sledgehammer
|
||||
inventory.add("item@basegame:13", 16) // steel sledgehammer
|
||||
inventory.add("item@basegame:5", 995) // test tiki torch
|
||||
|
||||
// inventory.add("item@basegame:5", 995) // test tiki torch
|
||||
|
||||
inventory.add("item@basegame:6", 95) // storage chest
|
||||
inventory.add("item@basegame:7", 1) // wire debugger
|
||||
inventory.add("item@basegame:8", 9995) // power source
|
||||
@@ -98,12 +100,12 @@ object PlayerBuilderSigrid {
|
||||
|
||||
inventory.add("item@basegame:11", 10) // calendar
|
||||
|
||||
inventory.add("item@basegame:256", 995) // doors
|
||||
inventory.add("item@basegame:257", 995) // doors
|
||||
inventory.add("item@basegame:258", 995) // doors
|
||||
inventory.add("item@basegame:259", 995) // doors
|
||||
// inventory.add("item@basegame:256", 995) // doors
|
||||
// inventory.add("item@basegame:257", 995) // doors
|
||||
// inventory.add("item@basegame:258", 995) // doors
|
||||
// inventory.add("item@basegame:259", 995) // doors
|
||||
|
||||
inventory.add("item@basegame:320", 1) // portal
|
||||
inventory.add("item@basegame:320", 5) // portal
|
||||
|
||||
WireCodex.getAll().forEach {
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
@@ -121,26 +120,10 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
// list of [Score, Ingredients, Recipe]
|
||||
recipes.map { recipe ->
|
||||
// list of (Item, How many player has, How many the recipe requires)
|
||||
val items = recipe.ingredients.map { ingredient ->
|
||||
val selectedItem = if (ingredient.keyMode == CraftingCodex.CraftingItemKeyMode.TAG) {
|
||||
// If the player has the required item, use it; otherwise, will take an item from the ItemCodex
|
||||
player.itemList.filter { (itm, qty) ->
|
||||
ItemCodex[itm]?.tags?.contains(ingredient.key) == true && qty >= ingredient.qty
|
||||
}.maxByOrNull { it.qty }?.itm ?: ((ItemCodex.itemCodex.firstNotNullOfOrNull { if (it.value.hasTag(ingredient.key)) it.key else null }) ?: throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed"))
|
||||
}
|
||||
else {
|
||||
ingredient.key
|
||||
}
|
||||
|
||||
val howManyPlayerHas = player.searchByID(selectedItem)?.qty ?: 0L
|
||||
|
||||
val howManyTheRecipeWants = ingredient.qty
|
||||
|
||||
listOf(selectedItem, howManyPlayerHas, howManyTheRecipeWants)
|
||||
}
|
||||
val items = recipeToIngredientRecord(player, recipe, listOf(/*todo: nearby crafting stations*/))
|
||||
|
||||
val score = items.fold(1L) { acc, item ->
|
||||
(item[1] as Long).times(16L) + 1L
|
||||
(item.howManyPlayerHas).times(16L) + 1L
|
||||
}
|
||||
|
||||
listOf(score, items, recipe)
|
||||
@@ -545,4 +528,36 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
data class RecipeIngredientRecord(
|
||||
val selectedItem: ItemID,
|
||||
val howManyPlayerHas: Long,
|
||||
val howManyRecipeWants: Long,
|
||||
val craftingStationAvailable: Boolean,
|
||||
)
|
||||
|
||||
/**
|
||||
* 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 (nearbyCraftingStations.isEmpty()) true else nearbyCraftingStations.contains(recipe.workbench)
|
||||
return recipe.ingredients.map { ingredient ->
|
||||
val selectedItem = if (ingredient.keyMode == CraftingCodex.CraftingItemKeyMode.TAG) {
|
||||
// If the player has the required item, use it; otherwise, will take an item from the ItemCodex
|
||||
inventory.itemList.filter { (itm, qty) ->
|
||||
ItemCodex[itm]?.tags?.contains(ingredient.key) == true && qty >= ingredient.qty
|
||||
}.maxByOrNull { it.qty }?.itm ?: ((ItemCodex.itemCodex.firstNotNullOfOrNull { if (it.value.hasTag(ingredient.key)) it.key else null }) ?: throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed"))
|
||||
}
|
||||
else {
|
||||
ingredient.key
|
||||
}
|
||||
|
||||
val howManyPlayerHas = inventory.searchByID(selectedItem)?.qty ?: 0L
|
||||
val howManyTheRecipeWants = ingredient.qty
|
||||
|
||||
RecipeIngredientRecord(selectedItem, howManyPlayerHas, howManyTheRecipeWants, hasStation)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.torvald.terrarum.UIItemInventoryCatBar
|
||||
import net.torvald.terrarum.ceilToInt
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.itemproperties.CraftingCodex
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2022-06-28.
|
||||
@@ -44,12 +45,19 @@ 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 }
|
||||
}
|
||||
|
||||
override fun rebuild(filter: Array<String>) {
|
||||
// TODO test fill craftingRecipes with every possible recipes in the game
|
||||
// filtering policy: if the player have all the ingredient item (regardless of the amount!), make the recipe visible
|
||||
craftingRecipes.clear()
|
||||
CraftingRecipeCodex.props.forEach { (_, recipes) -> craftingRecipes.addAll(recipes) }
|
||||
// end of test fill
|
||||
CraftingRecipeCodex.props.forEach { (_, recipes) ->
|
||||
recipes.forEach {
|
||||
// TODO check for nearby crafting stations
|
||||
if (isCraftable((parentUI as UICrafting).getPlayerInventory(), it, listOf(/*todo: nearby crafting stations*/))) craftingRecipes.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
recipesSortList.clear() // kinda like the output list
|
||||
|
||||
|
||||
Reference in New Issue
Block a user