Jump to content

[Help Request] Custom Character Resource in recipes


Recommended Posts

Hey all,

I've got a custom character resource (filth) for a goblin character I'm working on. I've got the resource ticking away, interactable, with the same sort of interfaces available to health and sanity (I think).

I am currently trying to add some character-specific recipes which use this resource in the same way that a reviver uses a chunk of current health.

  • I have added my FILTH value to CHARACTER_INGREDIENTS
  • I have added recipes to modmain in the structure of:
AddRecipe("takblowdart_poison",
	{
		Ingredient("cutreeds", 1), 
		Ingredient("flint", 1), 
		Ingredient(GLOBAL.CHARACTER_INGREDIENT.FILTH, 25)
	},
	RECIPETABS.WAR, 
	{
		SCIENCE = 0
	}, 
	nil, nil, nil, nil, "TakTheGoblin",
	"images/inventoryimages/blowdart_purple.xml", 
	"blowdart_purple.tex"
	)

 

 

The issue APPEARS to be that I don't know how to inform the game about my new resource as an ingredient. 

I have started looking at the code around recipe & builder, but I'm rapidly leaving my depth (given that not too long ago I didn't know lua, I feel OK about this).

I have tried to inject my own logic into some of recipe & builder's work by adding the following to my modmain trying to make anywhere I can see the game evaluate character ingredients also evaluate mine... but it's not working, and I'm stuck.  For reference:

local recipeclass = G.Ingredient--require "recipe"
local old_IsCharacterIngredient = recipeclass.IsCharacterIngredient
recipeclass.IsCharacterIngredient = function (ingredienttype)
	local oici = old_IsCharacterIngredient(ingredienttype)
	print("INJECT:recipe.IsCharIngredient1")
	print("INJECT:recipe.IsCharIngredient["..oici.ingredienttype.."]["..oici.is_character_ingredient[ingredienttype].."]["..oici.."]")

	return oici 
end

local builder = require "components/builder"
local old_RemoveIngredients = builder.RemoveIngredients
builder.RemoveIngredients = function(ingredients, recname)
	local ori = old_RemoveIngredients(ingredients, recname)
	local recipe = G.AllRecipes[recname]
    if recipe then
        for k,v in pairs(recipe.character_ingredients) do
        	print("INJECT: evaluating an ingredient with type "..tostring(v.type))
            if v.type == CHARACTER_INGREDIENT.FILTH then
            	print("INJECT: found filth to remove ingredient")
            	self.inst.components.filth:DoDelta(-v.amount)
        	elseif v.type == CHARACTER_INGREDIENT.MAX_FILTH then
        		 local b = nil --intentionally blank, dnt want anything modifying maxfilth
            end
        end
    end
    --self.inst:PushEvent("consumeingredients")

    return ori
end

local old_HasCharacterIngredient = builder.HasCharacterIngredient
builder.HasCharacterInrgedient = function(ingredient)
 	local ohci = old_HasCharacterIngredient(ingredient)
 	print("INJECT: HasCharIngredient")
 	if ingredient.type == CHARACTER_INGREDIENT.FILTH then
 		print("INJECT: found filth in ingredient")
        if self.inst.components.filth ~= nil then
            --round up filth to match UI display
            local current = math.ceil(self.inst.components.filth:GetFilth())
            return current >= ingredient.amount, current
        end
    elseif ingredient.type == CHARACTER_INGREDIENT.MAX_FILTH then
        if self.inst.components.filth ~= nil then
            local penalty = self.inst.components.filth:GetPenaltyPercent()
            return penalty + ingredient.amount <= TUNING.MAXIMUM_SANITY_PENALTY, 1 - penalty
        end
    end
    return

 

So a few questions:

  1. Can someone please explain to me how saving a function from a class and returning it works? Am I doing it right? I feel like I should be able to somehow access members of the function as if it were a table, but I cant figure out how to do so (for example in the code above, how can I access AllRecipes as the Builder class knows it during runtime? It always appears to be empty when this code runs?)
  2. Is there a 'checklist' of things to do to add a custom CHARACTER_INGREDIENT to the game such that it is recognized in the recipe tab/chooser and build processes? What am I missing?

Thanks in advance,

Regards,

Mr Boosch

Edited by mrboosch
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...