//=============================================================================
// UBerseker.
//=============================================================================
class UBerseker expands TournamentPickup;

//Model Import
#exec mesh import mesh=UT3_Berserk anivfile=Models\UT3_Berserk_a.3d datafile=Models\UT3_Berserk_d.3d x=0 y=0 z=0 mlod=0
#exec mesh origin mesh=UT3_Berserk x=0 y=0 z=0
#exec mesh sequence mesh=UT3_Berserk seq=All startframe=0 numframes=1

#exec meshmap new meshmap=UT3_Berserk mesh=UT3_Berserk
#exec meshmap scale meshmap=UT3_Berserk x=0.093 y=0.093 z=0.186

//Audio import
#exec AUDIO IMPORT NAME="BerzerkWarning" FILE=SOUNDS\BerzerkWarning.wav GROUP="UBerseker"
#exec AUDIO IMPORT NAME="BerzerkEnd" FILE=SOUNDS\BerzerkEnd.wav GROUP="UBerseker"
#exec AUDIO IMPORT NAME="BerzerkPickup" FILE=SOUNDS\BerzerkPickup.wav GROUP="UBerseker"
#exec AUDIO IMPORT NAME="BerserkRespawn" FILE=SOUNDS\BerserkRespawn.wav GROUP="UBerseker"

//Skins import
#exec TEXTURE IMPORT NAME=UBersSkin00 FILE=SKINS\udamExtraT.pcx GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=UBersSkin00 FILE=SKINS\udamExtraT.pcx GROUP=Skins PALETTE=UBersSkin00
#exec MESHMAP SETTEXTURE MESHMAP=UT3_Berserk NUM=0 TEXTURE=UBersSkin00

#exec MESHMAP SETTEXTURE MESHMAP=UT3_Berserk NUM=1 TEXTURE=BerserkFluid

#exec TEXTURE IMPORT NAME=UBersSkin02 FILE=SKINS\bdr01CS.pcx GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=UBersSkin02 FILE=SKINS\bdr01CS.pcx GROUP=Skins PALETTE=UBersSkin02
#exec MESHMAP SETTEXTURE MESHMAP=UT3_Berserk NUM=2 TEXTURE=UBersSkin02

#exec TEXTURE IMPORT NAME=InvSkin04 FILE=SKINS\PBbas18AL.pcx GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=InvSkin04 FILE=SKINS\PBbas18AL.pcx GROUP=Skins PALETTE=InvSkin04
#exec MESHMAP SETTEXTURE MESHMAP=UT3_Berserk NUM=3 TEXTURE=InvSkin04

#exec TEXTURE IMPORT NAME=UBersSkin04 FILE=SKINS\BerserkTop.pcx GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=UBersSkin04 FILE=SKINS\BerserkTop.pcx GROUP=Skins PALETTE=UBersSkin04
#exec MESHMAP SETTEXTURE MESHMAP=UT3_Berserk NUM=4 TEXTURE=UBersSkin04

#exec TEXTURE IMPORT NAME=UBersSkin05 FILE=SKINS\stngls02go.pcx GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=UBersSkin05 FILE=SKINS\stngls02go.pcx GROUP=Skins PALETTE=UBersSkin05
#exec MESHMAP SETTEXTURE MESHMAP=UT3_Berserk NUM=5 TEXTURE=UBersSkin05

#exec TEXTURE IMPORT NAME=UBersSkin06 FILE=SKINS\PBbas01AL.pcx GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=UBersSkin06 FILE=SKINS\PBbas01AL.pcx GROUP=Skins PALETTE=UBersSkin06
#exec MESHMAP SETTEXTURE MESHMAP=UT3_Berserk NUM=6 TEXTURE=UBersSkin06

//-----------------------------------------------------------------------

var Weapon UBersWeapon;
var int FinalCount;
var() sound WarnSound, EndSound;
var() texture GFXWeaponEffect;
var() float FireRateMultiplier;
var float BugFixC;
var bool AlreadyDone;

//Compatible weapons variables
var BersChainSaw UBers01;
var UBersEnforcer UBers02;
var UBersImpactHammer UBers03;
var UBersMinigun2 UBers04;
var UBersPulsegun UBers05;
var UBersRipper UBers06;
var UBersShockRifle UBers07;
var UBersSuperShockRifle UBers08;
var UBersSniperRifle UBers09;
var UBersUT_BioRifle UBers10;
var UBersUT_EightBall UBers11;
var UBersUT_FlakCannon UBers12;
var UBersWarHeadLauncher UBers13;


var() name WearedOffEvent;
var() name DroppedEvent;
var() name ReActivateEvent;

var bool bDroppedNWaiting;

var() sound GroundSound, UseSound;
var AmbientSTrail ast;

var BerserkEffect Effect1A, Effect1B;
var BerserkCoronaV Effect2;
var BerserkCoronaH Effect3A, Effect3B;

var float EffectTimeCountA;
var bool bEffectSpawnedA;

var name WOEvent[32];
var name DEvent[32];
var name RAEvent[32];

var() byte UseSoundRadius, UseSoundVol;

replication
{
    reliable if( Role==ROLE_Authority)
	bDroppedNWaiting;
}


simulated function PostBeginPlay()
{
	Effect1A = Spawn(Class'BerserkEffect', Self);
	Effect2 = Spawn(Class'BerserkCoronaV', Self);
	Effect3A = Spawn(Class'BerserkCoronaH', Self);
	Effect3A.PrePivotDelta = vect(2,0,22);
	Effect3B = Spawn(Class'BerserkCoronaH', Self);
	Effect3B.PrePivotDelta = vect(2,0,-22);

	Super.PostBeginPlay();
}


simulated function Destroyed()
{
local Actor A;
local byte bj;

	if (WearedOffEvent != '' && (Charge <= 0 || bDroppedNWaiting))
	{
	ForEach AllActors( class 'Actor', A, WearedOffEvent)
                		A.Trigger( Self, Instigator );

		For (bj=0; bj<32; bj++)
		{
			if (WOEvent[bj] != '')
			{
				ForEach AllActors( class 'Actor', A, WOEvent[bj])
                			A.Trigger( Self, Instigator );
			}
		}
	}

	if (DroppedEvent != '' && Charge > 0 && Pawn(Owner)!=None)
	{
	ForEach AllActors( class 'Actor', A, DroppedEvent)
                		A.Trigger( Self, Instigator );

		For (bj=0; bj<32; bj++)
		{
			if (DEvent[bj] != '')
			{
				ForEach AllActors( class 'Actor', A, DEvent[bj])
                			A.Trigger( Self, Instigator );
			}
		}
	}

	if (Effect1A != None)
		Effect1A.Destroy();
	if (Effect1B != None)
		Effect1B.Destroy();
	if (Effect2 != None)
		Effect2.Destroy();
	if (Effect3A != None)
		Effect3A.Destroy();
	if (Effect3B != None)
		Effect3B.Destroy();

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

	if (Charge > 0 && !bDroppedNWaiting)
		DropACopy();

	if (Pawn(Owner) == None && !bHidden)
		Level.Game.PlaySpawnEffect(Self);

	Super.Destroyed();
}

function DropACopy()
{
local UBerseker BS;
local vector PossibleLoc, HitLocation, HitNormal;
local actor AT;
local byte bj;

	PossibleLoc = Pawn(Owner).Location + (Rand(128) - 64)*vect(1,0,0) + (Rand(128) - 64)*vect(0,1,0);
	AT = Trace (HitLocation, HitNormal, PossibleLoc, Pawn(Owner).Location, False);

	if (AT == None)
		BS = Spawn(Class'UBerseker', None,, PossibleLoc, Rand(32768) * rot(0,1,0));
	else
		BS = Spawn(Class'UBerseker', None,, Pawn(Owner).Location, Rand(32768) * rot(0,1,0));

	BS.bDroppedNWaiting = True;
	BS.Charge = Charge;
	BS.Event = Event;
	BS.WearedOffEvent = WearedOffEvent;
	BS.SetPhysics(PHYS_Falling);
	BS.bRotatingPickup = False;
	BS.RotationRate = rot(0,0,0);
	BS.Tag = Tag;
	BS.bFixedRotationDir = False;
	BS.ReActivateEvent = ReActivateEvent;
	BS.DroppedEvent = DroppedEvent;
	BS.LifeSpan = 20.0;

	For (bj=0; bj<32; bj++)
	{
		BS.WOEvent[bj] = WOEvent[bj];
		BS.DEvent[bj] = DEvent[bj];
		BS.RAEvent[bj] = RAEvent[bj];
	}
}

function inventory SpawnCopy( pawn Other )
{
    local inventory Copy;

    if( Level.Game.ShouldRespawn(self) && !bDroppedNWaiting)
    {
        Copy = spawn(Class,Other,,,rot(0,0,0));
        Copy.Tag           = Tag;
        Copy.Event         = Event;
        GotoState('Sleeping');
    }
    else
        Copy = self;

    Copy.RespawnTime = 0.0;
    Copy.bHeldItem = true;
	UBerseker(Copy).WearedOffEvent = WearedOffEvent;
	UBerseker(Copy).DroppedEvent = DroppedEvent;
	UBerseker(Copy).ReActivateEvent = ReActivateEvent;
    Copy.Charge = Charge;
    Copy.GiveTo( Other );
    return Copy;
}


function bool HandlePickupQuery( inventory Item )
{
local byte bj, bi;
local bool bHaveThisEventReg;
local Inventory Inv;

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

		for( Inv=Pawn(Owner).Inventory; Inv!=None; Inv=Inv.Inventory )
    		{
			if (Ammo(Inv)!=None && !Ammo(Inv).IsA('WarHeadAmmo')) 
       			{
            			Ammo(Inv).AmmoAmount = Ammo(Inv).MaxAmmo;              
        		}

		}

		//Events management
		///////////////////////////////////////////////////////////

		if (WearedOffEvent == '')
			WearedOffEvent = UBerseker(Item).WearedOffEvent;
		if (DroppedEvent == '')
			DroppedEvent = UBerseker(Item).DroppedEvent;

		if (WearedOffEvent != UBerseker(Item).WearedOffEvent)
		{
			bHaveThisEventReg = False;
			For (bj=0; bj<32; bj++)
			{
				if (WOEvent[bj] == UBerseker(Item).WearedOffEvent)
				{
					bHaveThisEventReg = True;
					break;
				}
			}

			if (!bHaveThisEventReg)
			{
				For (bj=0; bj<32; bj++)
				{
					if (WOEvent[bj] == '')
					{
						WOEvent[bj] = UBerseker(Item).WearedOffEvent;
						break;
					}
				}
			}
		}

		if (DroppedEvent != UBerseker(Item).DroppedEvent)
		{
			bHaveThisEventReg = False;
			For (bj=0; bj<32; bj++)
			{
				if (DEvent[bj] == UBerseker(Item).DroppedEvent)
				{
					bHaveThisEventReg = True;
					break;
				}
			}

			if (!bHaveThisEventReg)
			{
				For (bj=0; bj<32; bj++)
				{
					if (DEvent[bj] == '')
					{
						DEvent[bj] = UBerseker(Item).DroppedEvent;
						break;
					}
				}
			}
		}

		if (ReActivateEvent != UBerseker(Item).ReActivateEvent)
		{
			bHaveThisEventReg = False;
			For (bj=0; bj<32; bj++)
			{
				if (RAEvent[bj] == UBerseker(Item).ReActivateEvent)
				{
					bHaveThisEventReg = True;
					break;
				}
			}

			if (!bHaveThisEventReg)
			{
				For (bj=0; bj<32; bj++)
				{
					if (RAEvent[bj] == '')
					{
						RAEvent[bj] = UBerseker(Item).ReActivateEvent;
						break;
					}
				}
			}
		}

		For (bj=0; bj<32; bj++)
		{
			if (UBerseker(Item).WOEvent[bj] != '')
			{
				bHaveThisEventReg = False;
				For (bi=0; bi<32; bi++)
				{
					if (UBerseker(Item).WOEvent[bj] == WOEvent[bi])
					{
						bHaveThisEventReg = True;
						break;
					}
				}

				
				if (!bHaveThisEventReg)
				{
					For (bi=0; bi<32; bi++)
					{
						if (WOEvent[bi] == '')
						{
							WOEvent[bi] = UBerseker(Item).WOEvent[bj];
							break;
						}
					}
				}
				
			}
			else
				break;
		}


		For (bj=0; bj<32; bj++)
		{
			if (UBerseker(Item).DEvent[bj] != '')
			{
				bHaveThisEventReg = False;
				For (bi=0; bi<32; bi++)
				{
					if (UBerseker(Item).DEvent[bj] == DEvent[bi])
					{
						bHaveThisEventReg = True;
						break;
					}
				}

				
				if (!bHaveThisEventReg)
				{
					For (bi=0; bi<32; bi++)
					{
						if (DEvent[bi] == '')
						{
							DEvent[bi] = UBerseker(Item).DEvent[bj];
							break;
						}
					}
				}
				
			}
			else
				break;
		}

		For (bj=0; bj<32; bj++)
		{
			if (UBerseker(Item).RAEvent[bj] != '')
			{
				bHaveThisEventReg = False;
				For (bi=0; bi<32; bi++)
				{
					if (UBerseker(Item).RAEvent[bj] == RAEvent[bi])
					{
						bHaveThisEventReg = True;
						break;
					}
				}

				
				if (!bHaveThisEventReg)
				{
					For (bi=0; bi<32; bi++)
					{
						if (RAEvent[bi] == '')
						{
							RAEvent[bi] = UBerseker(Item).RAEvent[bj];
							break;
						}
					}
				}
				
			}
			else
				break;
		}
			

		if (Event == '')
			Event = UBerseker(Item).Event;
		////////////////////////////////////////////////////////////////////////////////////
	}
            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 ( Item.PickupMessageClass == None )
                Pawn(Owner).ClientMessage(item.PickupMessage, 'Pickup');
            else
                Pawn(Owner).ReceiveLocalizedMessage( item.PickupMessageClass, 0, None, None, item.Class );
            Item.PlaySound (item.PickupSound,,2.0);
            Item.SetReSpawn();

        return true;        
    }

    if ( Inventory == None )
        return false;

    return Inventory.HandlePickupQuery(Item);
}


singular function UsedUp()
{
	if ( UBersWeapon != None )
	{			
		UBersWeapon.SetDefaultDisplayProperties();

		if (UBers01 != None)
			UBers01.UBFireRate = 1;
		else if (UBers02 != None)
			UBers02.UBFireRate = 1;
		else if (UBers03 != None)
			UBers03.UBFireRate = 1;
		else if (UBers04 != None)
			UBers04.UBFireRate = 1;
		else if (UBers05 != None)
			UBers05.UBFireRate = 1;
		else if (UBers06 != None)
			UBers06.UBFireRate = 1;
		else if (UBers07 != None)
			UBers07.UBFireRate = 1;
		else if (UBers08 != None)
			UBers08.UBFireRate = 1;
		else if (UBers09 != None)
			UBers09.UBFireRate = 1;
		else if (UBers10 != None)
			UBers10.UBFireRate = 1;
		else if (UBers11 != None)
			UBers11.UBFireRate = 1;
		else if (UBers12 != None)
			UBers12.UBFireRate = 1;
		else if (UBers13 != None)
			UBers13.UBFireRate = 1;
		else if (UbersWeapon != None)
			Pawn(Owner).DamageScaling /= 2;

	}

	bActive = False;	

	if ( Owner != None )
	{
		if ( Owner.bIsPawn )
		{
			if ( !Pawn(Owner).bIsPlayer || 

(Pawn(Owner).PlayerReplicationInfo.HasFlag == None) )
			{
				Owner.AmbientGlow = Owner.Default.AmbientGlow;
				Owner.LightType = LT_None;
			}
		}

		bActive = false;

		if ( Owner.Inventory != None )
		{
			Owner.Inventory.SetOwnerDisplay();
			Owner.Inventory.ChangedWeapon();
		}

		if (Level.Game.LocalLog != None)
			Level.Game.LocalLog.LogItemDeactivate(Self, Pawn(Owner));
		if (Level.Game.WorldLog != None)
			Level.Game.WorldLog.LogItemDeactivate(Self, Pawn(Owner));
	}

	Destroy();
}


function SetOwnerLighting()
{

	if (Pawn(Owner).FindInventoryType(Class'UbersInvisibility')==None
		|| Pawn(Owner).FindInventoryType(Class'UbersInvisibility').Charge <= 0)
		{

	if ( Owner.bIsPawn && Pawn(Owner).bIsPlayer
		&& (Pawn(Owner).PlayerReplicationInfo.HasFlag != None) ) 
		return;
	Owner.AmbientGlow = 254; 
	Owner.LightEffect=LE_NonIncidence;
	Owner.LightBrightness=255;
	Owner.LightHue=0;
	Owner.LightRadius=10;
	Owner.LightSaturation=0;
	Owner.LightType=LT_Steady;

	}
}

simulated function Tick(float DeltaTime)
{
	if (!bHidden && Pawn(Owner) == None && AmbientSound != GroundSound)
		AmbientSound = GroundSound;
	else if (bHidden && AmbientSound == GroundSound)
		AmbientSound = None;

	if (!bEffectSpawnedA)
		EffectTimeCountA += DeltaTime;

	if (!bEffectSpawnedA && EffectTimeCountA > 0.3)
	{
		bEffectSpawnedA = True;
		Effect1B = Spawn(Class'BerserkEffect', Self);
	}

	if ((Region.Zone.bDestructive || Region.Zone.bKillZone || Region.Zone.DamagePerSec > 0) && Pawn(Owner) == None)
	{
		Charge = 0;
		Destroy();
	}
}

simulated function SpawnAS()
{
	ast = Spawn(Class'AmbientSTrail', Pawn(Owner));
	ast.AmbientSound = UseSound;
	ast.SoundRadius = UseSoundRadius;
	ast.SoundVolume = UseSoundVol;
}


function SetBersekerWeapon()
{
	if ( !bActive )
		return;

	SetOwnerLighting();

	// Make old weapon normal again.
		if (UBers01 != None)
			UBers01.UBFireRate = 1;
		else if (UBers02 != None)
			UBers02.UBFireRate = 1;
		else if (UBers03 != None)
			UBers03.UBFireRate = 1;
		else if (UBers04 != None)
			UBers04.UBFireRate = 1;
		else if (UBers05 != None)
			UBers05.UBFireRate = 1;
		else if (UBers06 != None)
			UBers06.UBFireRate = 1;
		else if (UBers07 != None)
			UBers07.UBFireRate = 1;
		else if (UBers08 != None)
			UBers08.UBFireRate = 1;
		else if (UBers09 != None)
			UBers09.UBFireRate = 1;
		else if (UBers10 != None)
			UBers10.UBFireRate = 1;
		else if (UBers11 != None)
			UBers11.UBFireRate = 1;
		else if (UBers12 != None)
			UBers12.UBFireRate = 1;
		else if (UBers13 != None)
			UBers13.UBFireRate = 1;
		else if (UbersWeapon != None)
			Pawn(Owner).DamageScaling /= 2;



	if ( UBersWeapon != None )
	{
		UBersWeapon.SetDefaultDisplayProperties();
	}
		

	//Set new weapon
	UBersWeapon = Pawn(Owner).Weapon;

	UBers01 = BersChainSaw(UBersWeapon);
	UBers02 = UBersEnforcer(UBersWeapon);
	UBers03 = UBersImpactHammer(UBersWeapon);
	UBers04 = UBersMinigun2(UBersWeapon);
	UBers05 = UBersPulsegun(UBersWeapon);
	UBers06 = UBersRipper(UBersWeapon);
	UBers07 = UBersShockRifle(UBersWeapon);
	UBers08 = UBersSuperShockRifle(UBersWeapon);
	UBers09 = UBersSniperRifle(UBersWeapon);
	UBers10 = UBersUT_BioRifle(UBersWeapon);
	UBers11 = UBersUT_EightBall(UBersWeapon);
	UBers12 = UBersUT_FlakCannon(UBersWeapon);
	UBers13 = UBersWarHeadLauncher(UBersWeapon);

	if (UBers01 != None)
			UBers01.UBFireRate = FireRateMultiplier;
		else if (UBers02 != None)
			UBers02.UBFireRate = FireRateMultiplier;
		else if (UBers03 != None)
			UBers03.UBFireRate = FireRateMultiplier;
		else if (UBers04 != None)
			UBers04.UBFireRate = FireRateMultiplier;
		else if (UBers05 != None)
			UBers05.UBFireRate = FireRateMultiplier;
		else if (UBers06 != None)
			UBers06.UBFireRate = FireRateMultiplier;
		else if (UBers07 != None)
			UBers07.UBFireRate = FireRateMultiplier;
		else if (UBers08 != None)
			UBers08.UBFireRate = FireRateMultiplier;
		else if (UBers09 != None)
			UBers09.UBFireRate = FireRateMultiplier;
		else if (UBers10 != None)
			UBers10.UBFireRate = FireRateMultiplier;
		else if (UBers11 != None)
			UBers11.UBFireRate = FireRateMultiplier;
		else if (UBers12 != None)
			UBers12.UBFireRate = FireRateMultiplier;
		else if (UBers13 != None)
			UBers13.UBFireRate = FireRateMultiplier;
		else if (UBersWeapon != None)
			Pawn(Owner).DamageScaling *= 2;


	// Make new weapon cool.
	if ( UBersWeapon != None )
	{
	if (!UBersWeapon.IsA('BersChainSaw') && !UBersWeapon.IsA('UbersImpactHammer') && !UBersWeapon.IsA('UBersEnforcer') && !UBersWeapon.IsA('UbersUT_Biorifle')
 && !UBersWeapon.IsA('UBersShockRifle') && !UBersWeapon.IsA('UBersSuperShockRifle') && !UBersWeapon.IsA('UBersPulseGun') && !UBersWeapon.IsA('UBersRipper')
 && !UBersWeapon.IsA('UBersMinigun2') && !UBersWeapon.IsA('UBersUT_FlakCannon') && !UBersWeapon.IsA('UBersUT_Eightball') && !UBersWeapon.IsA('UBersSniperRifle')
 && !UBersWeapon.IsA('UBersWarheadLauncher') && !UBersWeapon.IsA('UBersTranslocator'))
	{

		if (Pawn(Owner).FindInventoryType(Class'UBersInvisibility')==None 
		|| Pawn(Owner).FindInventoryType(Class'UBersInvisibility').Charge <= 0)
		{

		if ( Level.bHighDetailMode )
			UBersWeapon.SetDisplayProperties(ERenderStyle.STY_Translucent, 
									 GFXWeaponEffect,
									 true,
									 true);
		else
			UBersWeapon.SetDisplayProperties(ERenderStyle.STY_Normal, 
							 GFXWeaponEffect,
							 true,
							 true);
		}

	}

		if (UBersWeapon.IsA('BersChainSaw'))
			BersChainSaw(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UbersImpactHammer'))
			UbersImpactHammer(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersEnforcer'))
			UBersEnforcer(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UbersUT_Biorifle'))
			UbersUT_Biorifle(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersShockRifle'))
			UBersShockRifle(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersSuperShockRifle'))
			UBersSuperShockRifle(UBersWeapon).SetPickupSkins();
		else if (UBersWeapon.IsA('UBersPulseGun'))
			UBersPulseGun(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersRipper'))
			UBersRipper(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersMinigun2'))
			UBersMinigun2(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersUT_FlakCannon'))
			UBersUT_FlakCannon(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersUT_Eightball'))
			UBersUT_Eightball(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersSniperRifle'))
			UBersSniperRifle(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersWarheadLauncher'))
			UBersWarheadLauncher(UBersWeapon).SetTranslucentWeapon();
		else if (UBersWeapon.IsA('UBersTranslocator'))
			UBersTranslocator(UBersWeapon).SetTranslucentWeapon();
	
	}

}

//
// Player has activated the item, duplicate fire rate.
//
state Activated
{

	function Timer()
	{

		Charge--;

		if (Charge <= FinalCount && Charge>0)
		{
			SetTimer(0.7, False);
			Owner.PlaySound(WarnSound,, 8);
		}
		else if (Charge <= 0)
		{
			Owner.PlaySound(EndSound,, 8);
			UsedUp();
		}
		else
			SetTimer(1.0, False);
	}

	//Little quick bug fix, until I realize why exacly it happens :)
	//--------------------------------
	simulated function Tick( float DeltaTime)
	{
		BugFixC += DeltaTime;

		if (BugFixC >= 0.04)
		{
			BugFixC = 0;
			if (Pawn(Owner).FindInventoryType(Class'UBersInvisibility')==None && !AlreadyDone)
			{
				SetBersekerWeapon();
				AlreadyDone = True;
			}
			else if (Pawn(Owner).FindInventoryType(Class'UBersInvisibility')!=None)
			{
				AlreadyDone = False;
			}
		}
	}
	//--------------------------------


	function SetOwnerDisplay()
	{
		if( Inventory != None )
			Inventory.SetOwnerDisplay();

		SetBersekerWeapon();
	}

	function ChangedWeapon()
	{
		if( Inventory != None )
			Inventory.ChangedWeapon();

		SetBersekerWeapon();
	}

	function EndState()
	{
		UsedUp();
	}

	function BeginState()
	{
	local Inventory Inv;
	local Actor A;
	local byte bj;

		SpawnAS();
		LifeSpan = 0.0;

		bActive = true;
		FinalCount = Min(FinalCount, Charge - 1);
		SetTimer(1.0,false);
		Owner.PlaySound(ActivateSound);	
		SetOwnerLighting();
		SetBersekerWeapon();	
		AmbientSound = None;

		for( Inv=Pawn(Owner).Inventory; Inv!=None; Inv=Inv.Inventory )
    		{
			if (Ammo(Inv)!=None && !Ammo(Inv).IsA('WarHeadAmmo')) 
       			{
            			Ammo(Inv).AmmoAmount = Ammo(Inv).MaxAmmo;              
        		}

		}

		if (ReActivateEvent != '' && bDroppedNWaiting)
		{
			ForEach AllActors( class 'Actor', A, ReActivateEvent)
                		A.Trigger( Self, Instigator );

		For (bj=0; bj<32; bj++)
		{
			if (RAEvent[bj] != '')
			{
				ForEach AllActors( class 'Actor', A, RAEvent[bj])
                			A.Trigger( Self, Instigator );
			}
		}

		}

		bDroppedNWaiting = False;
	}
}


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=BerserkRespawn
	FinalCount=4
	bMeshEnviroMap=False
	WarnSound=Sound'XPickups.UBerseker.BerzerkWarning'
	EndSound=Sound'XPickups.UBerseker.BerzerkEnd'
	GFXWeaponEffect=FireTexture'UnrealShare.Belt_fx.ShieldBelt.RedShield'
	FireRateMultiplier=2.000000
	PickupMessage="BERSERK"
	PickupSound=Sound'XPickups.UBerseker.BerzerkPickup'
	PickupViewMesh=Mesh'XPickups.UT3_Berserk'
	Mesh=Mesh'XPickups.UT3_Berserk'
	RespawnTime=82.000000
	bRotatingPickup=True
	RotationRate=(Yaw=30000)
	CollisionRadius=14.000000
	CollisionHeight=25.000000
	bAutoActivate=True
	Charge=30
	bActivatable=True
	bDisplayableInv=True
	MaxDesireability=4.000000
	SoundVolume=125
	SoundRadius=45
	GroundSound=Berserk_GroundLoop
	UseSound=Berserk_PowerLoop
	UseSoundRadius=20
	UseSoundVol=255
}