mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
metal working station and recipes
This commit is contained in:
@@ -20,9 +20,15 @@
|
||||
]
|
||||
},
|
||||
"item@basegame:17": { /* basic smelter */
|
||||
"workbench": "",
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [
|
||||
[1, 20, "$ROCK", 10, "item@basegame:25"] /* 1 smelter = 20 rocks, 10 clay balls */
|
||||
[1, 40, "$ROCK", 20, "item@basegame:25"] /* 1 smelter = 40 rocks, 20 clay balls */
|
||||
]
|
||||
},
|
||||
"item@basegame:27": { /* metalworking */
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [
|
||||
[1, 20, "$ROCK", 10, "item@basegame:25", 10, "item@basegame:113"] /* 1 smelter = 20 rocks, 10 clay balls, 10 iron ingots */
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"item@basegame:14": { /* wooden pick */
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [[1, 6, "$WOOD", 2, "item@basegame:18"]]
|
||||
"ingredients": [[1, 6, "$WOOD", 2, "item@basegame:18"]] /* 6 woods, 2 sticks */
|
||||
},
|
||||
/*"item@basegame:22": {
|
||||
"workbench": "basiccrafting",
|
||||
@@ -18,5 +18,44 @@
|
||||
"item@basegame:24": { /* stone axe */
|
||||
"workbench": "basiccrafting",
|
||||
"ingredients": [[1, 6, "$ROCK", 2, "item@basegame:18"]]
|
||||
},
|
||||
|
||||
"item@basegame:1": { /* copper pick */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:112", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
},
|
||||
"item@basegame:2": { /* iron pick */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:113", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
},
|
||||
"item@basegame:3": { /* steel pick */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:26", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
},
|
||||
|
||||
"item@basegame:12": { /* copper sledgehammer */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:112", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
},
|
||||
"item@basegame:4": { /* iron sledgehammer */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:113", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
},
|
||||
"item@basegame:13": { /* steel sledgehammer */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:26", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
},
|
||||
|
||||
"item@basegame:19": { /* copper sledgehammer */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:112", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
},
|
||||
"item@basegame:20": { /* iron sledgehammer */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:113", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
},
|
||||
"item@basegame:21": { /* steel sledgehammer */
|
||||
"workbench": "basiccrafting,metalworking",
|
||||
"ingredients": [[1, 6, "item@basegame:26", 2, "item@basegame:18"]] /* 6 bars, 2 sticks */
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ id;classname
|
||||
23;net.torvald.terrarum.modulebasegame.gameitems.PickaxeStone
|
||||
24;net.torvald.terrarum.modulebasegame.gameitems.AxeStone
|
||||
25;net.torvald.terrarum.modulebasegame.gameitems.ItemClayBall
|
||||
26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel
|
||||
27;net.torvald.terrarum.modulebasegame.gameitems.ItemMetalworkingStation
|
||||
|
||||
# ingots
|
||||
112;net.torvald.terrarum.modulebasegame.gameitems.IngotCopper
|
||||
|
||||
|
BIN
assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil.tga
LFS
Normal file
Binary file not shown.
BIN
assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil_illum.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil_illum.tga
LFS
Normal file
Binary file not shown.
@@ -106,7 +106,9 @@ class CraftingCodex {
|
||||
|
||||
|
||||
data class CraftingRecipe(val workbench: String, val ingredients: Array<CraftingIngredients>, val moq: Long, val product: ItemID, val addedBy: String)
|
||||
data class CraftingIngredients(val key: String, val keyMode: CraftingItemKeyMode, val qty: Long)
|
||||
data class CraftingIngredients(val key: String, val keyMode: CraftingItemKeyMode, val qty: Long) {
|
||||
override fun toString() = "$qty ${if (keyMode == CraftingItemKeyMode.TAG) "\$$key" else "$key"}"
|
||||
}
|
||||
enum class CraftingItemKeyMode { VERBATIM, TAG }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Lightbox
|
||||
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2023-12-05.
|
||||
*/
|
||||
class FixtureMetalworkingStation : FixtureBase, CraftingStation {
|
||||
|
||||
@Transient override val spawnNeedsFloor = true
|
||||
@Transient override val tags = listOf("metalworking")
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 3, 2), // temporary value, will be overwritten by spawn()
|
||||
nameFun = { Lang["ITEM_SMELTER_BASIC"] }
|
||||
) {
|
||||
CommonResourcePool.addToLoadingList("particles-tiki_smoke.tga") {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "particles/bigger_smoke.tga"), 16, 16)
|
||||
}
|
||||
CommonResourcePool.loadAll()
|
||||
|
||||
|
||||
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/metalworking_furnace_and_anvil.tga")
|
||||
// val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/metalworking_furnace_and_anvil_illum.tga") // put this sprite to the hypothetical "SpriteIllum"
|
||||
|
||||
density = BlockCodex[Block.STONE].density.toDouble()
|
||||
setHitboxDimension(itemImage.texture.width, itemImage.texture.height, 0, 0)
|
||||
|
||||
makeNewSprite(TextureRegionPack(itemImage.texture, itemImage.texture.width, itemImage.texture.height)).let {
|
||||
it.setRowsAndFrames(1,1)
|
||||
}
|
||||
/*makeNewSpriteGlow(TextureRegionPack(itemImage2.texture, itemImage.texture.width, itemImage.texture.height)).let {
|
||||
it.setRowsAndFrames(1,1)
|
||||
}*/
|
||||
|
||||
actorValue[AVKey.BASEMASS] = 100.0
|
||||
|
||||
mainUIopenFun = { ui ->
|
||||
(mainUI as? UIInventoryFull)?.openCrafting(mainUI!!.handler)
|
||||
}
|
||||
}
|
||||
|
||||
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TerrarumAppConfiguration.TILE_SIZED * 2, TerrarumAppConfiguration.TILE_SIZED * 2), Cvec(0.5f, 0.18f, 0f, 0f)))
|
||||
|
||||
@Transient private val actorBlocks = arrayOf(
|
||||
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
|
||||
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION),
|
||||
)
|
||||
override fun placeActorBlocks() {
|
||||
forEachBlockbox { x, y, ox, oy ->
|
||||
val tile = actorBlocks[oy][ox]
|
||||
if (tile != null) {
|
||||
world!!.setTileTerrain(x, y, tile, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var nextDelay = 0.25f
|
||||
private var spawnTimer = 0f
|
||||
|
||||
@Transient private var mainUIhookHackInstalled = false
|
||||
override fun update(delta: Float) {
|
||||
// adding UI to the fixture as players may right-click on the workbenches instead of pressing a keyboard key
|
||||
(INGAME as? TerrarumIngame)?.let { ingame ->
|
||||
if (!mainUIhookHackInstalled && ingame.uiInventoryPlayerReady) {
|
||||
mainUIhookHackInstalled = true
|
||||
this.mainUI = ingame.uiInventoryPlayer // this field is initialised only after a full load so this hack is necessary
|
||||
}
|
||||
}
|
||||
|
||||
super.update(delta)
|
||||
|
||||
|
||||
// emit smokes TODO: only when hot
|
||||
if (spawnTimer >= nextDelay) {
|
||||
(Terrarum.ingame as TerrarumIngame).addParticle(
|
||||
ParticleVanishingSprite(
|
||||
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
|
||||
25f, true, hitbox.startX + TerrarumAppConfiguration.TILE_SIZED, hitbox.startY + 21, false, (Math.random() * 256).toInt()
|
||||
)
|
||||
)
|
||||
|
||||
spawnTimer -= nextDelay
|
||||
nextDelay = Math.random().toFloat() * 0.25f + 0.25f
|
||||
|
||||
(sprite as? SheetSpriteAnimation)?.delays?.set(0, Math.random().toFloat() * 0.4f + 0.1f)
|
||||
}
|
||||
|
||||
spawnTimer += delta
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
it.setRowsAndFrames(1,1)
|
||||
}*/
|
||||
|
||||
actorValue[AVKey.BASEMASS] = 50.0
|
||||
actorValue[AVKey.BASEMASS] = 100.0
|
||||
|
||||
mainUIopenFun = { ui ->
|
||||
(mainUI as? UIInventoryFull)?.openCrafting(mainUI!!.handler)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2023-12-05.
|
||||
*/
|
||||
class ItemMetalworkingStation(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureMetalworkingStation") {
|
||||
|
||||
|
||||
override var baseMass = 100.0
|
||||
override val isDynamic = false
|
||||
override val materialId = ""
|
||||
override val itemImage: TextureRegion
|
||||
get() = getItemImageFromSingleImage("basegame", "sprites/fixtures/metalworking_furnace_and_anvil.tga")
|
||||
|
||||
override var baseToolSize: Double? = baseMass
|
||||
override var originalName = "ITEM_METALWORKING_STATION"
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import net.torvald.terrarum.gameitems.ItemID
|
||||
class ItemSmelterBasic(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureSmelterBasic") {
|
||||
|
||||
|
||||
override var baseMass = 50.0
|
||||
override var baseMass = 100.0
|
||||
override val isDynamic = false
|
||||
override val materialId = ""
|
||||
override val itemImage: TextureRegion
|
||||
|
||||
@@ -153,6 +153,11 @@ class OreLead(originalID: ItemID) : OreItemBase(originalID) {
|
||||
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(8,6)
|
||||
}
|
||||
|
||||
class IngotSteel(originalID: ItemID) : OreItemBase(originalID) {
|
||||
override var originalName = "ITEM_INGOT_IRON"
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(3,5)
|
||||
}
|
||||
class IngotCopper(originalID: ItemID) : OreItemBase(originalID) {
|
||||
override var originalName = "ITEM_INGOT_COPPER"
|
||||
override val itemImage: TextureRegion
|
||||
|
||||
@@ -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
|
||||
|
||||
BIN
work_files/graphics/sprites/fixtures/metalworking_furnace_and_anvil.kra
LFS
Normal file
BIN
work_files/graphics/sprites/fixtures/metalworking_furnace_and_anvil.kra
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user