class Graviton expands NaliWeapons;

//1st person
#exec MESH IMPORT MESH=Graviton ANIVFILE=MODELS\Graviton_a.3d DATAFILE=MODELS\Graviton_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=Graviton STRENGTH=0
#exec MESH ORIGIN MESH=Graviton X=0 Y=0 Z=0 YAW=128

//1st person special overlayer
#exec MESH IMPORT MESH=GravitonOv ANIVFILE=MODELS\Graviton_a.3d DATAFILE=MODELS\Graviton_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=GravitonOv STRENGTH=0
#exec MESH ORIGIN MESH=GravitonOv X=0 Y=0 Z=0 YAW=128

//1st person right handed
#exec MESH IMPORT MESH=GravitonR ANIVFILE=MODELS\Graviton_a.3d DATAFILE=MODELS\Graviton_d.3d X=0 Y=0 Z=0 UNMIRROR=1
#exec MESH LODPARAMS MESH=GravitonR STRENGTH=0
#exec MESH ORIGIN MESH=GravitonR X=0 Y=0 Z=0

//1st person right handed special overlayer
#exec MESH IMPORT MESH=GravitonROv ANIVFILE=MODELS\Graviton_a.3d DATAFILE=MODELS\Graviton_d.3d X=0 Y=0 Z=0 UNMIRROR=1
#exec MESH LODPARAMS MESH=GravitonROv STRENGTH=0
#exec MESH ORIGIN MESH=GravitonROv X=0 Y=0 Z=0

//Pickup
#exec MESH IMPORT MESH=GravitonPick ANIVFILE=MODELS\Graviton_a.3d DATAFILE=MODELS\Graviton_d.3d X=0 Y=0 Z=0
//#exec MESH LODPARAMS MESH=GravitonPick STRENGTH=0
#exec MESH ORIGIN MESH=GravitonPick X=0 Y=0 Z=0 YAW=128

//3rd person
#exec MESH IMPORT MESH=GravitonM ANIVFILE=MODELS\Graviton_a.3d DATAFILE=MODELS\Graviton_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=GravitonM STRENGTH=0
#exec MESH ORIGIN MESH=GravitonM X=480 Y=0 Z=-60 YAW=128


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

//Animations
#exec MESH SEQUENCE MESH=Graviton SEQ=All STARTFRAME=0 NUMFRAMES=18
#exec MESH SEQUENCE MESH=Graviton SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=Graviton SEQ=Fire STARTFRAME=0 NUMFRAMES=2 RATE=1.0
#exec MESH SEQUENCE MESH=Graviton SEQ=AltFire STARTFRAME=1 NUMFRAMES=8 RATE=8.0
#exec MESH SEQUENCE MESH=Graviton SEQ=Select STARTFRAME=9 NUMFRAMES=5 RATE=7.0 GROUP=Select
#exec MESH SEQUENCE MESH=Graviton SEQ=Down STARTFRAME=13 NUMFRAMES=5 RATE=14.0

#exec MESH SEQUENCE MESH=GravitonR SEQ=All STARTFRAME=0 NUMFRAMES=18
#exec MESH SEQUENCE MESH=GravitonR SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=GravitonR SEQ=Fire STARTFRAME=0 NUMFRAMES=2 RATE=1.0
#exec MESH SEQUENCE MESH=GravitonR SEQ=AltFire STARTFRAME=1 NUMFRAMES=8 RATE=8.0
#exec MESH SEQUENCE MESH=GravitonR SEQ=Select STARTFRAME=9 NUMFRAMES=5 RATE=7.0 GROUP=Select
#exec MESH SEQUENCE MESH=GravitonR SEQ=Down STARTFRAME=13 NUMFRAMES=5 RATE=14.0

#exec MESH SEQUENCE MESH=GravitonOv SEQ=All STARTFRAME=0 NUMFRAMES=18
#exec MESH SEQUENCE MESH=GravitonOv SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=GravitonOv SEQ=Fire STARTFRAME=0 NUMFRAMES=2 RATE=1.0
#exec MESH SEQUENCE MESH=GravitonOv SEQ=AltFire STARTFRAME=1 NUMFRAMES=8 RATE=8.0
#exec MESH SEQUENCE MESH=GravitonOv SEQ=Select STARTFRAME=9 NUMFRAMES=5 RATE=7.0 GROUP=Select
#exec MESH SEQUENCE MESH=GravitonOv SEQ=Down STARTFRAME=13 NUMFRAMES=5 RATE=14.0

#exec MESH SEQUENCE MESH=GravitonROv SEQ=All STARTFRAME=0 NUMFRAMES=18
#exec MESH SEQUENCE MESH=GravitonROv SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=GravitonROv SEQ=Fire STARTFRAME=0 NUMFRAMES=2 RATE=1.0
#exec MESH SEQUENCE MESH=GravitonROv SEQ=AltFire STARTFRAME=1 NUMFRAMES=8 RATE=8.0
#exec MESH SEQUENCE MESH=GravitonROv SEQ=Select STARTFRAME=9 NUMFRAMES=5 RATE=7.0 GROUP=Select
#exec MESH SEQUENCE MESH=GravitonROv SEQ=Down STARTFRAME=13 NUMFRAMES=5 RATE=14.0

#exec MESH SEQUENCE MESH=GravitonPick SEQ=Still STARTFRAME=0 NUMFRAMES=1

#exec MESH SEQUENCE MESH=GravitonM SEQ=Still STARTFRAME=0 NUMFRAMES=1


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

//Scale
#exec MESHMAP NEW MESHMAP=Graviton MESH=Graviton
#exec MESHMAP SCALE MESHMAP=Graviton X=0.05 Y=0.05 Z=0.1

#exec MESHMAP NEW MESHMAP=GravitonR MESH=GravitonR
#exec MESHMAP SCALE MESHMAP=GravitonR X=0.05 Y=0.05 Z=0.1

#exec MESHMAP NEW MESHMAP=GravitonOv MESH=GravitonOv
#exec MESHMAP SCALE MESHMAP=GravitonOv X=0.05 Y=0.05 Z=0.1

#exec MESHMAP NEW MESHMAP=GravitonROv MESH=GravitonROv
#exec MESHMAP SCALE MESHMAP=GravitonROv X=0.05 Y=0.05 Z=0.1

#exec MESHMAP NEW MESHMAP=GravitonPick MESH=GravitonPick
#exec MESHMAP SCALE MESHMAP=GravitonPick X=0.05 Y=0.05 Z=0.1

#exec MESHMAP NEW MESHMAP=GravitonM MESH=GravitonM
#exec MESHMAP SCALE MESHMAP=GravitonM X=0.05 Y=0.05 Z=0.1

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

//Skins
#exec TEXTURE IMPORT NAME=Sk_Graviton_01 FILE=SKINS\Sk_Graviton_01.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=Graviton NUM=1 TEXTURE=Sk_Graviton_01
#exec MESHMAP SETTEXTURE MESHMAP=GravitonR NUM=1 TEXTURE=Sk_Graviton_01
#exec MESHMAP SETTEXTURE MESHMAP=GravitonPick NUM=1 TEXTURE=Sk_Graviton_01
#exec MESHMAP SETTEXTURE MESHMAP=GravitonM NUM=1 TEXTURE=Sk_Graviton_01

#exec TEXTURE IMPORT NAME=Sk_Graviton_02 FILE=SKINS\Sk_Graviton_02.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=Graviton NUM=2 TEXTURE=Sk_Graviton_02
#exec MESHMAP SETTEXTURE MESHMAP=GravitonR NUM=2 TEXTURE=Sk_Graviton_02
#exec MESHMAP SETTEXTURE MESHMAP=GravitonPick NUM=2 TEXTURE=Sk_Graviton_02
#exec MESHMAP SETTEXTURE MESHMAP=GravitonM NUM=2 TEXTURE=Sk_Graviton_02

#exec TEXTURE IMPORT NAME=Sk_Graviton_03 FILE=SKINS\Sk_Graviton_03.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=Graviton NUM=3 TEXTURE=Sk_Graviton_03
#exec MESHMAP SETTEXTURE MESHMAP=GravitonR NUM=3 TEXTURE=Sk_Graviton_03
#exec MESHMAP SETTEXTURE MESHMAP=GravitonPick NUM=3 TEXTURE=Sk_Graviton_03
#exec MESHMAP SETTEXTURE MESHMAP=GravitonM NUM=3 TEXTURE=Sk_Graviton_03

#exec OBJ LOAD FILE=Textures\NaliEffects.utx PACKAGE=NaliWeaponsII.GFX

#exec MESHMAP SETTEXTURE MESHMAP=Graviton NUM=4 TEXTURE=GravFX01
#exec MESHMAP SETTEXTURE MESHMAP=GravitonR NUM=4 TEXTURE=GravFX01
#exec MESHMAP SETTEXTURE MESHMAP=GravitonPick NUM=4 TEXTURE=GravFX01
#exec MESHMAP SETTEXTURE MESHMAP=GravitonM NUM=4 TEXTURE=GravFX01

#exec MESHMAP SETTEXTURE MESHMAP=Graviton NUM=5 TEXTURE=GravFX02
#exec MESHMAP SETTEXTURE MESHMAP=GravitonR NUM=5 TEXTURE=GravFX02
#exec MESHMAP SETTEXTURE MESHMAP=GravitonPick NUM=5 TEXTURE=GravFX02
#exec MESHMAP SETTEXTURE MESHMAP=GravitonM NUM=5 TEXTURE=GravFX02

#exec MESHMAP SETTEXTURE MESHMAP=Graviton NUM=6 TEXTURE=GravFX03
#exec MESHMAP SETTEXTURE MESHMAP=GravitonR NUM=6 TEXTURE=GravFX03
#exec MESHMAP SETTEXTURE MESHMAP=GravitonPick NUM=6 TEXTURE=GravFX03
#exec MESHMAP SETTEXTURE MESHMAP=GravitonM NUM=6 TEXTURE=GravFX03

//-----------------------------------------------------------------------------------
//Icons
#exec TEXTURE IMPORT NAME=GravitonIcon FILE=ICONS\GravitonIcon.bmp GROUP=Icons MIPS=OFF

#exec OBJ LOAD FILE=Textures\NaliIcons.utx PACKAGE=NaliWeaponsII.Icons

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

//Sounds
#exec AUDIO IMPORT NAME="Grav_Pickup" FILE=SOUNDS\Grav_Pickup.wav GROUP="Graviton"
#exec AUDIO IMPORT NAME="Grav_AltFire" FILE=SOUNDS\Grav_AltFire.wav GROUP="Graviton"
#exec AUDIO IMPORT NAME="Grav_Select" FILE=SOUNDS\Grav_Select.wav GROUP="Graviton"
#exec AUDIO IMPORT NAME="Grav_Fire" FILE=SOUNDS\Grav_Fire.wav GROUP="Graviton"


var float Angle, Count, FireCount;
var GravBeam GravionBeam;
var bool bOutAmmo, bFireNow;


replication
{
	// Things the server should send to the client.
	reliable if( bNetOwner && (Role==ROLE_Authority) )
		bOutAmmo;
}

function PreBeginPlay()
{
	Super.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_Graviton;
	}
}

function setHand(float Hand)
{
	Super.SetHand(Hand);
	if ( Hand == 1 )
	{
		Mesh = mesh'Graviton';
		if ( GravionBeam != None )
        {
            GravionBeam.bCenter = false;
            GravionBeam.bRight = true;
        }
	}
	else
	{
		if ( GravionBeam != None )
        {
            GravionBeam.bCenter = false;
            GravionBeam.bRight = true;
        }
		Mesh = mesh'GravitonR';
	}

	if (Hand == 2)
	{
		if ( GravionBeam != None )
            GravionBeam.bCenter = true;
	}

}




simulated function Destroyed()
{
    if ( GravionBeam != None )
        GravionBeam.Destroy();

    Super.Destroyed();
}


function Fire( float Value )
{

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

    if (bInfinity)
    {
	bOutAmmo = False;
	GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);
			
    }	
    else if (AmmoType.UseAmmo(50))
    {
	bOutAmmo = False;
	GotoState('NormalFire');
        bPointing=True;
        bCanClientFire = true;
        ClientFire(Value);
    }
	else
	{
		bOutAmmo = True;
		PlayOwnedSound(Sound'Grav_Select', SLOT_None, Pawn(Owner).SoundDampening*9.0);
	}
}


simulated function PlayFiring()
{
	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*9.0);

	if (!bOutAmmo)
	{
		FireCount = FMax(0.7 / FireRateChange, 0.3);
		bFireNow = True;
	}
}

simulated function Tick( float DeltaTime)
{
local Projectile pj;

	if (FireCount > 0)
		FireCount -= DeltaTime;
	else if (bFireNow)
	{
		if (Role == ROLE_Authority)
		{
		pj = ProjectileFire(ProjectileClass, ProjectileSpeed, bWarnTarget);

        	if (pj.IsA('TriOrb'))
		{
			TriOrb(pj).HealthGiver = HealthGiver;
			TriOrb(pj).MoreDamage = MoreDamage;
			TriOrb(pj).Splasher = Splasher;
		}
		}

		bFireNow = False;

		PlayAnim('AltFire', 3.0 * FireRateChange, 0.0);
	}

	if (FireRateChange > 2.0)
	{
		FireRateChange = 2.0;
		if (SpecialHUD[0] == Texture'Fast_HUD')
			SpecialInfo[0] = "Fast " $ 2 $ "." $ 0 $ "X";
		else if (SpecialHUD[1] == Texture'Fast_HUD')
			SpecialInfo[1] = "Fast " $ 2 $ "." $ 0 $ "X";
		else
			SpecialInfo[2] = "Fast " $ 2 $ "." $ 0 $ "X";
	}
}


function AltFire( float Value )
{
local Projectile pj;

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

    if (bInfinity)
    {
	GotoState('AltFiring');
        bPointing=True;
        bCanClientFire = true;
        ClientAltFire(Value);

        /*if ( bRapidFire || (FiringSpeed > 0) )
            Pawn(Owner).PlayRecoil(FiringSpeed);*/

        pj = ProjectileFire(AltProjectileClass, AltProjectileSpeed, bAltWarnTarget);
	
	if (pj.IsA('StarterGravBeam'))
	{
		if ( FireOffset.Y == 0 )
                	StarterGravBeam(pj).bCenter = true;
            	else if ( Mesh == mesh'GravitonR' )
                	StarterGravBeam(pj).bRight = false;

		GravionBeam = StarterGravBeam(pj);
	}
		
    }	
    else if (AmmoType.UseAmmo(1))
    {
        GotoState('AltFiring');
        bPointing=True;
        bCanClientFire = true;
        ClientAltFire(Value);

        if ( bRapidFire || (FiringSpeed > 0) )
            Pawn(Owner).PlayRecoil(FiringSpeed);

	pj = ProjectileFire(AltProjectileClass, AltProjectileSpeed, bAltWarnTarget);

        if (pj.IsA('StarterGravBeam'))
	{
		if ( FireOffset.Y == 0 )
                	StarterGravBeam(pj).bCenter = true;
            	else if ( Mesh == mesh'GravitonR' )
                	StarterGravBeam(pj).bRight = false;

		GravionBeam = StarterGravBeam(pj);

	}
    }
	
}


simulated function PlayAltFiring()
{
	AmbientSound = AltFireSound;
	PlayAnim('Fire', 3.0);
}


function float RateSelf( out int bUseAltMode )
{
	local float EnemyDist, Rating;
	local bool bRetreating;
	local vector EnemyDir;
	local Pawn P;

	P = Pawn(Owner);

	//No enemy, ready to fire
	if ( P.Enemy == None )
        	return AIRating;

	//Don't recommend weapon if no ammo is left
	if (AmmoType.AmmoAmount < 50)
		return -2;

	//Never use second mode
	bUseAltMode = 0;
	return 3.0;
}


state ClientAltFiring
{
    simulated function AnimEnd()
    {
        if ( AmmoType.AmmoAmount <= 0 )
        {
            PlayIdleAnim();
            GotoState('');
        }
        else if ( !bCanClientFire )
            GotoState('');
        else if ( Pawn(Owner) == None )
        {
            PlayIdleAnim();
            GotoState('');
        }
        else if ( Pawn(Owner).bAltFire != 0 ){}
        else if ( Pawn(Owner).bFire != 0 )
            Global.ClientFire(0);
        else
        {
            PlayIdleAnim();
            GotoState('');
        }
    }
}

state AltFiring
{
    ignores AnimEnd;

    function Tick(float DeltaTime)
    {
        local Pawn P;

        P = Pawn(Owner);
        if ( P == None )
        {
            GotoState('Pickup');
            return;
        }
        if ( (P.bAltFire == 0) || (P.IsA('Bot')
                    && ((P.Enemy == None) || (Level.TimeSeconds - Bot(P).LastSeenTime > 5))) )
        {
            P.bAltFire = 0;
            Finish();
            return;
        }

        Count += Deltatime;
        if ( Count > 0.24 )
        {
            if ( Affector != None )
                Affector.FireEffect();
            Count -= 0.24;
		
	if (!bInfinity)
	{
            if ( !AmmoType.UseAmmo(1) )
                Finish();
	}
        }
    }
    
    function EndState()
    {
        AmbientGlow = 0;
        AmbientSound = None;
        if ( GravionBeam != None )
        {
            GravionBeam.Destroy();
            GravionBeam = None;
        }
        Super.EndState();
    }


Begin:
    AmbientGlow = 200;
    FinishAnim();
}



defaultproperties
{
	bSpecialOverlayer=True
	SpecialOvMeshR=GravitonROV
	SpecialOvMeshL=GravitonOV
	DrawType=DT_Mesh
	Mesh=GravitonPick
	CollisionHeight=10.000000
	CollisionRadius=15.000000
	AutoSwitchPriority=5
	Icon=GravitonIcon
	InventoryGroup=5
	ItemArticle="a"
	ItemName="Graviton"
	MaxDesireability=0.100000
	PickupMessage="You got the Graviton."
	PickupSound=Grav_Pickup
	PickupViewMesh=GravitonPick
	PickupViewScale=1.000000
	PlayerViewMesh=GravitonR
	PlayerViewOffset=(X=28.000000,Y=-20.000000,Z=-14.000000)
	PlayerViewScale=1.000000
	RespawnTime=30.000000
	StatusIcon=GravitonIcon
	ThirdPersonMesh=GravitonM
	ThirdPersonScale=0.850000
	AltDamageType="Gravity"
	AltFireSound=Grav_Fire
	AltProjectileClass=Class'StarterGravBeam'
	bInstantHit=False
	AmmoName=GravitonAmmo
	bRapidFire=True
	DeathMessage="%o was killed by %k's %w Gravity Law."
	FireOffset=(X=0.000000,Y=3.000000,Z=0.000000)
	FireSound=Grav_AltFire
	FiringSpeed=0.200000
	MaxTargetRange=4096.000000
	MyDamageType=None
	NameColor=(R=92,G=0,B=92)
	PickupAmmoCount=35
	ProjectileClass=Class'TriOrb'
	SelectSound=Grav_Select
	shakemag=1.000000
	shaketime=0.200000
	shakevert=1.000000
	AIRating=0.500000
	AltRefireRate=1.000000
	bAltWarnTarget=True
	bRecommendAltSplashDamage=True
	bRecommendSplashDamage=False
	bSplashDamage=False
	bWarnTarget=True
	RefireRate=1.200000
	Mass=50.000000
	bNoSmooth=False
	bOwnsCrossHair=True
	CustomCross=GravCross
	CrossHairSize=64
	LightBrightness=100
	LightHue=193
	LightSaturation=87
	LightEffect=LE_FireWaver
	LightRadius=4
	LightType=LT_Steady
	SoundVolume=128
	SoundRadius=20
	CrossHairScale=0.750000
}