Advanced Recipe book.

0 favourites
  • 7 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • I would like to know how to make an advanced recipe book with 20+ different categories.

    It is for an RPG for crafting.

    It is going to have a lot of recipes so I think Ajax is needed to prevent loading unneeded files.

    I am not sure if I would use JSON or XML, because I am not sure how to organize it for search by name, type, and ingredients.

    Also need to know how to hide a few from search for restrictions.

    Such as level or if recipe isn't unlocked yet.

    An example Capx would be great, but an explanation would work as well.

    I am thinking I will need a XML/JSON for the craft that has the recipe and a XML/JSON for each ingredient that has the names of the crafts the ingredient is in.

    Would I do Category the same? How would I show the recipe list in alphabetical order?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I would use JSON, simply because it is easier and more human readable.

    If you have lots of sub-attributes and categories or abstractions, then XML is better.

  • So am I right on organizing them? If a Hammer has ingredients of wood and iron then I would have three separate XML files.

    One for wood, one for iron and one with craftable items (hammer, basket, hat)?

    If user searches hammer then it will show wood and iron.

    If user searches wood then hammer will show up.

    If user searches wood and iron then I can compare and still bring up hammer since it is in both?

    If I search leaf and wood then hammer would not show up because hammer isn't under leaf.

    I assume I would compare the the leaf and wood XML and remove the ones that don't match.

    I am not sure how to do that. Would I somehow use an array to compare?

    Would this be the best way?

  • Also need to know how to hide a few from search for restrictions.

    Such as level or if recipe isn't unlocked yet.

    An example Capx would be great, but an explanation would work as well.

    I am thinking I will need a XML/JSON for the craft that has the recipe and a XML/JSON for each ingredient that has the names of the crafts the ingredient is in.

    Would I do Category the same? How would I show the recipe list in alphabetical order?

    While XML has a higher learning curve and is more of a pain to modify (I wrote an excel macro just to convert tables into the desired XML text output), it would be faster and easier to implement all the other functionality you want for this with XML. The reason for that is XPath queries. For JSON I think you would need to setup custom logic to get query-like functionality which you need for the recipe system features you desire (hiding unavailable recipes). Depending on what you need and how you organize the data, it can be more of a hassle but maybe that's just my ignorant opinion. I always used XML for these kinds of game databases (mostly for items, but not only).

    If you are already familiar with XML and XPath queries I would suggest XML as it will result in less stuff to debug within C2. Issue with it is human-readability, preparing the file itself and getting the XPath queries right.

    If I would be doing a system such as yours (actually I will need to do one, but probably after I get the skill trees fully working and combat turn logic working). I would do it as below:

    1) All recipes are stored within one XML file database. Every recipe is a single <recipe> element. The <recipe> element should have an attribute called "Output" and "OutputQuanity", these would define the item created and the quantity of the item created. You can also have additional attributes such as "Type", "ClassNeeded", "LevelNeeded" so that you can narrow down and filter the recipe list via XPath easily.

    Under each <recipe> element you would have <ingredient> child element. These <ingredient> elements should have an attribute called "QuantityNeeded". That would define how much of the ingredient would be needed to create one output batch of items.

    2) Now the hard part. What is an ingredient and how to check for it? There are two approaches here I can think of. The easy one is "each ingredient is a unique item", think WoW crafting. Then you just need to check the relevant inventory object (probably an array) with the player's items for the item named as the ingredient. If you are getting crafting materials directly from the natural source or resource nodes (mining copper veins, chopping trees for wood etc.). In this case the ingredients themselves would be listed with all the other items in an item XML object.

    The hard approach is what Fallout 4 did (yes, that game actually managed to not take the easy route with some RPG-ish mechanics, shocking I know), have ingredients not exist only as items, but as properties of other items. Say a telephone is made out of some copper and plastic. So basically allow breaking down junk items into components. This system is more realistic and depending on the theme of the game (in Fallout 4's case, a post-apocalyptic world of jury-rigging and salvage prospecting) may fit better. In this case your item system would need to be amended with data on what and how can be broken down into what. Also you would might want to add some logic to allow automatic breaking down of junk items when crafting a specific recipe, but that would also require additional logic to identify what can be broken down.

    3) Regardless of a picked approach at the end you need to show the available recipes via the games GUI, as a list. You will need an array. What I would do is fill this array using an xml object and the "for each node" condition, after entering an xpath query. So on a list refresh the array would have its width set to 0, next the query would be entered (you can build this dynamically out of function parameters with some text string appending) and the array would be filled by entering a new array X element for each node of the XML file returned by the XPath query. The main issue here really is setting up the XPath queries correctly. XPath is quite powerful but it is easy to make a mistake and get a broken query that does nothing, especially when building the XPath query dynamically based on function paremeters.

    4) Finally once the use selects one of the listed recipes (or for all visible recipes), you will need to use the XPath to the particular recipe (or for each recipe), get its components and check if they are in the required quantity in the player's inventory.

  • So am I right on organizing them? If a Hammer has ingredients of wood and iron then I would have three separate XML files.

    One for wood, one for iron and one with craftable items (hammer, basket, hat)?

    If user searches hammer then it will show wood and iron.

    If user searches wood then hammer will show up.

    If user searches wood and iron then I can compare and still bring up hammer since it is in both?

    If I search leaf and wood then hammer would not show up because hammer isn't under leaf.

    I assume I would compare the the leaf and wood XML and remove the ones that don't match.

    I am not sure how to do that. Would I somehow use an array to compare?

    Would this be the best way?

    As I wrote in my post above, have ALL recipes in one XML file. Have them as parent nodes of their <ingredient> nodes. Then all you would need is an XPath query saying return all recipe nodes where the ingredient child is wood OR iron. If you had an XPath query searching for recipes using wood OR leaf, the hammer would show up on the list. No need to eliminate anything yourself, Xpath would return only nodes containing either of the ingredients. That would be it.

    Well, the issue would be constructing an XPath query string dynamically based on inputs to the "search list recipes with specified properties" function. That requires some planning on what you want the player to able to search for.

  • I made an example showing how to filter/search for recipes by ingredient(s) used:

    https://www.dropbox.com/s/eo2ym6av6bqnm ... .capx?dl=1

    It should also show the XPath query used for filtering only the recipes containing the given selected components. There's also some extra attributes that could also be used in the searching but I was too lazy to do any GUI for them or implement the functionality.

    It also shows the quantity of the recipe output and the quantity of the component inputs. XML code is below (its also in the capx)

    Recipes:

    <?xml version="1.0"?>
    <recipes>
    <recipe name="Hammer" qty="1" lvl="3" type="weapon">
    	<component qty="2">Wood</component>
    	<component qty="1">Iron Bar</component>
    </recipe>
    <recipe name="Healing Salve" qty="3" lvl="1" type="consumable">
    	<component qty="2">Leaf</component>
    	<component qty="1">Wood</component>
    	<component qty="1">Medicinal Herb</component>
    </recipe>
    <recipe name="Staff of Bashing" qty="1" lvl="1" type="weapon">
    	<component qty="3">Wood</component>
    </recipe>
    <recipe name="Leaf Skirt" qty="1" lvl="2" type="armor">
    	<component qty="10">Leaf</component>
    	<component qty="2">Leather</component>
    </recipe>
    <recipe name="Short Sword" qty="1" lvl="5" type="weapon">
    	<component qty="7">Iron Bar</component>
    	<component qty="2">Leather</component>
    </recipe>
    </recipes>[/code:3atbg7v1]
    
    Items:
    
    [code:3atbg7v1]<?xml version="1.0"?>
    
    <items>
    <item type="armor" sprite="0" MaxStack="1">Leaf Skirt</item>
    <item type="weapon" sprite="0" MaxStack="1">Staff of Bashing</item>
    <item type="weapon" sprite="1" MaxStack="1">Hammer</item>
    <item type="weapon" sprite="2" MaxStack="1">Short Sword</item>
    <item type="component" sprite="0" MaxStack="99">Leaf</item>
    <item type="component" sprite="1" MaxStack="99">Iron Bar</item>
    <item type="component" sprite="2" MaxStack="99">Wood</item>
    <item type="component" sprite="3" MaxStack="99">Leather</item>
    <item type="component" sprite="4" MaxStack="99">Medicinal Herb</item>
    <item type="consumable" sprite="0" MaxStack="99">Healing Salve</item>
    
    </items>[/code:3atbg7v1]
  • So am I right on organizing them? If a Hammer has ingredients of wood and iron then I would have three separate XML files.

    One for wood, one for iron and one with craftable items (hammer, basket, hat)?

    If user searches hammer then it will show wood and iron.

    If user searches wood then hammer will show up.

    If user searches wood and iron then I can compare and still bring up hammer since it is in both?

    If I search leaf and wood then hammer would not show up because hammer isn't under leaf.

    I assume I would compare the the leaf and wood XML and remove the ones that don't match.

    I am not sure how to do that. Would I somehow use an array to compare?

    Would this be the best way?

    Yea, that looks good. The alternative is to do a backwards search through parameters, which would take considerable cpu power.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)