local assets = 
{
	Asset("ANIM", "anim/banyue.zip"),
	Asset("ANIM", "anim/liehuojianfa.zip"),
	Asset("ANIM", "anim/baofengxue.zip"),
	Asset("ANIM", "anim/diyuleiguang.zip"),
	Asset("ANIM", "anim/duanjin.zip"),
	Asset("ANIM", "anim/huoqiang.zip"),
	Asset("ANIM", "anim/huxiaoshanlin.zip"),
    Asset("ANIM", "anim/leidianshu.zip"),
	Asset("ANIM", "anim/zhihuihuanxing.zip"),
}

local function OnThrown(inst, owner, target)
	inst:FacePoint(Point(target.Transform:GetWorldPosition()))
	GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/boomerang_throw")
end

local function OnHit(inst, owner, target)
    local impactfx = SpawnPrefab("impact")
    if impactfx then
	    local follower = impactfx.entity:AddFollower()
	    follower:FollowSymbol(target.GUID, target.components.combat.hiteffectsymbol, 0, 0, 0 )
        impactfx:FacePoint(inst.Transform:GetWorldPosition())
    end
    inst:Remove()
end

local function banyue(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()

    anim:SetBank("banyue")
    anim:SetBuild("banyue")
    anim:PushAnimation("idle", true)
    trans:SetScale(1.25, 1.25, 1.25)
--    inst.Transform:SetFourFaced()

    MakeInventoryPhysics(inst)
    RemovePhysicsColliders(inst)

    inst:AddTag("projectile")
    inst:AddComponent("projectile")
    inst.components.projectile:SetSpeed(25)
    inst.components.projectile:SetOnMissFn(OnHit)
    inst.components.projectile:SetOnThrownFn(OnThrown)
    inst.components.projectile:SetLaunchOffset(Vector3(0, 0.2, 0))

    inst:AddTag("FX")
	inst:AddTag("NOCLICK")

    inst:ListenForEvent("animover", function() inst:Remove() end)
    return inst
end

local function liehuojianfa(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()

    anim:SetBank("liehuojianfa")
    anim:SetBuild("liehuojianfa")
    anim:PushAnimation("idle", true)
    trans:SetScale(5, 5, 5)

    inst:AddTag("FX")
	inst:AddTag("NOCLICK")
    return inst
end

local function baofengxue()
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()

    anim:SetBank("baofengxue")
    anim:SetBuild("baofengxue")
	anim:PlayAnimation("idle")
	anim:PushAnimation("idle", true)
    inst.Transform:SetFourFaced()
    MakeInventoryPhysics(inst)
    RemovePhysicsColliders(inst)

    trans:SetScale(4, 4, 4)

	inst:AddTag("FX")
	inst:AddTag("NOCLICK")

    inst:ListenForEvent("animover", function() inst:Remove() end)

    return inst
end

local function diyuleiguang(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()

    anim:SetBank("diyuleiguang")
    anim:SetBuild("diyuleiguang")
	anim:PlayAnimation("idle")
    anim:PushAnimation("idle", true)

    trans:SetScale(7, 7, 7)

    inst:AddTag("FX")
	inst:AddTag("NOCLICK")

	inst:DoTaskInTime(1, function() inst:Remove() end)
    return inst
end

local function duanjin(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()

    anim:SetBank("duanjin")
    anim:SetBuild("duanjin")
	anim:PlayAnimation("idle")
    anim:PushAnimation("idle", true)

    trans:SetScale(4, 4, 4)

    inst:AddTag("FX")
	inst:AddTag("NOCLICK")

	inst:DoTaskInTime(1, function() inst:Remove() end)
    return inst
end

local function huoqiang(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()

    anim:SetBank("huoqiang")
    anim:SetBuild("huoqiang")
	anim:PlayAnimation("idle")
    anim:PushAnimation("idle", true)

    trans:SetScale(6, 6, 6)

    inst:DoPeriodicTask(0.5, function()
    local pt = inst:GetPosition()
    local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, 2.5)
    for k,v in pairs(ents) do
        if v and v.components.health 
        and not v.components.health:IsDead() 
        and v.components.health.fire_damage_scale > 0
        and not v.components.yiyucast and not v:HasTag("wall")
        and v.components.combat then
            v.components.combat:GetAttacked(inst, GetPlayer().skill_LLv0*5)
        end
    end
    end)

    inst:AddTag("FX")
	inst:AddTag("NOCLICK")

	inst:DoTaskInTime(5, function() inst:Remove() end)
    return inst
end

local function leidianshu()
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()
    local light = inst.entity:AddLight()

    anim:SetBank("leidianshu")
    anim:SetBuild("leidianshu")
	anim:PlayAnimation("idle")
    anim:PushAnimation("idle", true)

    inst.Transform:SetScale(6,6,6)

    inst:AddTag("FX")
    inst:AddTag("NOCLICK")

	inst:DoTaskInTime(3, function() inst:Remove() end)
    return inst
end

local function huxiaoshanlin(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()

    anim:SetBank("huxiaoshanlin")
    anim:SetBuild("huxiaoshanlin")
	anim:PlayAnimation("idle")
	anim:PushAnimation("idle", true)

    trans:SetScale(4, 4, 4)
	inst:AddTag("FX")
	inst:AddTag("NOCLICK")

	inst:DoTaskInTime(2, function() inst:Remove() end)
    return inst
end

local function zhihuihuanxing()
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()
    local light = inst.entity:AddLight()

    anim:SetBank("zhihuihuanxing")
    anim:SetBuild("zhihuihuanxing")
	anim:PlayAnimation("idle")
    anim:PushAnimation("idle", true)
    inst.Transform:SetScale(3,3,3)
    inst:AddTag("FX")
    inst:AddTag("NOCLICK")

    inst:ListenForEvent("animover", function() anim:PlayAnimation("idle") end)
    return inst
end

local function yiyudragoon_charges(Sim)
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()

    anim:SetBank("fx")
    anim:SetBuild("yiyudragoon_charge_fx")
    anim:PlayAnimation("move")

    inst.persists = false--²»³ÖÐø
    inst:AddTag("fx")
    inst:AddTag("NOCLICK")
    inst:AddTag("yiyudragoon_charge")
--  inst:DoTaskInTime(3, function() inst:Remove() end)
    return inst
end

local function yuyi_fire()
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()
    local light = inst.entity:AddLight()

    anim:SetBank("campfire_fire")
    anim:SetBuild("campfire_fire")
--    anim:SetBloomEffectHandle( "shaders/anim.ksh" )
--    inst.AnimState:SetMultColour(0/255, 0/255, 0/255, .6)
	inst.Transform:SetScale(1,1,1)
    inst:AddTag("FX")
    inst:AddTag("NOCLICK")
    inst:AddComponent("firefx")
    inst.components.firefx.levels =
    {
    {anim="level1", sound="dontstarve/common/nightlight", radius=1, intensity=.8, falloff=.33, colour = {253/255,179/255,179/255}, soundintensity=.1},
    {anim="level2", sound="dontstarve/common/nightlight", radius=2, intensity=.8, falloff=.33, colour = {253/255,179/255,179/255}, soundintensity=.3},
    {anim="level3", sound="dontstarve/common/nightlight", radius=3, intensity=.8, falloff=.33, colour = {253/255,179/255,179/255}, soundintensity=.6},
    {anim="level4", sound="dontstarve/common/nightlight", radius=4, intensity=.8, falloff=.33, colour = {253/255,179/255,179/255}, soundintensity=1},
    }
    
    anim:SetFinalOffset(-1)
    inst.components.firefx:SetLevel(2)
    inst.components.firefx.usedayparamforsound = true

    inst:DoTaskInTime(5, function() inst:Remove() end)
    return inst
end

return Prefab( "common/banyue", banyue, assets),
       Prefab( "common/liehuojianfa", liehuojianfa, assets),
       Prefab( "common/baofengxue", baofengxue, assets),
       Prefab( "common/diyuleiguang", diyuleiguang, assets),
       Prefab( "common/duanjin", duanjin, assets),
       Prefab( "common/huoqiang", huoqiang, assets),
       Prefab( "common/huxiaoshanlin", huxiaoshanlin, assets),
       Prefab( "common/leidianshu", leidianshu, assets),
       Prefab( "common/yuyi_fire", yuyi_fire, assets),
       Prefab( "common/zhihuihuanxing", zhihuihuanxing, assets, prefabs)
