//=============================================================================
//Snowball Left Hand Proj. -Does less damage than the right
//=============================================================================
class snowballLP extends Projectile;

var float ExplodeTimer;
var bool bCanHitOwner, bHitWater;
var xEmitter Trail;
var() float DampenFactor, DampenFactorParallel;
var class<xEmitter> HitEffectClass;
var float LastSparkTime;
var bool bTimerSet;

replication
{
    reliable if (Role==ROLE_Authority)
        ExplodeTimer;
}

simulated function Destroyed()
{
    if ( Trail != None )
        Trail.mRegen = false; // stop the emitter from regenerating
	Super.Destroyed();
}

simulated function PostBeginPlay()
{
//	local PlayerController PC;
//Dont want the smoke effect to spawn when firing
//   Super.PostBeginPlay();

//              if ( Level.NetMode != NM_DedicatedServer)
//              {
//		PC = Level.GetLocalPlayerController();
//		if ( (PC.ViewTarget != None) && VSize(PC.ViewTarget.Location - Location) < 5500 )
//			Trail = Spawn(class'SnowballTrail', self,, Location, Rotation);
//              }

    if ( Role == ROLE_Authority )
    {
        Velocity = Speed * Vector(Rotation);
        RandSpin(25000);
        bCanHitOwner = false;
        if (Instigator.HeadVolume.bWaterVolume)
        {
            bHitWater = true;
            Velocity = 0.6*Velocity;
        }
    }
}

simulated function PostNetBeginPlay()
{
	if ( Physics == PHYS_None )
    {
        SetTimer(ExplodeTimer, false);
        bTimerSet = true;
    }
}

simulated function Timer()
{
Explode(Location, vect(0,0,1));
}

simulated function Landed( vector HitNormal )
{
HitWall( HitNormal, None );
Damage = 0; //when opponent steps on a fallen snowball, he is not hurt or pushed.
Momentumtransfer = 0;
Spawn(class'thrownsnowballpickup');

}

simulated function ProcessTouch( actor Other, vector HitLocation )
{
    if ( Pawn(Other) != None && (Other != Instigator || bCanHitOwner) )
    {
		Explode(HitLocation, Normal(HitLocation-Other.Location));
    }
}
  
simulated function HitWall( vector HitNormal, actor Wall )
{
    local Vector VNorm;
	//local PlayerController PC;

	if ( (Pawn(Wall) != None) || (GameObjective(Wall) != None) )
	{
		Explode(Location, HitNormal);
                return;
	}

    if (!bTimerSet)
    {
        SetTimer(ExplodeTimer, false);
        bTimerSet = true;

    }
    // Reflect off Wall w/damping
    VNorm = (Velocity dot HitNormal) * HitNormal;
    Velocity = -VNorm * DampenFactor + (Velocity - VNorm) * DampenFactorParallel;
    damage = 0;   //same thing as for the landing, so no damage is done from a snowball bouncing off wall.
    MomentumTransfer = 0;
    RandSpin(100000);
    DesiredRotation.Roll = 0;
    RotationRate.Roll = 0;
    Speed = VSize(Velocity);
    if ( Speed < 20 )
    {
        bBounce = False;
        PrePivot.Z = -1.5;
			SetPhysics(PHYS_None);
		DesiredRotation = Rotation;
		DesiredRotation.Roll = 0;
		DesiredRotation.Pitch = 0;
		SetRotation(DesiredRotation);
       // if ( Trail != None )
      //      Trail.mRegen = false; // stop the emitter from regenerating
    }
    else
    {
		if ( (Level.NetMode != NM_DedicatedServer) && (Speed > 250) )
			PlaySound(ImpactSound, SLOT_Misc );
		else
		{
		        damage = 0;
		        Momentumtransfer = 0;
			bFixedRotationDir = false;
			bRotateToDesired = true;
			DesiredRotation.Pitch = 0;
			RotationRate.Pitch = 50000;
		}		
        //if ( !Level.bDropDetail && (Level.DetailMode != DM_Low) && (Level.TimeSeconds - LastSparkTime > 0.5) && EffectIsRelevant(Location,false) )
        //{
	//		PC = Level.GetLocalPlayerController();
	//		if ( (PC.ViewTarget != None) && VSize(PC.ViewTarget.Location - Location) < 6000 )
	//			Spawn(HitEffectClass,,, Location, Rotator(HitNormal));
       //     LastSparkTime = Level.TimeSeconds;
       // }

    }
}
simulated function BlowUp(vector HitLocation)
{
	DelayedHurtRadius(Damage,DamageRadius, MyDamageType, MomentumTransfer, HitLocation );
	if ( Role == ROLE_Authority )
		MakeNoise(1.0);
}

simulated function Explode(vector HitLocation, vector HitNormal)
{
    BlowUp(HitLocation);
//	PlaySound(sound'WeaponSounds.BExplosion1',,2.5*TransientSoundVolume);
   //if ( EffectIsRelevant(Location,false) )
   //{
   //     Spawn(class'SnowballTrail',,, HitLocation, rotator(vect(0,0,1)));
//		Spawn(ExplosionDecal,self,,HitLocation, rotator(-HitNormal));
   // }
    Destroy();
}

defaultproperties
{
     ExplodeTimer=0.0001  //since the snowball SM is aound 600 polys, better keep this low.
     DampenFactor=4.000
     DampenFactorParallel=0.800000
     Speed=2000.000000
     TossZ=0.000000
     Damage=125.000000
     DamageRadius=150.00000
     MomentumTransfer=20000.000000
     MyDamageType=Class'snowballfight.DamTypesnowball'
     ImpactSound=SoundGroup'WeaponSounds.BioRifle.BioRifleGoo2'
     //ExplosionDecal=Class'snowballFight.SBSplat'
     Physics=PHYS_Falling
     DrawType=DT_StaticMesh
     StaticMesh=StaticMesh'snowballSM.snowballpickup'
     DrawScale=1.0000
     bUnlit=False
     bUseDynamicLights=True
     bShadowCast=True
     bStaticLighting=False
     AmbientGlow=53
     bBounce=False
     bFixedRotationDir=False
     bcanHitOwner=False
     DesiredRotation=(Pitch=12000,Yaw=5666,Roll=2334)
}
