Advertisement
Guest User

dgdata.zip/lua/sim/tasks/abilitytask.lua

a guest
Feb 2nd, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. prevClass = AbilityTask
  2.  
  3. AbilityTask = Class(prevClass) {
  4. BeginCastState = State {
  5. OnEnterState = function(self)
  6.  
  7. ##############THIS IS ALL I NEED################
  8. #LOG( "ABILITY: ", self.UnitID, " BeginCastState OnEnter" )
  9. # pre-cast check to make sure we can in fact launch this ability
  10. if self.Ability.CheckTargetAssign then
  11. # do we have any check that may prevent this ability from launching
  12. if not self.Ability:CheckTargetAssign(self, self.Unit, self.Target, self.Ability) then
  13. self.KillTask = true
  14. return
  15. end
  16. end
  17.  
  18. ##########################
  19.  
  20.  
  21.  
  22. #LOG( "ABILITY: ", self.UnitID, " BeginCastState OnEnter" )
  23. # pre-cast check to make sure we can in fact launch this ability
  24. if self.Ability.PreCastCheck then
  25. # do we have any check that may prevent this ability from launching
  26. if not self.Ability:PreCastCheck(self.Unit) then
  27. self.KillTask = true
  28. return
  29. end
  30. end
  31.  
  32. # starting to cast now
  33. self.Casting = true
  34.  
  35. # kill the movement if we cannot cast while moving
  36. if not self.Ability.CanCastWhileMoving then
  37. self:StopNav()
  38. end
  39.  
  40. self.Unit.Callbacks.OnAbilityBeginCast:Call( self, self.Unit )
  41.  
  42. #If the character doesn't have the proper action, the cast will fail immediately.
  43. #We put the fail callback here so that it will fail and end the cast task.
  44. if self.Unit.Character then
  45. self.Unit.Character.Callbacks.ActionFailed:Add(self.CharacterCastEnd, self)
  46. end
  47.  
  48. self.CastingStart = GetGameTimeSeconds()
  49.  
  50. # take care of multiplayer syncs
  51. self.Unit.Sync.Abilities[self.AbilityName].CastingStart = self.CastingStart
  52. AbilityHandler.SyncAbilities(self.Unit)
  53.  
  54. self.Unit:SetBusy(true)
  55.  
  56. #We are tracking the ability being cast; the AI wants to not interrupt a casting state
  57. self.Unit.CastingAbilityTask = self.AbilityName
  58.  
  59. # handle any special events set by the ability itself
  60. if self.Ability.OnStartCasting then
  61. self.Ability.OnStartCasting(self.Ability, self.Unit, self.Target)
  62. end
  63.  
  64. self:PlayAbilitySound('OnStartCasting')
  65.  
  66. # handle any special events set by the unit when casting
  67. if self.Unit.OnStartCasting and not self.Ability.NoCastAnim then
  68. self.Unit:OnStartCasting(self.Ability)
  69. end
  70.  
  71. # now if we do not have a casting time, just go straight to the finish here
  72. if not self.HasCastingTime then
  73. ChangeState(self, self.FinishCastState)
  74. end
  75. end,
  76.  
  77. TaskTick = function(self)
  78. #LOG( "ABILITY: ", self.UnitID, " BeginCastState tick" )
  79. if self:IsDone() then
  80. return TASKSTATUS.Done
  81. end
  82.  
  83. # wait for the casting to finish
  84. if GetGameTimeSeconds() - self.CastingStart < self.Ability.CastingTime then
  85. return TASKSTATUS.Wait
  86. end
  87.  
  88. #We put the end and aborted callbacks after the unit actually starts casting so
  89. #that the callbacks don't get mixed up with the abort of another action.
  90. if self.Unit.Character then
  91. self.Unit.Character.Callbacks.ActionEnd:Add(self.CharacterCastEnd, self)
  92. self.Unit.Character.Callbacks.ActionAborted:Add(self.CharacterCastEnd, self)
  93. end
  94.  
  95. ChangeState(self, self.FinishCastState)
  96. end,
  97.  
  98. OnDestroy = function(self)
  99. # overriding OnDestroy so that we can abort the casting
  100. self:AbortCast()
  101. self:CleanUp()
  102. end,
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement