From ceea2ff1a24e93bc8eb5c50eaeba06dfef00347d Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 6 Dec 2023 00:22:35 +0900 Subject: [PATCH] metal working station and recipes --- assets/mods/basegame/crafting/fixtures.json | 10 +- assets/mods/basegame/crafting/tools.json | 41 ++++++- assets/mods/basegame/items/itemid.csv | 2 + .../metalworking_furnace_and_anvil.tga | 3 + .../metalworking_furnace_and_anvil_illum.tga | 3 + .../terrarum/itemproperties/CraftingCodex.kt | 4 +- .../gameactors/FixtureMetalworkingStation.kt | 104 ++++++++++++++++++ .../gameactors/FixtureSmelterBasic.kt | 2 +- .../gameitems/ItemMetalworkingStation.kt | 21 ++++ .../gameitems/ItemSmelterBasic.kt | 2 +- .../modulebasegame/gameitems/OreItemBase.kt | 5 + .../terrarum/modulebasegame/ui/UICrafting.kt | 2 +- .../ui/UIItemCraftingCandidateGrid.kt | 20 +++- .../metalworking_furnace_and_anvil.kra | 3 + 14 files changed, 212 insertions(+), 10 deletions(-) create mode 100644 assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil.tga create mode 100644 assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil_illum.tga create mode 100644 src/net/torvald/terrarum/modulebasegame/gameactors/FixtureMetalworkingStation.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemMetalworkingStation.kt create mode 100644 work_files/graphics/sprites/fixtures/metalworking_furnace_and_anvil.kra diff --git a/assets/mods/basegame/crafting/fixtures.json b/assets/mods/basegame/crafting/fixtures.json index 16c286033..1e51fa9b4 100644 --- a/assets/mods/basegame/crafting/fixtures.json +++ b/assets/mods/basegame/crafting/fixtures.json @@ -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 */ ] }, diff --git a/assets/mods/basegame/crafting/tools.json b/assets/mods/basegame/crafting/tools.json index 774e9d778..d901033c6 100644 --- a/assets/mods/basegame/crafting/tools.json +++ b/assets/mods/basegame/crafting/tools.json @@ -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 */ } } \ No newline at end of file diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index 9197d8511..baab7e31c 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -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 diff --git a/assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil.tga b/assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil.tga new file mode 100644 index 000000000..aa6c60b32 --- /dev/null +++ b/assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c7b96c618c66cf96cb0afaaf097759a3c9644114019c5adcec8d66ae54f272e +size 6162 diff --git a/assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil_illum.tga b/assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil_illum.tga new file mode 100644 index 000000000..6ce7067ba --- /dev/null +++ b/assets/mods/basegame/sprites/fixtures/metalworking_furnace_and_anvil_illum.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8700c6a2e3d5f9a09995058d4088090dfe7a64327f75d89599fc530daad05dda +size 6162 diff --git a/src/net/torvald/terrarum/itemproperties/CraftingCodex.kt b/src/net/torvald/terrarum/itemproperties/CraftingCodex.kt index fe45e8ee8..3011038b1 100644 --- a/src/net/torvald/terrarum/itemproperties/CraftingCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/CraftingCodex.kt @@ -106,7 +106,9 @@ class CraftingCodex { data class CraftingRecipe(val workbench: String, val ingredients: Array, 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 } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureMetalworkingStation.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureMetalworkingStation.kt new file mode 100644 index 000000000..faf6b1b23 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureMetalworkingStation.kt @@ -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 + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSmelterBasic.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSmelterBasic.kt index a14e1eb8f..d137b9784 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSmelterBasic.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSmelterBasic.kt @@ -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) diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMetalworkingStation.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMetalworkingStation.kt new file mode 100644 index 000000000..e43632cff --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMetalworkingStation.kt @@ -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" + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemSmelterBasic.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemSmelterBasic.kt index 6c55bce17..fc9f1bb1d 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemSmelterBasic.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemSmelterBasic.kt @@ -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 diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt index 8e59a3670..2c4ed2819 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt @@ -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 diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt index 6cbc34614..ce6090b3b 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt @@ -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): List { - 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 diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt index 587add182..ad772a0b8 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt @@ -61,7 +61,11 @@ class UIItemCraftingCandidateGrid( } private fun isCraftable(player: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List): 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) { +// 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 diff --git a/work_files/graphics/sprites/fixtures/metalworking_furnace_and_anvil.kra b/work_files/graphics/sprites/fixtures/metalworking_furnace_and_anvil.kra new file mode 100644 index 000000000..1122aa280 --- /dev/null +++ b/work_files/graphics/sprites/fixtures/metalworking_furnace_and_anvil.kra @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c96d054406ac12259547763bccfe1f5eba8144592f0bf9a4002d208d612d6ac3 +size 162384