天工维度魔兽争霸开发者社区-全国最大的TJ集中营-原提百万联盟

标题: AI补刀的函数 [打印本页]

作者: 怪诞生    时间: 2020-3-7 20:28
标题: AI补刀的函数
  1. [jass]//远离一个单位一定距离
  2. function LeaveUnit takes unit AiUnit,unit target,real length returns nothing
  3. local real a=GetUnitX(AiUnit)-GetUnitX(target)
  4. local real b=GetUnitY(AiUnit)-GetUnitY(target)
  5. local real c=SquareRoot(a*a+b*b)
  6. local real x=(length/c)*a+GetUnitX(AiUnit)
  7. local real y=(length/c)*b+GetUnitY(AiUnit)
  8. call IssuePointOrder(AiUnit,"move",x,y)
  9. call DisplayTextToForce( GetPlayersAll(),"123456")
  10. endfunction
  11. //找到周围最弱的单位并A之
  12. function KillWeakestUnit takes unit center,real range,real hpkill returns nothing
  13. local unit temp
  14. local unit weakest
  15. local group g=CreateGroup()
  16. call GroupEnumUnitsInRange(g,GetUnitX(center),GetUnitY(center),range,null)
  17. call GroupRemoveUnit(g,center)
  18. loop
  19. set weakest=FirstOfGroup(g)
  20. if weakest==null then
  21. call DestroyGroup(g)
  22. set temp = null
  23. set g = null
  24. return
  25. endif
  26. call GroupRemoveUnit(g,weakest)
  27. exitwhen GetUnitState(weakest,UNIT_STATE_LIFE)>0 //IsUnitEnemy(weakest,GetOwningPlayer(center)) and
  28. endloop

  29. loop
  30. set temp=FirstOfGroup(g)
  31. exitwhen temp == null
  32. if GetUnitState(temp, UNIT_STATE_LIFE)>0 then
  33. if GetUnitState(weakest,UNIT_STATE_LIFE)>GetUnitState(temp, UNIT_STATE_LIFE) then
  34. set weakest = temp
  35. endif
  36. endif
  37. call GroupRemoveUnit(g,temp)
  38. endloop
  39. call DestroyGroup(g)
  40. set temp = null
  41. set g = null
  42. if IsUnitAliveBJ(weakest)and(weakest != null)and(GetUnitState(weakest,UNIT_STATE_LIFE)<hpkill)and(GetUnitCurrentOrder(center) != String2OrderIdBJ("attack"))and(not(IsUnitType(weakest, UNIT_TYPE_HERO))) then
  43. //call DisplayTextToForce( GetPlayersAll(), ("===|c000000FF"+GetUnitName(center)+ "|R当前尝试补刀目标单位是:" + ( GetUnitName(weakest) + ( "|||||当前血量" + R2S(GetUnitStateSwap(UNIT_STATE_LIFE,weakest ))))))
  44. call IssueTargetOrder(center,"attack",weakest)
  45. endif
  46. endfunction
  47. //单位是否死亡或者存活
  48. function IsDead takes unit TheUnit returns boolean
  49. return (TheUnit==null)or(IsUnitType(TheUnit,UNIT_TYPE_DEAD))or(IsUnitDeadBJ(TheUnit))
  50. endfunction

  51. function IsAlive takes unit TheUnit returns boolean
  52. return (TheUnit!=null)and(IsDead(TheUnit)==false)
  53. endfunction
  54. //取得单位身后的点
  55. function GetUnitBackLoc takes unit TheTarget,real TheRange returns location
  56. local real TheDir
  57. if (TheTarget!=null)and(GetUnitState(TheTarget,UNIT_STATE_LIFE)>0) then
  58. set TheDir=Deg2Rad(GetUnitFacing(TheTarget)+180)
  59. return (Location(TheRange*Cos(TheDir)+GetUnitX(TheTarget),TheRange*Sin(TheDir)+GetUnitY(TheTarget)))
  60. endif
  61. return null
  62. endfunction
  63. //单位组前面的点
  64. function GetUnitFrontLoc takes group whichGroup,real TheRange returns location
  65. local real TheDir
  66. local unit TheTarget
  67. set TheTarget=FirstOfGroup(whichGroup)
  68. if (TheTarget!=null)and(IsAlive(TheTarget)) then
  69. set TheDir=Deg2Rad(GetUnitFacing(TheTarget))
  70. return (Location(TheRange*Cos(TheDir)+GetUnitX(TheTarget),TheRange*Sin(TheDir)+GetUnitY(TheTarget)))
  71. endif
  72. return null
  73. endfunction
  74. [/jass]
复制代码


作者: haha7328    时间: 2020-3-23 11:10
楼主发贴辛苦了,谢谢楼主分享!我觉得天工社区是注册对了!
作者: tsmbw    时间: 2020-4-4 09:03
支持一下
作者: 海鸣丿Aqoo    时间: 2020-9-29 22:31
支持天工维度,支持天天RPG




欢迎光临 天工维度魔兽争霸开发者社区-全国最大的TJ集中营-原提百万联盟 (http://bbs.mvprpg.com/) Powered by Discuz! X3.4