#****************************************************************************
#**
#**  File     :  /cdimage/lua/modules/Hawkeyeweapons.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 HawkeyeCollisionBeamFile = import('/mods/Hawksunits/lua/hawkeyedefaultcollisionbeams.lua')
local BareBonesWeapon = WeaponFile.BareBonesWeapon
local DefaultProjectileWeapon = WeaponFile.DefaultProjectileWeapon
local DefaultBeamWeapon = WeaponFile.DefaultBeamWeapon
local RiotQuantumBeamGeneratorCollisionBeam = HawkeyeCollisionBeamFile.RiotQuantumBeamGeneratorCollisionBeam
local AALaserCollisionBeam = HawkeyeCollisionBeamFile.AALaserCollisionBeam
local EMCHPRFDisruptorBeam = HawkeyeCollisionBeamFile.EMCHPRFDisruptorBeam
local WARRIORDisruptorBeam = HawkeyeCollisionBeamFile.WARRIORDisruptorBeam
local HeavyPhasonLaserCollisionBeam = HawkeyeCollisionBeamFile.HeavyPhasonLaserCollisionBeam
local AirPhasonLaserCollisionBeam = HawkeyeCollisionBeamFile.AirPhasonLaserCollisionBeam
local GinsuCollisionBeam = CollisionBeams.GinsuCollisionBeam
local EffectTemplate = import('/lua/EffectTemplates.lua')
local QuantumBeamGeneratorCollisionBeam = CollisionBeamFile.QuantumBeamGeneratorCollisionBeam
local PhasonLaserCollisionBeam = CollisionBeamFile.PhasonLaserCollisionBeam
local MicrowaveLaserCollisionBeam01 = CollisionBeamFile.MicrowaveLaserCollisionBeam01
local ZapperCollisionBeam = CollisionBeamFile.ZapperCollisionBeam


# SeaDragon Battleship WEAPON!
MartyrHeavyMicrowaveLaserGenerator = Class(DefaultBeamWeapon) {
    BeamType = HawkeyeCollisionBeamFile.MartyrMicrowaveLaserCollisionBeam01,
    FxMuzzleFlash = {},
    FxChargeMuzzleFlash = {},
    FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01,
    FxUpackingChargeEffectScale = 1,
}

# Reaper Heavy Destroyer WEAPONs!
DesHeavyMicrowaveLaserGenerator2 = Class(DefaultBeamWeapon) {
    BeamType = HawkeyeCollisionBeamFile.DesMicrowaveLaserCollisionBeam02,
    FxMuzzleFlash = {},
    FxChargeMuzzleFlash = {},
    FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01,
    FxUpackingChargeEffectScale = 1,
}

RiotQuantumBeamGenerator = Class(DefaultBeamWeapon) {
    BeamType = RiotQuantumBeamGeneratorCollisionBeam,

    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,
}

HeavyPhasonLaser = Class(DefaultBeamWeapon) {
    BeamType = HawkeyeCollisionBeamFile.HeavyPhasonLaserCollisionBeam,
    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,
}

AALaserweapon = Class(DefaultBeamWeapon) {
    BeamType = AALaserCollisionBeam,

    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,
}

StunZapperWeapon = Class(DefaultBeamWeapon) {
    BeamType = HawkeyeCollisionBeamFile.EMCHPRFDisruptorBeam,
    FxMuzzleFlash = {'/effects/emitters/cannon_muzzle_flash_01_emit.bp',},
}

WarriorZapperWeapon = Class(DefaultBeamWeapon) {
    BeamType = HawkeyeCollisionBeamFile.WARRIORDisruptorBeam,
    FxMuzzleFlash = {'/effects/emitters/cannon_muzzle_flash_01_emit.bp',},
}
#Cybran t3 gunship weapons

HawkFreeMisWeapon01 = Class(DefaultProjectileWeapon) {
	FxMuzzleFlash = {'/effects/emitters/muzzle_flash_01_emit.bp',},

    OnWeaponFired = function(self)
    	self:ForkThread(self.DecloakTimeout)
    end,
    
    DecloakTimeout = function(self)
    	self.unit:DisableUnitIntel('Cloak')
    	WaitSeconds(2)
    	self.unit:EnableUnitIntel('Cloak')
    end,
}

LaserCannonWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = EffectTemplate.CLaserMuzzleFlash02,

    OnWeaponFired = function(self)
    	self:ForkThread(self.DecloakTimeout)
    end,
    
    DecloakTimeout = function(self)
    	self.unit:DisableUnitIntel('RadarStealth')
    	self.unit:DisableUnitIntel('Cloak')
    	WaitSeconds(1)
    	self.unit:EnableUnitIntel('RadarStealth')
    	self.unit:EnableUnitIntel('Cloak')
    end,
}

HawkSwarmMissileWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = {
        '/effects/emitters/cannon_muzzle_flash_04_emit.bp',
        '/effects/emitters/cannon_muzzle_smoke_11_emit.bp',
    },

    OnWeaponFired = function(self)
    	self:ForkThread(self.DecloakTimeout)
    end,
    
    DecloakTimeout = function(self)
    	self.unit:DisableUnitIntel('Cloak')
    	WaitSeconds(1)
    	self.unit:EnableUnitIntel('Cloak')
    end,
}

HawkNaniteWeapon = Class(DefaultProjectileWeapon) {
	# Uses default muzzle flash

    OnWeaponFired = function(self)
    	self:ForkThread(self.DecloakTimeout)
    end,
    
    DecloakTimeout = function(self)
    	self.unit:DisableUnitIntel('Cloak')
    	WaitSeconds(1)
    	self.unit:EnableUnitIntel('Cloak')
    end,
}


# UEF T3 AA Weapon
AAPlasmaWeapon02 = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = EffectTemplate.TCommanderOverchargeFlash01,
}

AAPlasmaWeapon01 = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = {
        '/effects/emitters/terran_commander_cannon_flash_01_emit.bp',
        '/effects/emitters/terran_commander_cannon_flash_02_emit.bp', },
        #'/effects/emitters/cannon_muzzle_smoke_01_emit.bp',
        #'/effects/emitters/cannon_muzzle_water_shock_01_emit.bp',},
}


#UEF Assualt bot weapons
HawkDeathWeapon = Class(BareBonesWeapon) {
    FiringMuzzleBones = {0}, # just fire from the base bone of the unit

    OnCreate = function(self)
        BareBonesWeapon.OnCreate(self)
        local myBlueprint = self:GetBlueprint()
        # The "or x" is supplying default values in case the blueprint doesn't have an overriding value
        self.Data = {
            NukeOuterRingDamage = myBlueprint.NukeOuterRingDamage or 10,
            NukeOuterRingRadius = myBlueprint.NukeOuterRingRadius or 40,
            NukeOuterRingTicks = myBlueprint.NukeOuterRingTicks or 20,
            NukeOuterRingTotalTime = myBlueprint.NukeOuterRingTotalTime or 10,

            NukeInnerRingDamage = myBlueprint.NukeInnerRingDamage or 2000,
            NukeInnerRingRadius = myBlueprint.NukeInnerRingRadius or 30,
            NukeInnerRingTicks = myBlueprint.NukeInnerRingTicks or 24,
            NukeInnerRingTotalTime = myBlueprint.NukeInnerRingTotalTime or 24,
        }
        self:SetWeaponEnabled(false)
    end,

    OnFire = function(self)

    end,

    Fire = function(self)
        local myBlueprint = self:GetBlueprint()
        local myProjectile = self.unit:CreateProjectile( myBlueprint.ProjectileId, 0, 0, 0, nil, nil, nil):SetCollision(false)
        myProjectile:PassDamageData(self:GetDamageTable())
        if self.Data then
            myProjectile:PassData(self.Data)
        end
    end,
}

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

#Cyrban assault bot missile
HawkMissileWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = {
        '/effects/emitters/cannon_muzzle_flash_04_emit.bp',
        '/effects/emitters/cannon_muzzle_smoke_11_emit.bp',
    },
}

# Bishop weapon
HawkMissileTacticalSerpentineWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = { '/effects/emitters/aeon_missile_launch_02_emit.bp', },
}


#aeon gunship laser
AirPhasonLaser = Class(DefaultBeamWeapon) {
    BeamType = HawkeyeCollisionBeamFile.AirPhasonLaserCollisionBeam,
    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,
}
#UEF Napalm bomb
HawkNapalmBombWeapon = Class(DefaultProjectileWeapon) {
    FxMuzzleFlash = {'/effects/emitters/antiair_muzzle_fire_02_emit.bp',},

    CreateProjectileForWeapon = function(self, bone)
        local projectile = self:CreateProjectile(bone)
        local damageTable = self:GetDamageTable()
        local blueprint = self:GetBlueprint()
        local data = {
            Instigator = self.unit,
            Damage = blueprint.DoTDamage,
            Duration = blueprint.DoTDuration,
            Frequency = blueprint.DoTFrequency,
            Radius = blueprint.DamageRadius,
            Type = 'Normal',
            DamageFriendly = blueprint.DamageFriendly,
        }
        if projectile and not projectile:BeenDestroyed() then
            projectile:PassData(data)
            projectile:PassDamageData(damageTable)
        end
        return projectile
    end,
}