//=============================================================================
//
//=============================================================================
class WeaponBotzor extends BOTDeusExWeapon;

var bool bDontDestroy;

simulated function SelectiveSpawnEffects( Vector HitLocation, Vector HitNormal, Actor Other, float Damage)
{
	local DeusExPlayer fxOwner;
	local Pawn aPawn;

	// The normal path before there was multiplayer
	if ( Level.NetMode == NM_Standalone )
	{
		SpawnEffects(HitLocation, HitNormal, Other, Damage);
		return;
	}
}



function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
    local int i;
    local DeusExPlayer PlayerOwner;
   
if (Other==None)
{
  HitNormal = -X;
  HitLocation = Owner.Location + X*10000.0;
 }
PlayerOwner = DeusExPlayer(Owner);
 if (PlayerOwner !=None)
 PlayerOwner.ClientInstantFlash( -0.4, vect(450, 190, 650));
 SpawnEffect(HitLocation, Owner.Location);

  if ( (Other !=self) && (Other !=Owner) && (Other !=None) )
{
if ( Role == ROLE_Authority )
 Other.TakeDamage(HitDamage, Pawn(Owner), HitLocation, Vect(0,0,0), 'Shocked');
// Other.TakeDamage(HitDamage, Pawn(Owner), HitLocation, Vect(0,0,0), 'EMP'); This is optional, makes the player take damage to their EMP too.
}
}

function SpawnEffect(vector HitLocation, vector SmokeLocation)
{
   local Tazerbeam Smoke,Shock;
   local Vector DVector;
   local int NumPoints;
   local rotator SmokeRotation;
   local Vector NewRot;

  DVector = HitLocation - SmokeLocation;
  NumPoints = VSize(DVector)/10.0;
   if ( NumPoints < 1)
       return;
 SmokeRotation = rotator(DVector);
 SmokeRotation.roll = Rand(6553595);
 
 Smoke = Spawn(class'TazerBeam',,,SmokeLocation,SmokeRotation);
 Smoke.MoveAmount = DVector/NumPoints;
 Smoke.NumPuffs = NumPoints - 1;
}


function name WeaponDamageType()
{
	return 'Shocked';
}


function Tick(float deltaTime)
{
	Super.Tick(deltaTime);

	if(Owner != None)
	{
		//If(!Owner.IsA('BOTSpiderBot'))
		//{
		//	Destroy();
		//}
	}

}


state NormalFire
{
	function AnimEnd()
	{
		if (bAutomatic)
		{
			if ((Pawn(Owner).bFire != 0) && (AmmoType.AmmoAmount > 0))
			{
				if (PlayerPawn(Owner) != None)
					Global.Fire(0);
				else 
					GotoState('FinishFire');
			}
			else 
				GotoState('FinishFire');
		}
		else
		{
			// if we are a thrown weapon and we run out of ammo, destroy the weapon
			if (bHandToHand && (ReloadCount > 0) && (AmmoType.AmmoAmount <= 0))
				Destroy();
		}
	}
	function float GetShotTime()
	{
		local float mult, sTime;

		if (ScriptedPawn(Owner) != None)
			return ShotTime * (ScriptedPawn(Owner).BaseAccuracy*2+1);
		else
		{
			// AugCombat decreases shot time
			mult = 1.0;
			if (bHandToHand && DeusExPlayer(Owner) != None)
			{
				mult = 1.0 / DeusExPlayer(Owner).AugmentationSystem.GetAugLevelValue(class'AugCombat');
				if (mult == -1.0)
					mult = 1.0;
			}
			sTime = ShotTime * mult;
			return (sTime);
		}
	}

Begin:
	if ((ClipCount >= ReloadCount) && (ReloadCount != 0))
	{
		if (!bAutomatic)
		{
			bFiring = False;
			FinishAnim();
		}

		if (Owner != None)
		{
			if (Owner.IsA('DeusExPlayer'))
			{
				bFiring = False;

				// should we autoreload?
				if (DeusExPlayer(Owner).bAutoReload)
				{
					// auto switch ammo if we're out of ammo and
					// we're not using the primary ammo
					if ((AmmoType.AmmoAmount == 0) && (AmmoName != AmmoNames[0]))
						CycleAmmo();
					ReloadAmmo();
				}
				else
				{
					if (bHasMuzzleFlash)
						EraseMuzzleFlashTexture();
					GotoState('Idle');
				}
			}
			else if (Owner.IsA('ScriptedPawn'))
			{
				bFiring = False;
				ReloadAmmo();
			}
		}
		else
		{
			if (bHasMuzzleFlash)
				EraseMuzzleFlashTexture();
			GotoState('Idle');
		}
	}
	if ( bAutomatic && (( Level.NetMode == NM_DedicatedServer ) || ((Level.NetMode == NM_ListenServer) && Owner.IsA('DeusExPlayer') && !DeusExPlayer(Owner).PlayerIsListenClient())))
		GotoState('Idle');

	Sleep(GetShotTime());
	if (bAutomatic)
	{
		GenerateBullet();	// In multiplayer bullets are generated by the client which will let the server know when
		Goto('Begin');
	}
	bFiring = False;
	FinishAnim();

	// if ReloadCount is 0 and we're not hand to hand, then this is a
	// single-use weapon so destroy it after firing once
	if ((ReloadCount == 0) && !bDontDestroy)
	{
		if (DeusExPlayer(Owner) != None)
			DeusExPlayer(Owner).RemoveItemFromSlot(Self);   // remove it from the inventory grid
		Destroy();
	}
	ReadyToFire();
Done:
	bFiring = False;
	Finish();
}



defaultproperties
{
    bDontDestroy=True
    LowAmmoWaterMark=0
    EnemyEffective=1
    ShotTime=0.30
    reloadTime=0.00
    BaseAccuracy=0.30
    bHasMuzzleFlash=False
    bOwnerWillNotify=True
    bNativeAttack=True
    shakemag=0.00
    HitDamage=25
    maxRange=1280
    AccurateRange=640
    Misc1Sound=Sound'DeusExSounds.Weapons.CombatKnifeHitFlesh'
    Misc2Sound=Sound'DeusExSounds.Weapons.CombatKnifeHitHard'
    Misc3Sound=Sound'DeusExSounds.Weapons.CombatKnifeHitSoft'
    InventoryGroup=99
    PlayerViewOffset=(X=0.00,Y=0.00,Z=0.00),
    PlayerViewMesh=LodMesh'DeusExItems.InvisibleWeapon'
    PickupViewMesh=LodMesh'DeusExItems.InvisibleWeapon'
    ThirdPersonMesh=LodMesh'DeusExItems.InvisibleWeapon'
    Icon=None
    largeIconWidth=1
    largeIconHeight=1
    Mesh=LodMesh'DeusExItems.InvisibleWeapon'
    CollisionRadius=1.00
    CollisionHeight=1.00
    Mass=5.00
     AmmoName=Class'DeusEx.AmmoNone'
     ReloadCount=0
     PickupAmmoCount=0
    FireSound=Sound'DeusExSounds.Weapons.ProdFire'
}
