local assets =
{
    Asset("ANIM", "anim/bloodpump.zip"),
	
	Asset("ATLAS", "images/inventoryimages/des_heart_green.xml"),
	Asset("ATLAS", "images/inventoryimages/des_heart_normal.xml"),
}

local function beat(inst)
    inst.AnimState:PlayAnimation("idle")
	inst.SoundEmitter:PlaySound("dontstarve/ghost/ghost_howl")
    inst.beattask = inst:DoTaskInTime(.75 + math.random() * .75, beat)
end

local function ondropped(inst)
    if inst.beattask ~= nil then
        inst.beattask:Cancel()
    end
	
	--TUNING.PLAYER_HEART_WORKS_WITH
	if inst.type=="green" then ---charge
		local skel = nil
		if TUNING.PLAYER_HEART_WORKS_WITH == 1 then
			skel = FindEntity(inst, 2, function(guy) return (guy.prefab == "skeleton" or guy.prefab == "skeleton_player" or guy.prefab == "mound")end)
		else
			skel = FindEntity(inst, 2, function(guy) return (guy.prefab == "skeleton" or guy.prefab == "skeleton_player" or guy.prefab == "mound" or guy.prefab == "firepit")end)
		end
		
		if skel then
			inst.charged = skel
		else
			inst.charged = nil
		end
		
	end
	
	if inst.charged or inst.type == "normal" then
		if inst.light then inst.light:Enable(true) end
		inst.beattask = inst:DoTaskInTime(.75 + math.random() * .75, beat)
	end
end

local function onpickup(inst)
	if inst.light then inst.light:Enable(false) end
	
	inst.charged = nil
    if inst.beattask ~= nil then
        inst.beattask:Cancel()
        inst.beattask = nil
    end
end

function MakeHeart(name)

local function fn()
    local inst = CreateEntity()
	inst.type = name
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()

	
	inst.light = inst.entity:AddLight()
	local light = inst.light
	light:SetIntensity(.6)
	light:SetRadius(.5)
	light:SetFalloff(.6)
	light:Enable(false)
	light:SetColour(175/255, 70/255, 70/255)

	
	
	
	
    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("bloodpump01")
    inst.AnimState:SetBuild("bloodpump")
    inst.AnimState:PlayAnimation("idle")



	
	
	if name == "green" then
		inst.AnimState:SetMultColour(0.3,0.85,0.3,1)
		light:SetColour(75/255, 255/255, 50/255)

	else
		inst.AnimState:SetMultColour(1, 0.85,0.85,1)
	end
	
	
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem:SetOnDroppedFn(ondropped)
    inst.components.inventoryitem:SetOnPickupFn(onpickup)

    inst:AddComponent("inspectable")

	inst.components.inventoryitem.atlasname = "images/inventoryimages/des_heart_"..name..".xml"

	
	
    inst.beattask = nil
    ondropped(inst)

	return inst
	
	end
	
	
    return Prefab("common/des_heart_"..name, fn, assets) 
end


return MakeHeart("green"),
MakeHeart("normal")