#****************************************************************************
#**
#**  File     :  /cdimage/lua/modules/BlackOpsweapons.lua
#**  Author(s):  Lt_hawkeye
#**
#**  Summary  :  
#**
#**  Copyright © 2005 Gas Powered Games, Inc.  All rights reserved.
#****************************************************************************

local WeaponFile = import('/lua/sim/defaultweapons.lua')
local CollisionBeams = import('/lua/defaultcollisionbeams.lua')
local CollisionBeamFile = import('/lua/defaultcollisionbeams.lua')
local BlackOpsCollisionBeamFile = import('/mods/BlackOps/lua/BlackOpsdefaultcollisionbeams.lua')
local MiniQuantumBeamGeneratorCollisionBeam = BlackOpsCollisionBeamFile.MiniQuantumBeamGeneratorCollisionBeam
local HawkTractorClawCollisionBeam = BlackOpsCollisionBeamFile.HawkTractorClawCollisionBeam
local MiniPhasonLaserCollisionBeam = BlackOpsCollisionBeamFile.MiniPhasonLaserCollisionBeam
local TDFGoliathCollisionBeam = BlackOpsCollisionBeamFile.TDFGoliathCollisionBeam
local JuggLaserCollisionBeam = BlackOpsCollisionBeamFile.JuggLaserCollisionBeam
local MartyrMicrowaveLaserCollisionBeam01 = BlackOpsCollisionBeamFile.MartyrMicrowaveLaserCollisionBeam01
local KamikazeWeapon = WeaponFile.KamikazeWeapon
local BareBonesWeapon = WeaponFile.BareBonesWeapon
local DefaultProjectileWeapon = WeaponFile.DefaultProjectileWeapon
local DefaultBeamWeapon = WeaponFile.DefaultBeamWeapon
local GinsuCollisionBeam = CollisionBeams.GinsuCollisionBeam
local EffectTemplate = import('/lua/EffectTemplates.lua')
local BlackOpsEffectTemplate = import('/mods/BlackOps/lua/BlackOpsEffectTemplates.lua')
local QuantumBeamGeneratorCollisionBeam = CollisionBeamFile.QuantumBeamGeneratorCollisionBeam
local PhasonLaserCollisionBeam = CollisionBeamFile.PhasonLaserCollisionBeam
local MicrowaveLaserCollisionBeam01 = CollisionBeamFile.MicrowaveLaserCollisionBeam01


HawkNapalmWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = EffectTemplate.TGaussCannonFlash,
}

RebelArtilleryProtonWeapon = Class(DefaultProjectileWeapon) {
}

MiniQuantumBeamGenerator = Class(DefaultBeamWeapon) {
    BeamType = MiniQuantumBeamGeneratorCollisionBeam,

    FxUpackingChargeEffects = {},#'/effects/emitters/quantum_generator_charge_01_emit.bp'},
    FxUpackingChargeEffectScale = 0.2,

    PlayFxWeaponUnpackSequence = function( self )
        local army = self.unit:GetArmy()
        local bp = self:GetBlueprint()
        for k, v in self.FxUpackingChargeEffects do
            for ek, ev in bp.RackBones[self.CurrentRackSalvoNumber].MuzzleBones do
                CreateAttachedEmitter(self.unit, ev, army, v):ScaleEmitter(self.FxUpackingChargeEffectScale):ScaleEmitter(0.2)
            end
        end
        DefaultBeamWeapon.PlayFxWeaponUnpackSequence(self)
    end,
}

MiniPhasonLaser = Class(DefaultBeamWeapon) {
    BeamType = BlackOpsCollisionBeamFile.MiniPhasonLaserCollisionBeam,
    FxMuzzleFlash = {},
    FxChargeMuzzleFlash = {},
    FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01,
    FxUpackingChargeEffectScale = 0.002,

    PlayFxWeaponUnpackSequence = function( self )
        if not self.ContBeamOn then
            local army = self.unit:GetArmy()
            local bp = self:GetBlueprint()
            for k, v in self.FxUpackingChargeEffects do
                for ek, ev in bp.RackBones[self.CurrentRackSalvoNumber].MuzzleBones do
                    CreateAttachedEmitter(self.unit, ev, army, v):ScaleEmitter(self.FxUpackingChargeEffectScale):ScaleEmitter(0.002)
                end
            end
            DefaultBeamWeapon.PlayFxWeaponUnpackSequence(self)
        end
    end,
}

# SPIDER BOT WEAPON!
MiniHeavyMicrowaveLaserGenerator = Class(DefaultBeamWeapon) {
    BeamType = BlackOpsCollisionBeamFile.MiniMicrowaveLaserCollisionBeam01,
    FxMuzzleFlash = {},
    FxChargeMuzzleFlash = {},
    FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01,
    FxUpackingChargeEffectScale = 1,

    IdleState = State(DefaultBeamWeapon.IdleState) {
        Main = function(self)
            if self.RotatorManip then
                self.RotatorManip:SetSpeed(0)
            end
            if self.SliderManip then
                self.SliderManip:SetGoal(0,0,0)
                self.SliderManip:SetSpeed(2)
            end
            DefaultBeamWeapon.IdleState.Main(self)
        end,
    },

    CreateProjectileAtMuzzle = function(self, muzzle)
        if not self.SliderManip then
            self.SliderManip = CreateSlider(self.unit, 'Center_Turret_Barrel')
            self.unit.Trash:Add(self.SliderManip)
        end
        if not self.RotatorManip then
            self.RotatorManip = CreateRotator(self.unit, 'Center_Turret_Barrel', 'z')
            self.unit.Trash:Add(self.RotatorManip)
        end
        self.RotatorManip:SetSpeed(180)
        self.SliderManip:SetPrecedence(11)
        self.SliderManip:SetGoal(0, 0, -1)
        self.SliderManip:SetSpeed(-1)
        DefaultBeamWeapon.CreateProjectileAtMuzzle(self, muzzle)
    end,

    PlayFxWeaponUnpackSequence = function( self )
        if not self.ContBeamOn then
            local army = self.unit:GetArmy()
            local bp = self:GetBlueprint()
            for k, v in self.FxUpackingChargeEffects do
                for ek, ev in bp.RackBones[self.CurrentRackSalvoNumber].MuzzleBones do 
                    CreateAttachedEmitter(self.unit, ev, army, v):ScaleEmitter(self.FxUpackingChargeEffectScale):ScaleEmitter(0.2)  
                end
            end
            DefaultBeamWeapon.PlayFxWeaponUnpackSequence(self)
        end
    end,
}

HawkTractorClaw = Class(DefaultBeamWeapon) {
    BeamType = HawkTractorClawCollisionBeam,
    FxMuzzleFlash = {},

    PlayFxBeamStart = function(self, muzzle)
        local target = self:GetCurrentTarget()
        if not target or
            EntityCategoryContains(categories.STRUCTURE, target) or
            EntityCategoryContains(categories.COMMAND, target) or
            EntityCategoryContains(categories.EXPERIMENTAL, target) or
            EntityCategoryContains(categories.NAVAL, target) or
            EntityCategoryContains(categories.SUBCOMMANDER, target) or
           EntityCategoryContains(categories.TECH3, target) or
            not EntityCategoryContains(categories.ALLUNITS, target) then
            return
        end
        DefaultBeamWeapon.PlayFxBeamStart(self, muzzle)

        self.TT1 = self:ForkThread(self.TractorThread, target)
        self:ForkThread(self.TractorWatchThread, target)
    end,

    OnLostTarget = function(self)
        self:AimManipulatorSetEnabled(true)
        DefaultBeamWeapon.OnLostTarget(self)
    end,

    TractorThread = function(self, target)
        self.unit.Trash:Add(target)
        local beam = self.Beams[1].Beam
        if not beam then return end


        local muzzle = self:GetBlueprint().MuzzleSpecial
        if not muzzle then return end


        local pos0 = beam:GetPosition(0)
        local pos1 = beam:GetPosition(1)

        local dist = VDist3(pos0, pos1)

        self.Slider = CreateSlider(self.unit, muzzle, 0, 0, dist, -1, true)

        WaitFor(self.Slider)

        target:AttachBoneTo(-1, self.unit, muzzle)

        self.AimControl:SetResetPoseTime(10)
        target:SetDoNotTarget(true)

        self.Slider:SetSpeed(15)
        self.Slider:SetGoal(0,0,0)

        WaitFor(self.Slider)

        if not target:IsDead() then
            target:Kill()
        end
        self.AimControl:SetResetPoseTime(2)
    end,

    TractorWatchThread = function(self, target)
        while not target:IsDead() do
            WaitTicks(1)
        end
        KillThread(self.TT1)
        self.TT1 = nil
        if self.Slider then
            self.Slider:Destroy()
            self.Slider = nil
        end
        self.unit:DetachAll(self:GetBlueprint().MuzzleSpecial or 0)
        self:ResetTarget()
        self.AimControl:SetResetPoseTime(2)
    end,
}

# SeaDragon Battleship WEAPON!
MartyrHeavyMicrowaveLaserGenerator = Class(DefaultBeamWeapon) {
    BeamType = BlackOpsCollisionBeamFile.MartyrMicrowaveLaserCollisionBeam01,
    FxMuzzleFlash = {},
    FxChargeMuzzleFlash = {},
    FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01,
    FxUpackingChargeEffectScale = 1,
}
# ShadowCat WEAPON!
RailLaserGenerator = Class(DefaultBeamWeapon) {
    BeamType = BlackOpsCollisionBeamFile.RailLaserCollisionBeam01,
    FxMuzzleFlash = {},
    FxChargeMuzzleFlash = {},
    FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01,
    FxUpackingChargeEffectScale = 1,
}
#UEF heavy tank railgun and laser
RailGunWeapon01 = Class(DefaultProjectileWeapon) {
    FxChargeMuzzleFlash = {
		'/mods/BlackOps/effects/emitters/railgun_muzzle_charge_01_emit.bp',
		'/mods/BlackOps/effects/emitters/railgun_muzzle_charge_02_emit.bp',
        '/mods/BlackOps/effects/emitters/railgun_muzzle_charge_05_emit.bp',
    },
    FxMuzzleFlash = {
		'/mods/BlackOps/effects/emitters/railgun_muzzle_flash_01_emit.bp',
		'/mods/BlackOps/effects/emitters/railgun_muzzle_flash_02_emit.bp',
		'/mods/BlackOps/effects/emitters/railgun_muzzle_flash_03_emit.bp',
	},
	FxMuzzleFlashScale = 2,
	FxChargeMuzzleFlashScale = 2,
}

JuggLaserweapon = Class(DefaultBeamWeapon) {
    BeamType = JuggLaserCollisionBeam,

    FxUpackingChargeEffects = {},#'/effects/emitters/quantum_generator_charge_01_emit.bp'},
    FxUpackingChargeEffectScale = 0.2,

    PlayFxWeaponUnpackSequence = function( self )
        local army = self.unit:GetArmy()
        local bp = self:GetBlueprint()
        for k, v in self.FxUpackingChargeEffects do
            for ek, ev in bp.RackBones[self.CurrentRackSalvoNumber].MuzzleBones do
                CreateAttachedEmitter(self.unit, ev, army, v):ScaleEmitter(self.FxUpackingChargeEffectScale):ScaleEmitter(0.2)
            end
        end
        DefaultBeamWeapon.PlayFxWeaponUnpackSequence(self)
    end,
}
#SeaDragon Weapon
XCannonWeapon01 = Class(DefaultProjectileWeapon) {
    FxChargeMuzzleFlash = {
		'/mods/BlackOps/effects/emitters/xcannon_muzzle_charge_01_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_muzzle_charge_02_emit.bp',
        '/mods/BlackOps/effects/emitters/xcannon_muzzle_charge_05_emit.bp',
    },
    FxMuzzleFlash = {
		'/mods/BlackOps/effects/emitters/xcannon_cannon_muzzle_01_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_cannon_muzzle_02_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_cannon_muzzle_03_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_cannon_muzzle_04_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_cannon_muzzle_05_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_cannon_muzzle_06_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_cannon_muzzle_07_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_cannon_muzzle_08_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_hit_10_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_muzzle_flash_01_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_muzzle_flash_02_emit.bp',
		'/mods/BlackOps/effects/emitters/xcannon_muzzle_flash_03_emit.bp',
	},
	FxMuzzleFlashScale = 3,
	FxChargeMuzzleFlashScale = 5,
}

ShadowCannonWeapon01 = Class(DefaultProjectileWeapon) {
    FxChargeMuzzleFlash = {
		'/mods/BlackOps/effects/emitters/shadow_muzzle_charge_01_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_muzzle_charge_02_emit.bp',
        '/mods/BlackOps/effects/emitters/shadow_muzzle_charge_05_emit.bp',
        '/mods/BlackOps/effects/emitters/shadow_muzzle_charge_04_emit.bp',
    },
    FxMuzzleFlash = {
		'/mods/BlackOps/effects/emitters/shadow_cannon_muzzle_01_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_cannon_muzzle_02_emit.bp',
		#'/mods/BlackOps/effects/emitters/shadow_cannon_muzzle_03_emit.bp',
		#'/mods/BlackOps/effects/emitters/shadow_cannon_muzzle_04_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_cannon_muzzle_05_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_cannon_muzzle_06_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_cannon_muzzle_07_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_cannon_muzzle_08_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_hit_10_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_muzzle_flash_01_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_muzzle_flash_02_emit.bp',
		'/mods/BlackOps/effects/emitters/shadow_muzzle_flash_03_emit.bp',
	},
	FxMuzzleFlashScale = 0.5,
	FxChargeMuzzleFlashScale = 1,
}
#T3 PD stun weapon Cybran
StunZapperWeapon = Class(DefaultBeamWeapon) {
    BeamType = BlackOpsCollisionBeamFile.EMCHPRFDisruptorBeam,
    FxMuzzleFlash = {'/effects/emitters/cannon_muzzle_flash_01_emit.bp',},
}
ZCannonWeapon = Class(DefaultProjectileWeapon) {
	FxChargeMuzzleFlash = BlackOpsEffectTemplate.ZCannonMuzzleFlash,
    FxMuzzleFlash = EffectTemplate.TLandGaussCannonFlash,
	FxMuzzleFlashScale = 1,
}
ScorpDisintegratorWeapon = Class(DefaultProjectileWeapon) {
    FxChargeMuzzleFlash = {},
    FxMuzzleFlash = {
		'/effects/emitters/disintegratorhvy_muzzle_flash_01_emit.bp',
		'/effects/emitters/disintegratorhvy_muzzle_flash_02_emit.bp',
		'/effects/emitters/disintegratorhvy_muzzle_flash_03_emit.bp',
		'/effects/emitters/disintegratorhvy_muzzle_flash_04_emit.bp',
		'/effects/emitters/disintegratorhvy_muzzle_flash_05_emit.bp',
	},
	FxMuzzleFlashScale = 0.2,
}
HawkMissileTacticalSerpentineWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = { '/effects/emitters/aeon_missile_launch_02_emit.bp', },
}
LambdaWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = EffectTemplate.SDFExperimentalPhasonProjMuzzleFlash,
    FxChargeMuzzleFlash = EffectTemplate.SDFExperimentalPhasonProjChargeMuzzleFlash,
}
ArtemisWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = BlackOpsEffectTemplate.ArtemisMuzzleFlash,
    FxChargeMuzzleFlash = BlackOpsEffectTemplate.ArtemisMuzzleChargeFlash,
    FxMuzzleFlashScale = 2,
    FxChargeMuzzleFlashScale = 2,
}
TDFGoliathShoulderBeam = Class(DefaultBeamWeapon) {
    BeamType = BlackOpsCollisionBeamFile.TDFGoliathCollisionBeam,
    FxMuzzleFlash = {},
    FxChargeMuzzleFlash = {},
    FxUpackingChargeEffects = {},
    FxUpackingChargeEffectScale = 1,

    PlayFxWeaponUnpackSequence = function( self )
        if not self.ContBeamOn then
            local army = self.unit:GetArmy()
            local bp = self:GetBlueprint()
            for k, v in self.FxUpackingChargeEffects do
                for ek, ev in bp.RackBones[self.CurrentRackSalvoNumber].MuzzleBones do
                    CreateAttachedEmitter(self.unit, ev, army, v):ScaleEmitter(self.FxUpackingChargeEffectScale)
                end
            end
            DefaultBeamWeapon.PlayFxWeaponUnpackSequence(self)
        end
    end,
}

HawkGaussCannonWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = EffectTemplate.TGaussCannonFlash,
}
UEFNavyMineWeapon = Class(KamikazeWeapon){
	FxDeath = BlackOpsEffectTemplate.NavalMineHit01,

    OnFire = function(self)
		local army = self.unit:GetArmy()
        for k, v in self.FxDeath do
            CreateEmitterAtBone(self.unit,-2,army,v)
        end   
        ####CreateLightParticle( self.unit, -1, -1, 15, 10, 'flare_lens_add_02', 'ramp_red_10' ) 
		KamikazeWeapon.OnFire(self)
    end,
}

UEFNavyMineDeathWeapon = Class(BareBonesWeapon) {
	FxDeath = BlackOpsEffectTemplate.NavalMineHit01,
    
    OnCreate = function(self)
        BareBonesWeapon.OnCreate(self)
        self:SetWeaponEnabled(false)   
    end,
    

    OnFire = function(self)
    end,
    
    Fire = function(self)
		local army = self.unit:GetArmy()
        for k, v in self.FxDeath do
            CreateEmitterAtBone(self.unit,-2,army,v)
        end 
        ###CreateLightParticle( self.unit, -1, -1, 15, 10, 'flare_lens_add_02', 'ramp_red_10' )  
		local myBlueprint = self:GetBlueprint()
        DamageArea(self.unit, self.unit:GetPosition(), myBlueprint.DamageRadius, myBlueprint.Damage, myBlueprint.DamageType or 'Normal', myBlueprint.DamageFriendly or false)
    end,    
}

AeonMineDeathWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = {
		'/effects/emitters/default_muzzle_flash_01_emit.bp',
        '/effects/emitters/default_muzzle_flash_02_emit.bp',
        '/effects/emitters/torpedo_underwater_launch_01_emit.bp',
    },
    OnWeaponFired = function(self)
    	self.unit:Kill()
    end,
}

SeraNavyMineWeapon = Class(KamikazeWeapon){
	FxDeath = BlackOpsEffectTemplate.SDFExperimentalPhasonProjHit01,

    OnFire = function(self)
		local army = self.unit:GetArmy()
        for k, v in self.FxDeath do
            CreateEmitterAtBone(self.unit,-2,army,v)
        end   
        ####CreateLightParticle( self.unit, -1, -1, 15, 10, 'flare_lens_add_02', 'ramp_red_10' ) 
		KamikazeWeapon.OnFire(self)
    end,
}

SeraNavyMineDeathWeapon = Class(BareBonesWeapon) {
	FxDeath = BlackOpsEffectTemplate.SDFExperimentalPhasonProjHit01,
    
    OnCreate = function(self)
        BareBonesWeapon.OnCreate(self)
        self:SetWeaponEnabled(false)   
    end,
    

    OnFire = function(self)
    end,
    
    Fire = function(self)
		local army = self.unit:GetArmy()
        for k, v in self.FxDeath do
            CreateEmitterAtBone(self.unit,-2,army,v)
        end 
        ###CreateLightParticle( self.unit, -1, -1, 15, 10, 'flare_lens_add_02', 'ramp_red_10' )  
		local myBlueprint = self:GetBlueprint()
        DamageArea(self.unit, self.unit:GetPosition(), myBlueprint.DamageRadius, myBlueprint.Damage, myBlueprint.DamageType or 'Normal', myBlueprint.DamageFriendly or false)
    end,    
}
MGAALaserWeapon = Class(DefaultBeamWeapon) {
    BeamType = BlackOpsCollisionBeamFile.MGAALaserCollisionBeam,
    FxMuzzleFlash = {'/effects/emitters/particle_cannon_muzzle_01_emit.bp'},
}