//--------------------------------------
// FireworksGun
//--------------------------------------

//--------------------------------------------------------------------------
// Force-Feedback Effects
//--------------------------------------


datablock AudioProfile(FireworksGunExpSound)
{
   filename    = "fx/powered/turret_mortar_explode.wav";
   description = AudioBIGExplosion3d;
   //effect = FireworksGunExpEffect;
   minDistance = 500;
   maxDistance = 500;
};


//--------------------------------------------------------------------------
// FireworksGun Particle effects
//--------------------------------------------------------------------------

datablock ParticleData(FireworksGunExplosionSmoke)
{
   dragCoeffiecient     = 105.0;
   gravityCoefficient   = -0.0;   // rises slowly
   inheritedVelFactor   = 0.025;

   constantAcceleration = -0.80;

   lifetimeMS           = 1250;
   lifetimeVarianceMS   = 0;

   textureName          = "particleTest";

   useInvAlpha =  true;
   spinRandomMin = -200.0;
   spinRandomMax =  200.0;

   textureName = "special/Smoke/smoke_001";

   colors[0]     = "1.0 0.7 0.0 1.0";
   colors[1]     = "0.2 0.2 0.2 1.0";
   colors[2]     = "0.9 0.18 0.07";
   sizes[0]      = 0.001;
   sizes[1]      = 0.001;
   sizes[2]      = 0.001;
   times[0]      = 0.0;
   times[1]      = 0.2;
   times[2]      = 1.0;

};

datablock ParticleEmitterData(FireworksGunExplosionSmokeEmitter)
{
   ejectionPeriodMS = 8;
   periodVarianceMS = 0;

   ejectionVelocity = 10.25;
   velocityVariance = 0.25;

   thetaMin         = 0.0;
   thetaMax         = 180.0;

   lifetimeMS       = 250;

   particles = "FireworksGunExplosionSmoke";
};



datablock ParticleData(FireworksGunSparks)
{
   dragCoefficient      = 1;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.8;
   lifetimeMS           = 3000;
   lifetimeVarianceMS   = 0;
   textureName          = "special/bigSpark";
   colors[0]     = "0.0 0.0 1.0";
   colors[1]     = "16.70";
   colors[2]     = "0.9 0.18 0.07";
   sizes[0]      = 6.0;
   sizes[1]      = 4.5;
   sizes[2]      = 1.0;
   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;

};

datablock ParticleEmitterData(FireworksGunSparkEmitter)
{
   ejectionPeriodMS = 8;
   periodVarianceMS = 0;
   ejectionVelocity = 18;
   velocityVariance = 6.75;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   orientParticles  = true;
   lifetimeMS       = 1200;
   particles = "FireworksGunSparks";
};

datablock ParticleData(FireworksGunSparks2)
{
   dragCoefficient      = 1;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.8;
   lifetimeMS           = 3000;
   lifetimeVarianceMS   = 0;
   textureName          = "special/BlueImpact";
   colors[0]     = "0.200000 0.848000 0.336000 1.000000";
   colors[1]     = "0.560000 0.360000 0.260000 1.000000";
   colors[2]     = "0.472441 1.000000 0.000000 1.000000";
   sizes[0]      = 6.0;
   sizes[1]      = 4.5;
   sizes[2]      = 2.0;
   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;

};

datablock ParticleEmitterData(FireworksGunSparkEmitter2)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;

   ejectionVelocity = 55;
   velocityVariance = 0;

   ejectionOffset   = 0;

   thetaMin         = 0.0;
   thetaMax         = 180.0;

   phiReferenceVel  = 0.0;
   phiVariance      = 360.0;

   overrideAdvances = false;

   lifeTimeMS       = 300;

   particles = "FireworksGunSparks2";
};


datablock ParticleData(FireworksGunSparks3)
{
   dragCoefficient      = 1;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.8;
   lifetimeMS           = 3000;
   lifetimeVarianceMS   = 0;
   textureName          = "skins/flaregreen";
   colors[0]     = "0.251969 0.096000 0.000000 1.000000";
   colors[1]     = "0.944882 0.912000 0.128000 0.709677";
   colors[2]     = "1 0.5 0.5 0.0";
   sizes[0]      = 6.0;
   sizes[1]      = 4.5;
   sizes[2]      = 2.0;
   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;

};

datablock ParticleEmitterData(FireworksGunSparkEmitter3)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;

   ejectionVelocity = 100;
   velocityVariance = 0;

   ejectionOffset   = 0;

   thetaMin         = 90.0;
   thetaMax         = 90.0;

   phiReferenceVel  = 0.0;
   phiVariance      = 360.0;

   overrideAdvances = false;

   lifeTimeMS       = 0;

   particles = "FireworksGunSparks3";
};


//--------------------------------------------------------------------------
// Explosion
//--------------------------------------
datablock ExplosionData(FireworksGunSubExplosion1)
{
   offset = 0.0;
   emitter[0] = FireworksGunExplosionSmokeEmitter;
   emitter[1] = FireworksGunSparkEmitter;
   explosionShape = "energy_explosion.dts";
   scale ="9 9 9";
   playSpeed = 1.5;
};

datablock ExplosionData(FireworksGunSubExplosion2)
{
   offset = 20.0;
   emitter[0] = FireworksGunExplosionSmokeEmitter;
   emitter[1] = FireworksGunSparkEmitter2;
   explosionShape = "energy_explosion.dts";
   scale ="9 9 9";
   playSpeed = 1.5;
};

datablock ExplosionData(FireworksGunSubExplosion3)
{
   offset = 40.0;
   emitter[0] = FireworksGunExplosionSmokeEmitter;
   emitter[1] = FireworksGunSparkEmitter3;
   explosionShape = "energy_explosion.dts";
   scale ="9 9 9";
   playSpeed = 1.5;
};

datablock ExplosionData(FireworksGunSubExplosion4)
{
   offset = 60.0;
   emitter[0] = FireworksGunExplosionSmokeEmitter;
   emitter[1] = FireworksGunSparkEmitter2;
   explosionShape = "energy_explosion.dts";
   scale ="9 9 9";
   playSpeed = 1.5;
};

datablock ExplosionData(FireworksGunSubExplosion5)
{
   offset = 80.0;
   emitter[0] = FireworksGunExplosionSmokeEmitter;
   emitter[1] = FireworksGunSparkEmitter3;
   explosionShape = "energy_explosion.dts";
   scale ="9 9 9";
   playSpeed = 1.5;
};

datablock ExplosionData(FireworksGunSubExplosion6)
{
   offset = 100.0;
   emitter[0] = FireworksGunExplosionSmokeEmitter;
   emitter[1] = FireworksGunSparkEmitter;
   explosionShape = "energy_explosion.dts";
   scale ="9 9 9";
   playSpeed = 1.5;
};

datablock ExplosionData(FireworksGunSubExplosion7)
{
   offset = 110.0;
   emitter[0] = FireworksGunExplosionSmokeEmitter;
   emitter[1] = FireworksGunSparkEmitter2;
   explosionShape = "energy_explosion.dts";
   scale ="9 9 9";
   playSpeed = 1.5;
};

datablock ExplosionData(FireworksGunExplosion)
{
   soundProfile   = FireworksGunExpSound;

   emitter[0] = FireworksGunExplosionSmokeEmitter;
   emitter[1] = FireworksGunSparkEmitter;

   subExplosion[0] = FireworksGunSubExplosion1;
   subExplosion[1] = FireworksGunSubExplosion2;
   subExplosion[2] = FireworksGunSubExplosion3;
   subExplosion[3] = FireworksGunSubExplosion4;
   subExplosion[4] = FireworksGunSubExplosion5;
   subExplosion[5] = FireworksGunSubExplosion6;
   subExplosion[6] = FireworksGunSubExplosion7;

   shakeCamera = true;
   camShakeFreq = "12.0 13.0 11.0";
   camShakeAmp = "35.0 35.0 35.0";
   camShakeDuration = 1.0;
   camShakeRadius = 15.0;
};

//---------------------------------------------------------------------------
// Smoke particles
//---------------------------------------------------------------------------
datablock ParticleData(FireworksGunSmokeParticle)
{
   dragCoeffiecient     = 0.4;
   gravityCoefficient   = -0.3;   // rises slowly
   inheritedVelFactor   = 0.125;

   lifetimeMS           =  1200;
   lifetimeVarianceMS   =  200;
   useInvAlpha          =  false;
   spinRandomMin        = -100.0;
   spinRandomMax        =  100.0;

   animateTexture = false;

   textureName = "special/tracer00.PNG";

   colors[0]     = "1.0 0.7 0.5 1.0";
   colors[1]     = "1.0 0.5 0.2 1.0";
   colors[2]     = "1.0 0.25 0.1 1.0";
   colors[3]     = "0.6 0.7 0.4 1.0";
   sizes[0]      = 1.0;
   sizes[1]      = 2.0;
   sizes[2]      = 4.5;
   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;

};


datablock ParticleEmitterData(FireworksGunSmokeEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 3;

   ejectionVelocity = 2.25;
   velocityVariance = 0.55;

   thetaMin         = 0.0;
   thetaMax         = 40.0;

   particles = "FireworksGunSmokeParticle";
};


//--------------------------------------------------------------------------
// Projectile
//--------------------------------------


//--------------------------------------------------------------------------
// Projectile
//--------------------------------------
datablock LinearFlareProjectileData(Fireworks)
{
   projectileShapeName = "weapon_missile_projectile.dts";
   scale               = "5.0 5.0 5.0";
   faceViewer          = true;
   directDamage        = 0.0;
   hasDamageRadius     = false;
   indirectDamage      = 0;
   damageRadius        = 0;
   kickBackStrength    = 0.0;
   radiusDamageType    = $DamageType::Plasma;

   explosion           = "FireworksGunExplosion";
   baseEmitter         = FireworksGunSmokeEmitter;


   dryVelocity       = 95.0;
   wetVelocity       = -1;
   velInheritFactor  = 0.3;
   fizzleTimeMS      = 2000;
   lifetimeMS        = 2000;
   explodeOnDeath    = true;
   reflectOnWaterImpactAngle = 0.0;
   explodeOnWaterImpact      = true;
   deflectionOnWaterImpact   = 0.0;
   fizzleUnderwaterMS        = -1;

   //activateDelayMS = 100;
   activateDelayMS = -1;

   size[0]           = 0.2;
   size[1]           = 0.5;
   size[2]           = 0.1;
   
   numFlares         = 35;
   flareColor        = "0.9 0.18 0.07";
   flareModTexture   = "flaremod";
   flareBaseTexture  = "flarebase";


   sound        = PlasmaProjectileSound;
   fireSound    = PlasmaFireSound;
   wetFireSound = PlasmaFireWetSound;

   hasLight    = true;
   lightRadius = 3.0;
   lightColor  = "1 0.75 0.25";
};

//--------------------------------------------------------------------------
// Ammo
//--------------------------------------


//--------------------------------------------------------------------------
// Weapon
//--------------------------------------
datablock ItemData(FireworksGun)
{
   className = Weapon;
   catagory = "Spawn Items";
   shapeFile = "weapon_plasma.dts";
   image = FireworksGunImage;
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 2;
	pickUpName = "a FireworksGun";
};
$Firework::Spread = 200.0 / 1000.0;
datablock ShapeBaseImageData(FireworksGunImage)
{
   className = WeaponImage;
   shapeFile = "weapon_plasma.dts";
   item = FireworksGun;
   usesEnergy = true;
   fireEnergy = 3;
   minEnergy = 3;
   offset = "0 0 0";

   projectile = Fireworks;
   projectileType = LinearFlareProjectile;
   
   isfireworks = true;
   
   projectileSpread = $Firework::Spread;

   stateName[0]                     = "Activate";
   stateTransitionOnTimeout[0]      = "ActivateReady";
   stateSound[0]                    = PlasmaSwitchSound;
   stateTimeoutValue[0]             = 0.5;
   stateSequence[0]                 = "Activate";

   stateName[1]                     = "ActivateReady";
   stateTransitionOnLoaded[1]       = "Ready";
   stateTransitionOnNoAmmo[1]       = "NoAmmo";

   stateName[2]                     = "Ready";
   stateTransitionOnNoAmmo[2]       = "NoAmmo";
   stateTransitionOnTriggerDown[2]  = "CheckWet";

// ----------------------
// Multiple Projectiles
// there are 6 shots per fire
   stateName[3]                     = "Fire";
   stateSequence[3]                 = "Fire";
   stateSequenceRandomFlash[3]      = true;
   stateTimeoutValue[3]             = 0;
   stateTransitionOnTimeout[3]      = "Reload";
   stateFire[3]                     = true;
   stateAllowImageChange[3]         = false;
   stateScript[3]                   = "onFire";
//   stateRecoil[3]                   = LightRecoil;
   stateEjectShell[3]               = false;
//   stateSound[3]			= FireworksGunFireSound;


   stateName[6]                     = "Reload";
   stateTransitionOnTimeout[6]      = "Ready";
   stateTransitionOnNoAmmo[6]		= "NoAmmo";
   stateTimeoutValue[6]             = 0.5;
   stateAllowImageChange[6]         = false;
   stateSequence[6]                 = "Reload";
   stateSound[6]				= PlasmaReloadSound;

   stateName[7]				= "CheckWet";
   stateTransitionOnWet[7]		= "Fire";
   stateTransitionOnNotWet[7]	= "Fire";

   stateName[8]				= "NoAmmo";
   stateTransitionOnAmmo[8]		= "Reload";
   stateTransitionOnTriggerDown[8]	= "DryFire";
   stateSequence[8]			= "NoAmmo";

   stateName[9]				= "DryFire";
   stateSound[9]				= PlasmaDryFireSound;
   stateTimeoutValue[9]		= 0.5;
   stateTransitionOnTimeout[9]	= "NoAmmo";
};
function FireworksGunImage::onmount(%this, %obj, %slot)
{
commandToClient(%obj.client, 'BottomPrint', "<spush><font:Arial Black:20><color:cccc04>Fireworks Gun<spop>\n<spush><font:Arial:14><color:ffcc00>Shoot FireWorks!<spop>\n<spush><font:arial:14><color:ff1100>Total Damage: 0<spop>", 3, 3);

}
$FireworkCount = 6;
 function FireworksGunImage::onFire(%data, %obj, %slot)
{
   for(%i=0;%i<$FireworkCount;%i++)
   {
  %vector = %obj.getMuzzleVector(%slot);
       %x = (getRandom() - 0.5) * 2 * 3.1415926 * 150/1000;
       %y = (getRandom() - 0.5) * 2 * 3.1415926 * 150/1000;
       %z = (getRandom() - 0.5) * 2 * 3.1415926 * 150/1000;
      %mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
      %vector = MatrixMulVector(%mat, %vector);
   %p = new (%data.projectileType)() {
      dataBlock        = Fireworks;
      initialDirection = %vector;
      initialPosition  = %obj.getMuzzlePoint(%slot);
      sourceObject     = %obj;
      sourceSlot       = %slot;
   };
   MissionCleanup.add(%p);
   %obj.lastProjectile = %p;
   %client.projectile = %p;
   }
}
//datablock ShapeBaseImageData(FireworksGunImage2)
//{
//   shapeFile = "weapon_plasma.dts";
//   offset = "0.0 0.0 0.0";
//   rotation = "0 1 0 180";
//   emap = true;
//};

//function FireworksGunImage::onMount(%this,%obj,%slot)
//{
//   Parent::onMount(%this, %obj, %slot);
//   %obj.mountImage(FireworksGunImage2, 1);
//}
//
//function FireworksGunImage::onUnmount(%this,%obj,%slot)
//{
//   Parent::onUnmount(%this, %obj, %slot);
//   %obj.unmountImage(1);
//}




