class SuperBoltRifle expands BoltRifle;

#exec TEXTURE IMPORT NAME=Sk_SBoltR_01 FILE=SKINS\Sk_SBoltR_01.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec TEXTURE IMPORT NAME=Sk_SBoltR_02 FILE=SKINS\Sk_SBoltR_02.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec TEXTURE IMPORT NAME=Sk_SBoltR_03 FILE=SKINS\Sk_SBoltR_03.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec TEXTURE IMPORT NAME=Sk_SBoltR_04 FILE=SKINS\Sk_SBoltR_04.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec TEXTURE IMPORT NAME=Sk_SBoltR_05 FILE=SKINS\Sk_SBoltR_05.bmp GROUP=Skins FLAGS=2 LODSET=2

#exec AUDIO IMPORT NAME="SBoltRFire" FILE=SOUNDS\SBoltRFire.wav GROUP="SuperBoltR"
#exec AUDIO IMPORT NAME="SBoltRSelect" FILE=SOUNDS\SBoltRSelect.wav GROUP="SBoltRSelect"
#exec AUDIO IMPORT NAME="SBoltRPickup" FILE=SOUNDS\SBoltRPickup.wav GROUP="SBoltRPickup"

function PreBeginPlay()
{
	Super(NaliWeapons).PreBeginPlay();
	if ((Level.Game.IsA('MonsterHunt') && Class'NWMutator'.Default.EnableMonsterHuntMode && Class'NWMutator'.Default.MonsterHuntOnly) || (Class'NWMutator'.Default.EnableMonsterHuntMode && !Class'NWMutator'.Default.MonsterHuntOnly))
	{
		PickupAmmoCount *= Class'NWMutator'.default.ammo_SBoltR;
	}
}

function Fire( float Value )
{
    if ( (AmmoType == None) && (AmmoName != None) )
    {
        // ammocheck
        GiveAmmo(Pawn(Owner));
    }

    if ( AmmoType.UseAmmo(1) )
    {
        GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);
        if ( bRapidFire || (FiringSpeed > 0) )
            Pawn(Owner).PlayRecoil(FiringSpeed);

        TraceFire(0.0);
    }
}


simulated function PlayFiring()
{

	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	PlayAnim('Fire', 6.0, 0.0);
	MultiSkins[7] = Texture'TranslucentInvisible';
}


function AltFire( float Value )
{
    local actor HitActor;
    local vector HitLocation, HitNormal, Start; 

    if ( Owner == None )
        return;

	if ( AmmoType.UseAmmo(1) )
    {
        GotoState('AltFiring');
        bPointing=True;
        bCanClientFire = true;
        ClientAltFire(Value);
        if ( bRapidFire || (FiringSpeed > 0) )
            Pawn(Owner).PlayRecoil(FiringSpeed);

        TraceFire(0.0);
    }
}

simulated function PlayAltFiring()
{
	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	PlayAnim('Fire', 6.0, 0.0);
	MultiSkins[7] = Texture'TranslucentInvisible';
}

simulated function TraceFire( float Accuracy )
{
	local vector HitLocation, HitNormal, StartTrace, EndTrace, X,Y,Z;
	local actor Other;
	local Pawn PawnOwner, P;
	local Vector DVector, LocPoint;
    	local int NumPoints, NumI, u;
	local SuperBoltTrace Bdc;
	local SuperBoltFlareEnd b;

	PawnOwner = Pawn(Owner);

	Owner.MakeNoise(PawnOwner.SoundDampening);
	GetAxes(PawnOwner.ViewRotation,X,Y,Z);
	StartTrace = PawnOwner.Location + CalcDrawOffset() + HitScanOffset.X * X + HitScanOffset.Y * Y + HitScanOffset.Z * Z;  
	AdjustedAim = PawnOwner.AdjustAim(1000000, StartTrace, 2*AimError, False, False);	
	X = vector(AdjustedAim);
	EndTrace = StartTrace + 30000 * X; 
	Other = PawnOwner.TraceShot(HitLocation,HitNormal,EndTrace,StartTrace);

	if (Other == None)
		HitLocation = EndTrace;

	//Bolt Effect -------------------------------------

	Spawn(class'SuperBoltFlare',,, StartTrace + 64*X);

	DVector = HitLocation - StartTrace;
     	NumPoints = Int(VSize(DVector)/512.0);

	for (NumI = 0; NumI < NumPoints + 1; NumI++)
	{
		For(u=0; u<3; u++)
		{
			LocPoint = StartTrace + ((256 + 512 * NumI) * X);
					
			Bdc = Spawn(class'SuperBoltTrace',,, LocPoint, rotator(HitLocation - StartTrace));
			Bdc.AnimSequence = RandSequence[Rand(4)];

			If (NumI == 0)
				Bdc.MultiSkins[1]=Texture'SuperBoltStart';
			else if (NumI == NumPoints || Bdc.Region.Zone.bWaterZone)
				Bdc.MultiSkins[1] = Texture'SuperBoltEnd';
		}
	}

	
	Spawn(class'SuperBoltFlareEnd',,, HitLocation+HitNormal, Rotator(HitNormal));

	//-------------------------------------------------

	ProcessTraceHit(Other, HitLocation, HitNormal, X,Y,Z);
}


function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{

	if ( (Other != self) && (Other != Owner) && (Other != None) ) 
		Other.TakeDamage(20000,  Pawn(Owner), HitLocation, vect(0,0,25000), MyDamageType);

	Spawn(Class'SuperBoltShock',,, HitLocation, rotator(HitNormal));
}


simulated function Timer()
{
	if (!bCanClientFire)
	{
		bCanClientFire = True;
		if ( Pawn(Owner).bFire != 0 )
            Global.ClientFire(0);
        else if ( Pawn(Owner).bAltFire != 0 )
            Global.ClientAltFire(0);
	}

	MultiSkins[7] = Default.MultiSkins[7];
}


function DropFrom(vector StartLocation)
{
	Super.DropFrom(StartLocation);
	MultiSkins[7] = Default.MultiSkins[7];
}


/////////////////////////////////////////////////////////////////////////////////////////

state NormalFire
{

	function AnimEnd()
    	{
		MultiSkins[7] = Default.MultiSkins[7];
		bCanClientFire = False;
		SetTimer(1.0, False);
	}

	simulated function Timer()
	{
		bCanClientFire = True;
		MultiSkins[7] = Default.MultiSkins[7];
		Finish();
	}
}

state ClientFiring
{
    simulated function AnimEnd()
    {
	SetTimer(1.0, False);
	bCanClientFire = False;

	Super.AnimEnd();
    }
}

state AltFiring
{

	function AnimEnd()
    	{
		MultiSkins[7] = Default.MultiSkins[7];
		bCanClientFire = False;
		SetTimer(1.0, False);
	}

	simulated function Timer()
	{
		bCanClientFire = True;
		MultiSkins[7] = Default.MultiSkins[7];
		Finish();
	}
}

state ClientAltFiring
{
    simulated function AnimEnd()
    {
	SetTimer(1.0, False);
	bCanClientFire = False;

	Super.AnimEnd();
    }
}


defaultproperties
{
	AutoSwitchPriority=10
	ItemName="Enhanced Bolt Rifle"
	MaxDesireability=2.000000
	PickupMessage="You got the Enhanced Bolt Rifle."
	PickupSound=SBoltRPickup
	RespawnTime=60.000000
	AmmoName=SuperBoltAmmo
	DeathMessage="%o was fried by %k's %w."
	FireSound=SBoltRFire
	MyDamageType=SuperElectrified
	NameColor=(R=255,G=0,B=0)
	PickupAmmoCount=5
	SelectSound=SBoltRSelect
	bAltWarnTarget=False
	bRecommendAltSplashDamage=False
	CustomCross=SuperBoltCross
	LightBrightness=100
	LightHue=0
	LightSaturation=0
	bMegaWeapon=True
	MultiSkins(1)=Sk_SBoltR_01
	MultiSkins(2)=Sk_SBoltR_02
	MultiSkins(3)=Sk_SBoltR_03
	MultiSkins(4)=Sk_SBoltR_04
	MultiSkins(5)=Sk_SBoltR_05
	MultiSkins(6)=SuperElectric01
	MultiSkins(7)=SuperElectric02
	AIRating=2.000000
}
