Advertisement
A-G-D

DummyCaster

Feb 9th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. library DummyCaster /*
  2.  
  3.  
  4. */uses /*
  5.  
  6. */Timer /*
  7. */Initializer /*
  8.  
  9.  
  10. *///! novjass
  11.  
  12. |=====|
  13. | API |
  14. |=====|
  15.  
  16. struct DummyCaster/*
  17.  
  18. */static method operator [][] takes integer spellId, integer orderId returns DummyCaster/*
  19. - Adds an ability to the dummy caster that will be removed automatically after the current thread
  20. execution and prepared the orderId to be issued to the dummy
  21.  
  22. */static method reset takes nothing returns nothing/*
  23. - Resets the position of the dummy unit and removes all its abilities in case AUTO_REMOVE_ABILITY
  24. is false
  25.  
  26. */method cast takes nothing returns boolean/*
  27. - Issues an immediate order to the dummy unit
  28.  
  29. */method castOnPoint takes nothing returns boolean/*
  30. - Issues a point order to the dummy unit
  31.  
  32. */method castOnTarget takes nothing returns boolean/*
  33. - Issues a target order to the dummy unit
  34.  
  35. *///! endnovjass
  36.  
  37.  
  38. globals
  39. private constant integer DUMMY_CASTER_ID = 'dCtr'
  40. private constant boolean AUTO_REMOVE_ABILITY = true
  41. private constant boolean AUTO_RESET_DUMMY = false
  42. endglobals
  43.  
  44. struct DummyCaster extends array
  45.  
  46. private static unit dummy
  47. private static code onAbilityRemove
  48.  
  49. static if not AUTO_REMOVE_ABILITY then
  50. private static thistype instance = 0
  51. private integer spellId
  52. endif
  53.  
  54. static method operator [] takes integer spellId returns thistype
  55. static if AUTO_REMOVE_ABILITY then
  56. if UnitAddAbility(dummy, spellId) then
  57. call Timer.newEx(spellId).start(0.00, false, onAbilityRemove)
  58. endif
  59. else
  60. set instance = instance + 1
  61. set instance.spellId = spellId
  62. call UnitAddAbility(dummy, spellId)
  63. endif
  64. return 0
  65. endmethod
  66.  
  67. method operator [] takes integer orderId returns thistype
  68. return orderId
  69. endmethod
  70.  
  71. method cast takes nothing returns boolean
  72. return IssueImmediateOrderById(dummy, this)
  73. endmethod
  74.  
  75. method castOnPoint takes real x, real y returns boolean
  76. call SetUnitX(dummy, x)
  77. call SetUnitY(dummy, y)
  78. return IssuePointOrderById(dummy, this, x, y)
  79. endmethod
  80.  
  81. method castOnTarget takes widget target returns boolean
  82. call SetUnitX(dummy, GetWidgetX(target))
  83. call SetUnitY(dummy, GetWidgetY(target))
  84. return IssueTargetOrderById(dummy, this, target)
  85. endmethod
  86.  
  87. static method reset takes nothing returns nothing
  88. static if not AUTO_REMOVE_ABILITY then
  89. loop
  90. exitwhen instance == 0
  91. call UnitRemoveAbility(dummy, instance.spellId)
  92. set instance = instance - 1
  93. endloop
  94. endif
  95. call SetUnitX(dummy, 0.00)
  96. call SetUnitX(dummy, 0.00)
  97. endmethod
  98.  
  99. static if not AUTO_RESET_DUMMY and not AUTO_REMOVE_ABILITY then
  100. else
  101. private static method removeAbility takes nothing returns nothing
  102. static if AUTO_REMOVE_ABILITY then
  103. local Timer expired = Timer.expired
  104. call UnitRemoveAbility(dummy, expired.data)
  105. call expired.free()
  106. else
  107. call Timer.expired.free()
  108. endif
  109. static if AUTO_RESET_DUMMY then
  110. call reset()
  111. endif
  112. endmethod
  113. endif
  114.  
  115. private static method init takes nothing returns nothing
  116. set onAbilityRemove = function thistype.removeAbility
  117. set dummy = CreateUnit(Player(14), DUMMY_CASTER_ID, 0, 0, 0)
  118. endmethod
  119.  
  120. implement Initializer
  121.  
  122. endstruct
  123.  
  124.  
  125. endlibrary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement