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

local prefabs =
{
    "staffmeteor",

}



local summonchance = 0.30
local function MeteorChance(inst, owner)

 if math.random() < summonchance then
SpawnPrefab("amuletmeteor").Transform:SetPosition(inst.Transform:GetWorldPosition())

end
end



local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_body", "torso_lunarammy", "purpleamulet")
   owner:ListenForEvent("attacked", MeteorChance, owner)
	   if inst.components.fueled then
        inst.components.fueled:StartConsuming()
    end

end

local function onunequip(inst, owner)
    owner.AnimState:ClearOverrideSymbol("swap_body")


    owner:RemoveEventCallback("attacked", MeteorChance, owner)

	    if inst.components.fueled then
        inst.components.fueled:StopConsuming()
    end

end


local function fn()
	local inst = CreateEntity()

	local trans = inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("amulets")
    inst.AnimState:SetBuild("lunarammy")
    inst.AnimState:PlayAnimation("blueamulet")

    inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end


    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = FUELTYPE.USAGE
    inst.components.fueled:InitializeFuelLevel(TUNING.RAINCOAT_PERISHTIME)
    inst.components.fueled:SetDepletedFn(inst.Remove)

	inst:AddComponent("inspectable")
	inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "lunarammy"
    inst.components.inventoryitem.atlasname = "inventoryimages/lunarammy.xml"







	inst:AddComponent("equippable")
  if EQUIPSLOTS["NECK"] then --for additional equipslot mods
    inst.components.equippable.equipslot = EQUIPSLOTS.NECK
  else
    inst.components.equippable.equipslot = EQUIPSLOTS.BODY
  end
  inst.components.equippable.walkspeedmult = 1.1

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

	MakeHauntableLaunch(inst)

	return inst
end

return Prefab( "lunarammy", fn, assets, prefabs)
