class FireBall expands Projectile;


var bool bHitWater;

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

var FlameTBTrail FlameTrail;


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


simulated function Destroyed()
{
    if ( FlameTrail != None )
        FlameTrail.Destroy();
    Super.Destroyed();
}

simulated function PostBeginPlay()
{
    FlameTrail = Spawn(Class'FlameTBTrail', Self);
    SetTimer(0.05, true);
}


simulated function Timer()
{
    local FireBallSmk b;

       	b = Spawn(class'FireBallSmk');
        b.RemoteRole = ROLE_None;
}

//Special HurtRadius - With Health giving implementation
//******************************************************************************************************************
function HurtRadiusX( float DamageAmount, float DamageRadius, name DamageName, float Momentum, vector HitLocation )
{
    local actor Victims;
    local float damageScale, dist;
    local vector dir;
    local Pawn P;
    
    if( bHurtEntry )
        return;

    bHurtEntry = true;
    foreach VisibleCollidingActors( class 'Actor', Victims, DamageRadius, HitLocation )
    {
	if (HealthGiver && Victims.IsA('Pawn'))
	{
		dir = Victims.Location - HitLocation;
		dist = FMax(1,VSize(dir));
		dir = dir/dist; 
		damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);

		P = Pawn(Victims);
		If (((P.PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team && Level.Game.IsA('TeamGamePlus') && !Level.Game.IsA('MonsterHunt')) ||
		(Level.Game.IsA('MonsterHunt') && !P.IsA('ScriptedPawn')) || P==Instigator) && 
		P.Health < Class'NWMutator'.default.MaxHealth)
		{
			P.Health += damageScale * DamageAmount * FMax(1.0,MoreDamage);
			if (P.Health > Class'NWMutator'.default.MaxHealth)
				P.Health = Class'NWMutator'.default.MaxHealth;
		}
		else
		{
        	if( Victims != self )
        	{
         	   Victims.TakeDamage(
                	damageScale * DamageAmount,
                	Instigator, 
			Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
			(damageScale * Momentum * dir),
			DamageName
			);
        	}
	}
		
	}
	else
	{
        if( Victims != self )
        {
            dir = Victims.Location - HitLocation;
            dist = FMax(1,VSize(dir));
            dir = dir/dist; 
            damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);
            Victims.TakeDamage
            (
                damageScale * DamageAmount,
                Instigator, 
                Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
                (damageScale * Momentum * dir),
                DamageName
            );
        }
	}
    }

    bHurtEntry = false;
}
//******************************************************************************************************************


auto state Flying
{

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

        bHitWater = True;
        if ( Level.NetMode != NM_DedicatedServer )
        {
            w = Spawn(class'WaterRing',,,,rot(16384,0,0));
            w.DrawScale = 0.2;
            w.RemoteRole = ROLE_None;
        }       
        Velocity=0.6*Velocity;
    }

    simulated function ProcessTouch (Actor Other, Vector HitLocation)
    {
        if ( (Other != instigator) && (!Other.IsA('Projectile') || Other.bProjTarget)) 
            Explode(HitLocation,Normal(HitLocation-Other.Location));
    }

function BlowUp(vector HitLocation)
{
	HurtRadiusX(Damage * FMax(1.0,MoreDamage), 350 * FMax(1.0, Splasher), MyDamageType, MomentumTransfer * (KickBack + 1), HitLocation);
	MakeNoise(1.0);
}



    simulated function Explode(vector HitLocation, vector HitNormal)
    {
        local FireBallBlast s;

        s = spawn(class'FireBallBlast',,,HitLocation + HitNormal*16);  
        s.RemoteRole = ROLE_None;

        BlowUp(HitLocation);

        Destroy();
    }

    function BeginState()
    {
        local vector Dir;

        Dir = vector(Rotation);
        Velocity = speed * Dir;
        Acceleration = Dir * 50;
        if (Region.Zone.bWaterZone)
        {
            bHitWater = True;
            Velocity=0.6*Velocity;
        }
    }
}


defaultproperties
{
	DrawType=DT_Mesh
	Mesh=FlameTBall
	ExplosionDecal=class'Botpack.BlastMark'
	MyDamageType=Burned
	speed=1100.000000
	MaxSpeed=1500.000000
	Damage=120.000000
	MomentumTransfer=80000
	SpawnSound=None
	RemoteRole=ROLE_SimulatedProxy
	DrawScale=1.000000
	bUnlit=True
	SoundRadius=128
	SoundVolume=255
	SoundPitch=65
	AmbientSound=Flamming
	LightType=LT_Steady
	LightEffect=LE_NonIncidence
	LightBrightness=255
	LightHue=0
	LightSaturation=0
	LightRadius=6
	bBounce=True
}
