class ObjectsFlames expands Actor;

#exec AUDIO IMPORT NAME="PawnBurn" FILE=SOUNDS\PawnBurn.wav GROUP="FlameT"
#exec AUDIO IMPORT NAME="OtherBurn" FILE=SOUNDS\OtherBurn.wav GROUP="FlameT"

#exec TEXTURE IMPORT NAME=TranslucentInvisible FILE=SKINS\TranslucentInvisible.bmp GROUP=Skins FLAGS=2 LODSET=2

#exec AUDIO IMPORT NAME="PosFireSteam" FILE=SOUNDS\PosFireSteam.wav GROUP="FlameT"


var float MoreDamage;
var bool HealthGiver;
var Actor DamVic;

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

simulated function PostBeginPlay()
{
local int i;

	if (Region.Zone.bWaterZone) //Flames cannot exist underwater
		Destroy();

	if (Owner != None)
	{
	if (Owner.IsA('Pawn') || Owner.IsA('Carcass'))
		AmbientSound = Sound'PawnBurn';
	else
	{
		AmbientSound = Sound'OtherBurn';
		SoundVolume *= 2;
	}

	if (Owner.IsA('Decoration') && Owner.Tag != 'NoCarbonize' && !Owner.IsA('Vehicle') && !Owner.IsA('StrangeShell'))
	{
		For (i=0; i<8; i++)
			Owner.MultiSkins[i] = Texture'TranslucentInvisible';
	}
	}

	SetTimer(0.2,True);
}

simulated function Timer()
{
local RisingFlames F;
local Actor A;
local bool bOwnedSome;
	
	if (Owner != None)
	{
		ForEach VisibleCollidingActors (Class'Actor', A, 32, Owner.Location)
		{
			if (A == Owner)
				bOwnedSome = True;
		}
	}

	If (Owner == None || !bOwnedSome)
	{
		Destroy();
		return;
	}
	else if (Owner.bHidden)
	{
		Destroy();
		return;
	}

	if (Level.NetMode != NM_DedicatedServer)
	{
		F = Spawn(Class'RisingFlames', Owner,, Owner.Location, Owner.Rotation);
		F.Mesh = Owner.Mesh;
		F.AnimSequence = Owner.AnimSequence;
		F.AnimFrame = Owner.AnimFrame;
	}

	
	if (Role == ROLE_Authority)
	{
	/*if (!HealthGiver)
		Owner.TakeDamage( FMax(1.0,MoreDamage), Instigator, Location, vect(0,0,0), 'Burned');
	else If (Owner.IsA('Pawn'))
	{
	If ((Pawn(Owner).PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team && Level.Game.IsA('TeamGamePlus') && !Level.Game.IsA('MonsterHunt')) ||
		(Level.Game.IsA('MonsterHunt') && !Pawn(Owner).IsA('ScriptedPawn')) && Pawn(Owner).Health < Class'NWMutator'.default.MaxHealth)
		{
			Pawn(Owner).Health += FMax(1.0,MoreDamage);
				if (Pawn(Owner).Health > Class'NWMutator'.default.MaxHealth)
					Pawn(Owner).Health = Class'NWMutator'.default.MaxHealth;
		}
		else if (Pawn(Owner) == Instigator && Pawn(Owner).Health < Class'NWMutator'.default.MaxHealth)
		{
			Pawn(Owner).Health += FMax(1.0,MoreDamage);
				if (Pawn(Owner).Health > Class'NWMutator'.default.MaxHealth)
					Pawn(Owner).Health = Class'NWMutator'.default.MaxHealth;
		}
		else
			Owner.TakeDamage( FMax(1.0,MoreDamage), Instigator, Location, vect(0,0,0), 'Burned');
	}*/

	HurtRadiusX(FMax(1.0,MoreDamage), 48.0, 'Burned', 0.0, Location);

	}
		
	
	If (Region.Zone.bWaterZone)
	{
		PlaySound(Sound'PosFireSteam',,10.0,,2200);
		Destroy();
	}
}


//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;
}
//******************************************************************************************************************

defaultproperties
{
	DrawType=DT_Sprite
	RemoteRole=ROLE_SimulatedProxy
	LifeSpan=5.000000
	bHidden=True
	Physics=PHYS_Trailer
	LightBrightness=100
	LightHue=0
	LightSaturation=0
	LightRadius=8
	LightEffect=LE_NonIncidence
	LightType=LT_Steady
	SoundVolume=96
	bStasis=False
}

