Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library DummyCaster /*
- */uses /*
- */Timer /*
- */Initializer /*
- *///! novjass
- |=====|
- | API |
- |=====|
- struct DummyCaster/*
- */static method operator [][] takes integer spellId, integer orderId returns DummyCaster/*
- - Adds an ability to the dummy caster that will be removed automatically after the current thread
- execution and prepared the orderId to be issued to the dummy
- */static method reset takes nothing returns nothing/*
- - Resets the position of the dummy unit and removes all its abilities in case AUTO_REMOVE_ABILITY
- is false
- */method cast takes nothing returns boolean/*
- - Issues an immediate order to the dummy unit
- */method castOnPoint takes nothing returns boolean/*
- - Issues a point order to the dummy unit
- */method castOnTarget takes nothing returns boolean/*
- - Issues a target order to the dummy unit
- *///! endnovjass
- globals
- private constant integer DUMMY_CASTER_ID = 'dCtr'
- private constant boolean AUTO_REMOVE_ABILITY = true
- private constant boolean AUTO_RESET_DUMMY = false
- endglobals
- struct DummyCaster extends array
- private static unit dummy
- private static code onAbilityRemove
- static if not AUTO_REMOVE_ABILITY then
- private static thistype instance = 0
- private integer spellId
- endif
- static method operator [] takes integer spellId returns thistype
- static if AUTO_REMOVE_ABILITY then
- if UnitAddAbility(dummy, spellId) then
- call Timer.newEx(spellId).start(0.00, false, onAbilityRemove)
- endif
- else
- set instance = instance + 1
- set instance.spellId = spellId
- call UnitAddAbility(dummy, spellId)
- endif
- return 0
- endmethod
- method operator [] takes integer orderId returns thistype
- return orderId
- endmethod
- method cast takes nothing returns boolean
- return IssueImmediateOrderById(dummy, this)
- endmethod
- method castOnPoint takes real x, real y returns boolean
- call SetUnitX(dummy, x)
- call SetUnitY(dummy, y)
- return IssuePointOrderById(dummy, this, x, y)
- endmethod
- method castOnTarget takes widget target returns boolean
- call SetUnitX(dummy, GetWidgetX(target))
- call SetUnitY(dummy, GetWidgetY(target))
- return IssueTargetOrderById(dummy, this, target)
- endmethod
- static method reset takes nothing returns nothing
- static if not AUTO_REMOVE_ABILITY then
- loop
- exitwhen instance == 0
- call UnitRemoveAbility(dummy, instance.spellId)
- set instance = instance - 1
- endloop
- endif
- call SetUnitX(dummy, 0.00)
- call SetUnitX(dummy, 0.00)
- endmethod
- static if not AUTO_RESET_DUMMY and not AUTO_REMOVE_ABILITY then
- else
- private static method removeAbility takes nothing returns nothing
- static if AUTO_REMOVE_ABILITY then
- local Timer expired = Timer.expired
- call UnitRemoveAbility(dummy, expired.data)
- call expired.free()
- else
- call Timer.expired.free()
- endif
- static if AUTO_RESET_DUMMY then
- call reset()
- endif
- endmethod
- endif
- private static method init takes nothing returns nothing
- set onAbilityRemove = function thistype.removeAbility
- set dummy = CreateUnit(Player(14), DUMMY_CASTER_ID, 0, 0, 0)
- endmethod
- implement Initializer
- endstruct
- endlibrary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement