datablock ParticleData(rfireTrailParticle)
{
	dragCoefficient = 1.75;
	windCoefficient = 0;
	gravityCoefficient = 0;
	inheritedVelFactor = 0;
	constantAcceleration = 0;
	lifetimeMS = 600;
	lifetimeVarianceMS = 400;
	textureName = "Add-Ons/Projectile_Pong/Square.png";
	spinSpeed = 0;
	spinRandomMin = -300;
	spinRandomMax = 300;
	useInvAlpha = false;

colors[0] = "0.5 0 1 0.3"; //light color
	colors[1] = "0.5 0 1 0.3"; //dark color
	colors[2] = "0.5 0 1 0.3"; //barley noticeable color
	sizes[0] = 0.2;
	sizes[1] = 0.4;
};
datablock ParticleEmitterData(rfireTrailEmitter)
{
	ejectionPeriodMS = 15;
	periodVarianceMS = 12;
	ejectionVelocity = 0.5;
	velocityVariance = 0.2;
	ejectionOffset = 0.0;
	thetaMin = 0;
	thetaMax = 90;
	phiReferenceVel = 0;
	phiVariance = 360;
	overrideAdvance = false;
	particles = rfireTrailParticle;
	   useEmitterColors = true;

	uiName = "Purple Pixel";
};
datablock ParticleData(rfireParticle)
{
	dragCoefficient = 1.75;
	windCoefficient = 0;
	gravityCoefficient = 0;
	inheritedVelFactor = 0;
	constantAcceleration = 0;
	lifetimeMS = 1500;
	lifetimeVarianceMS = 500;
	textureName = "Add-Ons/Projectile_Pong/Square.png";
	spinSpeed = 0;
	spinRandomMin = -300;
	spinRandomMax = 300;
	useInvAlpha = false;

colors[0] = "0.5 0 1 0.3"; //light color
	colors[1] = "0.5 0 1 0.3"; //dark color
	colors[2] = "0.5 0 1 0.3"; //barley noticeable color
	sizes[0] = 0.1;
	sizes[1] = 0.2;
};
datablock ParticleEmitterData(rfireEmitter)
{
	ejectionPeriodMS = 15;
	periodVarianceMS = 0;
	ejectionVelocity = 1.5;
	velocityVariance = 1;
	ejectionOffset = 0.0;
	thetaMin = 0;
	thetaMax = 180;
	phiReferenceVel = 0;
	phiVariance = 360;
	overrideAdvance = false;
	particles = rfireParticle;

	uiName = "";
};
datablock ParticleData(rfireExplosionParticle)
{
	dragCoefficient      = 5;
	gravityCoefficient   = 0.0;
	inheritedVelFactor   = 1.0;
	constantAcceleration = 0.0;
	lifetimeMS           = 500;
	lifetimeVarianceMS   = 300;
	textureName          = "Add-Ons/Projectile_Pong/Square.png";
	spinSpeed		= 0.0;
	spinRandomMin		= -0.0;
	spinRandomMax		= 0.0;
colors[0] = "0.5 0 1 0.3"; //light color
	colors[1] = "0.5 0 1 0.3"; //dark color
	colors[2] = "0.5 0 1 0.3"; //barley noticeable color
	sizes[0]      = 0.5;
	sizes[1]      = 0.1;
};

datablock ParticleEmitterData(rfireExplosionEmitter)
{
   ejectionPeriodMS = 7;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "rfireExplosionParticle";

   useEmitterColors = true;

   uiName = "";
};
datablock ParticleData(rfiresmokeParticle)
{
	dragCoefficient      = 8;
	gravityCoefficient   = 0;
	inheritedVelFactor   = 0.2;
	constantAcceleration = 0.0;
	lifetimeMS           = 100;
	lifetimeVarianceMS   = 50;
	textureName          = "base/data/particles/cloud";
	spinSpeed		= 10.0;
	spinRandomMin		= -50.0;
	spinRandomMax		= 50.0;
colors[0] = "0.5 0 1 0.3"; //light color
	colors[1] = "0.5 0 1 0.3"; //dark color
	colors[2] = "0.5 0 1 0.3"; //barley noticeable color
	sizes[0]      = 0.25;
	sizes[1]      = 0.75;

	useInvAlpha = true;
};
datablock ParticleEmitterData(rfiresmokeEmitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 2;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 89;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "rfiresmokeParticle";

   useEmitterColors = true;
   uiName = "";
};
datablock ExplosionData(rfireExplosion)
{
   //explosionShape = "";
	soundProfile = pixelHitSound;

   lifeTimeMS = 150;

   particleEmitter = rfireExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = rfiresmokeEmitter;
   

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Dynamic light
   lightStartRadius = 10;
   lightEndRadius = 10;
   lightStartColor = "0.7 0 1 1";
   lightEndColor = "0 0 0";
};

AddDamageType("rfire",   '<bitmap:Add-Ons/Weapon_PixelSpells/ci_rfire> %1',    '%2 <bitmap:Add-Ons/Weapon_PixelSpells/ci_rfire> %1',0.2,1);
datablock ProjectileData(rfireProjectile)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 15;
   directDamageType    = $DamageType::rfire;
   radiusDamageType    = $DamageType::rfire;
   

   brickExplosionRadius = 0;
   brickExplosionImpact = true;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 10;
   brickExplosionMaxVolume = 1;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 2;  //max volume of bricks that we can destroy if they aren't connected to the ground

   impactImpulse	     = 0;
   verticalImpulse	  = 0;
   explosion           = rfireExplosion;
   particleEmitter     = rfiretrailEmitter; 

   muzzleVelocity      = 100;
   velInheritFactor    = 1;

   armingDelay         = 00;
   lifetime            = 600;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = false;
   gravityMod = 0.0;
   explodeOnDeath = true;

  hasLight    = true;
   lightRadius = 5.0;
   lightColor  = "0.7 0 1 1";

   uiName = "Rapid Fire Pixel";
};

//////////
// item //
//////////
datablock ItemData(rfireItem)
{
	category = "Weapon";  // Mission editor category
	className = "Weapon"; // For inventory system

	 // Basic Item Properties
	shapeFile = "./pixelitem.dts";
	rotate = false;
	mass = 1;
	density = 0.2;
	elasticity = 0.2;
	friction = 0.6;
	emap = true;

	//gui stuff
	uiName = "Rapid Fire Pixel";
	iconName = "./rfire";
	doColorShift = true;
	colorShiftColor = "0.7 0 1 1";

	 // Dynamic properties defined by the scripts
	image = rfireImage;
	canDrop = true;
};

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(rfireImage)
{
   // Basic Item properties
   shapeFile = "./emptyWeapon.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset = 0; //"0.7 1.2 -0.5";
   rotation = eulerToMatrix( "0 0 0" );

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off.  
   correctMuzzleVector = true;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = BowItem;
   ammo = " ";
   projectile = rfireProjectile;
   projectileType = Projectile;

   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = true;

   doColorShift = true;
   colorShiftColor = rfireItem.colorShiftColor;//"0.400 0.196 0 1.000";
   
	stateName[0]                     = "Activate";
	stateTimeoutValue[0]             = 0.15;
	stateTransitionOnTimeout[0]       = "Ready";
	stateSound[0]					= pixelequip5Sound;
	stateEmitter[0] 				= rfireEmitter;
		stateEmitterTime[0]            = 600;

	stateName[1]                     = "Ready";
	stateTransitionOnTriggerDown[1]  = "Fire";
	stateAllowImageChange[1]         = true;
	stateSequence[1]	= "Ready";

	stateName[2]                    = "Fire";
	stateTransitionOnTimeout[2]     = "Smoke";
	stateTimeoutValue[2]            = 0.05;
	stateFire[2]                    = true;
	stateAllowImageChange[2]        = false;
	stateSequence[2]                = "Fire";
	stateScript[2]                  = "onFire";
	stateWaitForTimeout[2]			= true;
	stateSound[2]					= pixelfire3Sound;

	stateName[3] = "Smoke";
	stateTimeoutValue[3]            = 0.05;
	stateTransitionOnTimeout[3]     = "Ready";

	stateName[4]			= "Reload";
	stateSequence[4]                = "Reload";
	stateTransitionOnTriggerUp[4]     = "Ready";
	stateSequence[4]	= "Ready";

};
function rfireImage::onFire(%this,%obj,%slot)
{
	%projectile = rfireProjectile;
	%spread = 0.0;
	%shellcount = 1;

	%obj.playThread(2, plant);
	%shellcount = 1;
	%obj.spawnExplosion(feedbackProjectile,"1 1 1");
            		
	for(%shell=0; %shell<%shellcount; %shell++)
	{
		%vector = %obj.getMuzzleVector(%slot);
		%objectVelocity = %obj.getVelocity();
		%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
		%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
		%velocity = VectorAdd(%vector1,%vector2);
		%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
		%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
		%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
		%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
		%velocity = MatrixMulVector(%mat, %velocity);

		%p = new (%this.projectileType)()
		{
			dataBlock = %projectile;
			initialVelocity = %velocity;
			initialPosition = %obj.getMuzzlePoint(%slot);
			sourceObject = %obj;
			sourceSlot = %slot;
			client = %obj.client;
		};
		MissionCleanup.add(%p);
	}
	return %p;
}
function rfireItem::onAdd(%this, %obj)
{
%obj.canPickup = true;

%obj.playThread(0, rotate);
%obj.rotate = true;
Parent::onAdd(%this, %obj);
}
