1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Choose the best Old Gods themed skin at the Texturing Contest #29 - Poll!
    Dismiss Notice
  3. Melee Mapping Contest #2 - Poll is up! Vote for the best competitive 1v1 map!
    Dismiss Notice
  4. Please help test custom maps and more on the latest PTR!
    Dismiss Notice
  5. Evolution complete! Make Darwin proud and go vote in the Techtree Contest #12 - Poll.
    Dismiss Notice
  6. Icon Contest #17 - Results are out! Step by to congratulate our winners!
    Dismiss Notice
  7. We've created the Staff Job Openings thread. We're currently in need of icon, video production, and social/multimedia positions to be filled. Thank you!
    Dismiss Notice

Recipe System

Submitted by Chaosy
This bundle is marked as substandard. It may contain bugs, not perform optimally or otherwise be in violation of the submission rules.
A simple API for combining multiple items into one.

Check the demo code for simple API usage.

Code (WurstScript):

package Hello

import LinkedListModule
import LinkedList

function unit.craft() returns LinkedList<int>
    LinkedList<ItemRecipe> recipes = getRecipes()
    LinkedList<int> craftables = new LinkedList<int>()

    for ItemRecipe ir in recipes
        if(this.canCraft(ir))
            craftables.push(ir.craftable)
   
    return craftables

function getRecipes() returns LinkedList<ItemRecipe>
    return ItemRecipe.getRecipes()

function unit.canCraft(ItemRecipe recipe) returns boolean
    return recipe.canCraft(this)

function unit.getInventory() returns LinkedList<item>
    LinkedList<item> list = new LinkedList<item>()

    for int i = 0 to 5
        item tempItem = this.itemInSlot(i)
        if(tempItem != null)
            list.push(tempItem)

    return list

function unit.hasItem(int id, int quantity) returns boolean
    LinkedList<item> inventory = this.getInventory()
    int count = 0

    for item i in inventory
        if(i.getTypeId() == id)
            count ++

    return count >= quantity

class ItemComponent
    int component
    int quantity
    construct(int id, int count)
        component = id
        quantity = count

class ItemRecipe
    use LinkedListModule
    LinkedList<ItemComponent> components = new LinkedList<ItemComponent>()
    int craftable
    construct(int id)
        craftable = id

    function addComponent(int id, int quantity)
        components.push(new ItemComponent(id, quantity))

    static function getRecipes() returns LinkedList<thistype>
        LinkedList<thistype> recipes = new LinkedList<thistype>()
        let iterator = iterator()

        for segment from iterator
            recipes.push(segment)
           
        return recipes
   
    function canCraft(unit u) returns boolean
        bool craftable = true
        for ItemComponent ic in components
            if(u.hasItem(ic.component, ic.quantity) == false)
                craftable = false
                break

        return craftable

   
unit u
init
    // Create recipe and add components
    new ItemRecipe('shar')
    ..addComponent('whwd', 2)
    ..addComponent('pghe', 1)
    ..addComponent('phlt', 1)

    // Crafting Demo

    u = createUnit(players[0], 'Hpal', vec2(0, 0), angle(0))
   
    // try to craft on esc press

    CreateTrigger()
    ..registerPlayerEvent(players[0], EVENT_PLAYER_END_CINEMATIC)
    ..addAction() ->
        print(u.getName() + " is crafting!")
        let ids = u.craft()
        if(ids.size() > 0)
            print("The following items can be crafted: ")
            for id in ids
                let i = createItem(id, vec2(0, 0))
                print(i.getName())
                i.remove()
        else
            print("No items can be crafted")
Contents

Recipe System (Map)

Reviews
MyPad
Remarks: Due to another resource being recently approved, specifically ItemRecipe, ... this has been moved to Substandard. However, by being moved here, the moderator does not wish to insinuate that the resource is buggy, or done with minimal...
  1. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,022
    Resources:
    2
    Models:
    1
    Icons:
    1
    Resources:
    2
    This is what I got from the preview triggers. Please note that this is subject to changes, and may soon be overridden.

    NOTES:


    • Function unit.getInventroy() is a typo; but a trivial one. Suggest renaming it to getInventory?
    • In lambda expression found in addAction,
      () -> begin
      can be converted to
      ->
      .
    • The end keyword in the lambda expression can be omitted.
    • Documentation could be added.
    From my understanding of the script, the system does not automatically combine items when picking them up as there is no function exposing these. A hotdoc of the class is probably in order here for clarity.

    Overall, I think that this could be a good system for Wursters.
     
  2. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,210
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    1. Wopsie. Will fix.
    2/3. really? I will defiantly do that if it works for me.

    The system was meant as a core to build around, my original idea was to make a separate system which handles the actual crafting.
    But I need this to be approved first.

    edit: whaaaat, that somehow works? O_O
    interesting.
     
    Last edited: Mar 26, 2018
  3. BlueSaint

    BlueSaint

    Joined:
    Jun 18, 2012
    Messages:
    2,652
    Resources:
    3
    Tools:
    1
    Spells:
    2
    Resources:
    3
    Yeah: Best of the Wurst 5
     
  4. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,022
    Resources:
    2
    Models:
    1
    Icons:
    1
    Resources:
    2

    Remarks:


    • Due to another resource being recently approved, specifically ItemRecipe, ...
    • this has been moved to Substandard.
    • However, by being moved here, the moderator does not wish to insinuate that the resource is buggy, or done with minimal effort. Rather, the resource has been deprecated by the aforementioned resource.

    Status:


    • Substandard
     
  5. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,135
    Resources:
    17
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    17
    This looks pretty great to me - I like the simplicity.

    For a demo I would like to see the API usage script separate from the implementation - not clear to me which parts are built-in and which parts are convenience functions.

    Would also be good to see some documentation about the high-level API and some explanation about intended uses/limitations.

    Finally, I guess applying generic constraints over recipes like unit type of crafter, time of day, etc could somehow be added to the API (using some kind of constraing function that accepts a closure) - what do you think?

    4 stars from me
     
  6. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,210
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    There are plenty of things which I could have done, and possibly would have done.
    But another system was made, and while I possibly could compete with it.. I do not really see the need for doing so right now.

    If I am a bit naive, I might hope to create something even better but I do not think it is worth the time investment for a very minor improvement.