{
  "settings": {
    "is_borderless": false,
    "is_cloneable": false,
    "is_initial_spawning_enabled": true,
    "is_void_button_visible": true,
    "void_filter": []
  },
  "elements": {
    "Mine": {
      "display": "Mine",
      "class": "lead",
      "is_static": true,
      "description": "Combine with one or more working pickaxes. All selected pickaxes lose 10% durability. Each reaction produces Stone, with a 35% chance of an extra resource."
    },
    "Stone Pickaxe": {
      "display": [
        "Stone Pickaxe [",
        {
          "type": "bind",
          "target": {
            "name": "durability",
            "precision": 0
          }
        },
        "%]"
      ],
      "class": "lead",
      "is_static": true,
      "is_cloneable": true,
      "description": "Durability belongs to this pickaxe only. Clone it to make an independent copy. Broken pickaxes are removed. Repair at the Workshop.",
      "custom_props": {
        "durability": {
          "scope": "local",
          "type": "number",
          "value": 100,
          "events": {
            "min": {
              "value": 0
            },
            "max": {
              "value": 100
            }
          }
        }
      }
    },
    "Workshop": {
      "display": "Workshop",
      "class": "cyan",
      "is_static": true,
      "description": "Combine with one or more damaged pickaxes to repair the entire selected group."
    },
    "Shop": {
      "display": "Shop",
      "class": "gold",
      "is_static": true,
      "description": "Combine with one or more priced resources to sell them."
    },
    "Money": {
      "display": [
        "Money: $",
        {
          "type": "bind",
          "target": {
            "name": "amount",
            "precision": 0
          }
        }
      ],
      "class": "gold",
      "is_static": true,
      "description": "Selling resources at the Shop increases it.",
      "custom_props": {
        "amount": {
          "type": "number",
          "value": 0,
          "events": {
            "min": {
              "value": 0
            }
          }
        }
      }
    },
    "Stone": {
      "display": "Stone",
      "class": "lead",
      "description": [
        "Price: $",
        {
          "type": "bind",
          "target": {
            "name": "cost",
            "precision": 0
          }
        },
        ". Sell at the Shop."
      ],
      "custom_props": {
        "cost": {
          "type": "number",
          "value": 1
        }
      }
    },
    "Copper Ore": {
      "display": "Copper Ore",
      "class": "gold",
      "description": [
        "Price: $",
        {
          "type": "bind",
          "target": {
            "name": "cost",
            "precision": 0
          }
        },
        ". Sell at the Shop."
      ],
      "custom_props": {
        "cost": {
          "type": "number",
          "value": 5
        }
      }
    },
    "Coal": {
      "display": "Coal",
      "class": "dark",
      "description": [
        "Price: $",
        {
          "type": "bind",
          "target": {
            "name": "cost",
            "precision": 0
          }
        },
        ". Sell at the Shop."
      ],
      "custom_props": {
        "cost": {
          "type": "number",
          "value": 3
        }
      }
    },
    "Iron Ore": {
      "display": "Iron Ore",
      "class": "lead",
      "description": [
        "Price: $",
        {
          "type": "bind",
          "target": {
            "name": "cost",
            "precision": 0
          }
        },
        ". Sell at the Shop."
      ],
      "custom_props": {
        "cost": {
          "type": "number",
          "value": 8
        }
      }
    }
  },
  "events": {
    "on_start": [
      "Mine",
      "Stone Pickaxe",
      "Stone Pickaxe",
      "Workshop",
      "Shop",
      "Money"
    ],
    "on_join": [],
    "on_leave": []
  },
  "functions": {
    "sell": {
      "args": {
        "price": {
          "type": "number"
        }
      },
      "result": [
        {
          "type": "set",
          "target": {
            "id": "Money",
            "name": "amount"
          },
          "value": {
            "type": "computed",
            "expression": "g('Money', 'amount') + arg('price')"
          }
        }
      ]
    }
  },
  "reactions": [
    {
      "reagents": [
        "Mine",
        {
          "id": "Stone Pickaxe",
          "filter": "l(el_uuid(), 'durability') > 0",
          "limit": -1,
          "alias": "tools"
        }
      ],
      "result": [
        {
          "type": "set",
          "target": {
            "from": "tools",
            "id": "Stone Pickaxe",
            "limit": -1,
            "name": "durability"
          },
          "value": {
            "type": "computed",
            "expression": "l(el_uuid(), 'durability') - 10"
          }
        },
        "Stone",
        {
          "type": "if",
          "condition": "randf() < 0.35",
          "then": [
            {
              "type": "spawn",
              "element": {
                "type": "computed",
                "expression": "['Copper Ore', 'Coal', 'Iron Ore'].pick_random()"
              }
            }
          ]
        },
        {
          "type": "remove",
          "target": {
            "from": "tools",
            "filter": "l(el_uuid(), 'durability') <= 0",
            "limit": -1
          }
        }
      ]
    },
    {
      "reagents": [
        "Workshop",
        {
          "id": "Stone Pickaxe",
          "filter": "l(el_uuid(), 'durability') < 100",
          "limit": -1,
          "alias": "damaged_tools"
        }
      ],
      "result": [
        {
          "type": "set",
          "target": {
            "from": "damaged_tools",
            "id": "Stone Pickaxe",
            "limit": -1,
            "name": "durability"
          },
          "value": 100
        }
      ]
    },
    {
      "reagents": [
        "Shop",
        {
          "filter": "g(el_id(), 'cost') != null",
          "limit": -1,
          "alias": "goods"
        }
      ],
      "result": [
        {
          "type": "call",
          "function": "sell",
          "target": { "from": "goods", "limit": -1 },
          "args": {
            "price": {
              "type": "computed",
              "expression": "g(el_id(), 'cost')"
            }
          }
        }
      ]
    }
  ]
}
