现在的位置: 首页 > 综合 > 正文

真三选英雄Demo之一

2018年02月05日 ⁄ 综合 ⁄ 共 6595字 ⁄ 字号 评论关闭
//真三司马懿
//1.选择英雄 
globals
    integer hid_simayi='U00A' //司马懿 
    location mBaseLoc=null    //本阵
    location suguoBaseLoc=Location(-6600,-7800) //蜀国本阵 
    location weiguoBaseLoc=Location(6000,7000)  //魏国本阵 
    unit mHero=null           //自己的英雄
    integer mHeroId=0         //自己英雄的ID 
    integer zsHeroIndex=0     //真三英雄ID索引值 
    string mHeroName=null     //英雄名称
    string array heroNameArray  //英雄名字
    integer mHeroLevel=0            //我方英雄等级
    integer mHeroSkillPoints=0             //技能点
    integer FG=0                //英雄类型  近战 远程敏捷 远程智力 
    integer array mSkillArray             //技能数组
    integer array HeroBaseAttackRange  //英雄基本攻击范围
    real zsAttackRange=600             //攻击范围 
    real zs_budaoXieLiangBaseD=78         //补刀血量 -敌方小兵 
    real zs_budaoXieLiangBaseW=78         //补刀血量 - 我方小兵 
    real zs_BingTime=1.8
    real zs_BingBaseTime=1.6
    real zs_budaoXieLiangBaseD2=280
    real zs_budaoXieLiangBaseW2=230
    real zs_BingTime2=3
    real zs_BingBaseTime2=4
    integer mForceId=0              //势力 
    timer zs_Timer=CreateTimer()    //计时器 
    boolean isDebug=true 
    
endglobals
function printf takes string msg returns nothing
    if isDebug then 
        call DisplayTextToPlayer(GetLocalPlayer(),0,0,msg)
    endif
endfunction
//单位到目的地的距离 
function RangeToLoc takes unit TheUnit,location TheTarget returns real
    local real TheXRange
    local real TheYRange
    if(TheUnit!=null)and(UnitAlive(TheUnit))then
        set TheXRange=GetLocationX(TheTarget)-GetUnitX(TheUnit)
        set TheXRange=TheXRange*TheXRange
        set TheYRange=GetLocationY(TheTarget)-GetUnitY(TheUnit)
        set TheYRange=TheYRange*TheYRange
        return(SquareRoot(TheXRange+TheYRange))
    endif
    return 9999.0
endfunction

//物品是否可用 
function setItemCanUse takes unit u,boolean flag returns nothing
    if flag then
        call SetUnitUserData(u,0)
    else
        call SetUnitUserData(u,11)
    endif
endfunction

//通过ID获取单位 
function getUnitById takes integer iunitid,location loc,real radius returns unit
    local real TheRange
    local real nearestRange=999999
    local unit u=null
    local unit ru=null
    local group g=CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(g,loc,radius,null)
    loop
        set u=FirstOfGroup(g)
        exitwhen u==null
        if(GetUnitTypeId(u)==iunitid)then
            set TheRange=RangeToLoc(u,loc)
            if TheRange<nearestRange then
                set nearestRange=TheRange
                set ru=u
            endif
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g=null
    if(ru==null)then
    endif
    return ru
endfunction
//单位类型-远程攻击者
function IsRangeAttacker takes unit TheUnit returns boolean
    return(IsUnitType(TheUnit,UNIT_TYPE_RANGED_ATTACKER))
endfunction

//单位类型-肉搏攻击者
function IsMeleeAttacker takes unit TheUnit returns boolean
    return(IsUnitType(TheUnit,UNIT_TYPE_MELEE_ATTACKER))
endfunction
//单位类型-地面攻击单位 
function IsGroundAttacker takes unit TheUnit returns boolean
    return(IsUnitType(TheUnit,UNIT_TYPE_ATTACKS_GROUND))
endfunction
//智力远程0,敏捷远程1,近程2
function V6 takes unit u returns integer
    if not IsRangeAttacker(u)then
        return 2
    endif
    if IsRangeAttacker(u)then
        if GetHeroInt(u,false)>GetHeroAgi(u,false)then
            return 0
        else
            return 1
        endif
    endif
    return 0
endfunction
//司马懿技能树 
function initSkillArry_simayi takes nothing returns nothing
    set mSkillArray[0]='A07A'
    set mSkillArray[1]='A03O'
    set mSkillArray[2]='A07A'
    set mSkillArray[3]='A03O'
    set mSkillArray[4]='A07A'
    set mSkillArray[5]='A041'
    set mSkillArray[6]='A07A'
    set mSkillArray[7]='A03O'
    set mSkillArray[8]='A03O'
    set mSkillArray[9]='Aamk'
    set mSkillArray[10]='A041'
    set mSkillArray[11]='Aamk'
    set mSkillArray[12]='Aamk'
    set mSkillArray[13]='Aamk'
    set mSkillArray[14]='Aamk'
    set mSkillArray[15]='A041'
    set mSkillArray[16]='A03P'
    set mSkillArray[17]='A03P'
    set mSkillArray[18]='A03P'
    set mSkillArray[19]='A03P'
    set mSkillArray[20]='Aamk'
    set mSkillArray[21]='Aamk'
    set mSkillArray[22]='Aamk'
    set mSkillArray[23]='Aamk'
    set mSkillArray[24]='Aamk'
endfunction

function getFirstHeroOfPlayer takes player p returns unit
    local unit u=null
    local unit ru=null
    local group g=CreateGroup()
    call GroupEnumUnitsOfPlayer(g,p,null)
    loop
        set u=FirstOfGroup(g)
        exitwhen u==null or ru!=null
        if(IsUnitType(u,UNIT_TYPE_HERO) and GetUnitUserData(u)<100)then
            set ru=u
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g=null
    set u=null
    return ru
endfunction
function setAttackRange takes nothing returns nothing	 // Modify by maple	
    if HeroBaseAttackRange[zsHeroIndex]<400 then	
        set zsAttackRange=HeroBaseAttackRange[zsHeroIndex]
        set zs_budaoXieLiangBaseD=zs_budaoXieLiangBaseD-16
        set zs_budaoXieLiangBaseW=zs_budaoXieLiangBaseW-16
        set zs_BingTime=zs_BingBaseTime-.5
        set zs_budaoXieLiangBaseD2=zs_budaoXieLiangBaseD2+80
        set zs_budaoXieLiangBaseW2=zs_budaoXieLiangBaseW2+80
        set zs_BingTime2=zs_BingBaseTime2+1.6
	else
		set zsAttackRange=HeroBaseAttackRange[zsHeroIndex]
    endif
endfunction
//获取第一个英雄 
function getFirstHero takes nothing returns unit
    local unit ru=getFirstHeroOfPlayer(ai_player)
    if(ru!=null)then
        set mHero=ru	
        set mHeroId=GetUnitTypeId(mHero)
		set zsHeroIndex=GetUnitPointValueByType(mHeroId)
		set mHeroName=heroNameArray[zsHeroIndex]
		//call debugstr(ITS(zsHeroIndex) + ITS(mHeroId))		
        set mHeroLevel=GetHeroLevel(mHero)
        set mHeroSkillPoints=GetHeroSkillPoints(mHero)
        set FG=V6(mHero)
        call setItemCanUse(mHero,false)
        call UnitRemoveAbility(mHero,'A088')
        //call initSkillArry()
        call SetUnitAcquireRange(mHero,60)
		call setAttackRange()
        //call setFightLine()		       
        //call T0()
    endif
    return ru
endfunction
//购买英雄 
function BuyHero takes integer shopid,integer heroid returns boolean
    local unit shop=getUnitById(shopid,mBaseLoc,9999999)
    local boolean bgeted=false 
    call printf("BuyHero") 
    if shop==null then 
        call printf("商店为空...") 
        return false
    endif
    //set bgeted=IssueNeutralImmediateOrderById(ai_player,shop,heroid)
    set bgeted=(IssueNeutralImmediateOrderById(ai_player,shop,heroid))or(IssueImmediateOrderById(shop,heroid))
    call printf("如果没答应购买成功,就是购买失败了")
    if(bgeted)then
        call printf("购买英雄成功") 
        call getFirstHero()
    endif
    set shop=null
    return bgeted
endfunction
//魏国购买英雄 
function buyHeros_weiguo takes nothing returns nothing
    call printf("司马懿")
    call BuyHero('n001','H008')
endfunction
function Select_55 takes nothing returns nothing
    call Sleep(3)
    //if mForceId==2 then
    call printf("魏国选将") 
    call buyHeros_weiguo()
    //endif
endfunction

function ChooseHero takes nothing returns nothing
    call printf("55--") 
    call Select_55()
endfunction
//获取游戏过去的时间  real 
function GetElapsedGameTime_R takes nothing returns real
    return TimerGetElapsed(zs_Timer)
endfunction
function isToLoop takes nothing returns boolean	
    call printf("选择英雄中....")
    if mHero==null then
        call printf("我的英雄确实为空....") 
        //if GetElapsedGameTime_R()>20.2 then
            call printf("请选择英雄.....")
            call ChooseHero()
        //endif
        call Sleep(1.0)
        return false
    endif
    return true
endfunction
function mainLoop takes nothing returns nothing
    loop
        call Sleep(1.0) 
        call printf("main----")
        if isToLoop()then
            //call oneLoop()
            call printf("已经完成选择英雄")
        endif
    endloop
endfunction

//通过字符串释放技能,参数:单位 技能代码 基础命令ID 施法地点 
function CastPointSkillByOderStr takes unit TheUnit,integer abilcode,string order,location TheLoc returns boolean
    local player ThePlayer=ai_player
    local boolean Casted
    call SetPlayerAbilityAvailable(ThePlayer,abilcode,true)
    set Casted=IssuePointOrderLoc(TheUnit,order,TheLoc)
    if Casted then
    endif
    call SetPlayerAbilityAvailable(ThePlayer,abilcode,false)
    return(Casted)
endfunction
function getBaseLoc takes nothing returns location
    return weiguoBaseLoc
endfunction
//主函数 
function main takes nothing returns nothing
    call printf("Init AI>>>") 
    call InitAI()//初始化AI 
    set mBaseLoc=getBaseLoc()
    call StartThread(function mainLoop)
endfunction

抱歉!评论已关闭.