//=============================================================================
// WeaponFAMAS w/ scope. 
//=============================================================================
class WeaponFAMAS extends DeusExWeapon;

var float	mpRecoilStrength;
var float ZoomingScale, ZoomGrow, MaxZoom, MinZoom;

replication
{
	reliable if(Role<ROLE_Authority)
		UpdateScope;

	reliable if(Role==ROLE_Authority)
		ZoomingScale, ZoomIn, ZoomOut;

}



function UpdateScope(float ZoomFOV, bool bScoping)
{
	ScopeFOV = ZoomFOV;
	bZoomed  = bScoping;
	RefreshScopeDisplay(DeusExPlayer(Owner), False, bZoomed);
}


function ScopeOn()
{
	if (bHasScope && !bZoomed && Owner.IsA('DeusExPlayer'))
	{
		bZoomed = True;
		RefreshScopeDisplay(DeusExPlayer(Owner), False, bZoomed);
	}
}

function ScopeOff()
{
	if (bHasScope && bZoomed && Owner.IsA('DeusExPlayer'))
	{
		bZoomed = False;
		RefreshScopeDisplay(DeusExPlayer(Owner), False, bZoomed);
	}
}


simulated function RefreshScopeDisplay(DeusExPlayer player, bool bInstant, bool bScopeOn)
{
	if (bScopeOn && (Player !=None))
	{
		DeusExRootWindow(Player.RootWindow).ScopeView.ActivateView(ScopeFOV, False, bInstant);
	}

	else if (!bScopeOn)
	{
		DeusExRootWindow(Player.RootWindow).ScopeView.DeActivateView();
	}
}


function ScopeToggle()
{
	if(!bZoomed)
	{
		ScopeOn();
	}
	else
	{
		ScopeOff();
	}
}



simulated function bool ZoomOut()
{
	if(bZoomed)
	{
		bZoomed=True;

		if(ZoomingScale < MaxZoom)
		{
			ZoomingScale += ZoomGrow;

			//ZoomingScale=MaxZoom;
			ScopeFOV=80*ZoomingScale;
			UpdateScope(ScopeFOV,True);
		}
	}

	return bZoomed;
}

simulated function bool ZoomIn()
{
	if(bZoomed)
	{
		bZoomed=True;

		if(ZoomingScale > MinZoom)
		{
			ZoomingScale -= ZoomGrow;

			//ZoomingScale=MinZoom;
			ScopeFOV=80*ZoomingScale;
			UpdateScope(ScopeFOV,True);
		}

		return bZoomed;
	}
}



simulated function PreBeginPlay()
{
	Super.PreBeginPlay();

	// If this is a netgame, then override defaults
	if ( Level.NetMode != NM_StandAlone )
	{
		HitDamage = mpHitDamage;
		BaseAccuracy = mpBaseAccuracy;
		ReloadTime = mpReloadTime;
		AccurateRange = mpAccurateRange;
		MaxRange = mpMaxRange;
		ReloadCount = mpReloadCount;

		// Tuned for advanced -> master skill system (Monte & Ricardo's number) client-side
		recoilStrength = 0.75;
	}
}




simulated function bool ClientFire( float value )
{
		if((Region.Zone.IsA('ArenaZoneSafe')) || (Region.Zone.IsA('MMRPGRoomArea')) || (Region.Zone.IsA('MMRPGSafeArea')))
		{
			return False;
		}

		if((!Region.Zone.IsA('ArenaZoneSafe')) && (!Region.Zone.IsA('MMRPGRoomArea')) && (!Region.Zone.IsA('MMRPGSafeArea')))
		{
			return Super.ClientFire(value);
		}
}


simulated function bool TestMPBeltSpot(int BeltSpot)
{
   return ( (BeltSpot >= 1) && (BeltSpot <=9) );
}

function Fire(float Value)
{
	if((Region.Zone.IsA('ArenaZoneSafe')) || (Region.Zone.IsA('MMRPGRoomArea')) || (Region.Zone.IsA('MMRPGSafeArea')))
	{
		return;
	}

	if((!Region.Zone.IsA('ArenaZoneSafe')) && (!Region.Zone.IsA('MMRPGRoomArea')) && (!Region.Zone.IsA('MMRPGSafeArea')))
	{
		Super.Fire(Value);
	}
}

defaultproperties
{
     MaxZoom=1.500000
     MinZoom=0.200000
     ZoomingScale=0.100000
     ZoomGrow=0.100000
     ScopeFOV=25
     LowAmmoWaterMark=30
     GoverningSkill=Class'DeusEx.SkillWeaponRifle'
     EnviroEffective=ENVEFF_Air
     Concealability=CONC_Visual
     bAutomatic=True
     ShotTime=0.35000
     reloadTime=3.000000
     HitDamage=7
     bHasScope=True
     bCanHaveScope=True
     BaseAccuracy=0.800000
     bCanHaveLaser=True
     bCanHaveSilencer=True
     recoilStrength=0.500000
     MinWeaponAcc=0.200000
     mpReloadTime=0.500000
     mpHitDamage=7
     mpBaseAccuracy=0.800000
     mpAccurateRange=2400
     mpMaxRange=2400
     mpReloadCount=25
     bCanHaveModBaseAccuracy=True
     bCanHaveModReloadCount=True
     bCanHaveModAccurateRange=True
     bCanHaveModReloadTime=True
     bCanHaveModRecoilStrength=True
     AmmoName=Class'Contender.Ammo556FAMAS'
     ReloadCount=25
     BobDamping=1.4
     PickupAmmoCount=25
     bInstantHit=True
     FireOffset=(X=-16.000000,Y=5.000000,Z=11.500000)
     shakemag=350.000000
     FireSound=Sound'ContenderStuff.Weapons.FAMASFire'
     AltFireSound=Sound'ContenderStuff.Weapons.FAMASReloadEnd'
     CockingSound=Sound'ContenderStuff.Weapons.FAMASReloadBegin'
     SelectSound=Sound'ContenderStuff.Weapons.FAMASSelect'
     InventoryGroup=174
     ItemName="St-Étienne F.A.M.A.S. |p3[Scoped]|p1"
     ItemArticle="a"
     PlayerViewOffset=(X=16.000000,Y=-5.000000,Z=-11.500000)
     PlayerViewMesh=LodMesh'famas1st'
     PickupViewMesh=LodMesh'famaspickup'
     ThirdPersonMesh=LodMesh'famas3rd'
     LandSound=Sound'DeusExSounds.Generic.DropMediumWeapon'
     Icon=Texture'ContenderStuff.FamasBelt'
     largeIcon=Texture'ContenderStuff.FamasLarge'
     largeIconWidth=94
     largeIconHeight=65
     invSlotsX=2
     invSlotsY=2
     Description="A FAMAS with a scope."
     beltDescription="FAMAS |p3(SC)|p1"
     Mesh=LodMesh'famaspickup'
     CollisionRadius=15.000000
     CollisionHeight=1.100000
     Mass=30.000000
}
