
//-----------------
//----BeamSound----
//-----------------
datablock AudioProfile(BeamSwitchSound)
{
filename = "fx/Bonuses/med-level6-brilliant.wav";
description = AudioClosest3d;
preload = true;
};
datablock AudioProfile(BeamFireSound)
{
filename = "fx/powered/vehicle_screen_off.wav";
//filename = "fx/powered/vehicle_screen_on.wav";
description = AudioClosest3d;
preload = true;
};
datablock AudioProfile(BeamLoopSound)
{
//filename = "fx/powered/vehicle_screen_on.wav";
filename = "gui/inventory_off.wav";
description = CloseLooping3d;
preload = true;
};

//----------------
//---Projectile---
//----------------
datablock TargetProjectileData(LightBeam)
{
maxRifleRange = 20;
beamColor = "1 0.01 0.01";
startBeamWidth = 0.16;
pulseBeamWidth = 0.16;
beamFlareAngle = 3.0;
minFlareSize = 0.0;
maxFlareSize = 0.0;
pulseSpeed = 5;
pulseLength = 0.450;
textureName[0] = "special/nonlingradient";
textureName[1] = "special/flare";
textureName[2] = "special/sniper00";
textureName[3] = "skins/generic_scorch";
beacon = true;

};
datablock ItemData(BeamSword)
{
   className = Weapon;
   catagory = "Spawn Items";
   shapeFile = "weapon_targeting.dts";
   image = BeamSwordGunImage;
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 2;
   pickUpName = "a light saber";
   computeCRC = true;

};
datablock ShapeBaseImageData(BeamSwordGunImage)
{
className = WeaponImage;
shapeFile = "weapon_targeting.dts";
item = BeamSword;
    offset = "0 0 0";
   emap = true;

projectile = LightBeam;
projectileType = TargetProjectile;
deleteLastProjectile = true;

usesEnergy = true;
minEnergy = 0.1;

stateName[0] = "Activate";
stateSequence[0] = "Activate";
stateSound[0] = BeamSwitchSound;
stateTimeoutValue[0] = 0.1;
stateTransitionOnTimeout[0] = "ActivateReady";

stateName[1] = "ActivateReady";
stateTransitionOnAmmo[1] = "Ready";
stateTransitionOnNoAmmo[1] = "NoAmmo";

stateName[2] = "Ready";
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "DelayFire";

statename[6] = "delayfire";
stateTimeoutValue[6] = 0.35;
stateSound[6] = BeamFireSound;
stateTransitionOnTimeout[6] = "Fire";

stateName[3] = "Fire";
stateEnergyDrain[3] = 8;
stateSound[3] = BeamLoopSound;
stateRecoil[3] = LightRecoil;
stateFire[3] = true;
stateAllowImageChange[3] = false;
stateScript[3] = "onFire";
stateTransitionOnTriggerUp[3] = "Deconstruction";
stateTransitionOnNoAmmo[3] = "Deconstruction";

stateName[4] = "NoAmmo";
stateTransitionOnAmmo[4] = "Ready";

stateName[5] = "Deconstruction";
stateScript[5] = "onRelease";
stateRecoil[5] = LightRecoil;
stateTimeoutValue[5] = 0.0;
stateTransitionOnTimeout[5] = "Ready";

};
datablock ExplosionData(beamfakeexp)
{
emitter = "";
};
datablock LinearProjectileData(BeamSwordFakeProj)
{
projectileShapeName = "turret_muzzlepoint.dts";
scale = "0.1 0.1 0.1";
faceViewer = true;
directDamageType = $DamageType::Plasma;
directDamage = 0.60;
hasDamageRadius = true;
indirectDamage = 0.60;
damageRadius = 0.01;
kickBackStrength = 0;
radiusDamageType = $DamageType::Plasma;
explosion = "beamfakeexp";
dryVelocity = 0;
wetVelocity = 0;
velInheritFactor = 0.0;
lifetimeMS = 0.00001;
explodeOnDeath = true;
reflectOnWaterImpactAngle = 0.0;
explodeOnWaterImpact = true;
deflectionOnWaterImpact = 0.0;
hasLight = false;
};




function BeamSwordGunImage::onMount(%this,%obj,%slot)
{
   %obj.mountImage(BeamSwordDecalImage, 2);
   %obj.setArmThread(look);
}

function BeamSwordGunImage::onUnmount(%this,%obj,%slot)
{
   %obj.fired = "";
   %obj.lastProjectile.delete();
     %obj.unmountImage(7);
}



//--------------
//---Release----
//--------------
function BeamSwordGunImage::onRelease(%data,%obj,%slot)
{
%obj.fired = "";
%obj.lastProjectile.delete();
}

function checkfortarg(%obj)
{
%mask = $TypeMasks::PlayerObjectType | $TypeMasks::VehicleObjectType | $TypeMasks::StationObjectType | $TypeMasks::GeneratorObjectType | $TypeMasks::SensorObjectType | $TypeMasks::TurretObjectType;
%muzzlePos = %obj.getMuzzlePoint(%slot);
%muzzleVec = %obj.getMuzzleVector(%slot);
%endPos = VectorAdd(%muzzlePos, VectorScale(%muzzlevec, 20));
%obj.hit = ContainerRayCast(%muzzlePos, %endPos, %mask, %obj);
%obj.hitpos = getWord(%obj.hit, 1) @ " " @ getWord(%obj.hit, 2) @ " " @ getWord(%obj.hit, 3);


if (%obj.fired)
{
if (%obj.hit !$= "0")
{
%fake = new (LinearProjectile)() {
dataBlock = BeamSwordFakeProj;
initialDirection = "0 0 0";
initialPosition = %obj.hitpos;
sourceSlot = %obj.sourceslot;
sourceobject = %obj;
};
MissionCleanup.add(%fake);
}
if (%obj.hit $= "0")
{
}
schedule(190, 0, "checkfortarg", %obj);
}
}
//---------------
//----OnFire-----
//---------------
function BeamSwordGunImage::onFire(%pos, %obj, %target)
{
%obj.fired = true;

%p = new (TargetProjectile)() {
dataBlock = LightBeam;
initialDirection = %obj.getMuzzleVector(%slot);
initialPosition = %obj.getMuzzlePoint(%slot);
sourceSlot = %obj.sourceslot;
sourceobject = %obj;
};
MissionCleanup.add(%p);
%obj.lastProjectile = %p;
checkfortarg(%obj);
}
