#****************************************************************************
#**
#**  File     :  /cdimage/units/UAL0303/UAL0303_script.lua
#**  Author(s):  John Comes, David Tomandl
#**
#**  Summary  :  Aeon Siege Assault Bot Script
#**
#**  Copyright © 2005 Gas Powered Games, Inc.  All rights reserved.
#****************************************************************************

local AWalkingLandUnit = import('/lua/aeonunits.lua').AWalkingLandUnit
local ADFLaserHighIntensityWeapon = import('/lua/aeonweapons.lua').ADFLaserHighIntensityWeapon
local EffectUtil = import('/lua/EffectUtilities.lua')

local AWalkingLandUnit = import('/lua/aeonunits.lua').AWalkingLandUnit 
local ADFLaserHighIntensityWeapon = import('/lua/aeonweapons.lua').ADFLaserHighIntensityWeapon 
local EffectUtil = import('/lua/EffectUtilities.lua') 

UAL0303 = Class(AWalkingLandUnit) {    
    Weapons = { 
        FrontTurret01 = Class(ADFLaserHighIntensityWeapon) {}, 
    }, 
    OnShieldEnabled = function(self) 
    self:ForkThread(self.HarbingerBugFixThread) 
    end,    
    OnShieldDisabled = function(self) 
       self:SetCanTakeDamage(true) 
    end, 
    CreateBuildEffects = function( self, unitBeingBuilt, order ) 
        EffectUtil.CreateAeonCommanderBuildingEffects( self, unitBeingBuilt, self:GetBlueprint().General.BuildBones.BuildEffectBones, self.BuildEffectsBag ) 
    end,  

    HarbingerBugFixThread = function(self) 
    while true do 
      WaitTicks(1) 
      #LOG('I am starting the harb thread and checking the conditions - so I am at least run every tick like I should be')    
      local aiBrain = self:GetAIBrain() 
          if aiBrain:GetEconomyStored('ENERGY') > 0 then 
               if self.MyShield:IsOn() == true then 
                   if self.MyShield:GetHealth() > 0 then 
                       self:SetCanTakeDamage(false) 
                   else 
                       self:SetCanTakeDamage(true) 
                   end 
               else 
                   self:SetCanTakeDamage(true) 
               end 
           else 
               self:SetCanTakeDamage(true) 
           end 
        end 
    end 
} 

TypeClass = UAL0303