local assets =
{
	Asset("ANIM", "anim/spmace.zip"),
	Asset("ANIM", "anim/swap_spmace.zip"),
    Asset("ATLAS", "inventoryimages/spmace.xml"),
}

local function onattack(inst, attacker, target)
	local groundpound = SpawnPrefab("groundpoundring_fx")
	local pos = target:GetPosition()
	groundpound.Transform:SetPosition(pos.x, pos.y, pos.z)
	groundpound.Transform:SetScale(0.3, 0.3, 0.3)

	local groundpound2 = SpawnPrefab("groundpound_fx")
	local pos = target:GetPosition()
	groundpound2.Transform:SetPosition(pos.x, pos.y, pos.z)
	groundpound2.Transform:SetScale(0.3, 0.3, 0.3)
end

local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_spmace", "swap_spear")
    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 fn(Sim)
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("spear")
    inst.AnimState:SetBuild("spmace")
    inst.AnimState:PlayAnimation("idle")

    inst:AddTag("sharp")

    if not TheWorld.ismastersim then
        return inst
    end

    inst.entity:SetPristine()

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(TUNING.SPMACE_DAMAGE)
		inst.components.weapon:SetOnAttack(onattack)
    -------

    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.SPMACE_USES)
    inst.components.finiteuses:SetUses(TUNING.SPMACE_USES)

    inst.components.finiteuses:SetOnFinished(inst.Remove)

    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "inventoryimages/spmace.xml"

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

    MakeHauntableLaunch(inst)

    return inst
end

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