class LittleVulcanRock expands Projectile;

var bool bHitWater;

var int Kickback;
var float MoreDamage;
var bool HealthGiver;
var VulcanFlare vf;


replication
{
	// Things the server should send to the client.
	reliable if(Role==ROLE_Authority)
		Kickback, MoreDamage, HealthGiver;
}

simulated function PostBeginPlay()
{
	local vector X,Y,Z;
	local rotator RandRot;

	Super.PostBeginPlay();

	if (!Region.Zone.bWaterZone)
		vf = Spawn(Class'VulcanFlare', Self);

	/*if ( Role == ROLE_Authority )
	{
		GetAxes(Instigator.ViewRotation,X,Y,Z);	
		Velocity = X * (Instigator.Velocity Dot X)*0.4 + Vector(Rotation) * (Speed +
			FRand() * 100);
		Velocity.z += 210;
		MaxSpeed = 1000;
		RandSpin(50000);
		if (Instigator.HeadRegion.Zone.bWaterZone)
		{
			bHitWater = True;
			Disable('Tick');
			Velocity=0.6*Velocity;			
		}
	}*/	
}

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

	Super.Destroyed();
}

simulated function ZoneChange( Zoneinfo NewZone )
{
	local waterring w;
	
	if (!NewZone.bWaterZone || bHitWater) Return;

	bHitWater = True;
	w = Spawn(class'WaterRing',,,,rot(16384,0,0));
	w.DrawScale = 0.2;
	w.RemoteRole = ROLE_None;
	Velocity=0.6*Velocity;

	if (vf != None)
		vf.Destroy();
}

simulated function Landed( vector HitNormal )
{
	HitWall( HitNormal, None );
}

simulated function ProcessTouch( actor Other, vector HitLocation )
{
	if (Other != Level)
	{
		if (Role == ROLE_Authority)
		{
		if ((HealthGiver && Other != Instigator) || !HealthGiver)
			Other.TakeDamage(Damage * FMax(1.0,MoreDamage), Instigator, HitLocation, MomentumTransfer * vector(Rotation) * FMin(KickBack * 1000, 1.0), MyDamageType);
		
		if (Other.IsA('Pawn') && HealthGiver)
		{
			If (((Pawn(Other).PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team && Level.Game.IsA('TeamGamePlus') && !Level.Game.IsA('MonsterHunt')) ||
			(Level.Game.IsA('MonsterHunt') && !Pawn(Other).IsA('ScriptedPawn')) || Pawn(Other) == Instigator)  && Pawn(Other).Health < Class'NWMutator'.default.MaxHealth)
			{
				Pawn(Other).Health += Damage * FMax(1.0, MoreDamage) * DrawScale;
				if (Pawn(Other).Health > Class'NWMutator'.default.MaxHealth)
					Pawn(Other).Health = Class'NWMutator'.default.MaxHealth;
			}
		}
		}

		Destroy();
	}
}

simulated function HitWall( vector HitNormal, actor Wall )
{
	Velocity = 0.75*(( Velocity dot HitNormal ) * HitNormal * (-2.0) + Velocity);   // Reflect off Wall w/damping
	RandSpin(100000);
	speed = VSize(Velocity);
	if ( Velocity.Z > 400 )
		Velocity.Z = 0.5 * (400 + Velocity.Z);	
	else if ( speed < 20 ) 
	{
		bBounce = False;
		SetPhysics(PHYS_None);
	}

	Wall.TakeDamage(Damage * FMax(1.0,MoreDamage), Instigator, Location, MomentumTransfer * vector(Rotation) * FMin(KickBack * 1000, 1.0), MyDamageType);
}

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



defaultproperties
{
	DrawType=DT_Mesh
	Mesh=LodMesh'UnrealI.TBoulder'
	bBounce=True
	bFixedRotationDir=True
	Physics=PHYS_Falling
	RemoteRole=ROLE_SimulatedProxy
	Damage=12.000000
	MaxSpeed=1000.000000
	MomentumTransfer=50000
	MyDamageType=Rock
	speed=800.000000
	DrawScale=2.000000
	LifeSpan=3.000000
	bNetTemporary=True
	MultiSkins(1)=VRock
	CollisionHeight=2.000000
	CollisionRadius=2.000000
}
