//--------------------------------------------------------------------------
// Nerf Ball Launcher
// ------------------------------------------------------------------------

//--------------------------------------------------------------------------
// Nerf Ball Launcher Ball
// ------------------------------------------------------------------------

datablock AudioProfile(NerfBallBurnSound)
{
   filename = "fx/armor/bubbletrail.wav";
   description = ProjectileLooping3d;
   preload = true;
};

//datablock AudioProfile(NerfBallExplosionSound)
//{
//   filename = "fx/weapons/cg_water2.wav";
//   description = AudioClosest3d;
//   preload = true;
//};
//--------------------------------------------------------------------------
// Explosion - Nerf Ball Launcher Ball
//--------------------------------------
datablock ExplosionData(NerfBallExplosion)
{
   emitter[0]   = BlasterExplosionEmitter;
   soundProfile = NerfBallExplosionSound;
};

//--------------------------------------------------------------------------
// Projectile - Nerf Ball Launcher Ball
//--------------------------------------
datablock GrenadeProjectileData(NerfBall)
{
   projectileShapeName = "grenade_projectile.dts";
   emitterDelay        = -1;
   directDamage        = 0;
   directDamageType    = $DamageType::Default;
   radiusDamageType    = $DamageType::Default;
   hasDamageRadius     = false;
   indirectDamage      = 0;
   damageRadius        = 3.0;  // used in onExplode()
   kickBackStrength    = 0;
   useLensFlare        = false;

   sound 	       = NerfBallBurnSound;
   explosion           = NerfBallExplosion;
   velInheritFactor    = 0.5;

   texture[0]          = "special/bubbles";

   baseEmitter         = GrenadeBubbleEmitter;

   grenadeElasticity = 0.35;
   grenadeFriction   = 0.1;
   armingDelayMS     = 1500;
   muzzleVelocity    = 60;
   drag = 0.1;
   gravityMod = 3.0;
};

//--------------------------------------
// Nerf Ball Launcher
//--------------------------------------

datablock AudioProfile(NerfBallLauncherFireSound)
{
   filename    = "fx/vehicles/crash_ground_vehicle.wav";
   description = AudioDefault3d;
   preload = true;
   effect = GrenadeFireEffect;
};

datablock AudioProfile(NerfBallLauncherReloadSound)
{
   filename    = "heavy_RF_uw.wav";
   description = AudioClosest3d;
   preload = true;
   effect = GrenadeReloadEffect;
};

//--------------------------------------------------------------------------
// Ammo
//--------------------------------------

datablock ItemData(NerfBallLauncherAmmo)
{
   className	= Ammo;
   catagory	= "Ammo";
   shapeFile	= "ammo_grenade.dts";
   mass		= 1;
   elasticity	= 0.2;
   friction	= 0.6;
   pickupRadius	= 2;
   pickUpName	= "some nerf ball launcher ammo";
   computeCRC	= true;
   emap		= true;
};

//--------------------------------------------------------------------------
// Weapon
//--------------------------------------
datablock ItemData(NerfBallLauncher)
{
   className = Weapon;
   catagory = "Spawn Items";
   shapeFile = "weapon_grenade_launcher.dts";
   image = NerfBallLauncherImage;
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 2;
   pickUpName = "a nerf ball launcher";
   computeCRC = true;

};

datablock ShapeBaseImageData(NerfBallLauncherImage)
{
   className = WeaponImage;
   shapeFile = "weapon_grenade_launcher.dts";
   item = NerfBallLauncher;
   ammo = NerfBallLauncherAmmo;
   offset = "0 0 0";
   emap = true;

   projectile = NerfBall;
   projectileType = GrenadeProjectile;

   projectileSpread = 30.0 / 1000.0;

   stateName[0] = "Activate";
   stateTransitionOnTimeout[0] = "ActivateReady";
   stateTimeoutValue[0] = 0.5;
   stateSequence[0] = "Activate";
   stateSound[0] = GrenadeSwitchSound;

   stateName[1] = "ActivateReady";
   stateTransitionOnLoaded[1] = "Ready";
   stateTransitionOnNoAmmo[1] = "NoAmmo";

   stateName[2] = "Ready";
   stateTransitionOnNoAmmo[2] = "NoAmmo";
   stateTransitionOnTriggerDown[2] = "Fire";

   stateName[3] = "Fire";
   stateTransitionOnTimeout[3] = "Reload";
   stateTimeoutValue[3] = 0.05;
   stateFire[3] = true;
   stateRecoil[3] = LightRecoil;
   stateAllowImageChange[3] = false;
   stateSequence[3] = "Fire";
   stateScript[3] = "onFire";
   stateSound[3] = NerfBallLauncherFireSound;

   stateName[4] = "Reload";
   stateTransitionOnNoAmmo[4] = "NoAmmo";
   stateTransitionOnTimeout[4] = "Ready";
   stateTimeoutValue[4] = 0.1;
   stateAllowImageChange[4] = false;
   stateSequence[4] = "Reload";
   stateSound[4] = NerfBallLauncherReloadSound;

   stateName[5] = "NoAmmo";
   stateTransitionOnAmmo[5] = "Reload";
   stateSequence[5] = "NoAmmo";
   stateTransitionOnTriggerDown[5] = "DryFire";

   stateName[6]       = "DryFire";
   stateSound[6]      = GrenadeDryFireSound;
   stateTimeoutValue[6]        = 1.5;
   stateTransitionOnTimeout[6] = "NoAmmo";
};

function NerfBall::onExplode(%data,%projectile,%pos,%mod) {
	InitContainerRadiusSearch(%pos, %data.damageRadius, $TypeMasks::PlayerObjectType);
	while ((%targetObject = containerSearchNext()) != 0) {
		if (isObject(%targetObject)) {
			if (%targetObject.getClassName() $= "Player")
				applyNerf(%targetObject,%projectile.sourceObject,%pos);
		}
	}
}

// Bot fun!
//function NerfBallLauncherImage::onFire(%data,%obj,%slot) {
//	%p = Parent::onFire(%data, %obj, %slot);
//	AIGrenadeThrown(%p);
//}
