//=============================================================================
// CoreDamage.
//=============================================================================
class CoreDamage expands Mutator config(SiegeUltimateRC7UB01);

var bool Initialized;
var config float DamageMultiplyer;
var config float PlayerDamageMultiplyer;
var config bool NukesAllowed;

var int PlayersActive;

function PostBeginPlay()
{
	if (Initialized)
		return;

	Initialized = True;

	Level.Game.RegisterDamageMutator( Self );

}

event Tick( float DeltaTime )
{
	local PlayerPawn Player;
	
	PlayersActive = 0;

	foreach AllActors(class'PlayerPawn', Player)
		{
			if ( Player != None )
				if ( Player.bIsPlayer == true && Spectator(Player) == None )
					{
						if ( Player.PlayerReplicationInfo.Team != 0 )
							{
								level.game.ChangeTeam(Player, 0);
								level.game.RestartPlayer(Player);
							}
						PlayersActive++;
					}
		}
		
}

function MutatorTakeDamage( out int ActualDamage, Pawn Victim, Pawn InstigatedBy, out Vector HitLocation, 
						out Vector Momentum, name DamageType)
{
	local sgBaseCore Core;
	local actor a;
	local float FinalDamage;
	
	// log("ActualDamage:"@ActualDamage);
	// log("instigatedBy:"@instigatedBy);
	
	foreach AllActors(class'sgBaseCore', Core)
		{
			if ( PlayerPawn(Victim) != None && ScriptedPawn(instigatedBy) != None  )
				if ( PlayerPawn(Victim).PlayerReplicationInfo.Team == Core.Team && Victim != instigatedBy )
					{
						if ( PlayerDamageMultiplyer != 0 )
							FinalDamage = ActualDamage * DamageMultiplyer / max(1, PlayersActive*PlayerDamageMultiplyer);
						else
							FinalDamage = ActualDamage * DamageMultiplyer;
						
						Core.MonsterDamage(FinalDamage, instigatedBy);
					}
		}

	if ( NextDamageMutator != None )
		NextDamageMutator.MutatorTakeDamage( ActualDamage, Victim, InstigatedBy, HitLocation, Momentum, DamageType );
}
defaultproperties
{
}
