//=============================================================================
// Helmet. 20 points of armor, 50% absorption, but has the special ability to block a Head Shot
//=============================================================================
class Helmet expands TournamentPickup;

//Model Import
#exec mesh import mesh=Helmet anivfile=Models\Helmet_a.3d datafile=Models\Helmet_d.3d x=0 y=0 z=0
#exec MESH LODPARAMS MESH=Helmet STRENGTH=0.25
#exec mesh origin mesh=Helmet x=0 y=0 z=0

#exec mesh sequence mesh=Helmet seq=All startframe=0 numframes=1

#exec meshmap new meshmap=Helmet mesh=Helmet
#exec meshmap scale meshmap=Helmet x=0.0656 y=0.0656 z=0.1312

//Skins import
#exec TEXTURE IMPORT NAME=HelmetSkin FILE=SKINS\HelmetSkin.bmp GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=HelmetSkin FILE=SKINS\HelmetSkin.bmp GROUP=Skins PALETTE=HelmetSkin
#exec MESHMAP SETTEXTURE MESHMAP=Helmet NUM=0 TEXTURE=HelmetSkin

//Audio import
#exec AUDIO IMPORT NAME="HelmetSnd" FILE=SOUNDS\UT3_Helmet.wav GROUP="Armor"
#exec AUDIO IMPORT NAME="ArmourRespawn" FILE=SOUNDS\ArmourRespawn.wav GROUP="Armor"


var GoldenDarkOver OvShader;
var ShieldCoronaV Effect1;

simulated function PostBeginPlay()
{

	OvShader = Spawn(Class'GoldenDarkOver', Self);
	OvShader.Mesh = Mesh;

	Effect1 = Spawn(Class'ShieldCoronaV', Self);
	Effect1.DrawScale = 0.3;

	Super.PostBeginPlay();
}

simulated function Destroyed()
{

	if (Effect1 != None)
		Effect1.Destroy();

	if (OvShader != None)
		OvShader.Destroy();

	Super.Destroyed();
}


function bool HandlePickupQuery( inventory Item )
{

    if ( item.class == class ) 
    {
            if ( Charge<Item.Charge )   
                Charge = Item.Charge;

        if (Level.Game.LocalLog != None)
            Level.Game.LocalLog.LogPickup(Item, Pawn(Owner));
        if (Level.Game.WorldLog != None)
            Level.Game.WorldLog.LogPickup(Item, Pawn(Owner));
        if ( PickupMessageClass == None )
            Pawn(Owner).ClientMessage(PickupMessage, 'Pickup');
        else
            Pawn(Owner).ReceiveLocalizedMessage( PickupMessageClass, 0, None, None, Self.Class );
        Item.PlaySound (PickupSound,,2.0);
        Item.SetReSpawn();
        return true;                
    }
    if ( Inventory == None )
        return false;

    return Inventory.HandlePickupQuery(Item);
}


function int ArmorAbsorbDamage(int Damage, name DamageType, vector HitLocation)
{
    local int ArmorDamage;

    if ( DamageType != 'Drowned' )
        ArmorImpactEffect(HitLocation);
    if( (DamageType!='None') && ((ProtectionType1==DamageType) || (ProtectionType2==DamageType)) )
        return 0;
    
    if (DamageType=='Drowned') Return Damage;
    
    ArmorDamage = (Damage * ArmorAbsorption) / 100;
    if( ArmorDamage >= Charge )
    {
        ArmorDamage = Charge;
        Destroy();
    }
    else 
        Charge -= ArmorDamage;

	//Headshot protection
    if (DamageType == 'decapitated')
    {
	ArmorDamage = 0;
	Damage = 0;
	Destroy();
    }

    return (Damage - ArmorDamage);
}



State Sleeping
{
    ignores Touch;

    function BeginState()
    {
        BecomePickup();
        bHidden = true;
    }
    function EndState()
    {
        local int i;

        bSleepTouch = false;
        for ( i=0; i<4; i++ )
            if ( (Touching[i] != None) && Touching[i].IsA('Pawn') )
                bSleepTouch = true;
    }           
Begin:
    Sleep( ReSpawnTime ); 
    Sleep( XPlaySpawnEffect(self) );
    GoToState( 'Pickup' );
}


function float XPlaySpawnEffect(inventory Inv)
{
    spawn(class 'EnhancedReSpawnX',Inv,, Inv.Location );
    return 0.3;
}


defaultproperties
{
     RespawnSound=ArmourRespawn
     bDisplayableInv=True
     PickupMessage="You got the Helmet."
     RespawnTime=27.000000
     PickupViewMesh=Helmet
     Charge=20
     ArmorAbsorption=75
     bIsAnArmor=True
     AbsorptionPriority=7
     MaxDesireability=2.000000
     PickupSound=Sound'XPickups.Armor.HelmetSnd'
     Mesh=Helmet
     AmbientGlow=64
     CollisionHeight=18.750000
     CollisionRadius=18.750000
     ItemName="Helmet"
     PickupViewScale=1.0
     ArmorAbsorption=50
     AbsorptionPriority=5
     AmbientGlow=64
     RotationRate=(Yaw=30000)
}