
class FryingPan extends TournamentWeapon;

//First person mesh
#exec MESH IMPORT MESH=FryingPanAnimated ANIVFILE=MODELS\FryingPanAnimated_a.3d DATAFILE=MODELS\FryingPanAnimated_d.3d X=0 Y=0 Z=0 UNMIRROR=1
#exec MESH LODPARAMS MESH=FryingPanAnimated STRENGTH=0
#exec MESH ORIGIN MESH=FryingPanAnimated X=0 Y=0 Z=0 PITCH=-10 ROLL=10 YAW=0

#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=All 						STARTFRAME=0 	NUMFRAMES=72
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=Still 						STARTFRAME=1 	NUMFRAMES=1
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=PrimaryAttack 			STARTFRAME=2 	NUMFRAMES=17
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=SecondaryAttackStart 	STARTFRAME=19 	NUMFRAMES=3
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=SecondaryCharge 		STARTFRAME=22 	NUMFRAMES=24
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=SecondaryRelease 		STARTFRAME=46 	NUMFRAMES=10
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=Select 					STARTFRAME=61 	NUMFRAMES=6
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=Deselect 					STARTFRAME=67 	NUMFRAMES=5
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=Down 						STARTFRAME=67 	NUMFRAMES=5

#exec MESHMAP NEW MESHMAP=FryingPanAnimated MESH=FryingPanAnimated
#exec MESHMAP SCALE MESHMAP=FryingPanAnimated X=0.1 Y=0.1 Z=0.2

#exec TEXTURE IMPORT NAME=SimpleGloveHandTexture FILE=Textures/SimpleGloveHandTexture.pcx GROUP=Skins FLAGS=2
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanAnimated NUM=1 TEXTURE=SimpleGloveHandTexture

#exec TEXTURE IMPORT NAME=FPTexture FILE=Textures/FPTexture.bmp GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=FPTexture FILE=Textures/FPTexture.bmp GROUP=Skins PALETTE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanAnimated NUM=2 TEXTURE=FPTexture

// Third person mesh
#exec MESH IMPORT MESH=FryingPanThird ANIVFILE=MODELS\FryingPanPickup_a.3d DATAFILE=MODELS\FryingPanPickup_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=FryingPanThird STRENGTH=0
#exec MESH ORIGIN MESH=FryingPanThird X=0 Y=850 Z=-50 PITCH=0 ROLL=44 YAW=128

#exec MESH SEQUENCE MESH=FryingPanThird SEQ=All 	STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=FryingPanThird SEQ=Still 	STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=FryingPanThird SEQ=Shoot 	STARTFRAME=0 NUMFRAMES=1

#exec MESHMAP NEW MESHMAP=FryingPanThird MESH=FryingPanPickup
#exec MESHMAP SCALE MESHMAP=FryingPanThird X=0.05 Y=0.05 Z=0.1

#exec MESHMAP SETTEXTURE MESHMAP=FryingPanThird NUM=1 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanThird NUM=2 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanThird NUM=3 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanThird NUM=4 TEXTURE=FPTexture

// Pickup
#exec MESH IMPORT MESH=FryingPanPickup ANIVFILE=MODELS\FryingPanPickup_a.3d DATAFILE=MODELS\FryingPanPickup_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=FryingPanPickup STRENGTH=0
#exec MESH ORIGIN MESH=FryingPanPickup X=0 Y=450 Z=-50 PITCH=0 ROLL=64 YAW=0

#exec MESH SEQUENCE MESH=FryingPanPickup SEQ=All 	STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=FryingPanPickup SEQ=Still STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=FryingPanPickup SEQ=Select STARTFRAME=0 NUMFRAMES=1

#exec MESHMAP NEW MESHMAP=FryingPanPickup MESH=FryingPanPickup
#exec MESHMAP SCALE MESHMAP=FryingPanPickup X=0.05 Y=0.05 Z=0.1

#exec TEXTURE IMPORT NAME=FPTexture FILE=Textures/FPTexture.bmp GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=FPTexture FILE=Textures/FPTexture.bmp GROUP=Skins PALETTE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanPickup NUM=1 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanPickup NUM=2 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanPickup NUM=3 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanPickup NUM=4 TEXTURE=FPTexture

//Sounds 
#exec AUDIO IMPORT FILE="Sounds\Bong1.Wav" 		NAME=Bong1 			GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\Gong1.Wav" 		NAME=Gong1 			GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\Swoosh.Wav" 		NAME=Swoosh 		GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\Swoosh1.Wav" 	NAME=Swoosh1 		GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\PanSplat.Wav" 	NAME=PanSplat 		GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\PanPickup.Wav" 	NAME=PanPickup 	GROUP="Pan"

//Icon
#exec TEXTURE IMPORT NAME=FPanIcon FILE=Textures/FPanIcon.BMP GROUP="Icons" MIPS=OFF

var sound Swing, Swing1, Bong;
var bool bselected;
var PlayerPawn LastHit;
var int SwingDamage, AltSwingDamage;

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

function float RateSelf(out int bUseAltMode)
{
   local float EnemyDist;
   local bool bRetreating;
   local vector EnemyDir;

   bUseAltMode = 0;

   if ((Pawn(Owner) == None) || (Pawn(Owner).Enemy == None))
      return 0;

   EnemyDist = VSize(Pawn(Owner).Enemy.Location - Owner.Location);
   if (EnemyDist > 400)
      return -2;

   if (EnemyDist < 110)
      bUseAltMode = 0;

   return (FMin(1.0, 81/(EnemyDist + 1)));
}

function setHand(float Hand)
{
   local rotator newRot;

   Super.SetHand(Hand);
   if (Hand == 1) 
      Mesh = mesh'FryingPanAnimated';
   else
 		Mesh = mesh'FryingPanAnimated';
}

function Fire(float value)
{
	GotoState('NormalFire');
}

function AltFire(float value) 
{
	GoToState('AltFiring');
}

state NormalFire
{
	//looks for an actor directly in front of the player when they swing
	function Beginstate()
   {
      local vector X,Y,Z, dir, HitLocation, backforce;
      local actor E;
      local actor F;
      local float viewangle, blockangle;
      local int i;
   	local ProjectileFragments b;

		viewangle=cos(PI*150/360);
		blockangle=cos(PI*100/360);
      GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);

		//looking for a player or decoration to smash
      foreach RadiusActors(class'Actor', E, 100, Owner.Location)
      {
      	dir=E.Location-Owner.Location;

         if((normal(dir) DOT normal(X)) > viewangle)
         {
         	HitLocation = E.Location - normal(dir) * E.CollisionRadius;

            if (E.IsA('PlayerPawn') || E.IsA('Bot') || E.IsA('Decoration'))
            {
               E.TakeDamage(SwingDamage, Pawn(Owner), HitLocation, 6000.0 * X, 'cut');
	       		PlaySound(sound'Gong1', SLOT_None, 150);
	       		spawn(class'SpriteSmokePuff',,,HitLocation);
            }
            else if (E.IsA('Carcass'))
            {
               PlaySound(sound'PanSplat', SLOT_None, 150);
               E.TakeDamage(100, Pawn(Owner), HitLocation, 3000.0*X, 'gibbed');
            }
         }
      }
      //looking for an incoming projectile
      foreach RadiusActors(class'Actor', F, 300, Owner.Location)
      {
      	dir=F.Location-Owner.Location;

         if((normal(dir) DOT normal(X)) > viewangle)
         {
         	HitLocation = F.Location - normal(dir) * F.CollisionRadius;
            if (F.IsA('Projectile'))
            {
               if(F.IsA('Chunk') ||F.IsA('ForceFieldProj') || F.IsA('Arc') || F.IsA('Fragment') || F.IsA('ShellCase') || F.IsA('FFProjectileDeco') || F.IsA('Mtracer'))
						return;
					//found a valid projectile, spawn some effects and destroy it
            	for (i=0; i<(3); i++)
	   			{
						b = Spawn(class'ProjectileFragments',,, HitLocation);
		  				b.Velocity = vector(RotRand()) * (FRand() * 200);
					}
					Spawn(class'SpriteBallExplosion',,,HitLocation);
					F.Destroy();
	       		PlaySound(sound'Gong1', SLOT_None, 150);
            }
      	}
      }
   }
   
   function AnimEnd()
   {
      if (Pawn(Owner) != None && Pawn(Owner).bFire != 0)
         TweenAnim('Still', 0.1);
      else
         Super.AnimEnd();
   }

Begin:
	if (Owner != none && !Owner.IsA('Bot'))
   	PlayAnim('PrimaryAttack',1.0);
   Owner.PlaySound(Swing, SLOT_None,1.0*Pawn(Owner).SoundDampening);
   FinishAnim();
   GotoState('Idle');
}

state AltFiring
{
   function BeginState()
   {
   	local vector X,Y,Z, dir, HitLocation, backforce;
      local actor E;
      local actor F;
      local float viewangle, blockangle;
      local int i;
   	local ProjectileFragments b;

      viewangle=cos(PI*150/360);
      blockangle=cos(PI*100/360);
      GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);

		if (!Owner.IsA('Bot'))
      	playanim('SecondaryRelease',0.5);
      Owner.PlaySound(Swing1, SLOT_None,1.0*Pawn(Owner).SoundDampening);

      foreach RadiusActors(class'Actor', E, 100, Owner.Location)
      {
         dir=E.Location-Owner.Location;

         if((normal(dir) DOT normal(X)) > viewangle)
         {
         	HitLocation = E.Location - normal(dir) * E.CollisionRadius;

            if (E.IsA('PlayerPawn') || E.IsA('Bot') || E.IsA('Decoration'))
            {
               E.TakeDamage(AltSwingDamage, Pawn(Owner), HitLocation, 100000.0 * X, 'cut');
	       		PlaySound(sound'Gong1', SLOT_None, 150);
	       		spawn(class'SpriteSmokePuff',,,HitLocation);
            }
            else if (E.IsA('Carcass'))
            {
               PlaySound(sound'PanSplat', SLOT_None, 150);
               E.TakeDamage(100, Pawn(Owner), HitLocation, 3000.0*X, 'gibbed');
            }
         }
      }
      foreach RadiusActors(class'Actor', F, 300, Owner.Location)
      {
      	dir=F.Location-Owner.Location;

         if((normal(dir) DOT normal(X)) > viewangle)
         {
         	HitLocation = F.Location - normal(dir) * F.CollisionRadius;
            if (F.IsA('Projectile'))
            {
               if(F.IsA('Chunk') ||F.IsA('ForceFieldProj') || F.IsA('Arc') || F.IsA('Fragment') || F.IsA('ShellCase') || F.IsA('FFProjectileDeco') || F.IsA('Mtracer'))
						return;

            	for (i=0; i<(4); i++)
	   			{
						b = Spawn(class'ProjectileFragments',,, HitLocation);
		  				b.Velocity = vector(RotRand()) * (FRand() * 200);
					}
					Spawn(class'SpriteBallExplosion',,,HitLocation);
					F.Destroy();
	       		PlaySound(sound'Gong1', SLOT_None, 150);
            }
      	}
      }
   }

   function AnimEnd()
   {
      if (Pawn(Owner) != None && Pawn(Owner).bAltFire != 0)
         TweenAnim('Still', 0.1);
      else
         Super.AnimEnd();
   }

Begin:
   finishanim();
   GotoState('Idle');
}

simulated function PlayFiring()
{
	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	if (PlayerPawn(Owner) != None)
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	if (!Owner.IsA('Bot'))
		PlayAnim('PrimaryAttack',1.0);
}

simulated function PlayAltFiring()
{
   PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	if (PlayerPawn(Owner) != None)
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	if (!Owner.IsA('Bot'))
		playanim('SecondaryRelease',0.5);
}

state Idle
{
	function AnimEnd()
	{
		PlayIdleAnim();
	}
	function bool PutDown()
	{
		GotoState('DownWeapon');
		return True;
	}

Begin:
	SetTimer(2.5,True);
	if (Pawn(Owner).bFire!=0) Global.Fire(0.0);
	if (Pawn(Owner).bAltFire!=0) Global.AltFire(0.0);
	LoopAnim('Still');
}

simulated function PlayPrimaryAttack()
{
   if (Level.NetMode != NM_StandAlone)
      PlayAnim('PrimaryAttack',2.0);
}

simulated function PlayIdleAnim()
{
	PlayAnim('Still', 0.5, 0.04);
}

defaultproperties
{
	PickupSound=Sound'BRUT.PanPickup'
	SwingDamage=40
	AltSwingDamage=40
   Swing=Sound'Swoosh'
   Swing1=Sound'Swoosh1'
   Bong=Sound'Bong1'
   bMeleeWeapon=True
   AIRating=0.50
   AltRefireRate=0.00
   Icon=Texture'FPanIcon'
   StatusIcon=Texture'FPanIcon'
	bCanThrow=True
   PickupMessage="Cast Iron! This could stop a bullet"
   ItemName="Frying Pan"
   ItemArticle="a"
   PlayerViewOffset=(X=10.00,Y=-2.00,Z=-4.00),
   PlayerViewMesh=LodMesh'FryingPanAnimated'
   PlayerViewScale=0.20
   PickupViewMesh=LodMesh'FryingPanPickup'
   ThirdPersonMesh=LodMesh'FryingPanThird'
   ThirdPersonScale=0.50
   Mesh=LodMesh'FryingPanPickup'
   SoundVolume=96
   CollisionRadius=20.00
   CollisionHeight=35.00
   InventoryGroup=1
   AutoSwitchPriority=9
   Physics=PHYS_Falling      
}
