local assets=
{
	Asset("ANIM", "anim/marblblade.zip"),
	Asset("ANIM", "anim/swap_marblblade.zip"),
	Asset("IMAGE", "inventoryimages/marblblade.tex"),
	Asset("ATLAS", "inventoryimages/marblblade.xml"),
}

local function onequip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_object", "swap_marblblade", "swap_nightmaresword")
	owner.AnimState:Show("ARM_carry")
	owner.AnimState:Hide("ARM_normal")
	owner.mad_save_hungerrate = owner.components.hunger.burnrate
	--owner.components.hunger:SetRate(TUNING.MAD_MARBLBLADE.hungerrate)
	owner.components.hunger.burnrate = TUNING.MAD_MARBLBLADE.hungerrate
 end

local function onunequip(inst, owner)
	owner.AnimState:Hide("ARM_carry")
	owner.AnimState:Show("ARM_normal")
	if owner.components.hunger.burnrate ~= owner.mad_save_hungerrate
		and owner.components.hunger.burnrate ~= TUNING.MAD_MARBLBLADE.hungerrate
	then
		--Не как было и не как мы установили. Значит, поменялось в процессе. Значит, это и есть правильное значение.
		--Запоминаем еще раз, чтобы тут же вспомнить.
		owner.mad_save_hungerrate = owner.components.hunger.burnrate
	end
	--owner.components.hunger:SetRate(owner.mad_save_hungerrate or 1)
	owner.components.hunger.burnrate = owner.mad_save_hungerrate
	owner.mad_save_hungerrate = nil --Подчищаем за собой
end

local function onattack(inst, attacker, target)
	if attacker and attacker.components.sanity then
		attacker.components.hunger:DoDelta(TUNING.MAD_MARBLBLADE.hungerdelta)
	end
end

local function fn(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
	local anim = inst.entity:AddAnimState()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("nightmaresword")
	inst.AnimState:SetBuild("marblblade")
	inst.AnimState:PlayAnimation("idle")
	--inst.AnimState:SetMultColour(1, 1, 1, 1)

	inst:AddTag("sharp")
	inst:AddTag("marble")

	inst.entity:SetPristine()
	if not TheWorld.ismastersim then
		return inst
	end

	inst:AddComponent("weapon")
	inst.components.weapon:SetDamage(TUNING.MAD_MARBLBLADE.damage)
	inst.components.weapon:SetOnAttack(onattack)

	inst:AddComponent("finiteuses")
	inst.components.finiteuses:SetMaxUses(TUNING.MAD_MARBLBLADE.uses)
	inst.components.finiteuses:SetUses(TUNING.MAD_MARBLBLADE.uses)
	inst.components.finiteuses:SetOnFinished( inst.Remove )

	inst:AddComponent("inspectable")

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "inventoryimages/marblblade.xml"
	inst:AddComponent("equippable")
	inst.components.equippable.walkspeedmult = TUNING.MAD_MARBLBLADE.walkspeedmult --0.85
	inst.components.equippable:SetOnEquip( onequip )
	inst.components.equippable:SetOnUnequip( onunequip )

	MakeHauntableLaunch(inst)

	return inst
end

return Prefab( "common/inventory/marblblade", fn, assets)
