Scriptname _00E_MQ11c_OorbayaBossFightScript extends Actor 

Import Utility
Import Math

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

Event OnInit()

	Oorbaya.ForceRefTo(Self)
	Self.StartCombat(PlayerREF)
	BaseHealth = Self.GetBaseActorValue("Health")

EndEvent

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	  
	float CurrentHealth = Self.GetActorValue("Health")

	If (CurrentHealth < (Self.GetBaseActorValue("Health")*0.03))
		PlayDeathSequence()
	EndIf

EndEvent


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

Function PlayDeathSequence()

	Dying = True
	Self.SetGhost(True)	
	UnregisterForUpdate()
	;; Gavrant: the code below is commented out because combatIdleStart breaks something in AI and the oorbaya stops making attacks in a fight
	;Debug.SendAnimationEvent(Self, "combatIdleStart")
	AtronachUnsummonDeathFXS.Play(Self)
	int DyingSound = _00E_NPCOorbaya_DeathM.Play(Self)
	Sound.SetInstanceVolume(DyingSound, 8.0)
	Wait(1)
	Self.SetCriticalStage(Self.CritStage_DisintegrateStart)
	_00E_OorbayaFXShader.Stop(Self)
	Self.PlaceAtMe(_00E_NPCOorbayaUnleashHeavenExplosion)
	_00E_OorbayaPowerAttackIMOD.Apply()
	ObjectReference AshPile = Self.AttachAshPile(_00E_NPCOorbayaAshPile)
	
	if AshPile != None
		AshPile.SetScale(2)
	EndIf
	
	utility.wait(0.5)
	AtronachUnsummonDeathFXS.Stop(Self)
	_00E_FXOorbayaTrailEffect2.Stop(Self)
	Self.SetAlpha (0.0,True)
	Self.SetCriticalStage(Self.CritStage_DisintegrateEnd)
	Wait(1.5)
	Self.KillEssential(PlayerREF)
	_00E_Music_CombatEpicBoss.Remove()
	_00E_Music_Combat_Epic_Transition.Remove()
	MQ11c.SetStage(260)

EndFunction

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

Float Property PrepareTime = 1.0 Auto
{How long the Oorbaya waits before either finishing healing or launching his attack}
int Property HealingRounds = 5 Auto Hidden
{How often the Oorbaya heals himself when entering the recovering state.}
Float Property HealAmount = 20.0 Auto
{How much the Oorbaya heals with each "Burst"}
Float Property UpdateTime = 20.0 Auto
{How often the Oorbaya will raise his shield and launch a special attack - either healing himself or casting the spell}

bool Shield
bool HealInterrupted
bool Destroying = False
bool Dying
int BarrierLP
int BarrierConjure
Float DamageDealt
Float BaseHealth

Actor Property PlayerREF Auto

Activator Property _00E_NPCOorbayaHealingSphere Auto
Activator Property _00E_NPCOorbayaAshPile Auto

Idle Property AtronachFrostUnsummon Auto
Idle Property AtronachFrostCombatStart Auto
Idle Property AtronachFrostSummonedStart Auto

Light Property _00E_NPCOorbayaHealingLight Auto

EffectShader Property _00E_NPCOOrbayaTeleportBlue Auto
EffectShader Property _00E_NPCOOrbayaTeleportRed Auto
EffectShader Property _00E_TeleportReappearShader Auto
EffectShader Property _00E_OorbayaFXShader Auto
EffectShader Property GhostEtherealFXShaderIntro Auto
EffectShader Property AtronachUnsummonDeathFXS Auto

Explosion Property _00E_NPCOorbayaTeleportExplosionBlue Auto
Explosion Property _00E_NPCOorbayaTeleportExplosionRed Auto
Explosion Property _00E_NPCOorbayaUnleashHeavenExplosion Auto

Static Property XMarkerHeading Auto

Message Property _00E_MQ11c_sOorbayaHealingInterrupted Auto
Message Property _00E_MQ11c_sOorbayaPrepareForAttack Auto
Message Property _00E_MQ11c_sOorbayaScreamPain Auto

ReferenceAlias Property Oorbaya Auto

Sound Property _00E_NPCOorbaya_HitHeavyM Auto
Sound Property _00E_NPCOorbaya_IdleTauntM Auto
Sound Property _00E_NPCOorbaya_IdleGrowlM Auto
Sound Property _00E_NPCOorbaya_IdleIntimidateM Auto
Sound Property _00E_A2_RiftDrainSound Auto
Sound Property MAGMysticismSoulTrapCapture Auto
Sound Property _00E_NPC_OorbayaUnleashHeavenCharge Auto
Spell Property _00E_NPCOorbayaUnleashHeavenSpell Auto
Sound Property _00E_A1_Rift_ClosePortalSound Auto
Sound Property MAGPowerRacialHitskinM Auto
Sound Property _00E_NPCOorbaya_DeathM Auto
Sound Property _00E_NPCOorbaya_RoarM Auto

GlobalVariable Property _00E_MQ11c_BallistaFired Auto
GlobalVariable Property _00E_MQ11c_RyneusOorbayaNoCombat Auto

MusicType Property _00E_Music_CombatEpicBoss Auto
MusicType Property _00E_Music_Combat_Epic_Transition Auto

Quest Property MQ11c Auto

ObjectReference Property OorbayaOrigin Auto
ObjectReference Property MQ11c_SC10_OorbayaShootMarker Auto
ObjectReference Property TeleportBackMarker Auto Hidden

ImageSpaceModifier Property _00E_OorbayaPowerAttackIMOD Auto

VisualEffect Property _00E_FXOorbayaTrailEffect2 Auto