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

--[[
local function ShouldAcceptItem(inst, item)
    if item.prefab == "xinp" then
       return true
    end
    return false
end

local function onfinished(inst)

	inst:Remove()
end
]]


local jishu = 0

local function onAttackxt(inst, attacker, target)
if target:HasTag("monster") then
		target:DoTaskInTime(5, function() target.components.health:DoDelta(-2) end)
		attacker.components.locomotor:SetExternalSpeedMultiplier(inst, "datai", 2)
		attacker:DoTaskInTime(4, function() attacker.components.locomotor:SetExternalSpeedMultiplier(inst, "datai", 1) end)
end

        jishu = jishu + 1
		--local suofang = jishu * 0.1
		--attacker.old_min_attack_period = attacker.components.combat.min_attack_period 
		--attacker.components.combat.min_attack_period = 0.6 - suofang
 
if jishu >= 2 then
	attacker.components.combat.min_attack_period = 0.1
attacker:DoTaskInTime(20, function() 
		jishu = 0
		attacker.components.combat.min_attack_period = 0.6
		
		end)

end
		


end




local function onequip(inst, owner)
if owner.prefab == "xjj" then
    owner.AnimState:OverrideSymbol("swap_object", "swap_xiaotai", "swap_xiaotai")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
	else
		owner:DoTaskInTime(0, function()
			local pand = owner.components.inventory 
			if pand then
				pand:GiveItem(inst)
			end
			local talker = owner.components.talker 
			if talker then
				talker:Say("还是给小姐姐用吧~~QWQ!")
			end
		end)
	end

end

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

end

--[[
local function OnGetItemFromPlayer(inst, giver, item)
   
	 if item.prefab == "xinp" then
       inst.components.finiteuses.current = inst.components.finiteuses.current + inst.components.finiteuses.total *0.2
    end
    if inst.components.finiteuses.current > inst.components.finiteuses.total then
       inst.components.finiteuses.current = inst.components.finiteuses.total
    end
end


local function OnRefuseItem(inst, giver, item)
	if item.prefab ~= "xinp" then
		inst.components.talker:Say("需要芯片来修复!")
	end
end
]]
local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

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

    inst:AddTag("sharp")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(36)

    -------
    inst.components.weapon:SetRange(1.7)
    inst.components.weapon:SetOnAttack(onAttackxt)
	--[[
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(400)
    inst.components.finiteuses:SetUses(400)
	if inst.components.finiteuses.current < 0 then
       inst.components.finiteuses.current = 0
    end
	inst.components.finiteuses:SetOnFinished( onfinished )
]]
    inst:AddComponent("inspectable")
 --[[   
	inst:AddComponent("trader")
	inst.components.trader.onaccept = OnGetItemFromPlayer
    inst.components.trader:SetAcceptTest(ShouldAcceptItem)
 inst.components.trader.onrefuse = OnRefuseItem
 ]]
    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "xiaotai"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/xiaotai.xml"

    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)
	
		inst:AddComponent("talker")
    inst.components.talker.fontsize = 36
    inst.components.talker.font = TALKINGFONT
    inst.components.talker.colour = Vector3(.9, .4, .4)
    inst.components.talker.offset = Vector3(0, 0, 0)
    inst.components.talker.symbol = "swap_object"



    MakeHauntableLaunch(inst)

    return inst
end

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