globals
	//integer abcdefghij = 15	
	integer MoveMoreLevel_JumpTimer=3
	hashtable YDHT = null 
endglobals

function InitializeYD takes nothing returns nothing
    set YDHT=InitHashtable()
	//call BJDebugMsg("The result is " + I2S(abcdefghij))
endfunction


//===========================================================================
//===========================================================================
//Custom functions added by wataloo&Everguo
//===========================================================================
//===========================================================================


//===========================================================================
//Return bug
//===========================================================================
function YDWEH2I takes handle h returns integer
    return GetHandleId(h) 
endfunction

function GetGameCache takes nothing returns hashtable  
    return YDHT
endfunction

//============================
//转换handle为integer 
function YDWEGetUnitID takes unit u returns integer
    return YDWEH2I(u)           
endfunction

function YDWEGetItemID takes item it returns integer
    return YDWEH2I(it)
endfunction

//清空 
function YDWEFlushAllData takes nothing returns nothing
    call FlushParentHashtable(YDHT)
endfunction 

function FlushMissionByInteger takes integer i returns nothing
    call FlushChildHashtable(YDHT,i)
endfunction  

function FlushMissionByString takes string s returns nothing
    call FlushChildHashtable(YDHT,StringHash(s))
endfunction  

//store and get integer
function YDWESaveIntegerByInteger takes integer pTable,integer pKey,integer i returns nothing
    call SaveInteger(YDHT,pTable,pKey,i)
endfunction

function YDWESaveIntegerByString takes string pTable,string pKey,integer i returns nothing
    call SaveInteger(YDHT,StringHash(pTable),StringHash(pKey),i)
endfunction

function YDWEGetIntegerByInteger takes integer pTable,integer pKey returns integer
    return LoadInteger(YDHT,pTable,pKey)
endfunction

function YDWEGetIntegerByString takes string pTable,string pKey returns integer
    return LoadInteger(YDHT,StringHash(pTable),StringHash(pKey))
endfunction

//store and get real
function YDWESaveRealByInteger takes integer pTable,integer pKey,real r returns nothing
    call SaveReal(YDHT,pTable,pKey,r)
endfunction

function YDWESaveRealByString takes string pTable,string pKey,real r returns nothing
    call SaveReal(YDHT,StringHash(pTable),StringHash(pKey),r)
endfunction

function YDWEGetRealByInteger takes integer pTable,integer pKey returns real
    return LoadReal(YDHT,pTable,pKey)
endfunction

function YDWEGetRealByString takes string pTable,string pKey returns real
    return LoadReal(YDHT,StringHash(pTable),StringHash(pKey))
endfunction

//store and get string
function YDWESaveStringByInteger takes integer pTable,integer pKey,string s returns nothing
    call SaveStr(YDHT,pTable,pKey,s)
endfunction

function YDWESaveStringByString takes string pTable,string pKey,string s returns nothing
    call SaveStr(YDHT,StringHash(pTable),StringHash(pKey),s)
endfunction

function YDWEGetStringByInteger takes integer pTable,integer pKey returns string
    return LoadStr(YDHT,pTable,pKey)
endfunction

function YDWEGetStringByString takes string pTable,string pKey returns string
    return LoadStr(YDHT,StringHash(pTable),StringHash(pKey))
endfunction

//store and get boolean
function YDWESaveBooleanByInteger takes integer pTable,integer pKey,boolean b returns nothing
    call SaveBoolean(YDHT,pTable,pKey,b)
endfunction

function YDWESaveBooleanByString takes string pTable,string pKey,boolean b returns nothing
    call SaveBoolean(YDHT,StringHash(pTable),StringHash(pKey),b)
endfunction

function YDWEGetBooleanByInteger takes integer pTable,integer pKey returns boolean
    return LoadBoolean(YDHT,pTable,pKey)
endfunction

function YDWEGetBooleanByString takes string pTable,string pKey returns boolean
    return LoadBoolean(YDHT,StringHash(pTable),StringHash(pKey))
endfunction

//Covert Unit                
function YDWESaveUnitByInteger takes integer pTable,integer pKey,unit u returns nothing
    call SaveUnitHandle(YDHT,pTable,pKey,u)
endfunction

function YDWESaveUnitByString takes string pTable,string pKey,unit u returns nothing
    call SaveUnitHandle(YDHT,StringHash(pTable),StringHash(pKey),u)
endfunction

function YDWEGetUnitByInteger takes integer pTable,integer pKey returns unit
    return LoadUnitHandle(YDHT,pTable,pKey)
endfunction

function YDWEGetUnitByString takes string pTable,string pKey returns unit
    return LoadUnitHandle(YDHT,StringHash(pTable),StringHash(pKey))   
endfunction

//Covert Player                
function YDWESavePlayerByInteger takes integer pTable,integer pKey,player p returns nothing
    call SavePlayerHandle(YDHT,pTable,pKey,p)
endfunction

function YDWESavePlayerByString takes string pTable,string pKey,player p returns nothing
    call SavePlayerHandle(YDHT,StringHash(pTable),StringHash(pKey),p)
endfunction

function YDWEGetPlayerByInteger takes integer pTable,integer pKey returns player
    return LoadPlayerHandle(YDHT,pTable,pKey)
endfunction

function YDWEGetPlayerByString takes string pTable,string pKey returns player
    return LoadPlayerHandle(YDHT,StringHash(pTable),StringHash(pKey))   
endfunction

//Covert Item   
function YDWESaveItemByInteger takes integer pTable,integer pKey,item it returns nothing
    call SaveItemHandle(YDHT,pTable,pKey,it)
endfunction

function YDWESaveItemByString takes string pTable,string pKey,item it returns nothing
    call SaveItemHandle(YDHT,StringHash(pTable),StringHash(pKey),it)
endfunction

function YDWEGetItemByInteger takes integer pTable,integer pKey returns item
    return LoadItemHandle(YDHT,pTable,pKey)
endfunction

function YDWEGetItemByString takes string pTable,string pKey returns item
    return LoadItemHandle(YDHT,StringHash(pTable),StringHash(pKey))
endfunction

//Covert Timer  
function YDWESaveTimerByInteger takes integer pTable,integer pKey,timer t returns nothing
    call SaveTimerHandle(YDHT,pTable,pKey,t)
endfunction

function YDWESaveTimerByString takes string pTable,string pKey,timer t returns nothing
    call SaveTimerHandle(YDHT,StringHash(pTable),StringHash(pKey),t)
endfunction

function YDWEGetTimerByInteger takes integer pTable,integer pKey returns timer
    return LoadTimerHandle(YDHT,pTable,pKey)
endfunction

function YDWEGetTimerByString takes string pTable,string pKey returns timer
    return LoadTimerHandle(YDHT,StringHash(pTable),StringHash(pKey))
endfunction

//Covert Trigger  
function YDWESaveTriggerByInteger takes integer pTable,integer pKey,trigger trg returns nothing
    call SaveTriggerHandle(YDHT,pTable,pKey,trg)
endfunction

function YDWESaveTriggerByString takes string pTable,string pKey,trigger trg  returns nothing
    call SaveTriggerHandle(YDHT,StringHash(pTable),StringHash(pKey),trg)
endfunction

function YDWEGetTriggerByInteger takes integer pTable,integer pKey returns trigger
    return LoadTriggerHandle(YDHT,pTable,pKey)
endfunction

function YDWEGetTriggerByString takes string pTable,string pKey returns trigger
    return LoadTriggerHandle(YDHT,StringHash(pTable),StringHash(pKey))
endfunction

//Covert Location 
function YDWESaveLocationByInteger takes integer pTable,integer pKey,location pt returns nothing
    call SaveLocationHandle(YDHT,pTable,pKey,pt)
endfunction

function YDWESaveLocationByString takes string pTable,string pKey,location pt returns nothing
    call SaveLocationHandle(YDHT,StringHash(pTable),StringHash(pKey),pt)
endfunction

function YDWEGetLocationByInteger takes integer pTable,integer pKey returns location 
    return LoadLocationHandle(YDHT,pTable,pKey)
endfunction

function YDWEGetLocationByString takes string pTable,string pKey returns location 
    return LoadLocationHandle(YDHT,StringHash(pTable),StringHash(pKey))
endfunction

//Covert Group 
function YDWESaveGroupByInteger takes integer pTable,integer pKey,group g returns nothing
    call SaveGroupHandle(YDHT,pTable,pKey,g)
endfunction

function YDWESaveGroupByString takes string pTable,string pKey,group g returns nothing
    call SaveGroupHandle(YDHT,StringHash(pTable),StringHash(pKey),g)
endfunction

function YDWEGetGroupByInteger takes integer pTable,integer pKey returns group 
    return LoadGroupHandle(YDHT,pTable,pKey)
endfunction

function YDWEGetGroupByString takes string pTable,string pKey returns group 
    return LoadGroupHandle(YDHT,StringHash(pTable),StringHash(pKey))
endfunction


//===========================================================================
//返回参数 
//===========================================================================
//地图边界判断   
function YDWECoordinateX takes real x returns real    
    set x=RMaxBJ(x,GetCameraBoundMinX())  
    set x=RMinBJ(x,GetCameraBoundMaxX())  
    return x
endfunction

function YDWECoordinateY takes real y returns real
    set y=RMaxBJ(y,GetCameraBoundMinY())  
    set y=RMinBJ(y,GetCameraBoundMaxY())  
    return y
endfunction  
//两个单位之间的距离 
function YDWEDistanceBetweenUnits takes unit a,unit b returns real
    return SquareRoot((GetUnitX(a)-GetUnitX(b))*(GetUnitX(a)-GetUnitX(b))+(GetUnitY(a)-GetUnitY(b))*(GetUnitY(a)-GetUnitY(b)))
endfunction
//两个单位之间的角度 
function YDWEAngleBetweenUnits takes unit from, unit to returns real
    return bj_RADTODEG * Atan2(GetUnitY(to) - GetUnitY(from), GetUnitX(to) - GetUnitX(from))
endfunction
//生成区域 
function YDWEGetRect takes real x,real y,real width, real height returns rect
    return Rect( x - width*0.5, y - height*0.5, x + width*0.5, y + height*0.5 )
endfunction


//===========================================================================
//设置单位可以飞行 
//===========================================================================
function YDWEFlyEnable takes unit u returns nothing         
    call UnitAddAbility(u,'Amrf')
    call UnitRemoveAbility(u,'Amrf')             
endfunction  

//===========================================================================
//字符窜与ID转换 
//===========================================================================
function YDWEId2S takes integer value returns string         
    local string charMap = "..................................!.#$%&'()*+,-./0123456789:;<=>.@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................"
    local string result = ""
    local integer remainingValue = value
    local integer charValue
    local integer byteno
    set byteno = 0
    loop                      
        set charValue = ModuloInteger(remainingValue, 256)   
        set remainingValue = remainingValue / 256            
        set result = SubString(charMap, charValue, charValue + 1) + result    
        set byteno = byteno + 1               
        exitwhen byteno == 4     
    endloop                    
    return result              
endfunction   

function YDWES2Id takes string targetstr returns integer      
    local string originstr="..................................!.#$%&'()*+,-./0123456789:;<=>.@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................"
    local integer strlength=StringLength(targetstr)   
    local integer a=0            //分部当前数字  
    local integer b=0          //当前处理字   
    local integer numx=1    //位权          
    local integer result=0           
    loop        
        exitwhen b>strlength-1   
        set numx=R2I(Pow(256,strlength-1-b))  
        set a=1                              
        loop                                
        exitwhen a>255        
            if SubString(targetstr,b,b+1)==SubString(originstr,a,a+1) then     
            set result=result+a*numx     
            set a=256               
        endif                 
        set a=a+1       
        endloop  
        set b=b+1    
    endloop         
    return result       
endfunction

function YDWES2UnitId takes string targetstr returns integer  
    return YDWES2Id(targetstr) 
endfunction

function YDWES2ItemId takes string targetstr returns integer  
    return YDWES2Id(targetstr) 
endfunction

//===========================================================================
//测试 
//===========================================================================
function YDWEIfThenElse takes boolexpr b,code c1,code c2 returns nothing  
    local trigger trg=CreateTrigger()
    local triggercondition tc=TriggerAddCondition(trg,b)       
    local boolean b1=TriggerEvaluate(trg) 
    if b1==true then  
        call TimerStart(CreateTimer(),0,false,c1)
      else
        call TimerStart(CreateTimer(),0,false,c2)
    endif 
    call TriggerRemoveCondition(trg,tc)     
    //call DestroyCondition(tc)
    call DestroyTrigger(trg)
    set trg=null
    set tc=null
endfunction  

function YDWEIfThenElseMultiple takes nothing returns nothing  
    
endfunction                         
function  YDWEForLoopAMultiple takes nothing returns nothing  
endfunction    


//===========================================================================
//飘动的红丝带
//===========================================================================    
function YDWESetline takes nothing returns nothing
    local timer t = GetExpiredTimer()          
    local unit tru = YDWEGetUnitByString(I2S(YDWEH2I(t)),"tru")
    local integer count = YDWEGetIntegerByString(I2S(YDWEH2I(t)),"count") 
    local integer steps = YDWEGetIntegerByString(I2S(YDWEH2I(t)),"steps") 
    local integer stepscount = YDWEGetIntegerByString(I2S(YDWEH2I(t)),"stepscount") 
    local integer position = YDWEGetIntegerByString(I2S(YDWEH2I(t)),"position")         
    local real ux = GetUnitX(tru)
    local real uy = GetUnitY(tru)
    local real mjx
    local real mjy
    local real distance = YDWEGetRealByString(I2S(YDWEH2I(t)),"distance")
    local real angleadd = YDWEGetRealByString(I2S(YDWEH2I(t)),"angleadd")
    local unit array tempu
    local real array tempx
    local real array tempy
    local real array angle
    local integer i = 0
    local integer n = 0
    loop
        exitwhen i>count
        set tempu[i] = YDWEGetUnitByString(I2S(YDWEH2I(t)),I2S(1000+i))
        set angle[i] = YDWEGetRealByString(I2S(YDWEH2I(t)),I2S(2000+i))
        set tempx[i] = YDWEGetRealByString(I2S(YDWEH2I(t)),I2S(3000+i))
        set tempy[i] = YDWEGetRealByString(I2S(YDWEH2I(t)),I2S(4000+i))
        set i = i + 1
    endloop
    set i = 0
    if (steps > stepscount) or GetUnitState(tru,UNIT_STATE_LIFE)<=0  then
        loop
            exitwhen i == count
            call RemoveUnit(YDWEGetUnitByString(I2S(YDWEH2I(t)),I2S(1000+i)))
            set i = i + 1
        endloop                                                  
        call FlushMissionByString(I2S(YDWEH2I(t)))
        call PauseTimer(t)
        call DestroyTimer(t)
        //call SetUnitScalePercent( tru, 100, 100, 100 )
        return
    endif
    set i = 0
    loop
        exitwhen i == count
        set n = ModuloInteger(position + i,count)
        set mjx = GetUnitX(tempu[i])
        set mjy = GetUnitY(tempu[i])
        set mjx = mjx + (tempx[n] + i*distance*CosBJ(angle[n]) - mjx) * 0.2
        set mjy = mjy + (tempy[n] + i*distance*SinBJ(angle[n]) - mjy) * 0.2
        call SetUnitX(tempu[i],mjx)
        call SetUnitY(tempu[i],mjy)
        set i =  i + 1
    endloop
    set steps = steps + 1
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"steps",steps)      
    set position = ModuloInteger(position - 1 , count)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),I2S(2000+position),GetUnitFacing(tru) + 180 + angleadd) 
    call YDWESaveRealByString(I2S(YDWEH2I(t)),I2S(3000+position),ux)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),I2S(4000+position),uy)        
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"position",position)  
endfunction


//红丝带的先决条件            (udg_cinS_actor[11],'h01J',12,50,60,30,0.03,120,10,100,30)
function YDWECreateLine takes unit tru,integer ut,integer count,real angleadd,real distance,real lasttime,real eachtime,real heightstart,real heightadd,real sizestart,real sizeadd returns nothing
    local timer t = CreateTimer()
    local real ux = GetUnitX(tru)
    local real uy = GetUnitY(tru)
    local real angle = GetUnitFacing(tru) + 180 + angleadd
    local player p = GetOwningPlayer(tru)
    local integer i = 0
    local unit array tempu
    call YDWESaveUnitByString(I2S(YDWEH2I(t)),"tru",tru)  
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"count",count)
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"steps",0)
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"stepscount",R2I(lasttime/eachtime))
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"distance",distance)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"angleadd",angleadd)    
    loop
        exitwhen i==count
        set tempu[i] = CreateUnit(p,ut,ux,uy,0)
        call SetUnitFlyHeight( tempu[i],i*heightadd+heightstart+150, 75 )
        call SetUnitScalePercent( tempu[i], RMaxBJ(i*sizeadd+sizestart,1),RMaxBJ(i*sizeadd+sizestart,1),RMaxBJ(i*sizeadd+sizestart,1))
        call YDWESaveUnitByString(I2S(YDWEH2I(t)),I2S(1000+i),tempu[i])
        call YDWESaveRealByString(I2S(YDWEH2I(t)),I2S(2000+i),angle)
        call YDWESaveRealByString(I2S(YDWEH2I(t)),I2S(3000+i),ux)
        call YDWESaveRealByString(I2S(YDWEH2I(t)),I2S(4000+i),uy)
        set i = i + 1
    endloop
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"position",0)
    call TimerStart(t,eachtime,true,function YDWESetline)
    set t = null
    set p = null
endfunction

//===========================================================================
//修改生命
//===========================================================================
function YDWELifeChange takes unit u,integer mod,integer ch,integer aid returns nothing
    local integer a
    local integer b
    local integer c
    local integer d    
    if mod==1 then
        set ch=-ch
      elseif mod==2 then
        set ch=ch-R2I(GetUnitState(u,UNIT_STATE_MAX_LIFE))
    endif   
    if ch>99999 then
        set ch=99999
    endif
    if ch<-99999 then
        set ch=-99999
    endif
    if ch<0 then
        set a=2
        set ch=-ch
    else
        set a=7
    endif
    set b=0
    loop
        exitwhen b==5
        set c=ch-ch/10*10
        set d=0
        loop
            exitwhen d==c
            call UnitAddAbility(u,aid)
            call SetUnitAbilityLevel(u,aid,a)
            call UnitRemoveAbility(u,aid)
            set d=d+1
        endloop
        set ch=ch/10
        set a=a+1
        set b=b+1
    endloop
endfunction

//===========================================================================
//修改魔法
//===========================================================================
function YDWEManaChange takes unit u,integer mod,integer ch,integer aid returns nothing
    local integer a
    local integer b
    local integer c
    local integer d
    if mod==1 then
        set ch=-ch
      elseif mod==2 then
        set ch=ch-R2I(GetUnitState(u,UNIT_STATE_MAX_MANA))
    endif      
    if ch>99999 then
        set ch=99999
    endif
    if ch<-99999 then
        set ch=-99999
    endif
    if ch<0 then
        set a=2
        set ch=-ch
    else
        set a=7
    endif
    set b=0
    loop
        exitwhen b==5
        set c=ch-ch/10*10
        set d=0
        loop
            exitwhen d==c
            call UnitAddAbility(u,aid)
            call SetUnitAbilityLevel(u,aid,a)
            call UnitRemoveAbility(u,aid)
            set d=d+1
        endloop
        set ch=ch/10
        set a=a+1
        set b=b+1
    endloop
endfunction

//===========================================================================
//修改防御
//===========================================================================
//function YDWEDefendModifier takes unit u,integer N,integer a0,integer a1,integer a2,integer a3,integer a4,integer a5,integer a6.integer a7,integer a8,integer a9,integer a10 returns nothing

function YDWEDefendModifier takes unit u,integer N returns nothing
    local integer i=0
    local integer m=0
    local integer array ab
    set N=IMinBJ(2047,N)
    set N=IMaxBJ(0,N)
   // set ab[0]=a0
  //  set ab[1]=a1
  //  set ab[2]=a2
  //  set ab[3]=a3
  //  set ab[4]=a4
  //  set ab[5]=a5
  //  set ab[6]=a6
  //  set ab[7]=a7
  //  set ab[8]=a8
  //  set ab[9]=a9
 //   set ab[10]=a10
    set i=0  
    loop
        exitwhen i>=10
        call UnitRemoveAbility(u,ab[i]) 
        set i=i+1
    endloop     
    set i=0    
    loop                 
        exitwhen i>=10             
        if ModuloInteger(N,2)!=0 then
            call UnitAddAbility(u,ab[i])                          
        endif
        set N=N/2
        if N==0 then
            set i=10  
        endif    
        set i=i+1          
    endloop        
endfunction            

//===========================================================================
//修改攻击
//===========================================================================
function YDWEAttackModifier takes unit u,integer N returns nothing
    local integer i=0
    local integer m=0
    local integer array ab
    set N=IMinBJ(2047,N)
    set N=IMaxBJ(0,N)
    set ab[0]='AItg'
    set ab[1]='AIth'
    set ab[2]='AIti'
    set ab[3]='AItl'
    set ab[4]='AIat'
    set ab[5]='AItj'
    set ab[6]='AItn'
    set ab[7]='AItf'
    set ab[8]='AItc'
    set ab[9]='AIt9'
    set ab[10]='AItk'
    set i=0  
    loop
        exitwhen i>=11
        call UnitRemoveAbility(u,ab[i]) 
        set i=i+1
    endloop     
    set i=0    
    loop                 
        exitwhen i>=11             
        if ModuloInteger(N,2)!=0 then
            call UnitAddAbility(u,ab[i])                          
        endif
        set N=N/2
        if N==0 then
            set i=11  
        endif    
        set i=i+1          
    endloop        
endfunction   

//===========================================================================
//环绕技能模板 
//===========================================================================
function YDWEEwsp_LOOP takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit array tempUnit 
    local real array angle 
    local integer i = 0
    local unit orderUnit=YDWEGetUnitByString(I2S(YDWEH2I(t)),"orderUnit")     
    local real UnitLocX = GetUnitX(orderUnit)
    local real UnitLocY = GetUnitY(orderUnit)
    local real tempLocX  
    local real tempLocY  
    local real radius = YDWEGetRealByString(I2S(YDWEH2I(t)),"radius")    
    local real S = YDWEGetRealByString(I2S(YDWEH2I(t)),"speed") 
    local integer N = YDWEGetIntegerByString(I2S(YDWEH2I(t)),"number") 
    local integer steps = YDWEGetIntegerByString(I2S(YDWEH2I(t)),"steps") 
    if steps>0  then     
      set steps=steps-1
      call  YDWESaveIntegerByString(I2S(YDWEH2I(t)),"steps",steps)                  
      loop
          exitwhen i>N
          set i=i+1
          set tempUnit[i]=YDWEGetUnitByString(I2S(YDWEH2I(t)),I2S(1000+i)) 
          set angle[i]=YDWEGetRealByString(I2S(YDWEH2I(t)),I2S(2000+i)) 
          set angle[i]=angle[i]+S
          set tempLocX = UnitLocX + radius*CosBJ(angle[i])
          set tempLocY = UnitLocY + radius*SinBJ(angle[i])
          call SetUnitX(tempUnit[i],tempLocX)
          call SetUnitY(tempUnit[i],tempLocY)
          call YDWESaveRealByString(I2S(YDWEH2I(t)),I2S(2000+i),angle[i]) 
          set tempUnit[i]=null     
      endloop
      else 
        set i=0
        loop
            set i=i+1 
            exitwhen i>N            
            call RemoveUnit(YDWEGetUnitByString(I2S(YDWEH2I(t)),I2S(1000+i)))                     
        endloop 
        call FlushMissionByString(I2S(YDWEH2I(t)))
        call DestroyTimer(t)        
    endif
    set orderUnit=null
endfunction

function YDWECreateEwsp takes unit Hero,integer ewsp,integer N,real R,real T,real I,real S returns nothing
    local unit orderUnit=Hero
    local real UnitLocX = GetUnitX(orderUnit)
    local real UnitLocY = GetUnitY(orderUnit)  
    local unit array tempUnit  
    local player Masterplayer = GetOwningPlayer(orderUnit)
    local timer t=CreateTimer()
    local real interval=I
    local real lasttime=T
    local real radius=R
    local real tempLocX  
    local real tempLocY 
    local real array angle 
    local integer i=0
    local integer steps=R2I(lasttime/interval)
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"steps",steps)      
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"number",N) 
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"radius",radius)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"speed",S)
    loop
        set i=i+1
        exitwhen (i>N)
        set tempLocX = UnitLocX + radius*Cos(2*i*bj_PI/N)       
        set tempLocY = UnitLocY + radius*Sin(2*i*bj_PI/N)
        set angle[i] = 180*Atan2(UnitLocY - tempLocY, UnitLocX - tempLocX)/bj_PI
        set tempUnit[i]=CreateUnit(Masterplayer,ewsp,tempLocX,tempLocY,angle[i])
        call YDWESaveIntegerByString(I2S(YDWEH2I(t)),I2S(1000+i),YDWEH2I(tempUnit[i])) 
        call UnitGenerateAlarms( tempUnit[i], false )
        call YDWESaveRealByString(I2S(YDWEH2I(t)),I2S(2000+i),angle[i]) 
    endloop 
    call YDWESaveUnitByString(I2S(YDWEH2I(t)),"orderUnit",orderUnit) 
    call TimerStart(t,interval,true,function YDWEEwsp_LOOP)
    set t=null   
    set orderUnit=null
    set i=0
    loop
        set i=i+1  
        exitwhen (i>N) 
        set tempUnit[i]=null
    endloop
endfunction

//===========================================================================
//佣兵系统 
//===========================================================================
function YDWEGetUnitCurrentFree_Func takes unit u returns boolean
    local string s = OrderId2String(GetUnitCurrentOrder(u))
    if s == null then 
        return true
    endif
    return false    
endfunction

function YDWERemoveGuard takes unit pet returns nothing
    local integer tm = YDWEGetIntegerByString( I2S(YDWEH2I(pet)), "Timer")
    call FlushMissionByString(I2S(YDWEH2I(pet)))
    call FlushMissionByString(I2S(tm))
    call DestroyTimer(YDWEGetTimerByString(I2S(YDWEH2I(pet)), "Timer"))
endfunction

function YDWESetGuard_Func takes nothing returns nothing
  local timer tm = GetExpiredTimer()
  local unit pet = (YDWEGetUnitByString( I2S(YDWEH2I(tm)), "Pet"))
  local unit captain = (YDWEGetUnitByString( I2S(YDWEH2I(tm)), "Captain"))
  local real x = GetUnitX(captain) - GetUnitX(pet)
  local real y = GetUnitY(captain) - GetUnitY(pet)
  local real d = x*x + y*y
  local real v
  local real a
  local effect e
  local real life = YDWEGetRealByString( I2S(YDWEH2I(tm)), "Life")
  local integer p = YDWEGetIntegerByString(I2S(YDWEH2I(tm)), "Percent")
  set v = YDWEGetRealByString( I2S(YDWEH2I(tm)), "GuardRanger")      
  if GetUnitState(pet, UNIT_STATE_LIFE)>0 and GetUnitState(captain, UNIT_STATE_LIFE)> 0 then   
      if d<v*v then
         if YDWEGetUnitCurrentFree_Func(pet)==true and GetRandomInt(0,100)<p then
           set x = GetUnitX(captain)
           set y = GetUnitY(captain)
           set d = GetRandomReal(0,v)
           set a = GetRandomReal(0,360)
           call IssuePointOrder(pet, "patrol", x+d*CosBJ(a), y+d*SinBJ(a))
         endif
      else
        set v = YDWEGetRealByString( I2S(YDWEH2I(tm)), "ReturnRanger")
        if d<v*v then
          if YDWEGetUnitCurrentFree_Func(pet)==true  then
            call IssuePointOrder(pet, "patrol", GetUnitX(captain), GetUnitY(captain))
          endif
        else
          set v = YDWEGetRealByString( I2S(YDWEH2I(tm)), "OutRanger")
            if d!=0 and d>v*v then
              call SetUnitPosition(pet,GetUnitX(captain),GetUnitY(captain))
              set e =AddSpecialEffectTarget("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl" ,captain,"chest")
              call DestroyEffect(e)
            else
              call IssuePointOrder(pet, "move", GetUnitX(captain), GetUnitY(captain))
            endif
          endif
       endif
     else
       call IssuePointOrder(pet, "attack", GetUnitX(captain), GetUnitY(captain))
       call YDWERemoveGuard(pet)   
  endif
  set tm = null
  set pet = null
  set captain = null
endfunction


function YDWESetGuard takes unit pet, unit captain, real timeout, real guardRanger, real returnRanger, real outRanger,integer percent returns nothing
    local timer tm = CreateTimer()  
    call YDWESaveIntegerByString( I2S(YDWEH2I(pet)), "Timer", YDWEH2I(tm))
    call YDWESaveIntegerByString( I2S(YDWEH2I(tm)), "pet",YDWEH2I(pet))
    call YDWESaveIntegerByString( I2S(YDWEH2I(tm)), "Captain", YDWEH2I(captain))
    call YDWESaveIntegerByString( I2S(YDWEH2I(tm)), "Percent", percent)   
    call YDWESaveRealByString( I2S(YDWEH2I(tm)), "GuardRanger", guardRanger)    
    call YDWESaveRealByString( I2S(YDWEH2I(tm)), "ReturnRanger", returnRanger)   
    call YDWESaveRealByString( I2S(YDWEH2I(tm)), "OutRanger", outRanger)
    call TimerStart(tm, timeout, true, function YDWESetGuard_Func)
    set tm = null
endfunction



//===========================================================================
//跳跃系统 
//===========================================================================
function YDWEJumpTimerLoop takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local unit hero=(YDWEGetUnitByString(I2S(YDWEH2I(t)),"Hero"))
    local real angle=YDWEGetRealByString(I2S(YDWEH2I(t)),"Angle")
    local integer steeps=YDWEGetIntegerByString(I2S(YDWEH2I(t)),"steeps")
    local integer steepsMax=YDWEGetIntegerByString(I2S(YDWEH2I(t)),"steepsMax")
    local real heightMax=YDWEGetRealByString(I2S(YDWEH2I(t)),"heightMax")
    local real dist=YDWEGetRealByString(I2S(YDWEH2I(t)),"dist")
    local real dheig=YDWEGetRealByString(I2S(YDWEH2I(t)),"dheig")
    local real OriginHeight=YDWEGetRealByString(I2S(YDWEH2I(t)),"OriginHeight")
    local real x=YDWEGetRealByString(I2S(YDWEH2I(t)),"X")
    local real y=YDWEGetRealByString(I2S(YDWEH2I(t)),"Y")
    local real x1=0
    local real y1=0
    local real height=0  
    local integer lvJumpTimer=MoveMoreLevel_JumpTimer    
    local integer lvUnitMove=YDWEGetIntegerByString(I2S(YDWEH2I(hero)),"lvUnitMove")
call BJDebugMsg("unit is "+I2S(YDWEH2I(hero)))   
//call BJDebugMsg("steepsMax is "+I2S(steepsMax))        
    if steeps<steepsMax and lvJumpTimer>=lvUnitMove then
        set x1=x+steeps*dist*Cos(angle*3.14159/180.0)
        set y1=y+steeps*dist*Sin(angle*3.14159/180.0)
        set x1=YDWECoordinateX(x1)
        set y1=YDWECoordinateY(y1)
        call SetUnitX(hero,x1)
        call SetUnitY(hero,y1)
        set steeps=steeps+1
        call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"steeps",steeps) 
        set height=(-(2*I2R(steeps)*dheig-1)*(2*I2R(steeps)*dheig-1)+1)*heightMax+OriginHeight      
        call SetUnitFlyHeight(hero,height,99999)    
        call SetUnitFacing(hero,angle)             
      else               
        call SetUnitFlyHeight(hero,OriginHeight,99999)
        call SetUnitPathing(hero, true )
        call DestroyTimer(t)
        call FlushMissionByString(I2S(YDWEH2I(t)))
        call YDWESaveIntegerByString(I2S(YDWEH2I(hero)),"lvUnitMove",0)  
    endif
    set t=null
    set hero=null    
endfunction
                            

function YDWEJumpTimer takes unit hero,real angle,real distance,real lasttime,real timeout,real heightMax returns nothing
    local timer t=null
    local real x=GetUnitX(hero)
    local real y=GetUnitY(hero)
    local integer steepsMax=R2I(lasttime/timeout)
    local integer steeps=0
    local real dist=distance/steepsMax     
    local real dheig=1.0/steepsMax  
    local real OriginHeight=GetUnitFlyHeight(hero)
    local integer lvJumpTimer=MoveMoreLevel_JumpTimer 
    local integer lvUnitMove=YDWEGetIntegerByString(I2S(YDWEH2I(hero)),"lvUnitMove")     
    if lvJumpTimer>lvUnitMove then
        set t=CreateTimer()
        set lvUnitMove=lvJumpTimer
        call YDWESaveIntegerByString(I2S(YDWEH2I(hero)),"lvUnitMove",lvUnitMove)  
      else
        return
    endif                                          
    call UnitAddAbility(hero,'Amrf')
    call UnitRemoveAbility(hero,'Amrf')
    call SetUnitPathing(hero,false)          
    call YDWESaveUnitByString(I2S(YDWEH2I(t)),"Hero",hero)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"OriginHeight",OriginHeight)   
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"Angle",angle)    
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"dist",dist)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"heightMax",heightMax)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"dheig",dheig)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"X",x)
    call YDWESaveRealByString(I2S(YDWEH2I(t)),"Y",y)      
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"steeps",steeps)  
    call YDWESaveIntegerByString(I2S(YDWEH2I(t)),"steepsMax",steepsMax)   
    call TimerStart(t,timeout,true,function YDWEJumpTimerLoop)
    set t = null
endfunction

//===========================================================================
//刷兵系统 
//===========================================================================
function YDWEAttackWave takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real x1 = YDWEGetRealByString( "AttackWave"+I2S(YDWEH2I(t)), "x1")
    local real y1 = YDWEGetRealByString( "AttackWave"+I2S(YDWEH2I(t)), "y1")
    local real x2 = YDWEGetRealByString( "AttackWave"+I2S(YDWEH2I(t)), "x2")
    local real y2 = YDWEGetRealByString( "AttackWave"+I2S(YDWEH2I(t)), "y2")
    local real face = YDWEGetRealByString( "AttackWave"+I2S(YDWEH2I(t)), "face")
    local integer N = YDWEGetIntegerByString( "AttackWave"+I2S(YDWEH2I(t)), "N")
    local integer unitid = YDWEGetIntegerByString( "AttackWave"+I2S(YDWEH2I(t)), "unitid")
    local player playerid = YDWEGetPlayerByString("AttackWave"+I2S(YDWEH2I(t)), "playerid")     
    local unit tempUnit
    local integer n = 0                                                             
    loop              
        exitwhen (n>=N) 
        set tempUnit = CreateUnit(playerid,unitid,x1,y1,face)
        call IssuePointOrder(tempUnit, "attack", x2,y2) 
        set n=n+1
        set tempUnit = null
    endloop    
endfunction

function YDWEAttackWaveTimer takes player playerid,integer N,integer unitid,location whichLocation,real face,location TargetLocation,real timeout returns nothing
    local  real x1 = GetLocationX(whichLocation)
    local  real y1 = GetLocationY(whichLocation)  
    local  real x2 = GetLocationX(TargetLocation) 
    local  real y2 = GetLocationY(TargetLocation)   
    local  timer t = CreateTimer()   
    call YDWESaveIntegerByString( "AttackWave"+I2S(unitid)+R2S(x1)+R2S(y1)+R2S(timeout), "Timer", YDWEH2I(t))
    call YDWESaveIntegerByString( "AttackWave"+I2S(YDWEH2I(t)), "unitid", unitid)
    call YDWESaveIntegerByString( "AttackWave"+I2S(YDWEH2I(t)), "playerid", YDWEH2I(playerid))
    call YDWESaveIntegerByString( "AttackWave"+I2S(YDWEH2I(t)), "N", N)   
    call YDWESaveRealByString( "AttackWave"+I2S(YDWEH2I(t)), "x1", x1)       
    call YDWESaveRealByString( "AttackWave"+I2S(YDWEH2I(t)), "y1", y1)        
    call YDWESaveRealByString( "AttackWave"+I2S(YDWEH2I(t)), "x2", x2)        
    call YDWESaveRealByString( "AttackWave"+I2S(YDWEH2I(t)), "y2", y2)
    call YDWESaveRealByString( "AttackWave"+I2S(YDWEH2I(t)), "face", face)  
    call YDWESaveIntegerByString( "AttackWaveLastTimer", "Timer", YDWEH2I(t))
    call YDWESaveStringByString( "AttackWave"+I2S(YDWEH2I(t)), "Store", "AttackWave"+I2S(unitid)+R2S(x1)+R2S(y1)+R2S(timeout))
    call TimerStart(t,timeout,true,function YDWEAttackWave)    
    set t = null
endfunction

function YDWERemoveAttackWaveByUnitID takes integer unitid,location whichLocation,real timeout returns nothing
    local integer t = YDWEGetIntegerByString( "AttackWave"+I2S(unitid)+R2S(GetLocationX(whichLocation))+R2S(GetLocationY(whichLocation))+R2S(timeout), "Timer")
    call FlushMissionByString( "AttackWave"+I2S(unitid)+I2S(YDWEH2I(whichLocation))+R2S(timeout))    
// FlushMissionByString(    FlushMissionByString(
    call FlushMissionByString( "AttackWave"+I2S(t))
    call DestroyTimer(YDWEGetTimerByString("AttackWave"+I2S(unitid)+R2S(GetLocationX(whichLocation))+R2S(GetLocationY(whichLocation))+R2S(timeout), "Timer"))
endfunction

function YDWERemoveAttackWaveByTimer takes timer t returns nothing
    call FlushMissionByString( YDWEGetStringByString("AttackWave"+I2S(YDWEH2I(t)), "Store"))
    call FlushMissionByString( "AttackWave"+I2S(YDWEH2I(t)))
    call DestroyTimer(t)
endfunction   

function YDWERemoveAttackWaveReturnTimer takes nothing returns timer
    return YDWEGetTimerByString("AttackWaveLastTimer","Timer")
endfunction

//===========================================================================
//AI-自动学习技能 
//===========================================================================
 function YDWEAIStringFind takes string subject,string find,integer offset returns integer
    local integer len = StringLength(find)
    local integer pos = offset
    local string s
    local string str    
    if ( offset < 1 ) then
        set pos = 1
    endif 
    if ( find == "" ) then
        return -1
    endif   
    loop
        set s = SubString(subject, pos-1, pos+len-1)
        if ( s == find ) then
            return pos
        endif
        if ( SubString(subject, pos-1, pos) == "" ) then
            return -1
        endif
        set pos = pos + 1
    endloop
    return -1
endfunction                       

function YDWEAIRecordAbility takes integer uid,integer ab1,integer ab2,integer ab3,integer ab4,integer ab5 returns nothing
    call YDWESaveIntegerByString("HeroAbilities",I2S(uid)+"_1",ab1)
    call YDWESaveIntegerByString("HeroAbilities",I2S(uid)+"_2",ab2)
    call YDWESaveIntegerByString("HeroAbilities",I2S(uid)+"_3",ab3)
    call YDWESaveIntegerByString("HeroAbilities",I2S(uid)+"_4",ab4)
    call YDWESaveIntegerByString("HeroAbilities",I2S(uid)+"_5",ab5)
endfunction

function YDWEAIRecordLearn_sequence takes integer uid,string ls1,string ls2,string ls3,string ls4,string ls5 returns nothing
    call YDWESaveStringByString("learn_quence",I2S(uid)+"_1",ls1)
    call YDWESaveStringByString("learn_quence",I2S(uid)+"_2",ls2)
    call YDWESaveStringByString("learn_quence",I2S(uid)+"_3",ls3)
    call YDWESaveStringByString("learn_quence",I2S(uid)+"_4",ls4)
    call YDWESaveStringByString("learn_quence",I2S(uid)+"_5",ls5)
endfunction

function YDWEHeroLearnSkillAI takes unit hero,integer level returns integer
    local string array learn_sequence
    local integer numofskill = 5
    local integer array skills
    local integer i = 1
    local integer learnskill  
    local integer uid=GetUnitTypeId(hero) 
    set skills[1] = YDWEGetIntegerByString("HeroAbilities",I2S(uid)+"_1")
    set skills[2] = YDWEGetIntegerByString("HeroAbilities",I2S(uid)+"_2")
    set skills[3] = YDWEGetIntegerByString("HeroAbilities",I2S(uid)+"_3")
    set skills[4] = YDWEGetIntegerByString("HeroAbilities",I2S(uid)+"_4")
    set skills[5] = YDWEGetIntegerByString("HeroAbilities",I2S(uid)+"_5")
    set learn_sequence[1] = YDWEGetStringByString("learn_quence",I2S(uid)+"_1")
    set learn_sequence[2] = YDWEGetStringByString("learn_quence",I2S(uid)+"_2")
    set learn_sequence[3] = YDWEGetStringByString("learn_quence",I2S(uid)+"_3")
    set learn_sequence[4] = YDWEGetStringByString("learn_quence",I2S(uid)+"_4")
    set learn_sequence[5] = YDWEGetStringByString("learn_quence",I2S(uid)+"_5")       
    loop
        exitwhen i > numofskill     
        if YDWEAIStringFind(learn_sequence[i] , "^" + I2S(level) + "^", 1) != -1 then
        //trace msg          
            if GetUnitAbilityLevel(hero,skills[i])==0 then      
                call UnitAddAbility(hero,skills[i])
              else      
                call IncUnitAbilityLevel(hero,skills[i])    
            endif            
            call UnitModifySkillPoints(hero, -1)               
           // call SelectHeroSkill(hero,skills[i])
           // call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 3600, ( "学习  " + GetAbilityName(skills[i])+ "，" +  "目前技能等级为" +I2S(GetUnitAbilityLevel(hero,skills[i]))))   
            return skills[i]
        endif
        set i = i + 1
    endloop
    return 0
endfunction                                                 

function YDWEHeroMaxSkillAI takes unit hero returns nothing
    local integer level = GetHeroLevel(hero)
    local integer uid = GetUnitTypeId(hero)
    local integer numofskill = 5
    local integer i=0
    local integer array skills
    call ModifyHeroSkillPoints( hero, bj_MODIFYMETHOD_SET, level )    
    loop 
        set i = i + 1 
        exitwhen i>5
        call UnitRemoveAbility(hero,YDWEGetIntegerByString("HeroAbilities",I2S(uid)+"_"+I2S(i)))         
    endloop   
    set i = 0
    loop  
        set i = i + 1         
        exitwhen i>level           
        call  YDWEHeroLearnSkillAI(hero,i)
    endloop    
endfunction


//===========================================================================
//技能-钩子 
//===========================================================================

//===========================================================================


//=========================
function TBlast takes nothing returns nothing 
    local timer t = GetExpiredTimer()
    local string ors=I2S(YDWEH2I(t))  
    local integer loopIndex =YDWEGetIntegerByString(ors,"i")
    local integer red = YDWEGetIntegerByString(ors,"r")
    local integer green =YDWEGetIntegerByString(ors,"g")
    local integer blue =YDWEGetIntegerByString(ors,"b")
    local integer alpha =YDWEGetIntegerByString(ors,"a")
    local real height =YDWEGetRealByString(ors,"h")
    local string text = YDWEGetStringByString(ors,"t")
        
    if (loopIndex < 11) then
        set alpha = alpha - (31 - loopIndex*2)
        call YDWESaveIntegerByString(ors,"i",loopIndex+1)
        call YDWESaveRealByString(ors,"h",height+0.008)
        call YDWESaveIntegerByString(ors,"a",alpha)
        call TimerStart(t,0.04,FALSE,function TBlast)
    else
        call PauseTimer(t)
		call FlushMissionByString(ors)
		call PolledWait(1)
		call DestroyTimer(t)
    endif
    set text = ""
endfunction
function TgBlast takes string text,unit tuloc,real size,integer red, integer green, integer blue , integer alpha returns nothing
    local texttag tt = CreateTextTag()
    local timer t = CreateTimer()
    local string ors=I2S(YDWEH2I(t))
        
    call SetTextTagText(tt,text,size)
    call SetTextTagPosUnit(tt,tuloc,64)
    call SetTextTagVisibility(tt, TRUE)
    call SetTextTagPermanent(tt,FALSE)
    call SetTextTagColor(tt,red,green,blue,alpha)
    call YDWESaveIntegerByString(ors,"i",0)
    call YDWESaveStringByString(ors,"t",text)
    call YDWESaveRealByString(ors,"h",size)
    call YDWESaveIntegerByString(ors,"r",red)
    call YDWESaveIntegerByString(ors,"g",green)
    call YDWESaveIntegerByString(ors,"b",blue)
    call YDWESaveIntegerByString(ors,"a",alpha)
    call TimerStart(t,0.05,FALSE,function TBlast)
    
    call SetTextTagVelocity(tt,-0.12,-0.04)
    
    set tt = null
    set text = ""
endfunction
//==============================

//=========================
//=========================
function KillDestructableEnum takes nothing returns nothing
if GetDestructableTypeId(GetEnumDestructable())=='ATtr' or GetDestructableTypeId(GetEnumDestructable())=='ZTtw' or GetDestructableTypeId(GetEnumDestructable())=='ATtc' then
call KillDestructable(GetEnumDestructable())
endif
endfunction


//==================================================================
function Trig_Meat_Hook_Conditions takes nothing returns boolean
	return GetSpellAbilityId()=='A000'
endfunction
function IcanFly takes nothing returns nothing
	local timer Mt=GetExpiredTimer()
	local timer Mtt=YDWEGetTimerByString(I2S(YDWEH2I(Mt)),"ExtendCache")
	local string ors=I2S(YDWEH2I(Mtt))
	local integer Mn=YDWEGetIntegerByString(ors,"ChainLinkNumber")
    local unit Muu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(Mn))
	local unit lTl=YDWEGetUnitByString(ors,"Pudge")
    local real Mx=GetUnitX(Muu)
    local real My=GetUnitY(Muu)
    if Mn>=3 and GetUnitState(lTl,UNIT_STATE_LIFE)>0  then
    call SetUnitX(lTl,Mx)
    call SetUnitY(lTl,My)
    endif
    call KillUnit(Muu)
    call YDWESaveIntegerByString(ors,"ChainLinkNumber",Mn-1)
    if Mn==1 then
        call UnitRemoveAbility(lTl, 'A00A' )
    	call PauseTimer(Mt)
		call FlushMissionByString(ors)
		call FlushMissionByString(I2S(YDWEH2I(Mt)))
		call PolledWait(1)
		call DestroyTimer(Mt)
		call DestroyTimer(Mtt)
    endif
endfunction
//========旗重置============

function MeatHookFilter takes nothing returns boolean
	if GetUnitAbilityLevel(GetFilterUnit(),'A001')==1 or GetFilterUnit()==(YDWEGetUnitByString("YDWEMeatHook","MHtemp")) then
		return false
	endif
	if GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE)<=0 then //or GetUnitTypeId(GetFilterUnit())=='u000' or GetUnitTypeId(GetFilterUnit())=='u00F' or IsUnitType(GetFilterUnit(),UNIT_TYPE_ANCIENT) 
		return false
	endif
	return true
endfunction
function GhostHookFilter takes integer OGH,unit Maim,unit lTl returns boolean
	if OGH==2 and GetUnitTypeId(Maim)=='U000' then
		return true
	endif
	if OGH==1 and IsUnitEnemy(Maim,GetOwningPlayer(lTl)) and GetUnitTypeId(Maim)=='U000' then
		return true
	endif
	return false
endfunction
function MeatHookAim takes string ors,real Mxx,real Myy returns nothing
    local group lEw
    local group OHh=CreateGroup()
    local location OHf
    local boolexpr lTM
    local unit Maim
    local unit lTl=YDWEGetUnitByString(ors,"Pudge")
    local real Ma=YDWEGetRealByString(ors,"Angle")
    local item AimI
    local rect ItemRec
    local real Mb
    local unit OHu
    local unit Fhel
    local location Mtlo
    local integer OLe=YDWEGetIntegerByString(ors,"OLevel")
    local integer OHo=YDWEGetIntegerByString(ors,"OHook")
    local integer OGH=YDWEGetIntegerByString(ors,"OGH")
    local integer Mforward=YDWEGetIntegerByString(ors,"forward")
    local real damage=YDWEGetRealByString(ors,"Damage")
    local integer lmZ=4//GetUnitAbilityLevel(lTl,'A000')伤害有关
               set lEw=CreateGroup()
               call YDWESaveIntegerByString("YDWEMeatHook","MHtemp",YDWEH2I(lTl)) 
               set lTM=Condition(function MeatHookFilter)
               call GroupEnumUnitsInRange(lEw,Mxx,Myy,'}',lTM)
               call DestroyBoolExpr(lTM)
               set Maim=FirstOfGroup(lEw)
               call DestroyGroup(lEw)
               set lEw=null
               if(Maim!=null)then
               //检查印记
               if (GetUnitAbilityLevel(Maim,'A00A')==1) then
               //set udg_MH_Hit[GetPlayerId(GetOwningPlayer(lTl))+1] = (udg_MH_Hit[GetPlayerId(GetOwningPlayer(lTl))+1] + 1 )
               call YDWESaveIntegerByString(ors,"breakN",1)
               call UnitDamageTarget(lTl,Maim,20000, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED, WEAPON_TYPE_WHOKNOWS)
               call DestroyEffect(AddSpecialEffect("Units\\Undead\\Abomination\\AbominationExplosion.mdl",GetUnitX(Maim),GetUnitY(Maim)))
               call ShowUnit(Maim, false)
               //call FlyText("撕裂!!",5,Maim,255,0,0)
               call TgBlast("撕裂!!",Maim,0.03,255,0,0,255)
               else
               //检查扎钩
               if (GetUnitAbilityLevel(Maim,'A007')==1) then
                  if Mforward==2 then //让钩头延时3个
              //再检查一次状态=======================
               if (GetUnitAbilityLevel(lTl,'A00A')==1) then
               call UnitDamageTarget(lTl,lTl,20000, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED, WEAPON_TYPE_WHOKNOWS)
               call DestroyEffect(AddSpecialEffect("Units\\Undead\\Abomination\\AbominationExplosion.mdl",GetUnitX(lTl),GetUnitY(lTl)))
               call ShowUnit(lTl, false)
               //call FlyText("撕裂!!",5,lTl,255,0,0)
               endif
               //finish the check-up=
                  //set udg_MH_Hit[GetPlayerId(GetOwningPlayer(lTl))+1] = (udg_MH_Hit[GetPlayerId(GetOwningPlayer(lTl))+1] + 1 )
                  call YDWESaveIntegerByString(ors,"breakN",2)
                  call UnitAddAbility(lTl, 'A00A' )
                  else
                  set Mforward=Mforward+1
                  call YDWESaveIntegerByString(ors,"forward",Mforward)
                  endif
               else
               //change the hook head angle
              if UnitUseItem(Maim,GetItemOfTypeFromUnitBJ(Maim,'fwss')) then
              set OHu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(1))//borrow var OHu
              set Mb=YDWEAngleBetweenUnits(OHu,Maim)
              set Ma=Ma-2*(90-(Mb-Ma))
              call YDWESaveRealByString(ors,"Angle",Ma)
              else
               //set udg_MH_Hit[GetPlayerId(GetOwningPlayer(lTl))+1] = (udg_MH_Hit[GetPlayerId(GetOwningPlayer(lTl))+1] + 1 )
               //======Hook the Spirit========
               if GhostHookFilter(OGH,Maim,lTl) then
                call UnitDamageTarget(lTl,Maim,20000, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED, WEAPON_TYPE_WHOKNOWS)
                //call FlyT("灵魂出窍",3,Maim,0.025,255,0,0,255)
                set Maim=CreateUnit(GetOwningPlayer(Maim),'uaco',GetUnitX(Maim),GetUnitY(Maim),GetUnitFacing(Maim))
                call SetUnitAnimation(Maim, "Death")
                call SetUnitVertexColor(Maim,0,0,0,80)
               endif
               //==============
               call UnitAddAbility(Maim, 'A00A' )//add the tearing sign
               call YDWESaveUnitByString(ors,"Target",Maim) //save the target
               if IsUnitEnemy(Maim,GetOwningPlayer(lTl))then
               call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl",Maim,"origin"))
     if OHo==1 or OHo==2 then
     call UnitDamageTarget(lTl,Maim,damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED, WEAPON_TYPE_WHOKNOWS)
     else
//golden hook damage
     if (OHo==3) then
     call UnitDamageTarget(lTl,Maim,damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED, WEAPON_TYPE_WHOKNOWS)
     endif
     endif

               endif
//闪钩的伤害计算
     if (OHo==4) then
        if IsUnitEnemy(Maim,GetOwningPlayer(lTl)) then
           call UnitDamageTarget(lTl,Maim,damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED, WEAPON_TYPE_WHOKNOWS)
        endif
     set OHf=GetUnitLoc(Maim)
     call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl",OHf))
     set OHh=GetUnitsInRangeOfLocMatching(350,OHf,null)
loop
 set OHu=FirstOfGroup(OHh)
 exitwhen OHu==null
 if IsUnitEnemy(OHu,GetOwningPlayer(lTl)) then
    set Fhel=CreateUnit(GetOwningPlayer(lTl),'ushd',GetUnitX(OHu),GetUnitY(OHu),0)
    call UnitApplyTimedLife(Fhel, 'BHwe',1)
    call IssueTargetOrderById(Fhel,852111,OHu)
    call UnitDamageTarget(lTl,OHu,damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED, WEAPON_TYPE_WHOKNOWS)
endif
    call GroupRemoveUnit(OHh,OHu)
endloop
     call RemoveLocation(OHf)
     call DestroyGroup(OHh)
     set OHh=null
     endif
//==the damage finish====
               endif//change the angle
               endif//make the pudge flying
               endif//tear the pudge up
//itemmakebecome
else
set ItemRec=YDWEGetRect(Mxx,Myy,100,100)
set AimI=RandomItemInRectBJ(ItemRec,null)
call RemoveRect(ItemRec)
if AimI!=null then
//set udg_MH_Hit[GetPlayerId(GetOwningPlayer(lTl))+1] = (udg_MH_Hit[GetPlayerId(GetOwningPlayer(lTl))+1] + 1 )
call YDWESaveItemByString(ors,"AimItem",AimI)
call YDWESaveIntegerByString(ors,"breakN",1)
endif
//itemend
endif//if main!=null
endfunction

function MeatHookBack takes string ors returns nothing
local integer Mnn=YDWEGetIntegerByString(ors,"ChainLinkNumber")
local unit Maim=YDWEGetUnitByString(ors,"Target")
local unit lTl=YDWEGetUnitByString(ors,"Pudge")
local item AimI=YDWEGetItemByString(ors,"AimItem")
local integer OLe=YDWEGetIntegerByString(ors,"OLevel")
local integer OHo=YDWEGetIntegerByString(ors,"OHook")
local location FireLoc
local unit Mu
local unit Muu
local real Mxx
local real Myy
local real Maa
local real damage=YDWEGetRealByString(ors,"Damage")
    loop
        exitwhen Mnn<1
        set Mu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(Mnn+1))
        set Muu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(Mnn))
        if (Mu!=null)and(Muu!=null) then
        set Maa=bj_RADTODEG * Atan2(GetUnitY(Mu) - GetUnitY(Muu), GetUnitX(Mu) - GetUnitX(Muu))
        set Mxx=GetUnitX(Muu)+40*Cos(Maa*bj_DEGTORAD)
        set Myy=GetUnitY(Muu)+40*Sin(Maa*bj_DEGTORAD)
        call SetUnitFacing(Muu,Maa+180)
        call SetUnitX(Muu,Mxx)
        call SetUnitY(Muu,Myy)
        if (Mnn==1) then
            if(Maim!=null)then
		       call SetUnitX(Maim,Mxx)
		       call SetUnitY(Maim,Myy)
               //===吸血钩抽血代码===
               if IsUnitEnemy(Maim,GetOwningPlayer(lTl)) and OHo==2 then
                  call UnitDamageTarget(lTl,Maim,damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_ENHANCED, WEAPON_TYPE_WHOKNOWS)
                  call SetUnitLifeBJ(lTl, ( GetUnitStateSwap(UNIT_STATE_LIFE, lTl) + (( 14+( 6*OLe ) )*0.3) ) )
                  call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl",Maim,"origin"))
              endif
            //=======
            else
            //itemwillbeback
            if AimI!=null then
            if (GetRandomInt(1,100) < 15) then
            set AimI=null
            call YDWESaveItemByString(ors,"AimItem",AimI)
            //call FlyT("滑落",2,Mu,0.024,255,255,0,230)
            else
               call SetItemPosition(AimI,Mxx,Myy)
            endif
            else
               call MeatHookAim(ors,Mxx,Myy)//=====钩头目标====
            endif//itemend
            endif
        endif
        endif
        set Mnn=Mnn-1
    endloop
endfunction

function MeatHookPull takes nothing returns nothing
	local timer Mt=GetExpiredTimer()
	local timer Mtt=YDWEGetTimerByString(I2S(YDWEH2I(Mt)),"ExtendCache")
	local string ors=I2S(YDWEH2I(Mtt))
	local integer Mn=YDWEGetIntegerByString(ors,"ChainLinkNumber")
    local integer OHo=YDWEGetIntegerByString(ors,"OHook")
    local integer Noe=YDWEGetIntegerByString(ors,"ErrorAway")//==防出错
    local integer Mnn=0
    local integer MakerY
	local unit lTl=YDWEGetUnitByString(ors,"Pudge")
    local unit Maim
    local unit Mu
    local unit Muu
    local real Mxx
    local real Myy
    local real Mx
    local real My
    local real MDis
    local real Maa
    //========不让该function在同一时间运行两次..=================
    if (Noe==0) then
    call YDWESaveIntegerByString(ors,"ErrorAway",1)
    //=========检查距离(添加删除单位)==================
    set Mn=YDWEGetIntegerByString(ors,"ChainLinkNumber")
    set Muu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(Mn))
    if (Muu!=null) then
    set MDis=SquareRoot((GetUnitX(lTl)-GetUnitX(Muu))*(GetUnitX(lTl)-GetUnitX(Muu))+(GetUnitY(lTl)-GetUnitY(Muu))*(GetUnitY(lTl)-GetUnitY(Muu)))
    if (MDis<50) then//==删除链条==
    loop
    exitwhen MDis>=50
    call RemoveUnit(Muu)
    set Mn=Mn-1
    call YDWESaveIntegerByString(ors,"ChainLinkNumber",Mn)
    set Muu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(Mn))
    exitwhen Muu==null
    set MDis=SquareRoot((GetUnitX(lTl)-GetUnitX(Muu))*(GetUnitX(lTl)-GetUnitX(Muu))+(GetUnitY(lTl)-GetUnitY(Muu))*(GetUnitY(lTl)-GetUnitY(Muu)))
    endloop
    else//==添加链条===
    if (MDis>90) then
     set Maa=bj_RADTODEG * Atan2(GetUnitY(lTl) - GetUnitY(Muu), GetUnitX(lTl) - GetUnitX(Muu))
     set Mx=GetUnitX(Muu)
     set My=GetUnitY(Muu)
    loop
    exitwhen Mnn*40>MDis-50
        set Mnn=Mnn+1
        set Mn=YDWEGetIntegerByString(ors,"ChainLinkNumber")
        set Mxx=Mx+Mnn*40*Cos(Maa*bj_DEGTORAD)
        set Myy=My+Mnn*40*Sin(Maa*bj_DEGTORAD)
        set Mu=CreateUnit(GetOwningPlayer(lTl),'u001',Mxx,Myy,Maa+180)
     if (OHo==2) then
     call SetUnitVertexColor(Mu, 255, 0, 0, 255 )
     else
           if (OHo==3) then
     call SetUnitVertexColor(Mu, 255, 255, 0, 255 )
     else
           if (OHo==4) then
     call SetUnitVertexColor(Mu, 0, 255, 255, 255 )
     endif
     endif
     endif
        call YDWESaveUnitByString(ors,"ChainLinks"+I2S(Mn+1),Mu)
        call YDWESaveIntegerByString(ors,"ChainLinkNumber",Mn+1)
    endloop
    endif
    endif
    endif
    //=======开始移动=====
    set Mn=YDWEGetIntegerByString(ors,"ChainLinkNumber")
    call YDWESaveUnitByString(ors,"ChainLinks"+I2S(Mn+1),lTl)
    call MeatHookBack(ors)
    set MakerY=YDWEGetIntegerByString(ors,"breakN")
    //检查印记2
    if MakerY==2 then
		call PauseTimer(Mt)
		call TimerStart(Mt,.03,true,function IcanFly)
	endif
	if(Mn==0)then
//清除印记
set Maim=YDWEGetUnitByString(ors,"Target")
if(Maim!=null)then
call UnitRemoveAbility(Maim, 'A00A' )
if GetUnitTypeId(Maim)=='uaco' then
call RemoveUnit(Maim)
endif
endif
		call PauseTimer(Mt)
		call FlushMissionByString(ors)
		call FlushMissionByString(I2S(YDWEH2I(Mt)))
		call PolledWait(1)
		call DestroyTimer(Mt)
		call DestroyTimer(Mtt)
	endif
    call YDWESaveIntegerByString(ors,"ErrorAway",0)
    endif

endfunction

function MeatHookOut takes string ors,unit lTl returns nothing
local integer Mn=YDWEGetIntegerByString(ors,"ChainLinkNumber")
local integer Mnn=0
local real Ma=YDWEGetRealByString(ors,"Angle")
local real Maa
local group lEw
local boolexpr lTM
local unit Mu
local unit Muu
local real Mxx
local real Myy
//========钩头=====
set Mu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(1))
set Mxx=GetUnitX(Mu)+40*Cos(Ma*bj_DEGTORAD)
set Myy=GetUnitY(Mu)+40*Sin(Ma*bj_DEGTORAD)
//======检查边界====

call SetUnitX(Mu,YDWECoordinateX(Mxx))
call SetUnitY(Mu,YDWECoordinateY(Myy))
call MeatHookAim(ors,Mxx,Myy)//目标
//=========链条=====
loop
exitwhen Mnn>Mn-2
set Mnn=Mnn+1
set Mu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(Mnn))
set Muu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(Mnn+1))
set Maa=bj_RADTODEG * Atan2(GetUnitY(Mu) - GetUnitY(Muu), GetUnitX(Mu) - GetUnitX(Muu))
set Mxx=GetUnitX(Muu)+40*Cos(Maa*bj_DEGTORAD)
set Myy=GetUnitY(Muu)+40*Sin(Maa*bj_DEGTORAD)

call SetUnitX(Muu,YDWECoordinateX(Mxx))
call SetUnitY(Muu,YDWECoordinateY(Myy))
call SetUnitFacing(Muu,Maa)
endloop
endfunction

function YDWEMeatHookThrow takes nothing returns nothing
	local timer Mt=GetExpiredTimer()
	local string ors=I2S(YDWEH2I(Mt))
	local integer Mn=YDWEGetIntegerByString(ors,"ChainLinkMax")
    local integer Mnn=YDWEGetIntegerByString(ors,"ChainLinkNumber")
    local integer OHo=YDWEGetIntegerByString(ors,"OHook")
	local unit lTl=YDWEGetUnitByString(ors,"Pudge")
	local real Maa=YDWEGetRealByString(ors,"Angle")    
	local integer lmZ=YDWEGetIntegerByString(I2S(YDWEH2I(Mt)),"ChainLinkNumberMax")//15//GetUnitAbilityLevel(lTl,'A000')长度有关
    local integer Mnnn=1
    local unit Maim
	local unit Mu
    local unit Muu
    local integer Nbreak=0
    local real Mx
	local real My
	local real Mxx
	local real Myy
    local real MDis
	local boolexpr lTM
	local timer lTn
	local string lCache2
	local integer uid1=YDWEGetIntegerByString(I2S(YDWEH2I(Mt)),"ChainHead")
	local integer uid2=YDWEGetIntegerByString(I2S(YDWEH2I(Mt)),"ChainLink")
	local real timeout=YDWEGetRealByString(I2S(YDWEH2I(Mt)),"Timeout")
	if(Mn<lmZ)then
		set Mn=Mn+1
        call YDWESaveIntegerByString(ors,"ChainLinkMax",Mn)
		set Mxx=GetUnitX(lTl)+35*Cos(Maa*bj_DEGTORAD)
		set Myy=GetUnitY(lTl)+35*Sin(Maa*bj_DEGTORAD)
        if (Mn==1) then
        set Mu=CreateUnit(GetOwningPlayer(lTl),uid1,Mxx,Myy,Maa)
             if (OHo==2) then
     call SetUnitVertexColor(Mu, 255, 0, 0, 255 )
     else
           if (OHo==3) then
     call SetUnitVertexColor(Mu, 255, 255, 0, 255 )
     else
           if (OHo==4) then
     call SetUnitVertexColor(Mu, 0, 255, 255, 255 )
     endif
     endif
     endif
        call YDWESaveUnitByString(ors,"ChainLinks"+I2S(1),Mu)
        call YDWESaveIntegerByString(ors,"ChainLinkNumber",1)
        else
    set Muu=YDWEGetUnitByString(ors,"ChainLinks"+I2S(Mnn))
    set MDis=SquareRoot((GetUnitX(lTl)-GetUnitX(Muu))*(GetUnitX(lTl)-GetUnitX(Muu))+(GetUnitY(lTl)-GetUnitY(Muu))*(GetUnitY(lTl)-GetUnitY(Muu)))
    if (MDis>34) then
    set Mx=GetUnitX(Muu)
    set My=GetUnitY(Muu)
    set Maa=bj_RADTODEG * Atan2(GetUnitY(lTl) - GetUnitY(Muu), GetUnitX(lTl) - GetUnitX(Muu))
    loop
    exitwhen MDis-Mnnn*35<0
     set Mxx=Mx+Mnnn*35*Cos(Maa*bj_DEGTORAD)
     set Myy=My+Mnnn*35*Sin(Maa*bj_DEGTORAD)
     set Mu=CreateUnit(GetOwningPlayer(lTl),uid2,Mxx,Myy,Maa+180)
     if (OHo==2) then
     call SetUnitVertexColor(Mu, 255, 0, 0, 255 )
     else
           if (OHo==3) then
     call SetUnitVertexColor(Mu, 255, 255, 0, 255 )
     else
           if (OHo==4) then
     call SetUnitVertexColor(Mu, 0, 255, 255, 255 )
     endif
     endif
     endif
     set Mnn=Mnn+1
     set Mnnn=Mnnn+1
     call YDWESaveUnitByString(ors,"ChainLinks"+I2S(Mnn),Mu) 
     call YDWESaveIntegerByString(ors,"ChainLinkNumber",Mnn)
    endloop
    endif
    endif
    call MeatHookOut(ors,lTl)
     set Maim=YDWEGetUnitByString(ors,"Target")
     set Nbreak=YDWEGetIntegerByString(ors,"breakN")
     if (Maim!=null)or(Nbreak==1) then
            call PauseTimer(Mt)
			set lTn=CreateTimer()
			call YDWESaveTimerByString(I2S(YDWEH2I(lTn)),"ExtendCache",Mt)
			call TimerStart(lTn,timeout,true,function MeatHookPull)
    endif
    if Nbreak==2 then
            call PauseTimer(Mt)
			set lTn=CreateTimer()
			call YDWESaveTimerByString(I2S(YDWEH2I(lTn)),"ExtendCache",Mt)
			call TimerStart(lTn,timeout,true,function IcanFly)
	endif
	else
		call PauseTimer(Mt)
		set lTn=CreateTimer()
		call YDWESaveTimerByString(I2S(YDWEH2I(lTn)),"ExtendCache",Mt)
		call TimerStart(lTn,timeout,true,function MeatHookPull)
	endif
endfunction

//call YDWEMeatHook(GetTriggerUnit(),GetSpellTargetLoc(),'u004','u001',2000,35,.03)
function YDWEMeatHook takes unit lTl,location lng,integer uid1,integer uid2,real distance,real dis,real damage,real timeout returns nothing
	local location lTo=GetUnitLoc(lTl)
	local timer Mt=CreateTimer()
	local real lnM=AngleBetweenPoints(lTo,lng)
	local string ors=I2S(YDWEH2I(Mt))
    local integer oindex=0
    local integer OLe
    local integer OHo
    call YDWESaveUnitByString(ors,"Pudge",lTl)
	call YDWESaveRealByString(ors,"Angle",lnM)
	call YDWESaveIntegerByString(I2S(YDWEH2I(Mt)),"ChainHead",uid1)
	call YDWESaveIntegerByString(I2S(YDWEH2I(Mt)),"ChainLink",uid2)
	call YDWESaveIntegerByString(I2S(YDWEH2I(Mt)),"ChainLinkNumberMax",R2I(distance/dis))
	call YDWESaveRealByString(I2S(YDWEH2I(Mt)),"Timeout",timeout)
	call YDWESaveRealByString(I2S(YDWEH2I(Mt)),"Damage",damage)
    //set udg_MH_Throw[GetPlayerId(GetOwningPlayer(lTl))+1] = (udg_MH_Throw[GetPlayerId(GetOwningPlayer(lTl))+1] + 1 )
    //==================
        loop
        exitwhen oindex>7
        if (SubString(GetItemName(UnitItemInSlot(lTl,oindex-1)), 2, 4) == "AA" ) then
            set OLe = S2I(SubString(GetItemName(UnitItemInSlot(lTl,oindex-1)), 6, 8))
            //call EnableTrigger( gg_trg_MH_Extend1_Blood )
            set OHo=2
            call YDWESaveIntegerByString(ors,"OLevel",OLe)
            call YDWESaveIntegerByString(ors,"OHook",OHo)
            exitwhen true
        else
            if (SubString(GetItemName(UnitItemInSlot(lTl,oindex-1)), 2, 4) == "BB" ) then
                set OLe= S2I(SubString(GetItemName(UnitItemInSlot(lTl,oindex-1)), 8, 10))
                //call EnableTrigger( gg_trg_MH_Extend1_Golden )
                set OHo=3
                call YDWESaveIntegerByString(ors,"OLevel",OLe)
                call YDWESaveIntegerByString(ors,"OHook",OHo)
                exitwhen true
            else
                if (SubString(GetItemName(UnitItemInSlot(lTl,oindex-1)), 2, 4) == "CC") then
                    set OLe= S2I(SubString(GetItemName(UnitItemInSlot(lTl,oindex-1)), 4, 6))
                    //call EnableTrigger( gg_trg_MH_Extend1_Flash )
                    set OHo=4
                    call YDWESaveIntegerByString(ors,"OLevel",OLe)
                    call YDWESaveIntegerByString(ors,"OHook",OHo)
                    exitwhen true
                else
                if (oindex==7) then
                    set OHo=1
                    call YDWESaveIntegerByString(ors,"OHook",OHo)
                    endif
                endif
            endif
        endif
        set oindex=oindex + 1
    endloop
    //=======GhostSpirit===========
    if UnitHasItemOfTypeBJ(lTl,'I010')!=null then
        if (GetRandomInt(1,100) <= 25) then
            call YDWESaveIntegerByString(ors,"OGH",1)//1 considering the aim munst be dead
            else
                call YDWESaveIntegerByString(ors,"OGH",0)//0 means nothing
                endif
        elseif UnitHasItemOfTypeBJ(lTl,'I011')!=null then
               if (GetRandomInt(1,100) <= 15) then
                   call YDWESaveIntegerByString(ors,"OGH",2)
                   else
                       call YDWESaveIntegerByString(ors,"OGH",0)
                       endif
                       else
                       call YDWESaveIntegerByString(ors,"OGH",0)
                endif
    //================================================
	call TimerStart(Mt,timeout,true,function YDWEMeatHookThrow)
	call RemoveLocation(lTo)
	call RemoveLocation(lng)
	set lTo=null
	set lng=null
	set Mt=null
endfunction