local assets=
{
	Asset("ANIM", "anim/mushasword2.zip"),
	Asset("ANIM", "anim/swap_mushasword2.zip"),
    	Asset("ATLAS", "images/inventoryimages/mushasword2.xml"),
	Asset("IMAGE", "images/inventoryimages/mushasword2.tex"),

}

local function onfinished(inst)
    inst:Remove()
end

local function onequip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_object", "swap_mushasword2", "swap_nightmaresword")
    owner.AnimState:Show("ARM_carry") 
    owner.AnimState:Hide("ARM_normal") 
end

local function onunequip(inst, owner) 
    owner.AnimState:Hide("ARM_carry") 
    owner.AnimState:Show("ARM_normal") 
end


local function onattack(inst, owner, target)
    if owner.components.health and owner.components.health:GetPercent() < 1 and not target:HasTag("wall") then
        owner.components.health:DoDelta(TUNING.SPEAR_DRAIN,false,"spear")
        owner.components.sanity:DoDelta(TUNING.SPEAR_DRAIN * 0.5)
    end

end

local function onattack(inst, attacker, data)
	if attacker then
		SpawnPrefab("lightning").Transform:SetPosition(inst:GetPosition():Get())
	end
end

local function fn(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
	local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("nightmaresword")
    anim:SetBuild("mushasword2")
    anim:PlayAnimation("idle")
    
    inst:AddTag("dull")

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(30)
    inst.components.weapon.onattack = onattack
    

    -------
    
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES*1.5)
    inst.components.finiteuses:SetUses(TUNING.SPEAR_USES*1.5)
    
    inst.components.finiteuses:SetOnFinished( onfinished )

    inst:AddComponent("inspectable")
    inst:AddComponent("inventoryitem")


    	inst.components.inventoryitem.atlasname = "images/inventoryimages/mushasword2.xml"

    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
    
    return inst
end

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