//duality railgun... double beamed rail
datablock ShockwaveData(RailWave)
{
   width = 4.0;//4
   numSegments = 100;
   numVertSegments = 1;
   velocity = 5;//5
   acceleration = -2.0;//10
   lifetimeMS = 1000;
   verticalCurve = 0.5;

   height = 1.0;
   is2D = true;

   renderSquare = false;
   orientToNormal = true;
   renderBottom = false;

   texture[0] = "special/redbump2";//special/shockwave4
   texture[1] = "special/gradient";
   texWrap = 10.0;//6

   times[0] = 0.0;
   times[1] = 0.5;
   times[2] = 1.0;

   colors[0] = "1 0.4 0.0 1.00";
   colors[1] = "1 0.3 0.0 0.20";
   colors[2] = "1 0.3 0.0 0.0";
};

datablock ExplosionData(RailWaveExp)
{
   shockwave = RailWave;
};

datablock LinearProjectileData(RailWaveProj)
{
projectileShapeName = "turret_muzzlepoint.dts";
scale               = "1 1 1";
faceViewer          = true;
directDamage        = 0;
hasDamageRadius     = false;
indirectDamage      = 0.0;
damageRadius        = 1;
kickBackStrength    = 0.0;
radiusDamageType    = $DamageType::Disc;
explosion           = "RailWaveExp";
dryVelocity       = 0.001;
wetVelocity       = 0.001;
velInheritFactor  = 0.1;
lifetimeMS        = 0.1;
explodeOnDeath    = true;
reflectOnWaterImpactAngle = 0.0;
explodeOnWaterImpact      = true;
deflectionOnWaterImpact   = 0.0;
};

datablock SniperProjectileData(TLaser)
{
   directDamage        = 0.4;
   hasDamageRadius     = false;
   indirectDamage      = 0.0;
   damageRadius        = 0.0;
   velInheritFactor    = 1.0;
   sound 				  = SniperRifleProjectileSound;
   explosion           = "SniperExplosion";
   splash              = SniperSplash;
   directDamageType    = $DamageType::Laser;

   maxRifleRange       = 35;
   rifleHeadMultiplier = 1.3;
   beamColor           = "0.1 0.1 1";  //purple = "0.1 0.1 1"; red = "1 0.1 0.1";
   fadeTime            = 4;//10

   startBeamWidth		  = 0.05;
   endBeamWidth 	     = 0.7;
   pulseBeamWidth 	  = 0.5;
   beamFlareAngle 	  = 3.0;
   minFlareSize        = 0.0;
   maxFlareSize        = 0.01;
   pulseSpeed          = 6.0;
   pulseLength         = 0.150;

   lightRadius         = 1.0;
   lightColor          = "0.3 0.0 0.0";

   textureName[0]      = "special/flare";
   textureName[1]      = "special/nonlingradient";
   textureName[2]      = "special/laserrip01";
   textureName[3]      = "special/laserrip02";
   textureName[4]      = "special/laserrip03";
   textureName[5]      = "special/laserrip04";
   textureName[6]      = "special/laserrip05";
   textureName[7]      = "special/laserrip06";
   textureName[8]      = "special/laserrip07";
   textureName[9]      = "special/laserrip08";
   textureName[10]     = "special/laserrip09";
   textureName[11]     = "special/sniper00";
};
datablock SniperProjectileData(TLaser2)
{
   directDamage        = 0.4;
   hasDamageRadius     = false;
   indirectDamage      = 0.0;
   damageRadius        = 0.0;
   velInheritFactor    = 1.0;
   sound 				  = SniperRifleProjectileSound;
   explosion           = "SniperExplosion";
   splash              = SniperSplash;
   directDamageType    = $DamageType::Laser;

   maxRifleRange       = 35;
   rifleHeadMultiplier = 1.3;
   beamColor           = "1 1 0.0";
   fadeTime            = 4;

   startBeamWidth		  = 0.05;
   endBeamWidth 	     = 0.7;
   pulseBeamWidth 	  = 0.5;
   beamFlareAngle 	  = 3.0;
   minFlareSize        = 0.0;
   maxFlareSize        = 0.01;
   pulseSpeed          = 6.0;
   pulseLength         = 0.150;

   lightRadius         = 1.0;
   lightColor          = "0.3 0.0 0.0";

   textureName[0]      = "special/flare";
   textureName[1]      = "special/nonlingradient";
   textureName[2]      = "special/laserrip01";
   textureName[3]      = "special/laserrip02";
   textureName[4]      = "special/laserrip03";
   textureName[5]      = "special/laserrip04";
   textureName[6]      = "special/laserrip05";
   textureName[7]      = "special/laserrip06";
   textureName[8]      = "special/laserrip07";
   textureName[9]      = "special/laserrip08";
   textureName[10]     = "special/laserrip09";
   textureName[11]     = "special/sniper00";
};

//--------------------------------------
// Rifle and item...
//--------------------------------------
datablock ItemData(LaserSeeker)
{
   className    = Weapon;
   catagory     = "Spawn Items";
   shapeFile    = "weapon_sniper.dts";
   image        = LaserSeekerImage;
   mass         = 1;
   elasticity   = 0.2;
   friction     = 0.6;
   pickupRadius = 2;
	pickUpName = "a duality railgun";

   computeCRC = true;

};
datablock ItemData(LaserSeekerAmmo)
{
   className = Ammo;
   catagory = "Ammo";
   shapeFile = "ammo_disc.dts";
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 2;
	pickUpName = "some duality ammo";
};
datablock AudioProfile(DualitySwitchSound)
{
   filename    = "fx/weapons/blaster_activate.wav";
   description = AudioClosest3d;
   preload = true;
};
datablock AudioProfile(DualityChargeSound)
{
   filename    = "fx/environment/ctmelody1.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock AudioProfile(DualityFireSound)
{
   filename    = "fx/weapons/grenade_explode_UW.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock AudioProfile(DualityFireSound2)
{
   filename    = "fx/weapons/spinfusor_impact_UW.wav";
   description = AudioDefault3d;
   preload = true;
};

datablock AudioProfile(DualityReadySound)
{
   filename    = "fx/misc/diagnostic_beep.wav";
   description = ClosestLooping3d;
};
datablock ParticleData(DualityChargeP)
{
   dragCoeffiecient     = 0.4;
   gravityCoefficient   = -0.3;   // rises slowly
   inheritedVelFactor   = 0.125;

   lifetimeMS           =  500;
   lifetimeVarianceMS   =  200;
   useInvAlpha          =  false;
   spinRandomMin        = -100.0;
   spinRandomMax        =  100.0;

   animateTexture = false;

    times[0] = 0;
    times[1] = 0.1;
    times[2] = 1;
    textureName = "special/chutetexture.png";

    colors[0] = "0.350000 0.200000 1.0 0.000000";
    colors[1] = "0.300000 0.000000 1.0 1.000000";
    colors[2] = "0.200000 0.000000 1.0 0.000000";
    sizes[0] = 0;
    sizes[1] = 0.1;
    sizes[2] = 0;

};


datablock ParticleEmitterData(DualityChargeEmit)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 3;
    phiReferenceVel = -1;
    phiVariance = 1;
   ejectionVelocity = 4;
   velocityVariance = 0.55;

   thetaMin         = 0.0;
   thetaMax         = 180.0;

   particles = "DualityChargeP";
};

datablock ShapeBaseImageData(LaserSeekerImage)
{
	className = WeaponImage;
   shapeFile = "weapon_sniper.dts";
   item = LaserSeeker;
//   projectile = BasicSniperShot;
//   projectileType = SniperProjectile;
	armThread = look;
offset = "0.06 0.0 -0.1";

	ammo = LaserSeekerAmmo;

   stateName[0]                     = "Activate";
   stateTransitionOnTimeout[0]      = "ActivateReady";
   stateTimeoutValue[0]             = 0.5;
   stateSequence[0]                 = "Activate";

   stateName[1]                     = "ActivateReady";
   stateTransitionOnLoaded[1]       = "Ready";
   stateTransitionOnNoAmmo[1]       = "NoAmmo";

   stateName[2]                     = "Ready";
   stateTransitionOnNoAmmo[2]       = "NoAmmo";
   stateTransitionOnTriggerDown[2]  = "PreDelay";

   statename[8] = "predelay";
   statescript[8] = ondelay;
   stateTimeoutValue[8] = 3.0;
   stateTransitionOnTimeout[8]      = "Delay";
   stateEmitter[8] = "DualityChargeEmit";
   stateEmitterTime[8] = 3.0;
   stateEmitterNode[8] = 0;

   stateName[3] = "Delay";
   stateTransitionOnTriggerUp[3] = "Fire";
   stateSound[3]                    = DualityReadySound;

   stateName[4]                     = "Fire";
   stateRecoil[4] = LightRecoil;
   stateTransitionOnTimeout[4]      = "Ready";
   stateTimeoutValue[4]             = 0.1;
   stateFire[4]                     = true;
   stateAllowImageChange[4]         = false;
   stateSequence[4]                 = "Fire";
   stateScript[4]                   = "onFire";

   stateName[5]                     = "Reload";
   stateTransitionOnTimeout[5]      = "Ready";
   stateTimeoutValue[5]             = 0.1;
   stateAllowImageChange[5]         = false;

   stateName[6]                     = "NoAmmo";
   stateTransitionOnAmmo[6]         = "Ready";
   stateTransitionOnTriggerDown[6]  = "DryFire";
   stateSequence[6]                 = "NoAmmo";

   stateName[7]                     = "DryFire";
   stateSound[7]                    = SniperRifleDryFireSound;
   stateTimeoutValue[7]             = 0.5;
   stateTransitionOnTimeout[7]      = "Ready";
};
datablock ShapeBaseImageData(DualityImage2) : LaserSeekerImage
{
stateSound[0]                    = DualitySwitchSound;
shapeFile = "weapon_shocklance.dts";
offset = "-0.05 0.0 0";
rotation = "0 1 0 90";
};
datablock ShapeBaseImageData(DualityImage3) : LaserSeekerImage
{

shapeFile = "weapon_shocklance.dts";
offset = "0.0 0.6 -0.4";
rotation = "0 0 0 0";
};
datablock ShapeBaseImageData(DualityImage4) : LaserSeekerImage
{

shapeFile = "weapon_shocklance.dts";
offset = "0.15 0.0 0";
rotation = "0 -1 0 90";
};
datablock ShapeBaseImageData(DualityImage5) : LaserSeekerImage
{

shapeFile = "weapon_mortar.dts";
offset = "0.0 0.0 -0.2";
rotation = "0 0 0 0";
};

//--------------------------------------------------------------------------------------------


function twistlaser(%data,%obj,%slot)
{
//////////////////////////////////////
////////////////Damage////////////////
//////////////////////////////////////
%damageMasks = $TypeMasks::PlayerObjectType | $TypeMasks::VehicleObjectType |
$TypeMasks::StationObjectType | $TypeMasks::GeneratorObjectType |
$TypeMasks::SensorObjectType | $TypeMasks::TurretObjectType;

%endPos = VectorAdd(%obj.getMuzzlePoint(%slot), VectorScale(%obj.getMuzzleVector(%slot), 700));
%hit = ContainerRayCast(%obj.getMuzzlePoint(%slot), %endPos, %damageMasks, %obj);

	if(isobject(%hit))
	{
		if(%obj.RailDamage == 1)
		{
	%targetobject = getwords(%hit,0,0);
	%targetObject.damage(%obj, %obj.position, 1.0, $DamageType::Rail);

	%flydir = vectornormalize(vectorsub(%targetobject.position,%obj.position));
	%impulseVec = VectorScale(%flydir, 11500);
      %targetObject.applyImpulse(%obj.position, %impulseVec);
		}
	}

%vector = %obj.getMuzzleVector(%slot);
%length = 0;
%wave = 0;

if(%obj.pos1 == 1)
{
%obj.pos1 = 0;
%startpt = %obj.getMuzzlePoint(1);
}

if(%obj.pos1 == 2)
{
%obj.pos1 = 0;
%startpt = %obj.getMuzzlePoint(5);
}

%wavedist = vectoradd(%obj.getmuzzlepoint(%slot),vectorscale(%vector,6));

%w = new (linearprojectile)() {
dataBlock        = "RailWaveProj";//railwaveproj
initialDirection = %vector;
initialPosition  = %wavedist;
sourceObject     = %obj;
sourceSlot       = %obj.sourceslot;
};

for(%i=0;%i<35;%i++)
{
%wave += 20;
//////////////////////////////////////
//////////////ShockWaves//////////////
//////////////////////////////////////
%wavedist = vectoradd(%obj.getmuzzlepoint(%slot),vectorscale(%vector,%wave));

%w = new (linearprojectile)() {
dataBlock        = "RailWaveProj";
initialDirection = %vector;
initialPosition  = %wavedist;
sourceObject     = %obj;
sourceSlot       = %obj.sourceslot;
};
}

for(%i=0;%i<10;%i++)
{
%length += 70;

//////////////////////////////////////
//////////////RandomDir///////////////
//////////////////////////////////////
%x = (getRandom()-0.5) * 1 * 0.2 * 1;//0.1415926
%y = (getRandom()-0.5) * 1 * 0.2 * 1;
%z = (getRandom()-0.5) * 1 * 0.2 * 1;
%mat = matrixcreatefromeuler(%x @ "" @ %y @ "" @ %z);
%randomdir = MatrixMulVector(%mat,%vector);

	if(%obj.color == 1)
	{
	%p = new(sniperprojectile)()
	{
	datablock = Tlaser;
	initialdirection = %randomdir;
	initialposition = %startpt;
	};
	}

		if(%obj.color == 2)
		{
		%p = new(sniperprojectile)()
		{
		datablock = Tlaser2;
		initialdirection = %randomdir;
		initialposition = %startpt;
		};
		}

%p.setenergypercentage(1);
%startpt = vectoradd(%startpt,vectorscale(%randomdir,35));
//////////////////////////////////////
/////////////RecenterBeam/////////////
//////////////////////////////////////
%norm = vectoradd(%obj.getmuzzlepoint(%slot),vectorscale(%vector,%length));
%normdir = vectornormalize(vectorsub(%norm,%startpt));

	if(%obj.color == 1)
	{
	%p = new(sniperprojectile)()
	{
	datablock = Tlaser;
	initialdirection = %normdir;
	initialposition = %startpt;
	};
	}

		if(%obj.color == 2)
		{
		%p = new(sniperprojectile)()
		{
		datablock = Tlaser2;
		initialdirection = %normdir;
		initialposition = %startpt;
		};
		}

%p.setenergypercentage(1);
%startpt = vectoradd(%startpt,vectorscale(%normdir,35));
}
}


//--------------------------------------------------------------------------------------------
datablock ShockLanceProjectileData(DualityLance)
{
directDamage        = 0;
radiusDamageType    = $DamageType::Default;
kickBackStrength    = 0;
velInheritFactor    = 0;
sound               = "";
zapDuration = 2;//0.1
impulse = 0;
boltLength = 2.0;
extension = 2.0;
lightningFreq = 50.0;
lightningDensity = 18.0;
lightningAmp = 0.5;
lightningWidth = 0.1;
boltSpeed[0] = 2.0;
boltSpeed[1] = -0.5;
texWrap[0] = 1.0;
texWrap[1] = 1.0;
startWidth[0] = 0.3;
endWidth[0] = 0.6;
startWidth[1] = 0.3;
endWidth[1] = 0.6;
   texture[0] = "special/shrikebolt";//   texture[0] = "special/bluespark";
   texture[1] = "special/shrikebolt";
   texture[2] = "special/shrikebolt";
   texture[3] = "special/shrikebolt";
};
datablock ShockLanceProjectileData(DualityLanceYel)
{
directDamage        = 0;
radiusDamageType    = $DamageType::Default;
kickBackStrength    = 0;
velInheritFactor    = 0;
sound               = "";
zapDuration = 2;//0.1
impulse = 0;
boltLength = 2.0;
extension = 2.0;
lightningFreq = 50.0;
lightningDensity = 18.0;
lightningAmp = 0.5;
lightningWidth = 0.1;
boltSpeed[0] = 2.0;
boltSpeed[1] = -0.5;
texWrap[0] = 1.0;
texWrap[1] = 1.0;
startWidth[0] = 0.3;
endWidth[0] = 0.6;
startWidth[1] = 0.3;
endWidth[1] = 0.6;
   texture[0] = "special/tracer00";
   texture[1] = "special/tracer00";
   texture[2] = "special/tracer00";
   texture[3] = "special/tracer00";
};
function DualityChargeFx(%data,%obj)
{
if(%obj.DualityCharge == 0)
{
return;
}

if(isObject(%obj) && %obj.getMountedImage(0).getName() $= "LaserSeekerImage")
{
//		%c = new(linearprojectile)()
//		{
//		datablock = LightCamShake;
//		initialdirection = %obj.getMuzzleVector(0);
//		initialposition = %obj.getMuzzlePoint(0);
//		};

%a = new ShockLanceProjectile()
{
dataBlock        = "DualityLance";
initialDirection = "0 0 0";
initialPosition  = %obj.getworldboxcenter();
sourceSlot       = 0;
targetId         = %obj;
};
MissionCleanup.add(%a);

%a = new ShockLanceProjectile()
{
dataBlock        = "DualityLance";
initialDirection = "0 0 0";
initialPosition  = %obj.getMuzzlePoint(1);
sourceSlot       = 1;
sourceobject = %obj;
//targetId         = %obj;
};
MissionCleanup.add(%a);

%a = new ShockLanceProjectile()
{
dataBlock        = "DualityLanceYel";
initialDirection = "0 0 0";
initialPosition  = %obj.getMuzzlePoint(5);
sourceSlot       = 5;
sourceobject = %obj;
//targetId         = %obj;
};
MissionCleanup.add(%a);

schedule(1000, 0, "DualityChargeFx", %data,%obj);
}
}


function LaserSeekerImage::onFire(%data, %obj, %slot)
{
%obj.dualitycharge = 0;

%obj.decInventory(%data.ammo,1);
serverPlay3D(DualityFireSound, %obj.getTransform());
serverPlay3D(DualityFireSound2, %obj.getTransform());


%obj.color = 1;
%obj.pos1 = 1;
%obj.raildamage = 1;
twistlaser(%data, %obj, %slot);
%obj.color = 2;
%obj.pos1 = 2;
%obj.raildamage = 0;
twistlaser(%data, %obj, %slot);

}

function LaserSeekerImage::onDelay(%data, %obj, %slot)
{
serverPlay3D(DualityChargeSound, %obj.getTransform());
messageClient(%obj.client, 'msgDualityCharge', '~wfx/environment/ctmelody1.wav');
%obj.dualitycharge = 1;
DualityChargeFx(%data,%obj);
}

function LaserSeekerImage::onMount(%this, %obj, %slot)
{
Parent::onMount(%this, %obj, %slot);
%obj.client.setWeaponsHudActive("SniperRifle");
%obj.client.setWeaponsHudActive(%this.item);
%obj.mountImage(dualityimage2, 1);
//%obj.mountImage(dualityimage3, 4);
%obj.mountImage(dualityimage4, 5);
//%obj.mountImage(dualityimage5, 6);
%obj.mountImage(dualityimage6, 7);
//%obj.setImageTrigger(1, false);
}

function LaserSeekerImage::onunmount(%this,%obj,%slot)
{
Parent::onUnmount(%this, %obj, %slot);
%obj.unmountimage(1);
%obj.unmountimage(4);
%obj.unmountimage(5);
%obj.unmountimage(6);
%obj.unmountimage(7);
}


