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

colors[0] = "85 0 0 0.5"; //light color
        colors[1] = "102 0 0 0.5"; //dark color
        colors[2] = "255 0 0 0.5"; //barley noticeable color
        sizes[0] = 0.2;
        sizes[1] = 0.4;
};
datablock ParticleEmitterData(healTrailEmitter)
{
        ejectionPeriodMS = 15; 
        periodVarianceMS = 0;
        ejectionVelocity = 88;
        velocityVariance = 0;
        ejectionOffset = 0.0;
        thetaMin = 0;
        thetaMax = 0;
        phiReferenceVel = 0;
        phiVariance = 360;
        overrideAdvance = false;
        particles = healTrailParticle;
           useEmitterColors = true;

        uiName = "Health Pixel";
};
datablock ParticleData(healthpixParticle)
{
	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] = "85 0 0 0.5"; //light color
        colors[1] = "102 0 0 0.5"; //dark color
        colors[2] = "255 0 0 0.5"; //barley noticeable color
	sizes[0] = 0.1;
	sizes[1] = 0.2;
};
datablock ParticleEmitterData(healthpixEmitter)
{
	ejectionPeriodMS = 15;
	periodVarianceMS = 0;
	ejectionVelocity = 1.5;
	velocityVariance = 1;
	ejectionOffset = 0.0;
	thetaMin = 0;
	thetaMax = 180;
	phiReferenceVel = 0;
	phiVariance = 360;
	overrideAdvance = false;
	particles = healthpixParticle;

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

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


   uiName = "";
};
datablock ExplosionData(healpixExplosion)
{
   //explosionShape = "";
        soundProfile = pixelHitSound;

   lifeTimeMS = 150;

   particleEmitter = healpixExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   //emitter[0] = healsmokeEmitter;
   

   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 = "1 0 0 1";
   lightEndColor = "0 0 0";
};
AddDamageType("healpix",   '<bitmap:Add-Ons/Weapon_PixelSpells/ci_health> %1',    '%2 <bitmap:Add-Ons/Weapon_PixelSpells/ci_health> %1',0.2,1);
datablock ProjectileData(healpixProjectile)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 0;
   directDamageType    = $DamageType::healpix;
   radiusDamageType    = $DamageType::healpix;
   

   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           = healpixExplosion;

   muzzleVelocity      = 20000;
   velInheritFactor    = 0;

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

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

   uiName = "Health Pixel";
};

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

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

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

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

   doColorShift = true;
   colorShiftColor = healItem.colorShiftColor;//"0.400 0.196 0 1.000";
   
   	raycastWeaponRange = 50;
	raycastWeaponTargets = $Typemasks::PlayerObjectType | $Typemasks::FxBrickObjectType | $Typemasks::TerrainObjectType | 
		$TypeMasks::StaticObjectType | $TypeMasks::VehicleObjectType;
	raycastDirectDamage = 25;
	raycastExplosionProjectile = HealPixProjectile;
	raycastExplosionBrickSound = pixelhitSound;
	raycastExplosionPlayerSound = pixelhitSound;
	raycastDirectDamageType = $DamageType::healpix;

        hitHealAmount = 10;
        missDamageAmount = 2;
   
           stateName[0]                     = "Activate";
        stateTimeoutValue[0]             = 0.15;
        stateTransitionOnTimeout[0]       = "Ready";
        stateSound[0]                                        = pixelequip2Sound;
                stateEmitter[0]                                 = healthpixEmitter;
                stateEmitterTime[0]            = 600;

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

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

        stateName[3] = "Smoke";
        stateTimeoutValue[3]            = 0.01;
        stateTransitionOnTimeout[3]     = "Reload";

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

};
function healItem::onAdd(%this, %obj)
{
%obj.canPickup = true;

%obj.playThread(0, rotate);
%obj.rotate = true;
Parent::onAdd(%this, %obj);
}
function healImage::onFire(%this, %obj, %slot)
{
	if (%obj.weaponCharge[%this.getName()] < %this.discharge)
	{
		%obj.setImageAmmo(%slot, 0);
		return;
	}
	%obj.weaponCharge[%this.getName()] -= %this.discharge;

	if (vectorLen(%obj.getVelocity()) > 3)
		%spread = 0.0004;
	else
		%spread = 0.00001;

	%projectile = %this.projectile;
	%obj.spawnExplosion(feedbackProjectile,"1 1 1");
	%obj.playThread(2, plant);
	
	%vector = %obj.getMuzzleVector(%slot);
	%firevector = vectorNormalize(%vector);//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);
	%firevector = vectorNormalize(MatrixMulVector(%mat, %firevector));

	%obj.firevector = %firevector;
	
	%start = %obj.getMuzzlePoint(%slot);
	%end = vectorAdd(%start, vectorScale(%firevector, %this.raycastWeaponRange*getWord(%obj.getScale(),2)));
	%TypeMasks = %this.raycastWeaponTargets;
	%ray = containerRaycast(%start, %end, %typemasks, %obj);

	if(isObject(%hit = firstWord(%ray)))
	{
		drawHealthTracer(%start, posFromRaycast(%ray), 1);
	}else{
		drawHealthTracer(%start, %end, 1);
	}
        
	%this.PixelonFire(%obj, %slot);

	%obj.firevector = "";
}
function healpixProjectile::damage(%this,%obj,%col,%fade,%pos,%normal)
{
   if(%this.RaycastdirectDamage <= 0)
      return;

   %damageType = $DamageType::healpix;
   if(%this.RaycastDirectDamageType)
      %damageType = %this.RaycastDirectDamageType;

   %scale = getWord(%obj.getScale(), 2);
   %directDamage = mClampF(%this.directDamage, -100, 100) * %scale;
   
   if(isObject(%obj.sourceObject) && %obj.sourceObject.getType() & $TypeMasks::PlayerObjectType && %col.getType() & $TypeMasks::PlayerObjectType)
   {
      %firer = %obj.sourceObject;
      %col.damage(%obj, %pos, %directDamage, %damageType);
      
      if(%firer.getWhiteOut() < 0.2)
         %firer.setWhiteOut(0.2);
      
      if(getSimTime() - %firer.lastHealImageTime > 500)
      {
        // %firer.mountImage(healImage,3);
         %firer.lastHealImageTime = getSimTime();
      }
      
      if(%firer.getDamageLevel() > 0)
      {
         if(%firer.getDamageFlash() < 0.3)
            %firer.setDamageFlash(0.3);
         
         %firer.addHealth(5);
      }
      else
      {
         %firer.setHealth(%firer.dataBlock.maxDamage);
      }
   }
   else
   {
      %col.damage(%obj, %pos, %directDamage, %damageType);
   }	
}
