class UltimaElectric expands Effects;

#exec MESH IMPORT MESH=UltimaElectric ANIVFILE=MODELS\UltimaElectric_a.3d DATAFILE=MODELS\UltimaElectric_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=UltimaElectric STRENGTH=0
#exec MESH ORIGIN MESH=UltimaElectric X=0 Y=0 Z=0

#exec MESH SEQUENCE MESH=UltimaElectric SEQ=All STARTFRAME=0 NUMFRAMES=11
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec01 STARTFRAME=1 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec02 STARTFRAME=2 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec03 STARTFRAME=3 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec04 STARTFRAME=4 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec05 STARTFRAME=5 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec06 STARTFRAME=6 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec07 STARTFRAME=7 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec08 STARTFRAME=8 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec09 STARTFRAME=9 NUMFRAMES=1
#exec MESH SEQUENCE MESH=UltimaElectric SEQ=Elec10 STARTFRAME=9 NUMFRAMES=1

#exec MESHMAP NEW MESHMAP=UltimaElectric MESH=UltimaElectric
#exec MESHMAP SCALE MESHMAP=UltimaElectric X=0.2 Y=0.2 Z=0.4

#exec TEXTURE IMPORT NAME=ElecBoltBeam FILE=EFFECTS\ElecBoltBeam.bmp GROUP=Effects FLAGS=2
#exec MESHMAP SETTEXTURE MESHMAP=UltimaElectric NUM=1 TEXTURE=ElecBoltBeam

#exec AUDIO IMPORT NAME="UltimaThunder01" FILE=SOUNDS\UltimaThunder01.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder02" FILE=SOUNDS\UltimaThunder02.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder03" FILE=SOUNDS\UltimaThunder03.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder04" FILE=SOUNDS\UltimaThunder04.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder05" FILE=SOUNDS\UltimaThunder05.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder06" FILE=SOUNDS\UltimaThunder06.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder07" FILE=SOUNDS\UltimaThunder07.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder08" FILE=SOUNDS\UltimaThunder08.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder09" FILE=SOUNDS\UltimaThunder09.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder10" FILE=SOUNDS\UltimaThunder10.wav GROUP="UltimaProtos"
#exec AUDIO IMPORT NAME="UltimaThunder11" FILE=SOUNDS\UltimaThunder11.wav GROUP="UltimaProtos"


var() name ElecForm[10];
var() sound ThunderSoundRand[11];
var float SpanCount;

simulated function PostBeginPlay()
{
	SetTimer((Rand(20) + 10) / 10, False);
}

simulated function Timer()
{
local rotator R;
local byte B;
local vector X, Y, Z;
local UltimaBoltFlare UBFa, UBFb;

	if (Owner != None)
	{
		SpanCount = 0.5;
		bHidden = False;
		B = Min(9,Rand(10));
		AnimSequence = ElecForm[B];
		DrawScale = Owner.DrawScale;
		R.Yaw = Rand(16384) * 4;
		SetRotation(R);
		MakeSound();
		
		GetAxes(R, X, Y, Z);

		if (B==0 || B==5)
		{
			UBFa = Spawn(Class'UltimaBoltFlare', Self,, Location + 58*DrawScale*Z - 24*DrawScale*X);
			UBFb = Spawn(Class'UltimaBoltFlare', Self,, Location - 58*DrawScale*Z - 24*DrawScale*X);
		}
		else if (B==1 || B==6)
		{
			UBFa = Spawn(Class'UltimaBoltFlare', Self,, Location + 53*DrawScale*Z - 35*DrawScale*X);
			UBFb = Spawn(Class'UltimaBoltFlare', Self,, Location - 53*DrawScale*Z - 35*DrawScale*X);
		}
		else if (B==2 || B==7)
		{
			UBFa = Spawn(Class'UltimaBoltFlare', Self,, Location + 45*DrawScale*Z - 45*DrawScale*X);
			UBFb = Spawn(Class'UltimaBoltFlare', Self,, Location - 45*DrawScale*Z - 45*DrawScale*X);
		}
		else if (B==3 || B==8)
		{
			UBFa = Spawn(Class'UltimaBoltFlare', Self,, Location + 35*DrawScale*Z - 53*DrawScale*X);
			UBFb = Spawn(Class'UltimaBoltFlare', Self,, Location - 35*DrawScale*Z - 53*DrawScale*X);
		}
		else
		{
			UBFa = Spawn(Class'UltimaBoltFlare', Self,, Location + 24*DrawScale*Z - 58*DrawScale*X);
			UBFb = Spawn(Class'UltimaBoltFlare', Self,, Location - 24*DrawScale*Z - 58*DrawScale*X);
		}

		if (UBFa != None)
			UBFa.RemoteRole = ROLE_None;
		if (UBFb != None)
			UBFb.RemoteRole = ROLE_None;

		SetTimer((Rand(20) + 10) / 10, False);
	}
	else
		Destroy();
	
}

function MakeSound()
{
	PlaySound(ThunderSoundRand[Min(10,Rand(11))],,20.0,,30000);
}

simulated function Tick( float DeltaTime)
{
	if (SpanCount > 0)
	{
		SpanCount -= DeltaTime;
		ScaleGlow = SpanCount * Default.ScaleGlow / 0.5;
	}
	else if (!bHidden)
		bHidden = True;
}

defaultproperties
{
	DrawType=DT_Mesh
	Mesh=UltimaElectric
	Style=STY_Translucent
	bUnlit=True
	RemoteRole=ROLE_SimulatedProxy
	LifeSpan=25.000000
	bNetTemporary=False
	ElecForm(0)=Elec01
	ElecForm(1)=Elec02
	ElecForm(2)=Elec03
	ElecForm(3)=Elec04
	ElecForm(4)=Elec05
	ElecForm(5)=Elec06
	ElecForm(6)=Elec07
	ElecForm(7)=Elec08
	ElecForm(8)=Elec09
	ElecForm(9)=Elec10
	bHidden=True
	ScaleGlow=2.000000
	ThunderSoundRand(0)=UltimaThunder01
	ThunderSoundRand(1)=UltimaThunder02
	ThunderSoundRand(2)=UltimaThunder03
	ThunderSoundRand(3)=UltimaThunder04
	ThunderSoundRand(4)=UltimaThunder05
	ThunderSoundRand(5)=UltimaThunder06
	ThunderSoundRand(6)=UltimaThunder07
	ThunderSoundRand(7)=UltimaThunder08
	ThunderSoundRand(8)=UltimaThunder09
	ThunderSoundRand(9)=UltimaThunder10
	ThunderSoundRand(10)=UltimaThunder11
}
