--[[
飺
    1. ˫E˾NĬҪZֶĿԶEN
˽űĬû޸ֵΪϺĽԼӢ۲ʺԼ
ӳʱ(WaitTime)EN
    2. ĬϲZҪĿʹ÷ʱʵҼȡĬ
ZѾĿʹ÷㡾Ҫƶн򽫿ENʧܣ
ʱ̿׼ENʱнһ׼XAG˾׼AEFҲԼֱ
ӰXG˾EFټӵ棬ʵʶսʱE֮XܻûãE֮
Ҫ߲ʺXˣԲһű֮Ĳиʵɡ
    3. ʹĬϲʱȷϻзãܻһЧENĿʱȷ
Χ޵зλЧѡ𾭹βĿľ벻һ״һ
WaitTimeҲͬԳWaitTimeǸýűʵЧĹؼ

ע⣺ýűĬ²ʵսҪϸ޸ġ
      ýűڶϷģʽʹãģʽϷűܴԼպã

£
[2010625]
    1. Ľ˳ģʽŻģ룬ֻҪ㴦ʱʱ䣬˵зEN
ʱشȻʧԼգ
    2. ˷籩ʹ÷ʽҪָƷλã
[2009820]
Ľ˷紵ʱȴģʽʹöʱԱٶ۵
[2009 822]
Ľ˳űʱȴģʽ˴зλʱзλܵ⣬紵H
ԭصȴENɡ޸ĬϲΪZڲͿơ
[2009828]
Ϸڽɫ״ʾ֧1.2+汾֡
[2010412]

[2010510]
¶Ӧ°汾ֵĹܺ
                                       ߣҹ    ԣѩ
                                                              ]]
--űģ
--û޸Ĵ
unitClickKey=90        --ĬϲZԼɸı
freezeWaitTime=4800    --紵ȴʱ䣬ԼϷʵ״ı
starWaitTime=3100      --˾紵ȴʱ䣬ԼϷʵ״ı
--û޸Ĵ
hero1='800H'             --800HΪ14EID
hero2='A00U'             --A00UΪ14E˾ID
promptState1=0           --ʾϢ״̬
promptState2=0           --ʾϢ״̬
message1='ѡӢ𣬳԰ZԶE'
message2='ѡӢ˾԰ZԶN'
idm=0
ridm=0
idp=0
ridp=0
nSetting=0

setglobalint('EN_nSetting', nSetting)
setglobalint('EN_freezeWaitTime', freezeWaitTime)
setglobalint('EN_starWaitTime', starWaitTime)
setkeywatch('keyhookfunc')
setmousewatch('mousehookfunc')

if getwshscriptversion() < 8 then
    msgbox('ʹø߰汾')
end

function hasRes(hHD, sRes)
    hasPurif_=false
    for i=0,5,1 do
        gHD,gID,gNUM= getunititem(hHD,i)
        if gID==sRes and gNUM>0 then
            hasPurif_ = true
        end
    end
    return hasPurif_
end

function keyhookfunc(keycode, controlkeycode, downorup)
    if 0==iswar3front() then return 0 end
    if 1==ischat() then return 0 end
    strCurrSelUID,hCurrSelHD = getcurrentunit()
    war3w = getwar3window()
    win3wl,win3wr,win3wt,win3wb = getclientrect(war3w)
    x=(win3wr-win3wl)*0.0018
    y=(win3wb-win3wt)*0.66
    if strCurrSelUID==hero1 and promptState1==0 then
        idp,ridp=d3dsettext(idp,ridp,'֡', 20000, x,y, "", 0x0000ff, 255, 8, 16, 500, 0, 0, 0,1000, 2000)
        idm,ridm=d3dsettext(idm,ridm,message1, 20000, 16*4+x,y, "", 0xffffff, 255, 8, 16, 500, 0, 0, 0,1000, 2000)
        promptState1=1
    end
    if strCurrSelUID==hero2 and promptState2==0 then 
        idp,ridp=d3dsettext(idp,ridp,'֡', 20000, x,y, "", 0x0000ff, 255, 8, 16, 500, 0, 0, 0,1000, 2000)
        idm,ridm=d3dsettext(idm,ridm,message2, 20000, 16*4+x,y, "", 0xffffff, 255, 8, 16, 500, 0, 0, 0,1000, 2000)
        promptState2=1
    end
--[[
Ϊѡʱű]]
    if strCurrSelUID==hero1 and keycode==unitClickKey and downorup==0 and hasRes(hCurrSelHD, "gens") then    --800HΪID
        runkeys('ʹƷgens')
        setglobalint('EN_nSetting', 1)
        return 1
    end 
--[[
Ϊѡ˾ʱű]]
    if strCurrSelUID==hero2 and keycode==unitClickKey and downorup==0 and hasRes(hCurrSelHD, "gens") then    --A00UΪ˾ID
        runkeys('ʹƷgens')
        setglobalint('EN_nSetting', 1)
        return 1
    end
end 
function mousehookfunc(mousemsg)
    if 0==iswar3front() then return 0 end
    if 1==ischat() then return 0 end
    strCurrSelUID,hCurrSelHD = getcurrentunit()
--[[
ΪѡʱĲű]]
    if strCurrSelUID==hero1 and mousemsg==1 and getglobalvar('EN_nSetting')==1 then
	mouseclick(0)
        currentx,currenty = getcursorpos()
        setglobalint('EN_currentx', currentx)
        setglobalint('EN_currenty', currenty)
        keypress(72)
        runlua("autosgFreeze.j")
        return 1
    end
    if getcurrentunit()==hero1 and mousemsg==2 and getglobalvar('EN_nSetting')==1 then    --Ҽȡ紵
        mouseclick(1)
        setglobalint('EN_nSetting', 0) 
        return 1
    end
--[[
Ϊѡ˾ʱĲű]]
    if strCurrSelUID==hero2 and mousemsg==1 and getglobalvar('EN_nSetting')==1 then
	mouseclick(0)
        currentx,currenty = getcursorpos()
        setglobalint('EN_currentx', currentx)
        setglobalint('EN_currenty', currenty)
        keypress(72)
        runlua("autosgStar.j")
        return 1
    end
    if getcurrentunit()==hero2 and mousemsg==2 and getglobalvar('EN_nSetting')==1 then    --Ҽȡ紵
        mouseclick(1)
        setglobalint('EN_nSetting', 0) 
        return 1
    end
    return 0
end