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

 local ser = 0

local function SpawnIceFx(inst, target)
    if not inst then return end
    ser = 0   
    inst.SoundEmitter:PlaySound("dontstarve/creatures/deerclops/swipe")
    
    local numFX = math.random(15,20)
    local pos = inst:GetPosition()
    local targetPos = target and target:GetPosition()
    local vec = targetPos - pos
    vec = vec:Normalize()
    local dist = pos:Dist(targetPos)
    local angle = inst:GetAngleToPoint(targetPos:Get())

    for i = 1, numFX do
        inst:DoTaskInTime(math.random() * 0.25, function(inst)
            local prefab = "icespike_fx_"..math.random(1,4)
            local fx = SpawnPrefab(prefab)
            if fx then
                local x = GetRandomWithVariance(0, 5)
                local z = GetRandomWithVariance(0, 5)
                local offset = (vec * math.random(dist * 0.25, dist)) + Vector3(x,0,z)
                fx.Transform:SetPosition((offset+pos):Get())
                
                local x,y,z = fx.Transform:GetWorldPosition()
                
                --每根冰柱的伤害半径
                local r = 2.5
                
                --每根冰柱的伤害
                local dmg = 45
                
                local ents = TheSim:FindEntities(x,y,z,r)
                for k, v in pairs(ents) do
                
                    ----发招忽略队友
                    if v and v.components.health and not v.components.health:IsDead() and v.components.combat and
                        v ~= inst and
                        not (v.components.follower and v.components.follower.leader == inst ) and 
                        (TheNet:GetPVPEnabled() or not v:HasTag("player"))
                    then
                            v.components.combat:GetAttacked( inst, dmg )
                        
                        if v.components.freezable then
                            v.components.freezable:AddColdness(2)
                            v.components.freezable:SpawnShatterFX()
                        end
                        
                    end
                end
                
            end
        end)
    end
end




local function onequip(inst, owner)
inst:AddTag("feng")
    owner.AnimState:OverrideSymbol("swap_object", "swap_jingang", "swap_jingang")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")

end

local function onunequip(inst, owner)
inst:RemoveTag("feng")
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
inst:DoTaskInTime(0.001,function()inst:Remove()end)
end


--[[local function tishi(inst)
	 if ser >=4 then
	attacker.components.talker:Say("金钢枪破已就绪")

local x, y, z = target.Transform:GetWorldPosition()
	SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get())
		--target.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")

end	

end	
]]

local function longlinatt(weapon, attacker, target)
	
	 ser = ser + 1
	 
	--[[ if target.components.sleeper and target.components.sleeper:IsAsleep() then
        target.components.sleeper:WakeUp()
    end
    if target.components.burnable then
        if target.components.burnable:IsBurning() then
            target.components.burnable:Extinguish()
        elseif target.components.burnable:IsSmoldering() then
            target.components.burnable:SmotherSmolder()
        end
    end

    if target.components.combat then
        target.components.combat:SuggestTarget(attacker)
    end

    if target.sg and not target.sg:HasStateTag("frozen") then
        target:PushEvent("attacked", {attacker = attacker, damage = 0})
    end

    if target.components.freezable then
        target.components.freezable:AddColdness(0.7)
        target.components.freezable:SpawnShatterFX()
    end]]
	 
	 
	 --tishi(inst)
	 if ser >=4 then
	attacker.components.talker:Say("金钢枪破已就绪")

--local x, y, z = target.Transform:GetWorldPosition()
	--SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get())
	local x, y, z = target.Transform:GetWorldPosition()
	local fx = SpawnPrefab("statue_transition")
	fx.Transform:SetPosition(x, y, z)
	fx.Transform:SetScale(2,2,2)
	
	
end
	 
 	if attacker and ser >=5 then

	    SpawnIceFx(attacker, target)
        attacker.components.hunger:DoDelta(-2)
	    attacker.components.sanity:DoDelta(-1)
	end
end




local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

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

    inst:AddTag("sharp")
    inst:AddTag("frozen")
    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

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

    -------
    inst.components.weapon:SetRange(1.8)
inst.components.weapon:SetOnAttack(longlinatt)


    inst:AddComponent("inspectable")

	    inst:AddComponent("heater")
        inst.components.heater:SetThermics(false, true)
        inst.components.heater.equippedheat = 60
		
		inst:AddComponent("insulator")
        inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
        inst.components.insulator:SetSummer()
		
    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "tisuiya"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/tisuiya.xml"

			--[[inst:AddComponent("talker")
    inst.components.talker.fontsize = 26
    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"]]
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)



    MakeHauntableLaunch(inst)

    return inst
end

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