Scriptname nAssaultScript extends Quest  

import utility
import debug

actor player
int iFSize
int iFilter
int pIndex
actor ad
spell ws
actorbase abtemp
formlist dragonslist

Event onInit()
player = Game.GetPlayer()
If xFirstRun.Value  == 0
	gotoState("EventRun")
Else
	xFirstRun.Value  = 0
	stop()
Endif
endevent

state EventRun
Event onBeginState()
xMSG00.Show()
trace("Deadly Dragons: Assault has started.")
If dAssault[0].Value > 0 || dAssault[1].Value > 0 || dAssault[2].Value > 0 || dAssault[3].Value > 0
	iFilter = RandomInt(0, 3)
	while dAssault[iFilter].Value < 1
		iFilter = RandomInt(0, 3)
	endwhile
	trace("Deadly Dragons: Event index: " + (iFilter + 1))
	If iFilter < 3
		gotoState("DragonAssault")
	Else
		gotoState("WeatherAssault")
	Endif
Endif
Endevent
Endstate

state DragonAssault
Event onBeginState()
If IsLE.GetValueInt() == 0
	dragonslist = DDDragonsList
Else
	dragonslist = LEDragonsList
Endif
If DEventsUncapper.Value > 0
	iFSize = dragonslist.GetSize() - 1
	int iTemp = -1
	while itemp < iFilter
		abtemp = dragonslist.GetAt(RandomInt(0, iFSize)) as actorbase
		ad = player.placeatme(abtemp, 1, false, true) as actor
		ad.SetPosition((ad.GetPositionX() + RandomFloat(-fBase, fBase)), (ad.GetPositionY() + RandomFloat(-fBase, fBase)), (ad.GetPositionZ() + fHeight))
		ad.enable()
		itemp += 1
		wait(0.2)
	endwhile
Else
	pIndex = nDS.GetPIndex()
	int iTemp = -1
	while itemp < iFilter
		abtemp = dragonslist.GetAt(RandomInt(0, pIndex)) as actorbase
		ad = player.placeatme(abtemp, 1, false, true) as actor
		ad.SetPosition((ad.GetPositionX() + RandomFloat(-fBase, fBase)), (ad.GetPositionY() + RandomFloat(-fBase, fBase)), (ad.GetPositionZ() + fHeight))
		ad.enable()
		itemp += 1
		wait(0.2)
	endwhile
Endif
stop()
nAssaultQST00.start()
Endevent
Endstate

state WeatherAssault
Event onBeginState()
		ad = player.placeatme(nNPC, 1, false, true) as actor
		ad.SetPosition((ad.GetPositionX() + RandomFloat(-fBase, fBase)), (ad.GetPositionY() + RandomFloat(-fBase, fBase)), ad.GetPositionZ())
		ad.enable()
		ws = nAssaultWeathList.GetAt(RandomInt(0, 4)) as spell
		ws.cast(ad)
		ad.enableai(true)
		nDS.ClearDummy(ad)
stop()
nAssaultQST00.start()
Endevent
Endstate		

GlobalVariable[] Property DAssault  Auto
GlobalVariable Property DEventsUncapper  Auto
GlobalVariable Property xFirstRun  Auto
FormList Property DDDragonsList  Auto  
FormList Property LEDragonsList Auto  
FormList Property nAssaultWeathList Auto  
Float Property fHeight=2500.0  Auto  
Float Property fBase=300.0  Auto  
nDataStoreScript Property nDS  Auto  
ActorBase Property nNPC  Auto  
SPELL[] Property WeatherSpell  Auto  
Quest Property nAssaultQST00  Auto
Message Property xMSG00 Auto

GlobalVariable Property IsLE  Auto  
