--[[
BY
 _____   _____   __   _  
|  _  \ /  _  \ |  \ | | 
| | | | | | | | |   \| | 
| | | | | | | | | |\   | 
| |_| | | |_| | | | \  | 
|_____/ \_____/ |_|  \_| 

]]

PrefabFiles = {
"doncandymachine",
"doncandycoin",
}

Assets = {
	Asset("ATLAS", "images/inventoryimages/doncandymachine.xml"),
	Asset("IMAGE", "images/inventoryimages/doncandymachine.tex"),
	
	Asset("IMAGE", "images/minimap/doncandymachine_icon.tex"),
	Asset("ATLAS", "images/minimap/doncandymachine_icon.xml"),
	
	Asset("ATLAS", "images/inventoryimages/doncandycoin.xml"),
    Asset("IMAGE", "images/inventoryimages/doncandycoin.tex"),
}

AddMinimapAtlas("images/minimap/doncandymachine_icon.xml")




local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
local RECIPETABS = GLOBAL.RECIPETABS
local Recipe = GLOBAL.Recipe
local Ingredient = GLOBAL.Ingredient
local TECH = GLOBAL.TECH


local materialcoin = ""
local quantcoin = 0

if GetModConfigData("set_preco_coin") == "1goldrock" then
	materialcoin = "goldnugget"
	quantcoin = 1
elseif GetModConfigData("set_preco_coin") == "2goldrock" then
	materialcoin = "goldnugget"
	quantcoin = 2
elseif GetModConfigData("set_preco_coin") == "1rock" then
	materialcoin = "rocks"
	quantcoin = 1
elseif GetModConfigData("set_preco_coin") == "2rock" then
	materialcoin = "rocks"
	quantcoin = 2
elseif GetModConfigData("set_preco_coin") == "1flint" then
	materialcoin = "flint"
	quantcoin = 1
elseif GetModConfigData("set_preco_coin") == "2flint" then
	materialcoin = "flint"
	quantcoin = 2
end

if materialcoin == "" or quantcoin <= 0 then
	materialcoin = "goldnugget"
	quantcoin = 1
end

AddRecipe("doncandymachine", {Ingredient("log", 4),Ingredient("transistor", 3),Ingredient("gears", 1)}, GLOBAL.RECIPETABS.FARM, GLOBAL.TECH.SCIENCE_ONE, "doncandymachine_placer", nil, nil, nil, nil, "images/inventoryimages/doncandymachine.xml", "doncandymachine.tex" )

if GetModConfigData("usedubloonincandymachine") == "n" then
	AddRecipe("doncandycoin", {Ingredient(materialcoin, quantcoin)}, GLOBAL.RECIPETABS.REFINE, GLOBAL.TECH.SCIENCE_ONE, nil, nil, nil, nil, nil, "images/inventoryimages/doncandycoin.xml", "doncandycoin.tex" )
end



--SET INIFINITE USE:
AddPrefabPostInit("doncandymachine", function(inst) 
	if GetModConfigData("inifite_use_candy_machine") == "y" then
		inst.isinfiniteuse = true
	else
		inst.isinfiniteuse = false
	end
	if GetModConfigData("wonderful_candys") == "y" then
		inst.iswonderfulcandys = true
	else
		inst.iswonderfulcandys = false
	end	
	
	if GetModConfigData("usedubloonincandymachine") == "y" then
		inst.currentcoinmachine = "dubloon"
	else
		inst.currentcoinmachine = "doncandycoin"
	end
end)