Scriptname _00E_Smoking_AbSmokingSC extends activemagiceffect  

Import Utility
Import Debug

;=====================================================================================
;              							EVENTS                  					 
;=====================================================================================

Event OnEffectStart(Actor akTarget, Actor akCaster)

	akSelfActor = akTarget as Actor

	If (akSelfActor.HasSpell(_00E_Smoking_abSmoking))
		; _00E_Debug.PrintMessage("Start smoking.")
	EndIf

	StartSmokingAnimation()
	
	while !(akSelfActor.IsInCombat()) && (akSelfActor.HasSpell(_00E_Smoking_abSmoking))
	
		; _00E_Debug.PrintMessage("Loop smoking.")
		SmokingLoop()
		
	endwhile
	
	Self.Dispel()
	
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)

	StopSmokingAnimation()
	
EndEvent

;=====================================================================================
;              							FUNCTIONS                  					 
;=====================================================================================

Function StartSmokingAnimation()

	akSelfActor.setdontmove(true)
	SendAnimationEvent(akSelfActor, "WallPipeSmokingEnter")
	Wait(2.00000)
	_00E_Smoking_PipeSmokingFlameEffect.Play(akSelfActor, -1 as Float, none)
	Wait(2.00000)
	SendAnimationEvent(akSelfActor, "WallPipeSmokingBlaze")
	_00E_Smoking_PipeSmokingSmokeExhaleEffect.Play(akSelfActor, -1 as Float, none)
	_00E_Smoking_PipeSmokingFlameEffect.Stop(akSelfActor)
	Wait(0.40000)
	_00E_Smoking_PipeSmokingSmokeExhaleEffect.Stop(akSelfActor)
	Wait(0.40000)

EndFunction

Function SmokingLoop()

	SendAnimationEvent(akSelfActor, "WallPipeSmokingSmokeLoop")
	Wait(6.00000)
	_00E_Smoking_PipeSmokingSmokeExhaleEffect.Play(akSelfActor, -1 as Float, none)
	Wait(2.5)
	_00E_Smoking_PipeSmokingSmokeExhaleEffect.Stop(akSelfActor)

EndFunction

Function StopSmokingAnimation()

	_00E_Smoking_PipeSmokingSmokeExhaleEffect.Stop(akSelfActor)
	SendAnimationEvent(akSelfActor, "WallPipeSmokingExit")
	Wait(1.17000)
	SendAnimationEvent(akSelfActor, "WallPipeSmokingEnd")
	akSelfActor.setdontmove(false)
	
EndFunction

;=====================================================================================
;              							PROPERTIES                  					 
;=====================================================================================

Actor akSelfActor

visualeffect property _00E_Smoking_PipeSmokingFlameEffect auto
visualeffect property _00E_Smoking_PipeSmokingSmokeExhaleEffect auto

Spell Property _00E_Smoking_abSmoking Auto
Spell Property _00E_Smoking_abSmokingSitting Auto