Skip to content

Commit

Permalink
Redid how remnants work in crafting and fixed so that you do not get …
Browse files Browse the repository at this point in the history
…remnants when an ingredient was saved from being consumed using the glyph Daear
  • Loading branch information
brightrim committed Jan 14, 2025
1 parent 5723eea commit b07dd66
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 120 deletions.
75 changes: 62 additions & 13 deletions craft/base/crafts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,58 @@ local daear = require("magic.arcane.enchanting.effects.daear")
local ilyn = require("magic.arcane.enchanting.effects.ilyn")
local magic = require("base.magic")
local texts = require("magic.base.texts")
local bottles = require("item.bottles")

local M = {}

local itemsWithRemnants = {
-- Instead of having to add a remnant each time an item that should have one is in a recipe,
-- this list means we only have to put the remnant in once and no one will forget to add the corresponding remnant anymore.
-- Also necessary in order for the script to know when a remnant is to not be given due to daear procs..
{id = Item.lampOil, remnant = Item.oilBottle},
{id = Item.bucketOfWater, remnant = Item.bucket},
{id = Item.blackDye, remnant = Item.bucket},
{id = Item.greenDye, remnant = Item.bucket},
{id = Item.blueDye, remnant = Item.bucket},
{id = Item.redDye, remnant = Item.bucket},
{id = Item.yellowDye, remnant = Item.bucket},
{id = Item.whiteDye, remnant = Item.bucket},
{id = Item.bottleOfInk, remnant = Item.emptyInkBottle},
{id = Item.beeHoney, remnant = Item.emptyHoneyJar},
{id = Item.firewaspHoney, remnant = Item.emptyHoneyJar},
{id = Item.eggSalad, remnant = Item.soupBowl},
{id = Item.bottleOfBlackberryJuice, remnant = Item.emptyJuiceBottle},
{id = Item.bottleOfStrawberryJuice, remnant = Item.emptyJuiceBottle},
{id = Item.blueberryJuice, remnant = Item.emptyJuiceBottle},
{id = Item.cloudberryJuice, remnant = Item.emptyJuiceBottle},
{id = Item.raspberryJuice, remnant = Item.emptyJuiceBottle},
{id = Item.deerberryJuice, remnant = Item.emptyJuiceBottle},
{id = Item.elderberryJuice, remnant = Item.emptyJuiceBottle},
{id = Item.bottleOfCabbageJuice, remnant = Item.vegetableJuiceBottle},
{id = Item.bottleOfCarrotJuice, remnant = Item.vegetableJuiceBottle},
{id = Item.bellpepperJuice, remnant = Item.vegetableJuiceBottle},
{id = Item.cucumberJuice, remnant = Item.vegetableJuiceBottle},
{id = Item.pumpkinJuice, remnant = Item.vegetableJuiceBottle},
{id = Item.tomatoJuice, remnant = Item.vegetableJuiceBottle},
{id = Item.bottleOfGrapeJuice, remnant = Item.fruitJuiceBottle},
{id = Item.bottleOfOrangeJuice, remnant = Item.fruitJuiceBottle},
{id = Item.bottleOfTangerineJuice, remnant = Item.fruitJuiceBottle},
{id = Item.bottleOfBananaJuice, remnant = Item.fruitJuiceBottle},
{id = Item.appleJuice, remnant = Item.fruitJuiceBottle},
{id = Item.cherryJuice, remnant = Item.fruitJuiceBottle},
{id = Item.pearJuice, remnant = Item.fruitJuiceBottle},
{id = Item.mangoJuice, remnant = Item.fruitJuiceBottle},
{id = Item.peachJuice, remnant = Item.fruitJuiceBottle},
{id = Item.plumJuice, remnant = Item.fruitJuiceBottle},
{id = Item.pineappleJuice, remnant = Item.fruitJuiceBottle}
}

for _, bottle in pairs(bottles.bottles) do -- Since bottles conveniently already have the remnants listed, we just add that to the list using the existing one
table.insert(itemsWithRemnants, {id = bottle.full[1], remnant = bottle.empty[1]}) -- The bottle is always listed first, the rest are serving jugs and such that are not used in crafting
end

M.itemsWithRemnants = itemsWithRemnants -- for use in construction

local function checkRequiredMana(user, craftingTime, isPortalBookCrafting) -- Portal book creation uses the standard craft script to create the books, but requires mana consumption

if not isPortalBookCrafting then
Expand Down Expand Up @@ -70,8 +119,7 @@ local foodRarityTexts = {
local Product = {
quantity = 1,
ingredients = {},
difficulty = 0,
remnants = {},
difficulty = 0
}

function Product:new(p) -- new: constructor
Expand Down Expand Up @@ -140,12 +188,6 @@ function Product:addIngredient(item, quantity, data)
table.insert(self["ingredients"], {["item"]=item, ["quantity"]=quantity, ["data"]=data})
end

function Product:addRemnant(item, quantity, data)
quantity = quantity or 1
data = data or {}
table.insert(self["remnants"], {["item"]=item, ["quantity"]=quantity, ["data"]=data})
end

function Craft:addProduct(categoryId, itemId, quantity, data)
local difficulty = math.min(world:getItemStatsFromId(itemId).Level, 100)
local learnLimit = math.min(difficulty + 20, 100)
Expand All @@ -160,8 +202,7 @@ function Craft:addProduct(categoryId, itemId, quantity, data)
["learnLimit"] = learnLimit,
["quantity"] = quantity,
["data"] = data,
["ingredients"] = {},
["remnants"] = {},
["ingredients"] = {}
})

if self.categories[categoryId].minSkill then
Expand Down Expand Up @@ -776,6 +817,8 @@ function Craft:createItem(user, productId, toolItem)
local amountOfIngredients = #product.ingredients
local ingredientSaved = false

local itemsToReturnAsRemnants = {}

for i = 1, amountOfIngredients do

local ingredient = product.ingredients[i]
Expand All @@ -797,6 +840,12 @@ function Craft:createItem(user, productId, toolItem)
end
end

for _, remnant in pairs(itemsWithRemnants) do -- If the item has a corresponding remnant item, it gets added to the list for later
if ingredient.item == remnant.id and (totalToDelete - toSave > 0) then
table.insert(itemsToReturnAsRemnants, { id = remnant.remnant, amount = totalToDelete - toSave}) -- If the glyph saves any, the -toSave ensures that we dont return extra remnant items
end
end

if regularIngredients >= totalToDelete then -- Prioritises consuming normal items over rare ones
regularItemsToDelete = totalToDelete
else
Expand Down Expand Up @@ -859,10 +908,10 @@ function Craft:createItem(user, productId, toolItem)
common.CreateItem(user, product.item, product.quantity, quality, product.data)
end

for i=1, #product.remnants do
local remnant = product.remnants[i]
common.CreateItem(user, remnant.item, remnant.quantity, 333, remnant.data)
for _, remnant in pairs(itemsToReturnAsRemnants) do
common.CreateItem(user, remnant.id, remnant.amount, 333, {})
end

end

M.Product = Product
Expand Down
21 changes: 0 additions & 21 deletions craft/final/baking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ catId = baking:addCategory("Baked goods", "Backwaren")
product = baking:addProduct(catId, 191, 1)
product:addIngredient(2, 1) -- flour
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

-- cookies
product = baking:addProduct(catId, 453, 2)
product:addIngredient(2, 3) -- flour
product:addIngredient(Item.beeHoney, 1)
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket
product:addRemnant(Item.emptyHoneyJar, 1)

-- baked potato
product = baking:addProduct(catId, 3568, 1)
Expand All @@ -59,76 +56,61 @@ product = baking:addProduct(catId, 49, 1)
product:addIngredient(2, 4) -- flour
product:addIngredient(3567, 3) -- potato
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

-- sausage on bread
product = baking:addProduct(catId, 3631, 1)
product:addIngredient(2, 4) -- flour
product:addIngredient(3051, 2) -- sausage
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

-- banana bread
product = baking:addProduct(catId, 3609, 1)
product:addIngredient(2, 4) -- flour
product:addIngredient(785, 1) -- bottle of banana juice
product:addRemnant(Item.fruitJuiceBottle,1) -- empty juice bottle

-- blackberry muffin
product = baking:addProduct(catId, 454, 1)
product:addIngredient(2, 3) -- flour
product:addIngredient(Item.beeHoney, 2)
product:addRemnant(Item.emptyHoneyJar, 2)
product:addIngredient(147, 15) -- blackberry
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

-- apple pie
product = baking:addProduct(catId, 353, 1)
product:addIngredient(2, 4) -- flour
product:addIngredient(Item.beeHoney, 2)
product:addRemnant(Item.emptyHoneyJar, 2)
product:addIngredient(15, 20) -- apple
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

-- cherry cake
product = baking:addProduct(catId, 303, 1)
product:addIngredient(2, 4) -- flour
product:addIngredient(Item.beeHoney, 2)
product:addRemnant(Item.emptyHoneyJar, 2)
product:addIngredient(302, 20) -- cherries
product:addIngredient(759, 5) -- nuts
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

-- egg salad sandwich
product = baking:addProduct(catId, 3571, 1)
product:addIngredient(2, 1) -- flour
product:addIngredient(3570, 1) -- egg salad
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket
product:addRemnant(2935,1) -- soup bowl

-- strawberry cake
product = baking:addProduct(catId, 354, 1)
product:addIngredient(2, 4) -- flour
product:addIngredient(Item.beeHoney, 3)
product:addRemnant(Item.emptyHoneyJar, 3)
product:addIngredient(151, 20) -- strawberry
product:addIngredient(1150, 2) -- white egg
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

-- nut bread
product = baking:addProduct(catId, 3723, 1)
product:addIngredient(2, 4) -- flour
product:addIngredient(Item.beeHoney, 3)
product:addRemnant(Item.emptyHoneyJar, 3)
product:addIngredient(759, 20) -- nuts
product:addIngredient(1150, 3) -- white egg
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

-- custard pie
product = baking:addProduct(catId, 1153, 1)
Expand All @@ -137,8 +119,6 @@ product:addIngredient(1150, 10) -- white egg
product:addIngredient(778, 4) -- sugarcane
product:addIngredient(2502, 1) -- bottle of milk
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket
product:addRemnant(2498,1) -- large empty bottle

-- elderberry pie
product = baking:addProduct(catId, 3610, 1)
Expand All @@ -148,7 +128,6 @@ product:addIngredient(81, 5) -- berries
product:addIngredient(1207, 5) -- orange
product:addIngredient(778, 4) -- sugarcane
product:addIngredient(52, 1) -- bucket of water
product:addRemnant(51, 1) -- bucket

M.baking = baking
return M
Loading

0 comments on commit b07dd66

Please sign in to comment.