local assets =
{
	-- Sound files used by the item.
	Asset("SOUNDPACKAGE", "sound/flyswatter.fev"),
	Asset("SOUND", "sound/flyswatter1.fsb"),

	-- Animation files used for the item.
	Asset("ANIM", "anim/flyswatter.zip"),
	Asset("ANIM", "anim/swap_flyswatter.zip"),

	-- Inventory image and atlas file used for the item.
    Asset("ATLAS", "images/inventoryimages/flyswatter.xml"),
    Asset("IMAGE", "images/inventoryimages/flyswatter.tex"),
}

local function OnAttack(inst, attacker, target)
    inst.SoundEmitter:PlaySound("flyswatter/flyswatter1/flyswatter")
end

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

local function onequip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_object", -- Symbol to override.
    	"swap_flyswatter", -- Animation bank we will use to overwrite the symbol.
    	"swap_flyswatter") -- Symbol to overwrite it with.
    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 init()
	local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("flyswatter")
    inst.AnimState:SetBuild("flyswatter")
    inst.AnimState:PlayAnimation("flyswatter")

	if TheSim:GetGameID()=="DST" then
		inst.entity:AddNetwork()
		
		if not TheWorld.ismastersim then
			return inst
		end

		inst.entity:SetPristine()
		
		MakeHauntableLaunch(inst)
	end
	
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(15)
	inst.components.weapon.onattack = OnAttack

    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/flyswatter.xml"
    inst.components.inventoryitem.imagename = "flyswatter"
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)

	inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(20)
    inst.components.finiteuses:SetUses(20)
	
	inst.components.finiteuses:SetOnFinished( onfinished )
    
    return inst
end


return Prefab("common/inventory/flyswatter", init, assets)