datablock ParticleData(healTrailParticle)
{
        dragCoefficient = 1.75;
        windCoefficient = 0;
        gravityCoefficient = 0;
        inheritedVelFactor = 0;
        constantAcceleration = 0;
        lifetimeMS = 1500;
        lifetimeVarianceMS = 500;
        textureName = "./heart.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.5;
        sizes[1] = 0.3;
};
datablock ParticleEmitterData(healTrailEmitter)
{
        ejectionPeriodMS = 15; 
        periodVarianceMS = 0;
        ejectionVelocity = 1.5;
        velocityVariance = 1;
        ejectionOffset = 0.0;
        thetaMin = 0;
        thetaMax = 180;
        phiReferenceVel = 0;
        phiVariance = 360;
        overrideAdvance = false;
        particles = healTrailParticle;
           useEmitterColors = true;

        uiName = "Health Pixel";
};
datablock ParticleData(healpixParticle)
{
        dragCoefficient = 1.75;
        windCoefficient = 0;
        gravityCoefficient = 0;
        inheritedVelFactor = 0;
        constantAcceleration = 0;
        lifetimeMS = 1300;
        lifetimeVarianceMS = 500;
        textureName = "./heart.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.5;
        sizes[1] = 0.3;
};
datablock ParticleEmitterData(healpixEmitter)
{
        ejectionPeriodMS = 15;
        periodVarianceMS = 0;
        ejectionVelocity = 1.5;
        velocityVariance = 1;
        ejectionOffset = 0.0;
        thetaMin = 0;
        thetaMax = 180;
        phiReferenceVel = 0;
        phiVariance = 360;
        overrideAdvance = false;
        particles = healpixParticle;

        uiName = "";
};
datablock ParticleData(healpixExplosionParticle)
{
        dragCoefficient      = 5;
        gravityCoefficient   = 0.0;
        inheritedVelFactor   = 1.0;
        constantAcceleration = 0.0;
        lifetimeMS           = 500;
        lifetimeVarianceMS   = 300;
        textureName          = "./heart.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 = healExplosionEmitter;
   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        = 17;
   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;
   particleEmitter     = healtrailEmitter; 

   muzzleVelocity      = 200;
   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";
   
           stateName[0]                     = "Activate";
        stateTimeoutValue[0]             = 0.15;
        stateTransitionOnTimeout[0]       = "Ready";
        stateSound[0]                                        = pixelequip2Sound;
                stateEmitter[0]                                 = healpixEmitter;
                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]                                        = pixelfire1Sound;

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

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

};

function healImage::onFire(%this,%obj,%slot)
{
        %projectile = healpixProjectile;
        %spread = 0.0015;
        %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 healpixProjectile::onCollision(%this,%obj,%col,%pos,%fade)
{
     if((%obj.client.slyrTeam == %col.client.slyrTeam) && isSlayerMinigame(getMinigameFromObject(%obj.client)))
     {
          if(%col.getClassName() $= "Player")
          {
               if(%col.getDamageLevel() > 0)
               {  
                    %col.addHealth(20);
               }
               else
               {
                    %col.setHealth(%col.dataBlock.maxDamage);
               }
               bottomPrint(%obj.client,"\c0You have healed\c6 " @ %col.client.name @ "\c0. \c4" @ %col.dataBlock.maxDamage - %col.getDamageLevel() @ "\c6/\c3" @ %col.dataBlock.maxDamage @ " \c3Health",1,3);
               bottomPrint(%col.client,"\c6" @ %obj.client.name @ "\c0 has healed you.\c3 " @ %col.dataBlock.maxDamage - %col.getDamageLevel() @ "\c6/\c3" @ %col.dataBlock.maxDamage @ " \c0Health",1,3);
          }
     }
     else
     {
     Parent::onCollision(%this,%obj,%col,%pos,%fade);
     }
}

datablock DecalData(healIcon)
{
   textureName = "./health";
};

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

   %damageType = $DamageType::Direct;
   if(%this.DirectDamageType)
      %damageType = %this.DirectDamageType;

   %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(15);
      }
      else
      {
         %firer.setHealth(%firer.dataBlock.maxDamage);
      }
   }
   else
   {
      %col.damage(%obj, %pos, %directDamage, %damageType);
   }        
}
function healItem::onAdd(%this, %obj)
{
%obj.canPickup = true;

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