local assets =
{
	Asset("ANIM", "anim/bug_swatter.zip"),
	Asset("ANIM", "anim/swap_bug_swatter.zip"),
}

local function onequip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_object", "swap_bug_swatter", "swap_bug_swatter")
    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 chance = 0.50
local chance_dragonfly = 0.50

local function onattack(inst, owner, target)
    if owner.components.health and target:HasTag("insect") then
		if math.random() < chance then
		inst.components.weapon:SetDamage(0)
		else		
		inst.components.weapon:SetDamage(102)
		end
	elseif target:HasTag("dragonfly") then
		if math.random() < chance_dragonfly then
		inst.components.weapon:SetDamage(0)
		else		
		inst.components.weapon:SetDamage(102)
		end
	elseif target:HasTag("spider") then
		inst.components.weapon:SetDamage(51)
	else
		inst.components.weapon:SetDamage(0)
	end
end

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("bug_swatter")
    inst.AnimState:SetBuild("bug_swatter")
    inst.AnimState:PlayAnimation("idle")

	inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("weapon")
--	inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE)
	inst.components.weapon.onattack = onattack
	
    -------
    
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES)
    inst.components.finiteuses:SetUses(TUNING.SPEAR_USES)
	inst.components.finiteuses:SetOnFinished(inst.Remove)

    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/bug_swatter.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)
	
    MakeHauntableLaunch(inst)
    
    return inst
end

STRINGS.NAMES.BUG_SWATTER								= "Bug Swatter"
STRINGS.RECIPE_DESC.BUG_SWATTER 						= "Effective against insects, when it hits."

STRINGS.CHARACTERS.GENERIC.DESCRIBE.BUG_SWATTER 		= "For killing bugs."
STRINGS.CHARACTERS.WILLOW.DESCRIBE.BUG_SWATTER 			= "I can practice my swinging with this."
STRINGS.CHARACTERS.WOLFGANG.DESCRIBE.BUG_SWATTER 		= "Is bug killer!"
STRINGS.CHARACTERS.WENDY.DESCRIBE.BUG_SWATTER 			= "Physical insecticide."
STRINGS.CHARACTERS.WX78.DESCRIBE.BUG_SWATTER 			= "DEBUGS A DIFFERENT KIND OF BUG."
STRINGS.CHARACTERS.WICKERBOTTOM.DESCRIBE.BUG_SWATTER 	= "It seems to deal damage against arthropods as well."
STRINGS.CHARACTERS.WOODIE.DESCRIBE.BUG_SWATTER 			= "It'll keep those skeeters away."
STRINGS.CHARACTERS.WAXWELL.DESCRIBE.BUG_SWATTER 		= "Those annoying bugs won't see it coming."
STRINGS.CHARACTERS.WATHGRITHR.DESCRIBE.BUG_SWATTER 		= "A weapon made for battling insects."
STRINGS.CHARACTERS.WEBBER.DESCRIBE.BUG_SWATTER 			= "Mom had this in the kitchen."

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