datablock AudioProfile(chargefireSound)
{
   filename    = "./chargefire.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock AudioProfile(chargeSound)
{
   filename    = "./charge.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock ParticleData(rangedTrailParticle)
{
	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 153 0 0.3"; //light color
	colors[1] = "0 102 0 0.3"; //dark color
	colors[2] = "0 204 0 0.3"; //barley noticeable color
	sizes[0] = 0.2;
	sizes[1] = 0.4;
};
datablock ParticleEmitterData(rangedTrailEmitter)
{
	ejectionPeriodMS = 15;
	periodVarianceMS = 0;
	ejectionVelocity = 1.5;
	velocityVariance = 1;
	ejectionOffset = 0.0;
	thetaMin = 0;
	thetaMax = 180;
	phiReferenceVel = 0;
	phiVariance = 360;
	overrideAdvance = false;
	   useEmitterColors = true;
	particles = RangedTrailParticle;

	uiName = "Green Pixel";
};
datablock ParticleData(rangedTrail2Particle)
{
	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.8 1 0.9 0.3"; //light color
	colors[1] = "0 88 0 0.3"; //dark color
	colors[2] = "0 204 0 0.3"; //barley noticeable color
	sizes[0] = 0.2;
	sizes[1] = 0.4;
};
datablock ParticleEmitterData(rangedTrail2Emitter)
{
	ejectionPeriodMS = 15;
	periodVarianceMS = 0;
	ejectionVelocity = 1.5;
	velocityVariance = 1;
	ejectionOffset = 0.0;
	thetaMin = 0;
	thetaMax = 180;
	phiReferenceVel = 0;
	phiVariance = 360;
	overrideAdvance = false;
	   useEmitterColors = true;
	particles = RangedTrailParticle;

	uiName = "";
};
//charge emitters
datablock ParticleData(rangedParticle)
{
	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 153 0 0.3"; //light color
	colors[1] = "0 102 0 0.3"; //dark color
	colors[2] = "0 204 0 0.3"; //barley noticeable color
	sizes[0] = 0.1;
	sizes[1] = 0.2;
};
datablock ParticleEmitterData(rangedEmitter)
{
	ejectionPeriodMS = 15;
	periodVarianceMS = 0;
	ejectionVelocity = 1.5;
	velocityVariance = 1;
	ejectionOffset = 0.0;
	thetaMin = 0;
	thetaMax = 180;
	phiReferenceVel = 0;
	phiVariance = 360;
	overrideAdvance = false;
	particles = rangedParticle;

	uiName = "";
};
datablock ParticleData(rangedchargingParticle)
{
	dragCoefficient = 3;
	windCoefficient = 0;
	gravityCoefficient = 0;
	inheritedVelFactor = -0.5;
	constantAcceleration = -1;
	lifetimeMS = 800;
	lifetimeVarianceMS = 100;
	textureName = "Add-Ons/Projectile_Pong/Square.png";
	spinSpeed = 0;
	spinRandomMin = -50;
	spinRandomMax = 50;
	useInvAlpha = false;

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

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

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

	uiName = "";
};
datablock ParticleData(rangedExplosionParticle)
{
	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 153 0 0.3"; //light color
	colors[1] = "0 102 0 0.3"; //dark color
	colors[2] = "0 204 0 0.3"; //barley noticeable color
	sizes[0]      = 0.5;
	sizes[1]      = 0.1;
};

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

   useEmitterColors = true;

   uiName = "";
};
datablock ParticleData(rangedExplosion2Particle)
{
   dragCoefficient      = 10;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 300;
   lifetimeVarianceMS   = 290;
   spinSpeed		= 0.0;
	spinRandomMin		= -150.0;
	spinRandomMax		= 150.0;
   textureName          = "Add-Ons/Projectile_Pong/Square.png";
colors[0] = "0.8 1 0.9 0.3"; //light color
	colors[1] = "0 88 0 0.3"; //dark color
	colors[2] = "0 204 0 0.3"; //barley noticeable color

   sizes[0]      = 0.0;
   sizes[1]      = 0.7;
   sizes[2]      = 1.0;

   times[0] = 0.0;
   times[1] = 0.9;
   times[2] = 1.0;
};

datablock ParticleEmitterData(rangedExplosion2Emitter)
{
	lifeTimeMS = 50;

   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 15;
   velocityVariance = 4.0;
   ejectionOffset   = 2.0;
   thetaMin         = 0;
   thetaMax         = 179;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "rangedExplosion2Particle";

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

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

   useEmitterColors = true;
   uiName = "";
};
datablock ParticleData(rangedsmoke2Particle)
{
	dragCoefficient      = 8;
	gravityCoefficient   = 1;
	inheritedVelFactor   = 0.2;
	constantAcceleration = 0.0;
	lifetimeMS           = 150;
	lifetimeVarianceMS   = 400;
	textureName          = "base/data/particles/cloud";
	spinSpeed		= 10.0;
	spinRandomMin		= -50.0;
	spinRandomMax		= 50.0;
	colors[0] = "0.8 1 0.9 0.3"; //light color
	colors[1] = "0 88 0 0.3"; //dark color
	colors[2] = "0 204 0 0.3"; //barley noticeable color
	sizes[0]      = 1.6;
	sizes[1]      = 3.6;

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

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

   lifeTimeMS = 150;

   particleEmitter = rangedExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = rangedsmokeEmitter;
   

   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.3 0.6 0.7";
   lightEndColor = "0 0.6 0.7";
};
datablock ExplosionData(rangedchargedExplosion)
{
   //explosionShape = "";
	soundProfile = pixelExplodeSound;

   lifeTimeMS = 350;

   particleEmitter = rangedExplosion2Emitter;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = rangedsmoke2Emitter;

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

   shakeCamera = true;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "3.0 10.0 3.0";
   camShakeDuration = 0.5;
   camShakeRadius = 20.0;

   // Dynamic light
   lightStartRadius = 10;
   lightEndRadius = 25;
   lightStartColor = "0.0 0.6 0.9";
   lightEndColor = "0 0.6 0 1";

   damageRadius = 3;
   radiusDamage = 300;

   impulseRadius = 5;
   impulseForce = 4500;
};
AddDamageType("ranged",   '<bitmap:Add-Ons/Weapon_PixelSpells/ci_ranged> %1',    '%2 <bitmap:Add-Ons/Weapon_PixelSpells/ci_ranged> %1',0.2,1);
datablock ProjectileData(rangedProjectile)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 10;
   directDamageType    = $DamageType::ranged;
   radiusDamageType    = $DamageType::ranged;
   

   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           = rangedExplosion;
   particleEmitter     = rangedtrailEmitter; 

   muzzleVelocity      = 90;
   velInheritFactor    = 0;

   armingDelay         = 00;
   lifetime            = 4000;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = false;
   gravityMod = 0.0;

  hasLight    = true;
   lightRadius = 5.0;
   lightColor  = "0.3 0.6 0.7";

   uiName = "Ranged Pixel";
};
AddDamageType("rangedcharged",   '<bitmap:Add-Ons/Weapon_PixelSpells/ci_ranged> %1',    '%2 <bitmap:Add-Ons/Weapon_PixelSpells/ci_ranged> %1',0.2,1);
datablock ProjectileData(rangedchargedProjectile)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 100;
   directDamageType    = $DamageType::rangedcharged;
   radiusDamageType    = $DamageType::rangedcharged;
   

   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           = rangedchargedExplosion;
   particleEmitter     = rangedtrail2Emitter; 

   muzzleVelocity      = 200;
   velInheritFactor    = 0;

   armingDelay         = 00;
   lifetime            = 4000;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = false;
   gravityMod = 0.0;

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

   uiName = "";
};

//////////
// item //
//////////
datablock ItemData(rangedItem)
{
	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 = "Ranged Pixel";
	iconName = "./ranged";
	doColorShift = true;
	colorShiftColor = "0 0.15 0 1";

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

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(rangedImage)
{
   // 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 = rangedProjectile;
   projectileType = Projectile;

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

   doColorShift = true;
   colorShiftColor = rangedItem.colorShiftColor;//"0.400 0.196 0 1.000";
   
	stateName[0]                     = "Activate";
	stateTimeoutValue[0]             = 0.8;
	stateTransitionOnTimeout[0]       = "Ready";
	stateSound[0]					= pixelequip3Sound;
	stateEmitter[0]					= rangedEmitter;
	stateEmitterTime[0]				= 600;

	stateName[1]                     = "Ready";
	stateTransitionOnTriggerDown[1]  = "Charge";
	stateAllowImageChange[1]         = true;
	stateSequence[1]	= "Ready";
	stateEmitter[1]		= rangedEmitter;
	stateEmitterTime[1]	= 600;
	
	stateName[2]			= "Charge";
	statetransitionOnTimeOut[2]	= "ChargeFull";
	stateTransitiononTriggerup[2]   = "Fire";
	stateWaitForTimeout[2]		= false;
	stateAllowImageChange[1]        = true;
	stateTimeoutValue[2]		= 1.50;
	stateScript[2]              = "OnCharge";
	stateEmitter [2] 			= rangedchargingEmitter;
	
	stateName[3]                    = "Fire";
	stateTransitionOnTimeout[3]     = "Reload";
	stateTimeoutValue[3]            = 0.74;
	stateFire[3]                    = true;
	stateAllowImageChange[3]        = false;
	stateSequence[3]                = "Fire";
	stateScript[3]                  = "onFire";
	stateWaitForTimeout[3]			= true;
	stateSound[3]					= pixelfire1Sound;

	stateName[4]					= "ChargeFull";
	stateAllowImageChange[4]        = true;
	stateTransitiononTriggerup[4]   = "ChargeFire";
	stateEmitter[4]					= ranged2emitter;
	stateEmitterTime[4]				= 0.05;
	StateTransitionOnTimeout[4] 	= "ChargeFull";
	stateTimeoutValue[4]			= 0.01;
	
	stateName[5]                    = "ChargeFire";
	stateTransitionOnTimeout[5]     = "Reload";
	stateTimeoutValue[5]            = 1;
	stateFire[5]                    = true;
	stateAllowImageChange[5]        = false;
	stateSequence[5]                = "Fire";
	stateScript[5]                  = "onChargeFire";
	stateWaitForTimeout[5]			= true;
	stateSound[5]					= chargefireSound;

	stateName[6]			= "Reload";
	stateSequence[6]                = "Reload";
	stateTimeoutValue[6]            = 0.12;
	stateTransitionOntimeout[6]   = "Ready";
	stateSequence[6]	        = "Ready";
	stateEmitter[6] 			= rangedEmitter;
	stateEmitterTime[6]			= 600;
};
function rangedImage::onFire(%this,%obj,%slot)
{
	if(%obj.getDamagePercent() < 1.0)
		%obj.playThread(2, plant);
	Parent::onFire(%this,%obj,%slot);	
}

function rangedImage::onChargeFire(%this,%obj,%slot)
{
	if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
		return;
	%obj.lastFireTime = getSimTime();
      
	%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
	%obj.playThread(2, shiftAway);
	%obj.spawnExplosion(feedbackProjectile,"1 1 1");

	%projectile = rangedchargedprojectile;
	%spread = 0;
	%shellcount = 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 rangedItem::onAdd(%this, %obj)
{
%obj.canPickup = true;

%obj.playThread(0, rotate);
%obj.rotate = true;
Parent::onAdd(%this, %obj);
}
function rangedImage::onCharge(%this, %obj, %slot)
{
    %obj.playAudio(1, ChargeSound);
}

function rangedImage::onFire(%this,%obj,%slot)
{
	if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
		return;
	%obj.lastFireTime = getSimTime();
      
	%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
	%obj.playThread(2, plant);

	%projectile = rangedprojectile;
	%spread = 0;
	%shellcount = 1;
	%obj.stopAudio(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;
}