class IceSpike expands Projectile;

#exec MESH IMPORT MESH=IceSpike ANIVFILE=MODELS\IceSpike_a.3d DATAFILE=MODELS\IceSpike_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=IceSpike X=0 Y=0 Z=0

#exec MESH SEQUENCE MESH=IceSpike SEQ=All STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=IceSpike SEQ=Still STARTFRAME=0 NUMFRAMES=1

#exec MESHMAP NEW MESHMAP=IceSpike MESH=IceSpike
#exec MESHMAP SCALE MESHMAP=IceSpike X=0.025 Y=0.005 Z=0.01


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

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

simulated function Timer()
{
	DrawScale += 0.5;
}

simulated function PostBeginPlay()
{
	if (Region.Zone.bWaterZone)
	{
		SetTimer(0.1, True);
		Velocity *= 0.75;
	}
		
}

simulated function ReleaseFragEffect(class<fragment> FragType, texture FragSkin, vector Momentum, float DSize, int NumFrags) 
{
	local int i;
	local actor A, Toucher;
	local Fragment s;

	for (i=0 ; i<NumFrags ; i++) 
	{
		s = Spawn( FragType, Owner);

		if (s != None)
		{
			s.CalcVelocity(Momentum/100,0);
			s.Skin = FragSkin;
			s.Texture = FragSkin;
			s.DrawScale = DSize*0.5+0.7*DSize*FRand();
			s.LifeSpan = 3.0;
			s.Style = STY_Translucent;
			s.bMeshEnviroMap = True;
		}
	}

	Destroy();
}


auto state Flying
{

    simulated function ZoneChange( Zoneinfo NewZone )
    {
        if (NewZone.bWaterZone)
	{
		SetTimer(0.1, True);
		Velocity *= 0.75;
	}
    }


    simulated function ProcessTouch (Actor Other, Vector HitLocation)
    {
	if (Role == ROLE_Authority)
	{
	if (Other != Instigator && !Other.IsA('Projectile') && Other!=Level)
	{
		Other.TakeDamage(Damage * FMax(1.0,MoreDamage) * DrawScale, 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).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;
			}
		}

		Explode(HitLocation, vect(0,0,1));
	}
	else if (Other.IsA('Pawn') && HealthGiver && Other == Instigator)
		{
			If (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;
			}
		}
	}
	
    }


    simulated function Explode(vector HitLocation, vector HitNormal)
    {
	ReleaseFragEffect(Class'FragmentIce', Texture'Ice', -MomentumTransfer * vector(Rotation) * FMin(KickBack * 1000, 1.0), DrawScale / 12, 3);
    }

    function BeginState()
    {
        local vector Dir;

        Dir = vector(Rotation);
        Velocity = speed * Dir;
        Acceleration = Dir * 50;

	if (Region.Zone.bWaterZone)
		Velocity *= 0.75;	
    }
}



defaultproperties
{
	DrawType=DT_Mesh
	Mesh=IceSpike
	Style=STY_Translucent
	bBounce=True
	RemoteRole=ROLE_SimulatedProxy
	Damage=8
	MaxSpeed=2000.000000
	MomentumTransfer=2000
	MyDamageType="Spiked"
	speed=1500.000000
	DrawScale=1.000000
	bUnlit=True
	ScaleGlow=3.000000
	bNetTemporary=True
	bMeshEnviroMap=True
	Texture=Ice
}
