Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- prevClass = AbilityTask
- AbilityTask = Class(prevClass) {
- BeginCastState = State {
- OnEnterState = function(self)
- ##############THIS IS ALL I NEED################
- #LOG( "ABILITY: ", self.UnitID, " BeginCastState OnEnter" )
- # pre-cast check to make sure we can in fact launch this ability
- if self.Ability.CheckTargetAssign then
- # do we have any check that may prevent this ability from launching
- if not self.Ability:CheckTargetAssign(self, self.Unit, self.Target, self.Ability) then
- self.KillTask = true
- return
- end
- end
- ##########################
- #LOG( "ABILITY: ", self.UnitID, " BeginCastState OnEnter" )
- # pre-cast check to make sure we can in fact launch this ability
- if self.Ability.PreCastCheck then
- # do we have any check that may prevent this ability from launching
- if not self.Ability:PreCastCheck(self.Unit) then
- self.KillTask = true
- return
- end
- end
- # starting to cast now
- self.Casting = true
- # kill the movement if we cannot cast while moving
- if not self.Ability.CanCastWhileMoving then
- self:StopNav()
- end
- self.Unit.Callbacks.OnAbilityBeginCast:Call( self, self.Unit )
- #If the character doesn't have the proper action, the cast will fail immediately.
- #We put the fail callback here so that it will fail and end the cast task.
- if self.Unit.Character then
- self.Unit.Character.Callbacks.ActionFailed:Add(self.CharacterCastEnd, self)
- end
- self.CastingStart = GetGameTimeSeconds()
- # take care of multiplayer syncs
- self.Unit.Sync.Abilities[self.AbilityName].CastingStart = self.CastingStart
- AbilityHandler.SyncAbilities(self.Unit)
- self.Unit:SetBusy(true)
- #We are tracking the ability being cast; the AI wants to not interrupt a casting state
- self.Unit.CastingAbilityTask = self.AbilityName
- # handle any special events set by the ability itself
- if self.Ability.OnStartCasting then
- self.Ability.OnStartCasting(self.Ability, self.Unit, self.Target)
- end
- self:PlayAbilitySound('OnStartCasting')
- # handle any special events set by the unit when casting
- if self.Unit.OnStartCasting and not self.Ability.NoCastAnim then
- self.Unit:OnStartCasting(self.Ability)
- end
- # now if we do not have a casting time, just go straight to the finish here
- if not self.HasCastingTime then
- ChangeState(self, self.FinishCastState)
- end
- end,
- TaskTick = function(self)
- #LOG( "ABILITY: ", self.UnitID, " BeginCastState tick" )
- if self:IsDone() then
- return TASKSTATUS.Done
- end
- # wait for the casting to finish
- if GetGameTimeSeconds() - self.CastingStart < self.Ability.CastingTime then
- return TASKSTATUS.Wait
- end
- #We put the end and aborted callbacks after the unit actually starts casting so
- #that the callbacks don't get mixed up with the abort of another action.
- if self.Unit.Character then
- self.Unit.Character.Callbacks.ActionEnd:Add(self.CharacterCastEnd, self)
- self.Unit.Character.Callbacks.ActionAborted:Add(self.CharacterCastEnd, self)
- end
- ChangeState(self, self.FinishCastState)
- end,
- OnDestroy = function(self)
- # overriding OnDestroy so that we can abort the casting
- self:AbortCast()
- self:CleanUp()
- end,
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement